Re: optimization fminbnd, how to read the current value of an iteration
Kai Torben Ohlhus <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.general |
|---|---|
| Message-ID | <[email protected]> |
On 1/16/21 9:44 PM, Igor1954 wrote:
> optimization function fminbnd,
> 1. how to read the current value of an iteration
> 2. how to read some columns from the results table
> Func-count x f(x) Procedure
> 1 2.39996 0.67549 initial
> 2 3.88322 -0.67549 golden
> 3 4.79993 -0.996171 golden
> 4 5.08984 -0.929607 parabolic
> 5 4.70582 -0.999978 parabolic
> 6 4.7118 -1 parabolic
> 7 4.71239 -1 parabolic
> 8 4.71236 -1 parabolic
> 9 4.71242 -1 parabolic
>
Regarding 1: By "current value" you mean the last value of f(x)?
Regarding 2: You must fix bug #59901 in your version of Octave (small
typo in the m-file "edit fminbnd") then you can make use of the
following script:
```````````````````````````````````````````````````````````````````````
1; # Skript file
function stop = myOutputFcn (x, optimValues, state)
persistent vals;
## if-branch called from "fminbnd" in each iteration. Save values.
if ((nargin == 3) && strcmp (state, "iter"))
vals(end+1,:) = [optimValues.iteration, optimValues.funccount, x, ...
optimValues.fval];
stop = false;
else
## else-branch just returns the saved values.
stop = vals;
endif
endfunction
## https://www.octave.org/doc/v6.1.0/XREFoptimset.html
options = optimset ("fminbnd");
options.Display = "iter";
options.OutputFcn = @myOutputFcn;
fun = @(x) x^2;
a = -1;
b = 1;
## https://www.octave.org/doc/v6.1.0/XREFfminbnd.html
[x, fval, info, output] = fminbnd (fun, a, b, options)
## Read out array from OutputFcn.
valueArray = myOutputFcn ()
```````````````````````````````````````````````````````````````````````
HTH,
Kai