質問

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

役に立ちましたか?

解決

In the part of the code bsxfun(@rdivide,data,sigmas.^2), you need to align the matching non-singleton dimensions. In other words, if the size of sigmas is 1x784, and the size of data is 784x500, you need to match the 784 dimension. You probably want to transpose sigmas:

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

Then poshidprobspart will be 784x500, which can then be multiplied: vishid * poshidprobspart if vishid is 100x784, resulting in a 100x500 matrix.

If numcases is 100 and hidviases is a row vector of length 500, then your code will run.

他のヒント

It works fine,if i implement in following way.

neghidprobspart1=bsxfun(@rdivide,negdata,sigmas.^2);
neghidprobspart2=vishid'*neghidprobspart1';
neghidprobs  =1./(exp(-(neghidprobspart2'+repmat(hidbiases,numcases,1))));                                                            
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top