How to multiply 3 matrices?
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 19 Août 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
le 19 Août 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
le 19 Août 2014
Michael Haderlein
le 19 Août 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
le 19 Août 2014
MxN * NxP * PxK = MxK
Fundamental algebra. You need to multiply the matrices in the correct order, with correct dimensions
Michael Haderlein
le 19 Août 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
le 20 Août 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!