How can i fix this error?

1 Ansicht (letzte 30 Tage)
Hp2609
Hp2609 am 4 Mai 2021
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 Kommentare
Walter Roberson
Walter Roberson am 4 Mai 2021
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?
Hp2609
Hp2609 am 4 Mai 2021
size(X)=5000*784
size(Y)=5000*1
size(w)=784*1
I am calculating twice because its the derivative for the sigmoid function.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Mai 2021
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)

Weitere Antworten (0)

Kategorien

Mehr zu Multiobjective Optimization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by