필터 지우기
필터 지우기

How to multiply 3 matrices?

조회 수: 3 (최근 30일)
subha
subha 2014년 8월 19일
편집: subha 2014년 8월 21일
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
subha
subha 2014년 8월 19일
편집: subha 2014년 8월 19일
@Michael- I want to represent this equation. visbias+sigmas(poshidstates*vishid).
Dimensions are mentioned in the question. I want to get negdata variable to have dimension 100*784. I too guess the problem is with sigmas only. Because if i remove sigmas and write as below, my program works good( that is, i was able to see the output. Otherwise values are getting NAN after few iterations. ). I believe this is because of this two statements. Inparticular because of sigma. i removed sigma and run. It was working fine
negdatapart= vishid*poshidstates'
dpb
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2014년 8월 19일
편집: Matt J 2014년 8월 19일
negdata=bsxfun(@plus, sigmas+visbiases, poshidstates*vishid')
  댓글 수: 3
Matt J
Matt J 2014년 8월 20일
편집: Matt J 2014년 8월 20일
mult_result=bsxfun(@times, sigmas, poshidstates*vishid');
add_result=bsxfun(@plus, visbiases, mult_result);
If this istill sn't precisely what you want, you should still be able to figure it out from the documentation from bsxfun. It's generally what you would use for any kind of element-wise operation between a matrix and a vector.
subha
subha 2014년 8월 21일
편집: subha 2014년 8월 21일
Hi matt,
Thanks. I just found this answer and came to post the answer. You have given already.. Its working proper. This is the perfect answer

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by