ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_optimization::setMinBrent Interface Reference

Compute and return the minimum value and the corresponding abscissa xmin of the input 1-dimensional function isolated to a fractional precision of about tol using the Brent method.
More...

Detailed Description

Compute and return the minimum value and the corresponding abscissa xmin of the input 1-dimensional function isolated to a fractional precision of about tol using the Brent method.

Parameters
[in]getFunc: The scalar function be minimized.
  1. On input, it must take a scalar of the same type and kind as the input/output argument xmin.
  2. On output, it must return a scalar of the same type and kind as the input/output argument xmin, containing the function value at the specified input scalar point.
The following demonstrates the interface of getFunc,
function getFunc(x) result(func)
real(RKG), intent(in) :: x
real(RKG) :: func
end function
where RKG can refer to any real type kind parameter any supported by the processor (e.g., RK, RK32, RK64, or RK128) supported by the library.
[in,out]xmin: The input/output scalar of type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
  1. On input, it must contain the initial best guess abscissa at the function minimum.
    Note that the specified input value must be between the input arguments xlow and xupp, such that the triplet (xlow, getFunc(xlow)), (xmin, getFunc(fmin)), (xupp, getFunc(fupp)) can be interpolated by a convex parabolic curve.
  2. On output, it will contain the inferred abscissa at the function minimum, if the algorithm succeeds.
[in]xlow: The input scalar of the same type and kind as the input/output argument xmin, containing the lower bound of the search interval for the function minimum abscissa.
The condition xlow < xmin .and. getFunc(xmin) < getFunc(xlow) must hold for the corresponding input arguments.
[in]xupp: The input scalar of the same type and kind as the input/output argument xmin, containing the upper bound of the search interval for the function minimum abscissa.
The condition xmin < xupp .and. getFunc(xmin) < getFunc(xupp) must hold for the corresponding input arguments.
[in,out]fmin: The input/output scalar of the same type and kind as the input/output argument xmin.
  1. On input, it must contain getFunc(xmin).
  2. On output, it will contain the function value at the identified minimum xmin.
[in]tol: The input positive scalar of the same type and kind as the input/output argument xmin, containing the minimum distance that a new function evaluation point xmin can have from any previously evaluated point.
Values smaller than the suggestion below might lead to algorithm failure due to roundoff error accumulation.
A reasonable choice is tol = sqrt(epsilon(1._RKG)).
[in,out]niter: The input/output positive scalar of type integer of default kind IK containing the maximum number of allowed iterations in the algorithm in search of the minimum.
On output,
  1. If the algorithm succeeds, niter will be set to the actual number of iterations taken to find the minimum which is by definition, less than or equal to the input value.
  2. If the algorithm fails to converge, it will be a number larger than the input value (by only 1 unit).
The value of niter is effectively the number of calls to the user-specified input function.
A reasonable choice is niter = int(100 * precision(xmin) / 53.).


Possible calling interfaces

call setMinBrent(getFunc, xmin, xlow, xupp, fmin, tol, niter)
Compute and return the minimum value and the corresponding abscissa xmin of the input 1-dimensional f...
This module contains procedures, generic interfaces, and types for numerical optimizations of mathema...
Warning
The condition xlow < xmin .and. xmin < xupp must hold for the corresponding input arguments.
The condition getFunc(xlow) > fmin .or. fmin < getFunc(xupp) must hold for the corresponding input arguments.
The condition fmin == getFunc(xmin) must hold for the corresponding input arguments.
The condition 0 < niter must hold for the corresponding input arguments.
The condition 0 < tol must hold for the corresponding input arguments.
Remarks
The procedures under discussion are impure.
The procedures under discussion are recursive.
See also
getMinBrent
setMinBrent


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_kind, only: RKG => RKH ! all processor kinds are supported.
5 use pm_io, only: display_type
8
9 implicit none
10
11 integer(IK) :: niter, retin
12 real(RKG) :: xlow, xmin, xupp, fmin, tol
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("getSq(x) = (x - 1)**2")
18 call disp%show("xlow = -3; xupp = -1; tol = epsilon(xmin)**.8; retin = 100; niter = 100")
19 xlow = -3; xupp = -1; tol = epsilon(xmin)**.8; retin = 100; niter = 100
20 call disp%show("call setBracketMin(getSq, retin, xmin, xlow, xupp, fmin) ! find a good bracket, though here the choice is obvious.")
21 call setBracketMin(getSq, retin, xmin, xlow, xupp, fmin) ! find a good bracket, though here the choice is obvious.
22 call disp%show("if (100 < retin) error stop 'Bracketing failed.'")
23 if (100 < retin) error stop 'Bracketing failed.'
24 call disp%show("call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)")
25 call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
26 call disp%show("niter")
27 call disp%show( niter )
28 call disp%show("if (niter > 100) error stop 'minimization failed.'")
29 if (niter > 100) error stop 'minimization failed.'
30 call disp%show("[xmin, fmin]")
31 call disp%show( [xmin, fmin] )
32 call disp%skip()
33
34 call disp%skip()
35 call disp%show("getSq(x) = (x - 1)**2")
36 call disp%show("xlow = 1; xmin = 1; xupp = 3; tol = epsilon(xmin)**.8; niter = 100")
37 xlow = 1; xmin = 1; xupp = 3; tol = epsilon(xmin)**.8; niter = 100
38 call disp%show("call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)")
39 call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
40 call disp%show("niter")
41 call disp%show( niter )
42 call disp%show("if (niter > 100) error stop 'minimization failed.'")
43 if (niter > 100) error stop 'minimization failed.'
44 call disp%show("[xmin, fmin]")
45 call disp%show( [xmin, fmin] )
46 call disp%skip()
47
48 call disp%skip()
49 call disp%show("getSq(x) = (x - 1)**2")
50 call disp%show("xlow = 1; xmin = 1; xupp = 1; tol = epsilon(xmin)**.8; niter = 100")
51 xlow = 1; xmin = 1; xupp = 1; tol = epsilon(xmin)**.8; niter = 100
52 call disp%show("call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)")
53 call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
54 call disp%show("niter")
55 call disp%show( niter )
56 call disp%show("if (niter > 100) error stop 'minimization failed.'")
57 if (niter > 100) error stop 'minimization failed.'
58 call disp%show("[xmin, fmin]")
59 call disp%show( [xmin, fmin] )
60 call disp%skip()
61
62 call disp%skip()
63 call disp%show("getSq(x) = (x - 1)**2")
64 call disp%show("xmin = 0; xlow = -1; xupp = 3; fmin = getSq(xmin); tol = epsilon(xmin)**.8; niter = 100")
65 xmin = 0; xlow = -1; xupp = 3; fmin = getSq(xmin); tol = epsilon(xmin)**.8; niter = 100
66 call disp%show("call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)")
67 call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
68 call disp%show("niter")
69 call disp%show( niter )
70 call disp%show("if (niter > 100) error stop 'minimization failed.'")
71 if (niter > 100) error stop 'minimization failed.'
72 call disp%show("[xmin, fmin]")
73 call disp%show( [xmin, fmin] )
74 call disp%skip()
75
76contains
77
78 function getSq(x) result(func)
79 real(RKG), intent(in) :: x
80 real(RKG) :: func
81 func = (x - 1)**2
82 end function
83
84end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Refine an initial input interval such that the final returned interval is guaranteed to contain the m...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2getSq(x) = (x - 1)**2
3xlow = -3; xupp = -1; tol = epsilon(xmin)**.8; retin = 100; niter = 100
4call setBracketMin(getSq, retin, xmin, xlow, xupp, fmin) ! find a good bracket, though here the choice is obvious.
5if (100 < retin) error stop 'Bracketing failed.'
6call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
7niter
8+5
9if (niter > 100) error stop 'minimization failed.'
10[xmin, fmin]
11+1.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
12
13
14getSq(x) = (x - 1)**2
15xlow = 1; xmin = 1; xupp = 3; tol = epsilon(xmin)**.8; niter = 100
16call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
17niter
18+9
19if (niter > 100) error stop 'minimization failed.'
20[xmin, fmin]
21+1.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
22
23
24getSq(x) = (x - 1)**2
25xlow = 1; xmin = 1; xupp = 1; tol = epsilon(xmin)**.8; niter = 100
26call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
27niter
28+1
29if (niter > 100) error stop 'minimization failed.'
30[xmin, fmin]
31+1.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
32
33
34getSq(x) = (x - 1)**2
35xmin = 0; xlow = -1; xupp = 3; fmin = getSq(xmin); tol = epsilon(xmin)**.8; niter = 100
36call setMinBrent(getSq, xmin, xlow, xupp, fmin, tol, niter)
37niter
38+6
39if (niter > 100) error stop 'minimization failed.'
40[xmin, fmin]
41+1.00000000000000000000000000000000000, +0.00000000000000000000000000000000000
42
43
Test:
test_pm_optimization


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 935 of file pm_optimization.F90.


The documentation for this interface was generated from the following file: