How can I apply a filter using fminunc?

조회 수: 1 (최근 30일)
Pasquale
Pasquale 2017년 11월 25일
편집: Matt J 2017년 11월 25일
I have a function f(x) to minimize using fminunc, but I want to apply a filter to x after every iteration. This is a simple example, just to explain:
x=4;
func=@(x)myfunct(x)
options=optimoptions('fminunc','SpecifyObjectiveGradient',true,'Display','iter');
x0=2;
[best_x, fval, exitflag, output] = fminunc(func,x0,options)
% myfunction
function [OF,grad_OF]=myfunct(x)
OF=3*x^2+2*x;
grad_OF=6*x+2;
In this case the solver starts from x0, until it finds the minimum; I would that after every iteration, my x0 is x0=2*best_x (or x0=best_x - 2....) Now it is not important the specific relation, but how can I use and modify the best_x in every iteration, using it as the new starting point in fminunc solver.

채택된 답변

Matt J
Matt J 2017년 11월 25일
편집: Matt J 2017년 11월 25일
You can run fminunc in a loop with a single iteration in each pass (by setting MaxIter=1). Within the loop, you can also apply your filter.
options=optimoptions('fminunc','SpecifyObjectiveGradient',true,...
'Display','iter','MaxIter',1);
best_x=x0;
for i=1:N
[best_x, fval, exitflag, output] = fminunc(func,best_x,options)
best_x=myFilter(best_x);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver 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