How to implement fminunc for a function with a variable lenght vector input?

8 ビュー (過去 30 日間)
JoanOG
JoanOG 2017 年 3 月 2 日
コメント済み: JoanOG 2017 年 3 月 3 日
I need to use fminunc to minimize a function that has some inputs that are constants, one input that's a vector which increases in length in each iteration and another input which is also an optimization variable.
So my original function would be something like this:
[loglike] = hyp(V, x, const1, const2)
Where V is a vector of variables that grows in each iteration V = [v1 v2 v3 ... vN] (for example at the third iteration V = [V1 V2 V3]) and x is the other optimization variable.
Going through the documentation I've found that fminunc needs all the inputs to be in a vector, so it's necessary to create an anonymous function:
f = @(w)hyp([w1 w2 w3 ... wN], wN+1, const1, const2)
And then use the fminunc function:
[x fval] = fminunc(f,w0)
However, I can't find a way to make this work.
  4 件のコメント
Matt J
Matt J 2017 年 3 月 2 日
So, you're saying that you're trying to solve a sequence of minimization problems of different dimension?
JoanOG
JoanOG 2017 年 3 月 2 日
It's a real time control algorithm, at each iteration the parameters of the Gaussian process have to be calculated using this minimization.

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

採用された回答

Matt J
Matt J 2017 年 3 月 2 日
編集済み: Matt J 2017 年 3 月 2 日
Using vectorized commands, functions can be expressed in dimension-independent ways. For example, this function definition doesn't use any knowledge of length(unknowns):
function fval=hypothetical(unknowns)
x=unknowns(1);
V=unknowns(2:end);
fval=x.^3 +norm(V).^2;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by