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

Refine an initial input interval such that the final returned interval is guaranteed to contain the maximum 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 maximum of the user-specified input function.

Given two initial input values [xlow, xupp] representing the best-guess interval to hopefully contain the maximum of the input function, compute and return the refined interval and an interior point xmax within the interval such that the triple [xlow, xmax, 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 maximum of the user-specified input function.

Warning
The final output xmax is not the location of a function maximum.
It merely satisfies the condition xlow < xmax .and. xmax < xupp.
Parameters
[in]getFunc: The scalar function be maximized.
  1. On input, it must take a scalar of the same type and kind as the output argument xmax.
  2. On output, it must return a scalar of the same type and kind as the output argument xmax, 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]xmax: 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 maximum function value among the triplet [xlow, xmax, xupp].
[in,out]xlow: The input/output scalar of the same type and kind as the output argument xmax, containing the lower bound of the search interval for the function maximum abscissa.
The condition xlow < xmax .and. getFunc(xmax) < 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 xmax, containing the upper bound of the search interval for the function maximum abscissa.
The condition xmax < xupp .and. getFunc(xmax) < getFunc(xupp) must hold for the corresponding input arguments.
[out]fmax: The output scalar of the same type and kind as the output argument xmax, containing the user-specified function value at xmax.
[out]flow: The output scalar of the same type and kind as the output argument xmax, 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 xmax, containing the user-specified function value at the final refined xupp.
(optional.)


Possible calling interfaces

call setBracketMax(getFunc, niter, xmax, xlow, xupp, fmax, 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 concave (with negative second derivative) at least in one interval within its domain, otherwise the procedure will enter a semi-infinite loop in search of the maximum.
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, minniter = 1000
13 real(RKG) :: xlow, xmax, xupp, flow, fmax, fupp
14 type(display_type) :: disp
15 disp = display_type(file = "main.out.F90")
16
17 call disp%skip()
18 call disp%show("getSqNeg(x) = (x - 1)**2")
19 call disp%show("xlow = -3; xupp = -1; niter = minniter")
20 xlow = -3; xupp = -1; niter = minniter
21 call disp%show("call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax)")
22 call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax)
23 call disp%show("if (niter > minniter) error stop 'Bracketing failed.'")
24 if (niter > minniter) error stop 'Bracketing failed.'
25 call disp%show("[xlow, xmax, xupp, getSqNeg(xlow), fmax, getSqNeg(xupp)]")
26 call disp%show( [xlow, xmax, xupp, getSqNeg(xlow), fmax, getSqNeg(xupp)] )
27 call disp%show("niter")
28 call disp%show( niter )
29 call disp%show("call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, getSqNeg(xlow), getSqNeg(xupp)))")
30 call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, getSqNeg(xlow), getSqNeg(xupp)))
31 call disp%skip()
32
33 call disp%skip()
34 call disp%show("getSqNeg(x) = (x - 1)**2")
35 call disp%show("xlow = -3; xupp = -1; niter = minniter")
36 xlow = -3; xupp = -1; niter = minniter
37 call disp%show("call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)")
38 call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
39 call disp%show("if (niter > minniter) error stop 'Bracketing failed.'")
40 if (niter > minniter) error stop 'Bracketing failed.'
41 call disp%show("[xlow, xmax, xupp, flow, fmax, fupp]")
42 call disp%show( [xlow, xmax, xupp, flow, fmax, fupp] )
43 call disp%show("niter")
44 call disp%show( niter )
45 call disp%show("call setAsserted(isBracketMax(xmax, xlow, xupp, flow, fmax, fupp))")
46 call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))
47 call disp%skip()
48
49 call disp%skip()
50 call disp%show("getSqNeg(x) = (x - 1)**2")
51 call disp%show("xlow = 3; xupp = 9; niter = minniter")
52 xlow = 3; xupp = 9; niter = minniter
53 call disp%show("call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)")
54 call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
55 call disp%show("if (niter > minniter) error stop 'Bracketing failed.'")
56 if (niter > minniter) error stop 'Bracketing failed.'
57 call disp%show("[xlow, xmax, xupp, flow, fmax, fupp]")
58 call disp%show( [xlow, xmax, xupp, flow, fmax, fupp] )
59 call disp%show("niter")
60 call disp%show( niter )
61 call disp%show("call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))")
62 call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))
63 call disp%skip()
64
65 call disp%skip()
66 call disp%show("getSqNeg(x) = (x - 1)**2")
67 call disp%show("xlow = -5; xupp = 4; niter = minniter")
68 xlow = -5; xupp = 4; niter = minniter
69 call disp%show("call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)")
70 call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
71 call disp%show("if (niter > minniter) error stop 'Bracketing failed.'")
72 if (niter > minniter) error stop 'Bracketing failed.'
73 call disp%show("[xlow, xmax, xupp, flow, fmax, fupp]")
74 call disp%show( [xlow, xmax, xupp, flow, fmax, fupp] )
75 call disp%show("niter")
76 call disp%show( niter )
77 call disp%show("call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))")
78 call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))
79 call disp%skip()
80
81contains
82
83 function getSqNeg(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 concave quadratic curve can fit the specified input tripl...
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
2getSqNeg(x) = (x - 1)**2
3xlow = -3; xupp = -1; niter = minniter
4call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax)
5if (niter > minniter) error stop 'Bracketing failed.'
6[xlow, xmax, xupp, getSqNeg(xlow), fmax, getSqNeg(xupp)]
7-1.00000000000000000000000000000000000, +1.00000000000000000000000000000000000, +2.23606797749978969640917366873127632, -4.00000000000000000000000000000000000, -0.00000000000000000000000000000000000, -1.52786404500042060718165266253744775
8niter
9+1
10call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, getSqNeg(xlow), getSqNeg(xupp)))
11
12
13getSqNeg(x) = (x - 1)**2
14xlow = -3; xupp = -1; niter = minniter
15call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
16if (niter > minniter) error stop 'Bracketing failed.'
17[xlow, xmax, xupp, flow, fmax, fupp]
18-1.00000000000000000000000000000000000, +1.00000000000000000000000000000000000, +2.23606797749978969640917366873127632, -4.00000000000000000000000000000000000, -0.00000000000000000000000000000000000, -1.52786404500042060718165266253744775
19niter
20+1
21call setAsserted(isBracketMax(xmax, xlow, xupp, flow, fmax, fupp))
22
23
24getSqNeg(x) = (x - 1)**2
25xlow = 3; xupp = 9; niter = minniter
26call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
27if (niter > minniter) error stop 'Bracketing failed.'
28[xlow, xmax, xupp, flow, fmax, fupp]
29-6.70820393249936908922752100619382819, +3.00000000000000000000000000000000000, +9.00000000000000000000000000000000000, -64.0000000000000000000000000000000000, -4.00000000000000000000000000000000000, -59.4164078649987381784550420123876502
30niter
31+1
32call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, flow, fupp))
33
34
35getSqNeg(x) = (x - 1)**2
36xlow = -5; xupp = 4; niter = minniter
37call setBracketMax(getSqNeg, niter, xmax, xlow, xupp, fmax, flow, fupp)
38if (niter > minniter) error stop 'Bracketing failed.'
39[xlow, xmax, xupp, flow, fmax, fupp]
40-5.00000000000000000000000000000000000, +4.00000000000000000000000000000000000, +18.5623058987490536338412815092907438, -36.0000000000000000000000000000000000, -9.00000000000000000000000000000000000, -308.434588481235804507619222639361176
41niter
42+1
43call setAsserted(isBracketMax(xmax, xlow, xupp, fmax, 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 Austin

Definition at line 433 of file pm_optimization.F90.


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