How can i fix this error?
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to solve the gradient of the logistic regression function using the following formula but getting the error "MATRIX DIMENSIONS MUST AGREE".
gradf =(-Y*exp(-Y.*X.'*w).*X)./1+exp(-Y.*X.'*w);
how to fix the error?
2 件のコメント
Walter Roberson
2021 年 5 月 4 日
What is size(X) ? What is size(Y) ? What is size(w) ?
Why are you dividing by 1 ? Does your actual code have () around the 1+ ?
Why are you calculating exp(-Y.*X.'*w) twice instead of calculating it once and assigning to a variable and using the variable twice?
採用された回答
Walter Roberson
2021 年 5 月 4 日
size(X)=5000*784
size(Y)=5000*1
size(w)=784*1
OKay, so Y.*X.' would be (5000 x 1) .* (784 x 5000) which would be an error.
If you just happened to instead have
Y.*(X*w)
then that would be (5000 x 1) .* (5000 x 784 * 784 x 1) -> (5000 x 1) .* (5000 x 1) -> 5000 x 1
I am calculating twice because its the derivative for the sigmoid function.
So?
If you had
gradf =(-Y*exp(-Y.*X.'*w).*X)./1+exp(-Y.*X.'*w);
and supposing that was correct code, then
temp = exp(-Y.*X.'*w);
gradf = (-Y*temp.*X)./1 + temp
However since division by 1 is mostly useless, I suspect you are thinking of
temp = exp(-Y.*X.'*w);
gradf = (-Y*temp.*X)./(1 + temp)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multiobjective Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!