How should the value of objective function be returned for fmincon?

1 回表示 (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2020 年 3 月 28 日
コメント済み: Walter Roberson 2020 年 3 月 28 日
Hello,
I have an objective function that computes the difference between actual and predicted values. The value, f, computed below is returned to fmincon
f = (actual - predicted)
The size of actual and predicted is [ntime, nstate]. i.e ntime is the number of time points and nstate is the number of state variables
For instance, in my case both actal and predicted is of size 500 x 10 ( 500 time observations and 10 variables).
To lsqnonlin which accepts a vector values objective function , I could return `f = (actual - predicted)` directly. But I get an error that says, only a scalar value can be returned from the objective function to fmincon.
I tried the following in fmincon
f = (actual - predicted).*(actual - predicted);
f = sum(f, 'all'); % takes summation over rows (time points) and columns (variables)
But the solver didn't provide an optimal solution
Any suggestions on how to proceed?
Thanks

採用された回答

Walter Roberson
Walter Roberson 2020 年 3 月 28 日
f = sum((actual(:) - predicted(:)).^2);
  3 件のコメント
Deepa Maheshvare
Deepa Maheshvare 2020 年 3 月 28 日
Yes, it is
Walter Roberson
Walter Roberson 2020 年 3 月 28 日
Yes, but .^2 should be more efficient than the .*

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by