How can i fix this error?

2 vues (au cours des 30 derniers jours)
Hp2609
Hp2609 le 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 commentaires
Walter Roberson
Walter Roberson le 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 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 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)

Plus de réponses (0)

Catégories

En savoir plus sur Multiobjective Optimization dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by