How to multiply 3 matrices?
古いコメントを表示
I want to multiply 3 matrix. each has dimension sigmas=1*784, poshidstates=100*500, vishid=784*500. Then i want to add this with matrix of dimension visbiases=1*784. numdims=784,numcases=100.
i have done this as,
negdatapart=repmat(sigmas,numdims,1)' *(poshidstates*vishid')' ;
negdata= negdatapart'+repmat(visbiases,numcases,1)
something goes wrong here i guess. Can someone give me an idea
9 件のコメント
Geoff Hayes
2014 年 8 月 19 日
Subha - what do you mean by something goes wrong here i guess. What are you expecting to happen? Is there a problem because there is a variable named visbias and one named visbiases - are they one and the same?
dpb
2014 年 8 月 19 日
Looks ok if just fix the type with
negdata=negdatapart.'+repmat(visbiasenumcases,1);
NB: Probably (almost certainly) want the .' element-wise transpose instead of just ' here.
subha
2014 年 8 月 19 日
Michael Haderlein
2014 年 8 月 19 日
Dear Subha,
I guess most people here haven't programmed a Restriced Boltzmann Machine. So for us, the variables are just like a, b, c and so on. As you have a logical error and not a syntax error, we cannot help unless you tell us what is going wrong. Best would be a little example with, say, poshidstates of size (2,3), vishid of size (4,3) and so on. Set it to simple numbers and tell us what the result should be.
Patrik Ek
2014 年 8 月 19 日
MxN * NxP * PxK = MxK
Fundamental algebra. You need to multiply the matrices in the correct order, with correct dimensions
Michael Haderlein
2014 年 8 月 19 日
The dimensions are fine, (poshidstates*vishid') is 100x784, transposed is 784x100, multiplied with 784x784 is 784x100. No runtime error to expect. But if the result is not fine, we need to know what should be the result for a simple case. I see the repmat(sigmas,numdims,1)' part critical, but that's just a very wild guess.
dpb
2014 年 8 月 20 日
As others have suggested, you need to back off to a small-enough problem that you can compute the correct answer and then use debug to work thru the logic error in where it goes wrong. That it's "after a few iterations" probably means a logic error elsewhere as if it were a dimensions problem as has been pointed out, it wouldn't work at all.
IOW, as another has also suggested, what you apparently have is a logic error, not Matlab-specific error and you need to see why the result begins to deviate to follow where it goes wrong. That again is probably practical only w/ a very small problem sample size instead of order of 100's.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!