필터 지우기
필터 지우기

How to see the current value of the variable in "fminsearch" optimization?

조회 수: 15 (최근 30일)
Hi,
I am running fminsearch command to find a minimum of a function. It is taking very long. However, I want to see the current value of the variable being serached. For example,"X=fminsearch(@fcn,init0,options)" showld display X in each interation. I looked into documentaiton of "optimset" but I couldn't find something helpful.
Advance, Thanks,
Ahmed.

채택된 답변

Alan Weiss
Alan Weiss 2020년 7월 23일
You can do this using an Output Function. That example shows how to return the history of points, which is I think what you want.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Ahmed Rehan
Ahmed Rehan 2020년 7월 24일
Thank you so much. This does the job. Based on this solution, I also tried disp() command in my function code, which also did the work.

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

추가 답변 (1개)

Vladimir Sovkov
Vladimir Sovkov 2020년 7월 23일
optimset('Display','iter');
From Matlab documentation:
'Display' Level of display
'notify' (default) | 'final' | 'off' | 'none' | 'iter'
Level of display, specified as the comma-separated pair consisting of 'Display' and one of these values:
  • 'notify' — Display output only if the function does not converge.
  • 'final' — Display just the final output.
  • 'off' or 'none' — Display no output.
  • 'iter' — Display output at each iteration (not available for lsqnonneg).
Display is available for all optimization solvers.
Example: options = optimset('Display','iter')
Data Types: char | string
  댓글 수: 2
Ahmed Rehan
Ahmed Rehan 2020년 7월 23일
Thank you for the answer, but this command only displays the iteration number, not the current value of variable tht is being searched. I want the current value of X in f(X) in the iteration.
Iteration Func-count min f(x) Procedure
0 1 708.748
1 3 675.4 initial simplex
2 5 645.167 expand
3 7 638.839 expand
4 9 591.374 expand
5 10 591.374 reflect
6 12 554.554 expand
Vladimir Sovkov
Vladimir Sovkov 2020년 7월 23일
I do not think it is possible with fminsearch due to a (generally) multidimensional nature of the variable, which is hard to display in a compact form.
The things are easier with the 1D variable: this case you can use an alternative function such as fminbnd, which is able to output the X values at every next itereation via the same approach; besides, it must be faster in the 1D case.

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

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by