필터 지우기
필터 지우기

fminsearch for ligistic fit

조회 수: 2 (최근 30일)
Mona Berg
Mona Berg 2020년 5월 28일
댓글: Mona Berg 2020년 6월 2일
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.

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 28일
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
Mona Berg
Mona Berg 2020년 6월 2일
With defining ma data above, I assumed the data to be in my workspace.
But I missed the sse computation, thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by