1

I am implementing Gaussian input based RBM in MATLAB.

vi has dimension of 100*784, w has dimension of 784*500, sigma has dimension of 1*784.

p(h|v)= sigmoid(cj+wij*vi/sigma^2). I am getting dimensional error when I multiply w*v/sigma^2. I have implemented it as below,

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

What is causing the error in the code

4

2 回答 2

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 的行向量,那么您的代码将运行。

于 2013-11-23T05:36:47.037 回答
0

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

neghidprobspart1=bsxfun(@rdivide,negdata,sigmas.^2);
neghidprobspart2=vishid'*neghidprobspart1';
neghidprobs  =1./(exp(-(neghidprobspart2'+repmat(hidbiases,numcases,1))));                                                            
于 2013-11-23T23:23:40.547 回答