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

Refine an initial input interval such that the final returned interval is guaranteed to contain the minimum of the user-specified input function.
More...

Detailed Description

Refine an initial input interval such that the final returned interval is guaranteed to contain the minimum of the user-specified input function.

Given two initial input values [xlow, xupp] representing the best-guess interval to hopefully contain the minimum of the input function, compute and return the refined interval and an interior point xmin within the interval such that the triple [xlow, xmin, xupp] are guaranteed to pass through a convex parabola.
In addition, return the function values at the final computed triplet.
The output refined interval [xlow, xupp] is guaranteed to contain a minimum of the user-specified input function.

Warning
The final output xmin is not the location of a function minimum.
It merely satisfies the condition xlow < xmin .and. xmin < xupp.
Parameters
[in]getFunc: The scalar function be minimized.
  1. On input, it must take a scalar of the same type and kind as the output argument xmin.
  2. On output, it must return a scalar of the same type and kind as the 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]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 bracket.
On output,
  1. If the algorithm succeeds, niter will be set to the actual number of iterations taken to find the bracket 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 almost twice the maximum allowed number of calls to the user-specified input function.
The reasonable choice can be 1000.
[out]xmin: The output scalar of type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), containing the abscissa corresponding to the minimum function value among the triplet [xlow, xmin, xupp].
[in,out]xlow: The input/output scalar of the same type and kind as the 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,out]xupp: The input/output scalar of the same type and kind as the 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.
[out]fmin: The output scalar of the same type and kind as the output argument xmin, containing the user-specified function value at xmin.
[out]flow: The output scalar of the same type and kind as the output argument xmin, containing the user-specified function value at the final refined xlow.
(optional.)
[out]fupp: The output scalar of the same type and kind as the output argument xmin, containing the user-specified function value at the final refined xupp.
(optional.)


Possible calling interfaces

call setBracketMin(getFunc, niter, xmin, xlow, xupp, fmin, flow, fupp)
Refine an initial input interval such that the final returned interval is guaranteed to contain the m...
This module contains procedures, generic interfaces, and types for numerical optimizations of mathema...
Warning
The condition 0 < niter must hold for the corresponding input arguments.
The condition xlow < xupp must hold for the corresponding input arguments.
The input function getFunc() must be convex (with positive second derivative) at least in one interval within its domain, otherwise the procedure will enter a semi-infinite loop in search of the minimum.
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
7 use pm_err, only: setAsserted
8 use pm_val2str, only: getStr
9
10 implicit none
11
12 integer(IK) :: niter, maxniter = 1000
13 real(RKG) :: xlow, xmin, xupp, flow, fmin, fupp
14 type(display_type) :: disp
15 disp = display_type(file = "main.out.F90")
16
17 call disp%skip()
18 call disp%show("getSqPos(x) = (x - 1)**2")
19 call disp%show("xlow = -3; xupp = -1; niter = maxniter")
20 xlow = -3; xupp = -1; niter = maxniter
21 call disp%show("call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin)")
22 call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin)
23 call disp%show("if (niter > maxniter) error stop 'Bracketing failed.'")
24 if (niter > maxniter) error stop 'Bracketing failed.'
25 call disp%show("[xlow, xmin, xupp, getSqPos(xlow), fmin, getSqPos(xupp)]")
26 call disp%show( [xlow, xmin, xupp, getSqPos(xlow), fmin, getSqPos(xupp)] )
27 call disp%show("niter")
28 call disp%show( niter )
29 call disp%show("call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, getSqPos(xlow), getSqPos(xupp)))")
30 call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, getSqPos(xlow), getSqPos(xupp)))
31 call disp%skip()
32
33 call disp%skip()
34 call disp%show("getSqPos(x) = (x - 1)**2")
35 call disp%show("xlow = -3; xupp = -1; niter = maxniter")
36 xlow = -3; xupp = -1; niter = maxniter
37 call disp%show("call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)")
38 call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
39 call disp%show("if (niter > maxniter) error stop 'Bracketing failed.'")
40 if (niter > maxniter) error stop 'Bracketing failed.'
41 call disp%show("[xlow, xmin, xupp, flow, fmin, fupp]")
42 call disp%show( [xlow, xmin, xupp, flow, fmin, fupp] )
43 call disp%show("niter")
44 call disp%show( niter )
45 call disp%show("call setAsserted(isBracketMin(xmin, xlow, xupp, flow, fmin, fupp))")
46 call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))
47 call disp%skip()
48
49 call disp%skip()
50 call disp%show("getSqPos(x) = (x - 1)**2")
51 call disp%show("xlow = 3; xupp = 9; niter = maxniter")
52 xlow = 3; xupp = 9; niter = maxniter
53 call disp%show("call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)")
54 call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
55 call disp%show("if (niter > maxniter) error stop 'Bracketing failed.'")
56 if (niter > maxniter) error stop 'Bracketing failed.'
57 call disp%show("[xlow, xmin, xupp, flow, fmin, fupp]")
58 call disp%show( [xlow, xmin, xupp, flow, fmin, fupp] )
59 call disp%show("niter")
60 call disp%show( niter )
61 call disp%show("call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))")
62 call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))
63 call disp%skip()
64
65 call disp%skip()
66 call disp%show("getSqPos(x) = (x - 1)**2")
67 call disp%show("xlow = -5; xupp = 4; niter = maxniter")
68 xlow = -5; xupp = 4; niter = maxniter
69 call disp%show("call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)")
70 call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
71 call disp%show("if (niter > maxniter) error stop 'Bracketing failed.'")
72 if (niter > maxniter) error stop 'Bracketing failed.'
73 call disp%show("[xlow, xmin, xupp, flow, fmin, fupp]")
74 call disp%show( [xlow, xmin, xupp, flow, fmin, fupp] )
75 call disp%show("niter")
76 call disp%show( niter )
77 call disp%show("call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))")
78 call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))
79 call disp%skip()
80
81contains
82
83 function getSqPos(x) result(func)
84 real(RKG), intent(in) :: x
85 real(RKG) :: func
86 func = (x - 1)**2
87 end function
88
89end program example
Verify the input assertion holds and if it does not, print the (optional) input message on stdout and...
Definition: pm_err.F90:735
Generate and return an object of type stop_type with the user-specified input attributes.
Definition: pm_err.F90:1618
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return .true. if and only if a convex quadratic curve can fit the specified input triple...
Generate and return the conversion of the input value to an output Fortran string,...
Definition: pm_val2str.F90:167
This module contains classes and procedures for reporting and handling errors.
Definition: pm_err.F90:52
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
This module contains the generic procedures for converting values of different types and kinds to For...
Definition: pm_val2str.F90:58
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
2getSqPos(x) = (x - 1)**2
3xlow = -3; xupp = -1; niter = maxniter
4call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin)
5if (niter > maxniter) error stop 'Bracketing failed.'
6[xlow, xmin, xupp, getSqPos(xlow), fmin, getSqPos(xupp)]
7-1.00000000000000000000000000000000000, +1.00000000000000000000000000000000000, +2.23606797749978969640917366873127632, +4.00000000000000000000000000000000000, +0.00000000000000000000000000000000000, +1.52786404500042060718165266253744775
8niter
9+1
10call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, getSqPos(xlow), getSqPos(xupp)))
11
12
13getSqPos(x) = (x - 1)**2
14xlow = -3; xupp = -1; niter = maxniter
15call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
16if (niter > maxniter) error stop 'Bracketing failed.'
17[xlow, xmin, xupp, flow, fmin, fupp]
18-1.00000000000000000000000000000000000, +1.00000000000000000000000000000000000, +2.23606797749978969640917366873127632, +4.00000000000000000000000000000000000, +0.00000000000000000000000000000000000, +1.52786404500042060718165266253744775
19niter
20+1
21call setAsserted(isBracketMin(xmin, xlow, xupp, flow, fmin, fupp))
22
23
24getSqPos(x) = (x - 1)**2
25xlow = 3; xupp = 9; niter = maxniter
26call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
27if (niter > maxniter) error stop 'Bracketing failed.'
28[xlow, xmin, xupp, flow, fmin, fupp]
29-6.70820393249936908922752100619382819, +3.00000000000000000000000000000000000, +9.00000000000000000000000000000000000, +64.0000000000000000000000000000000000, +4.00000000000000000000000000000000000, +59.4164078649987381784550420123876502
30niter
31+1
32call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))
33
34
35getSqPos(x) = (x - 1)**2
36xlow = -5; xupp = 4; niter = maxniter
37call setBracketMin(getSqPos, niter, xmin, xlow, xupp, fmin, flow, fupp)
38if (niter > maxniter) error stop 'Bracketing failed.'
39[xlow, xmin, xupp, flow, fmin, fupp]
40-5.00000000000000000000000000000000000, +4.00000000000000000000000000000000000, +18.5623058987490536338412815092907438, +36.0000000000000000000000000000000000, +9.00000000000000000000000000000000000, +308.434588481235804507619222639361176
41niter
42+1
43call setAsserted(isBracketMin(xmin, xlow, xupp, fmin, flow, fupp))
44
45
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 605 of file pm_optimization.F90.


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