FORCES
FORtran lib for Comp. Env. Sys.
|
Optimize cost function with simulated annealing. More...
Public Member Functions | |
real(dp) function, dimension(size(para, 1)) | anneal_dp (eval, cost, para, prange, prange_func, temp, dt, nitermax, len, nst, eps, acc, seeds, printflag, maskpara, weight, changeparamode, reflectionflag, pertubflexflag, maxit, undef_funcval, tmp_file, funcbest, history) |
Optimize cost function with simulated annealing.
Optimizes a user provided cost function using the Simulated Annealing strategy.
Example
User defined function cost_dp
which calculates the cost function value for a parameter set (the interface given below has to be used for this function!).
See also test folder for a detailed example, "test/test_mo_anneal".
Literature
[in] | INTERFACE :: eval | Interface calculating the eval function at a given point. |
[in] | INTERFACE :: cost | Interface calculating the cost function at a given point. |
[in] | real(dp), dimension(:) :: para | Initial parameter set. |
[in] | real(dp), dimension(size(para),2), optional :: prange | Lower and upper bound per parameter. |
[in] | interface, optional :: prange_func | Interface calculating the feasible range for a parameter at a certain point, if ranges are variable. |
[in] | real(dp), optional :: temp | Initial temperature. DEFAULT: Get_Temperature. |
[in] | real(dp), optional :: DT | Geometrical decreement of temperature. 0.7<DT<0.999. DEFAULT: 0.9_dp. |
[in] | integer(i4), optional :: nITERmax | Maximal number of iterations. Will be increased by 10% if stopping criteria of acceptance ratio or epsilon decreement of cost function is not fullfilled. DEFAULT: 1000_i4. |
[in] | integer(i4), optional :: LEN | Length of Markov Chain. DEFAULT: MAX(250_i4, size(para,1)). |
[in] | integer(i4), optional :: nST | Number of consecutive LEN steps. DEFAULT: 5_i4. |
[in] | real(dp), optional :: eps | Stopping criteria of epsilon decreement of cost function DEFAULT: 0.0001_dp |
[in] | real(dp), optional :: acc | Stopping criteria for Acceptance Ratio acc <= 0.1_dp DEFAULT: 0.1_dp |
[in] | integer(i4/i8), dimension(3), optional :: seeds | Seeds of random numbers used for random parameter set generation DEFAULT: dependent on current time |
[in] | logical, optional :: printflag | If .true. detailed command line output is written DEFAULT: .false. |
[in] | logical, dimension(size(para)), optional :: maskpara | maskpara(i) = .true. --> parameter is optimized maskpara(i) = .false. --> parameter is discarded from optimiztaion DEFAULT: .true. |
[in] | real(dp), dimension(size(para)), optional :: weight | vector of weights per parameter: gives the frequency of parameter to be chosen for optimization (will be scaled to a CDF internally) eg. [1,2,1] --> parameter 2 is chosen twice as often as parameter 1 and 2 DEFAULT: weight = 1.0_dp |
[in] | integer(i4), optional :: changeParaMode | which and how many param.are changed in one step 1 = one parameter 2 = all parameter 3 = neighborhood parameter DEFAULT: 1_i4 |
[in] | logical, optional :: reflectionFlag | if new parameter values are Gaussian distributed and reflected (.true.) or uniform in range (.false.) DEFAULT: .false. |
[in] | logical, optional :: pertubFlexFlag | if pertubation of Gaussian distributed parameter values is constant at 0.2 (.false.) or depends on dR (.true.) DEFAULT: .true. |
[in] | logical, optional :: maxit | maximizing (.true.) or minimizing (.false.) a function DEFAULT: .false. (minimization) |
[in] | real(dp), optional :: undef_funcval | objective function value defining invalid model output, e.g. -999.0_dp |
[in] | character(len=*) , optional :: tmp_file | file with temporal output |
[out] | real(dp), optional :: funcbest | minimized value of cost function |
[out] | real(dp), dimension(:,:), allocatable, optional :: history | returns a vector of achieved objective after ith model evaluation |
real(dp) :: parabest(size(para)) | Parameter set minimizing the cost function. |
prange
) OR flexible parameter range (function interface prange_func
) has to be given in calling sequence.save_state
(random number variables) has to be replaced by i4.cost_func
and prange_func
are user defined functions. See interface definition. Definition at line 186 of file mo_anneal.f90.
real(dp) function, dimension(size(para, 1)) mo_anneal::anneal::anneal_dp | ( | procedure(eval_interface), intent(in), pointer | eval, |
procedure(objective_interface), intent(in), pointer | cost, | ||
real(dp), dimension(:), intent(in) | para, | ||
real(dp), dimension(size(para, 1), 2), intent(in), optional | prange, | ||
external subroutine(real(dp), dimension(:), intent(in) paraset, integer(i4), intent(in) ipar, real(dp), dimension(2), intent(out) rangepar), optional | prange_func, | ||
real(dp), intent(in), optional | temp, | ||
real(dp), intent(in), optional | dt, | ||
integer(i4), intent(in), optional | nitermax, | ||
integer(i4), intent(in), optional | len, | ||
integer(i4), intent(in), optional | nst, | ||
real(dp), intent(in), optional | eps, | ||
real(dp), intent(in), optional | acc, | ||
integer(i8), dimension(3), intent(in), optional | seeds, | ||
logical, intent(in), optional | printflag, | ||
logical, dimension(size(para, 1)), intent(in), optional | maskpara, | ||
real(dp), dimension(size(para, 1)), intent(in), optional | weight, | ||
integer(i4), intent(in), optional | changeparamode, | ||
logical, intent(in), optional | reflectionflag, | ||
logical, intent(in), optional | pertubflexflag, | ||
logical, intent(in), optional | maxit, | ||
real(dp), intent(in), optional | undef_funcval, | ||
character(len = *), intent(in), optional | tmp_file, | ||
real(dp), intent(out), optional | funcbest, | ||
real(dp), dimension(:, :), intent(out), optional, allocatable | history | ||
) |
[in] | para | initial parameter |
[in] | prange | lower and upper limit per parameter |
[in] | temp | starting temperature (DEFAULT: Get_Temperature) |
[in] | dt | geometrical decreement, 0.7<DT<0.999 (DEFAULT: 0.9) |
[in] | nitermax | maximal number of iterations (DEFAULT: 1000) |
[in] | len | Length of Markov Chain, DEFAULT: max(250, size(para,1)) |
[in] | nst | Number of consecutive LEN steps! (DEFAULT: 5) |
[in] | eps | epsilon decreement of cost function (DEFAULT: 0.01) |
[in] | acc | Acceptance Ratio, <0.1 stopping criteria (DEFAULT: 0.1) |
[in] | seeds | Seeds of random numbers (DEFAULT: Get_timeseed) |
[in] | printflag | If command line output is written (.true.) (DEFAULT: .false.) |
[in] | maskpara | true if parameter will be optimized false if parameter is discarded in optimization (DEFAULT: .true.) |
[in] | weight | vector of weights per parameter gives the frequency of parameter to be chosen for optimization (DEFAULT: uniform) |
[in] | changeparamode | which and how many param. are changed in a step 1 = one parameter 2 = all parameter 3 = neighborhood parameter (DEFAULT: 1_i4) |
[in] | reflectionflag | if new parameter values are selected normal distributed and reflected (.true.) or uniform in range (.false.) (DEFAULT: .false.) |
[in] | pertubflexflag | if pertubation of normal distributed parameter values is constant 0.2 (.false.) or depends on dR (.true.) (DEFAULT: .true.) |
[in] | maxit | Maximization or minimization of function maximization = .true., minimization = .false. (DEFAULT: .false.) |
[in] | undef_funcval | objective function value occuring if parameter set leads to invalid model results, e.g. -9999.0_dp! (DEFAULT: not present) |
[in] | tmp_file | file for temporal output |
[out] | funcbest | minimized value of cost function (DEFAULT: not present) |
[out] | history | returns a vector of achieved objective! after ith model evaluation (DEFAULT: not present) |
Definition at line 289 of file mo_anneal.f90.