フィルターのクリア

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 Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by