How to multiply 3 matrices?
Show older comments
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 Comments
Geoff Hayes
on 19 Aug 2014
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
on 19 Aug 2014
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
on 19 Aug 2014
Michael Haderlein
on 19 Aug 2014
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
on 19 Aug 2014
MxN * NxP * PxK = MxK
Fundamental algebra. You need to multiply the matrices in the correct order, with correct dimensions
Michael Haderlein
on 19 Aug 2014
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
on 20 Aug 2014
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.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!