Paropt is a python tool for optimizing an application's parameters using system calls and parsing performance data from STDOUT. From a starting value, it will call the command line given to it repeatedly, converging into optimal parameters using the Nelder-mead algorithm or grid search.
popt [options] {min,max} fn_call fval_regex x0 x1 x2 ...
popt -g [options] {min,max} fn_call fval_regex x0range x1range x2range ...
{min,max}The direction of optimizationfn_callA valid system call with placeholders ({}(only Python 2.7 or higher) or numbered with{0},{1}, etc.) representing parameters, e.g.'examples/rosenbrock.py {} {}'.fval_regexA valid regular expression that contains a capturing group representing the function value to parse out, e.g.'fx = (.*)'
All additional positional arguments will represent initial values for the variables - make sure the number of variables matches your function call!
-g--gridUse grid search (see Range specifications for details on how to specify value ranges)-n--neldermeadUse nelder-mead (default)-h--helpDisplay help-t--xtolSpecify a tolerance value for the optimization (default: 1e-6)-i--maxiterSpecify the maximum number of iterations for the optimization (default: None)
If optimizing using grid search, variables are not given as initial values but as ranges specifying the grid search space. Ranges are specified as 1-, 2- or 3-tuples giving minimal and maximal values plus an optional increment. Examples:
0,1,0.1 A range from 0 to 1 in increments of 0.1 (e.g 0.1, 0.2, ... 0.9)
1,4 A range from 1 to 4 in increments of 1 (e.g. 1, 2, 3)
0.5 A range from 0.5 to 0.5 (i.e. a constant value)
Valid delimiter characters are: ,;|
You can optionally specify lists of values for a variable by prefixing the range specification with the l character. For example, to specify the list of prime numbers smaller than 10: l2,3,5,7
The following example minimizes the Rosenbrock banana function located in examples/rosenbrock.py in 5 variables.
Let's say we have a python program calculating the value of the Rosenbrock function that takes values from the command line and returns the value of the function in STDOUT:
$ examples/rosenbrock.py 1.3 0.7 0.8 1.9 1.2
fx = 8.4822000000e+02
We can minimize this function using popt:
$ ./popt --xtol 1e-8 min 'examples/rosenbrock.py {0} {1} {2} {3} {4}' 'fx = (.*)' 1.3 0.7 0.8 1.9 1.2
[...]
success: True
status: 0
nfev: 571
fun: 4.8611534334e-17
nit: 339
message: 'Optimization terminated successfully.'
x: array([ 1., 1., 1., 1., 1.])
The following example minimizes the Rosenbrock banana function located in examples/rosenbrock.py in 2 variables using grid search covering the grid [0, 0.1, ... 1.9] for each of the variables.
$ ./popt -g min 'examples/rosenbrock.py {1} {2}' 'fx = (.*)' 0,2,0.1 0,2,0.1
- Python 2.6 or later (including Python 3)
- scipy 0.12