help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: optimization fminbnd, how to read the current value of an iteration


From: Kai Torben Ohlhus
Subject: Re: optimization fminbnd, how to read the current value of an iteration
Date: Mon, 18 Jan 2021 16:43:21 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]