Leap Frog Optimizer  Lite Edition
Project description
Leap Frog Optimizer Package  Lite Edition
 Author : Mark Redd
 Email : redddogjr@gmail.com
 GitHub : https://github.com/flythereddflagg
 Website : http://www.r3eda.com/
About:
This package is based the Leapfrogging Optimization Algorithm published by Dr. R. Russell Rhinehart.
The following publications explain the technique and may be found on the website:

Rhinehart, R. R., M. Su, and U. ManimegalaiSridhar, “Leapfrogging and Synoptic Leapfrogging: a new optimization approach”, Computers & Chemical Engineering, Vol. 40, 11 May 2012, pp. 6781.

ManimegalaiSridhar, U., A. Govindarajan, and R. R. Rhinehart, “Improved Initialization of Players in Leapfrogging Optimization”, Computers & Chemical Engineering, Vol. 60, 2014, 426429.

Rhinehart, R. R., “Convergence Criterion in Optimilsation of Stochastic Processes”, Computers & Chemical Engineering, Vol. 68, 4 Sept 2014, pp 16.
This is the stripped down version of the package with minimal tools. It is written in pure Python to allow compatibility for the alpha versions until the full version can be released.
Installation
You can install the lite versions via pip or using the setup.py script in the source code. Instructions are shown below.
System requirements for installation:
 Python >= 3.6
numpy
scipy
nose
Via pip
Lpfgopt may be installed with pip using the following command:
$ pip install lpfgoptlite # You may need root privileges or the user tag
If you wish to install locally with pip you may do the following:

Download the 'lite' branch and unzip the archive or clone it with git.

Open the main directory where "setup.py" is located and run the following command:
$ pip install .
Via setup.py

Download the 'lite' branch and unzip the archive or clone it with git.

Open the main directory where "setup.py" is located and run the following command:
$ python setup.py install # You may need root priviliges or use the user tag
The software should be installed correctly. You may validate the installation by executing the following commands:
$ python
>>> import lpfgopt
>>> lpfgopt.__version__
'X.X.X'
>>> lpfgopt.minimize(lambda x: x[0]**2 + 10, [[10, 10]])['x']
[<approximately 0.0>]
>>>
If the above commands produce the output congratulations! You have successfully installed the package!
Usage
Use the lpfgopt.minimize
function to solve optimization problems of the form:
minimize f(x)
subject to:
g(x) <= 0
bound[0][0] <= x[0] <= bound[0][1]
bound[1][0] <= x[0] <= bound[1][1]
...
bound[n][0] <= x[0] <= bound[n][1]
where n is the number of decsision variables and bound
is a n X 2 list of lists or 2d numpy array with shape (n,2)
lpfgopt.minimize
documentation
lpfgopt.minimize( fun, bounds, args=(), points=20, fconstraint=None, discrete=[], maxit=10000, tol=1e5, seedval=None, pointset=None, callback=None )
Generaluse wrapper function to interface with the LeapFrog optimizer class. Contains the data and methods necessary to run a LeapFrog optimization. Accepts constraints, discrete variables and allows for a variety of options.

Parameters:
 fun : callable Objective function
 bounds : arraylike, shape (n, 2) Decision variable upper and lower bounds
 args : iterable Other arguments to be passed into the function
 points : int Point set size
 fconstraint : callable Constraint function of the form g(x) <= 0
 discrete : arraylike List of indices that correspond to discrete variables. These variables will be constrained to integer values by truncating any randomly generated number (i.e. rounding down to the nearest integer absolute value)
 maxit : int Maximum iterations
 tol : float Convergence tolerance
 seedval : int Random seed
 pointset : arraylike, shape (m, n) Starting point set
 callback : callable Function to be called after each iteration

Returns:

solution : dict A dictionary containing the results of the optimization. The members of the solution are listed below.

x : list The solution vector or the vector of decision variables that produced the lowest objective function value

success : bool Whether or not the optimizer exited successfully.

status : int Termination status of the optimizer. Its value depends on the underlying solver. Refer to message for details.

message : string Description of the cause of the termination.

fun: float The objective function value at 'x'

nfev : int The number of function evaluations of the objective function

nit : int The number of iterations performed

maxcv : float The maximum constraint violation evaluated during optimization

best : list The member of the population that had the lowest objective value in the point set having the form [f(x), x[0], x[1], ..., x[n1]]


worst : list The member of the population that had the highest objective value in the point set having the form [f(x), x[0], x[1], ..., x[n1]]

final_error : float The optimization convergence value upon termination

pointset : list, shape(m, n) The entire point set state upon termination having the form:
[ [f(x[0]), x[0][0], x[0][1], ..., x[0][n1]], [f(x[1]), x[1][0], x[1][1], ..., x[1][n1]], ..., [f(x[m1]), x[m1][0], x[m1][1], ..., x[m1][n1]] ]
where n is the number of decision variables and m is the number of points in the search population.


Example Usage
The following is a simple optimization where the minimum value of the following equation is found:
 $f(x) = x^2+y^2$
 Subject to: $g(x) = x^2  y + 10 \le 0$ or g(x) = x^2  y + 10 <= 0
# test_lpfgopt.py
from lpfgopt import minimize
import matplotlib.pyplot as plt
# set up the objective funciton,
# constraint fuction and bounds
f = lambda x: sum([i**2 for i in x])
g = lambda x: x[0]**2 + 10  x[1]
bounds = [[5,5] for i in range(2)]
# run the optimization
sol = minimize(f, bounds, fconstraint=g)['x']
print(f"Solution is: {sol}")
# plot the results on a contour plot
gg = lambda x: x**2 + 10 # for plotting purposes
plt.figure(figsize=(8,8))
x, y = np.linspace(5,5,1000), np.linspace(5,5,1000)
X, Y = np.meshgrid(x,y)
Z = f([X,Y])
plt.contourf(X,Y,Z)
plt.plot(x, gg(x), "r", label="constraint")
plt.plot(*sol, 'x',
markersize=14,
markeredgewidth=4,
color="lime",
label="optimum")
plt.ylim(5,5)
plt.xlim(5,5)
plt.legend()
plt.show()
This code will produce the following output:
Solution is: [3.0958051486911997, 0.4159905027317925]
As well as a plot that should look similar to the following image:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for lpfgopt_lite0.9.1py3noneany.whl
Algorithm  Hash digest  

SHA256  a2875738b04fd2b3c793d14218e899d4bd6273b71efb055204f9c5316c6cc8ad 

MD5  1c5d44ba8a86e0b6e77e886e77cde784 

BLAKE2b256  568e79e0d35ed8c5d8173d8a267f4612c82ae1e69507085bb7c7ea3a5b24e503 
Hashes for lpfgopt_lite0.9.1py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  0aa13750e0e52393f25d5e5e8bcc12642ee7325d7ed15b7260fc586243c612c9 

MD5  8ef0c0dd1ff6cffcf8f5882a5d6ae3bd 

BLAKE2b256  ccc2f9260698ce1bbee1039f2847d9c6c8cb0bd5df14bd1148bb7e283aadb9f3 