Hi, I want to display the results of the calculations that I made, I want to add two values with different matrix sizes, I use 2 ways by adding regular (+) and using bsxfun. But both errors. have code like below :
D = 25 ;
K = 11;
h = 100;
reg = 0.01;
iteration=1000;
w1 = 0.01*randn(D,h);
w2 = 0.01*randn(h,K);
a = 0.5.*reg.*(W1.*W1);
b = 0.5.*reg.*(W2.*W2);
reg_los1 = a+b;
reg_los = bsxfun(@plus, a,b);
for i = 1:100;
fprintf('Iteration: %d \n' , i);
end
If there are another way to fix, I hope someone can improve my code, thank you.

댓글 수: 1

Jan
Jan 2018년 11월 24일
Please do not post just "But both errors", but pos the complete error messages in the forum. It is easier to fix a problem than to guess, what the problem is.

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

 채택된 답변

madhan ravi
madhan ravi 2018년 11월 24일
편집: madhan ravi 2018년 11월 24일

1 개 추천

Try :
D = 25 ;
K = 11;
h = 100;
reg = 0.01;
iteration=1000; % i can't see this being used anywhere?
w1 = 0.01*randn(D,h);
w2 = 0.01*randn(h,K);
a = 0.5.*reg.*(w1.*w1); % -> matlab is case sensitive
b = 0.5.*reg.*(w2.*w2);
reg_los1 = a+b; %remove this line because im not sure this will work in previous versions
reg_los = bsxfun(@plus, a,b);
for i = 1:100;
fprintf('Iteration: %d \n' , i);
end

댓글 수: 9

Oman Wisni
Oman Wisni 2018년 11월 24일
Dear Mr.Ravi. I'm sorry. Because of my typo I forget one line code. Im trying your code but still error using bsxfun. Here I attached my full code :
D = 25 ;
K = 11;
h = 100;
reg = 0.01;
data = rand(1,220);
w1 = 0.01*randn(D,h);
w2 = 0.01*randn(h,K);
a = 0.5.*reg.*(w1.*w1); % -> matlab is case sensitive
b = 0.5.*reg.*(w2.*w2);
reg_los = bsxfun(@plus, a,b);
loss = reg_los + data; % I adding my code
for i = 1:100;
fprintf('Iteration: %d \n' ,'loss :%f \n' , i,loss);
end
madhan ravi
madhan ravi 2018년 11월 25일
Did you see Jan’s comment?
Oman Wisni
Oman Wisni 2018년 11월 25일
편집: Oman Wisni 2018년 11월 25일
The error like below :
Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in Training (line 49)
reg_los = bsxfun(@plus, a,b);
.
madhan ravi
madhan ravi 2018년 11월 25일
>> size(a)
ans =
25 100
>> size(b)
ans =
100 11
How can you add them?
Oman Wisni
Oman Wisni 2018년 11월 25일
yes, but I got the formula like that? so what I do?
madhan ravi
madhan ravi 2018년 11월 25일
Better ask your teacher
Oman Wisni
Oman Wisni 2018년 11월 25일
편집: Oman Wisni 2018년 11월 25일
yes, I will ask my teacher.
one question again before I ask my teacher. here I have code Python like below
a = rand (220,11);
b = np.argmax(a, axis = 1);
print 'accuracy :%.2f', (np.mean(b))
what is argmax and mean in matlab, how I create code above to matlab? Thanks
madhan ravi
madhan ravi 2018년 11월 25일
please use google before asking , type argmax matlab and mean matlab you will find the answer in the first link
Oman Wisni
Oman Wisni 2018년 11월 25일
편집: Oman Wisni 2018년 11월 25일
already asking google, but I don't understand. Yes I will try ask again.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2018년 11월 24일

편집:

2018년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by