GRBM实施

时间:2013-11-23 04:54:39

标签: matlab rbm

我在MATLAB中实现基于高斯输入的RBM。

vi维度为100 * 784,w维度为784 * 500,sigma维度为1 * 784。

p(h|v)= sigmoid(cj+wij*vi/sigma^2)。我乘以w*v/sigma^2时出现尺寸误差。 我已经实现了如下,

poshidprobspart = bsxfun(@rdivide,data,sigmas.^2);
poshidprobs = 1./(1 + exp(-((vishid * poshidprobspart) + repmat(hidbiases,numcases,1))));

代码

中导致错误的原因

2 个答案:

答案 0 :(得分:1)

在代码bsxfun(@rdivide,data,sigmas.^2)的部分中,您需要对齐匹配的非单例维度。换句话说,如果sigmas的大小为1x784,且data的大小为784x500,则需要匹配784维度。您可能想转置sigmas

% bsxfun: 784x500 @rdivide 784x1 => 784x500
poshidprobspart = bsxfun(@rdivide,data,(sigmas.^2).');

然后poshidprobspart将是784x500,然后可以乘以:vishid * poshidprobspart如果vishid是100x784,则会产生100x500矩阵。

如果numcases为100且hidviases是长度为500的行向量,那么您的代码将会运行。

答案 1 :(得分:0)

如果按照以下方式实施,它可以正常工作。

neghidprobspart1=bsxfun(@rdivide,negdata,sigmas.^2);
neghidprobspart2=vishid'*neghidprobspart1';
neghidprobs  =1./(exp(-(neghidprobspart2'+repmat(hidbiases,numcases,1))));