Effacer les filtres
Effacer les filtres

fminsearch for ligistic fit

2 vues (au cours des 30 derniers jours)
Mona Berg
Mona Berg le 28 Mai 2020
Commenté : Mona Berg le 2 Juin 2020
I'm trying to use fminsearch to fit a logistic model to my data. My problem is that I'm rreally confused about how to define the input for the fminsearch function.
My data:
x = [0.5 2.7 6 8.8 9.7 12.8 16 20 23];
y = [0.8 1.1 3.4 7 9 13 13.4 13.2 18.8];
I want to fit the parameters of following function to my data:
Now I don't know how to define the right functions for the optimization.
What I've tried so far:
f = @(p,x)p(1)*(0.5-(1./(1+exp(p(2)*(x-p(3))))))+p(4)*x+p(5);
f2 = @(p)f(p,x);
p0 = [0.1 0.1 0.1 0.0001 0.1];
p = fminsearch(f2,p0);
But this is not the right way.

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Mai 2020
f2 = @(p)f(p,x);
That relies on x existing in your workspace. If you are going to do that you might as well assume it on the previous line, and use cleaner code.
But your bigger problem is that you are failing to calculate a sum-of-squared errors
f = @(p) p(1) * (0.5 - (1 ./ (1 + exp(p(2)*(x-p(3)))))) + p(4) .* x + p(5);
f2 = @(p) sum((f(p) - y).^2);
p0 = [0.1 0.1 0.1 0.0001 0.1];
p = fminsearch(f2, p0);
  1 commentaire
Mona Berg
Mona Berg le 2 Juin 2020
With defining ma data above, I assumed the data to be in my workspace.
But I missed the sse computation, thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Problem-Based Optimization Setup 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