Package: lpfgopt-lite
Leap Frog Optimizer Package - Lite EditionAuthor  : Mark ReddEmail   :redddogjr@gmail.comGitHub  :https://github.com/flythereddflaggWebsite :http://www.r3eda.com/About:This package is based theLeapfrogging Optimization
Algorithmpublished byDr. R. Russell Rhinehart.The following publications explain the technique and may be found on the website:Rhinehart, R. R., M. Su, and U. Manimegalai-Sridhar,
“Leapfrogging and Synoptic Leapfrogging: a new optimization approach”,
Computers & Chemical Engineering, Vol. 40, 11 May 2012, pp. 67-81.Manimegalai-Sridhar, U., A. Govindarajan, and R. R. Rhinehart,
“Improved Initialization of Players in Leapfrogging Optimization”,
Computers & Chemical Engineering, Vol. 60, 2014, 426-429.Rhinehart, R. R.,
“Convergence Criterion in Optimilsation of Stochastic Processes”,
Computers & Chemical Engineering, Vol. 68, 4 Sept 2014, pp 1-6.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.InstallationYou 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.6numpyscipynoseVia pipLpfgopt may be installed with pip using the following command:$pipinstalllpfgopt-lite# You may need root privileges or the --user tagIf 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:$pipinstall.Via setup.pyDownload 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:$pythonsetup.pyinstall# You may need root priviliges or use the --user tagThe software should be installed correctly. You may validate the installation by executing the following commands:$python>>>importlpfgopt>>>lpfgopt.__version__'X.X.X'>>>lpfgopt.minimize(lambdax:x[0]**2+10,[[-10,10]])['x'][<approximately0.0>]>>>If the above commands produce the output congratulations! You have successfully installed the package!UsageUse thelpfgopt.minimizefunction 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.minimizedocumentationlpfgopt.minimize(fun, bounds, args=(), points=20, fconstraint=None, discrete=[], maxit=10000, tol=1e-5, seedval=None, pointset=None, callback=None)General-use 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 : callableObjective functionbounds : array-like, shape (n, 2)Decision variable upper and lower boundsargs : iterableOther arguments to be passed
into the functionpoints : intPoint set sizefconstraint : callableConstraint function of the form g(x) <= 0discrete : array-likeList 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 : intMaximum iterationstol : floatConvergence toleranceseedval : intRandom seedpointset : array-like, shape (m, n)Starting point setcallback : callableFunction to be called after each iterationReturns:solution : dictA dictionary containing the results of the optimization.
The members of the solution are listed below.x : listThe solution vector or the vector of
decision variables that produced the lowest
objective function valuesuccess : boolWhether or not the optimizer exited successfully.status : intTermination status of the optimizer. Its value
depends on the underlying solver. Refer to
message for details.message : stringDescription of the cause of the termination.fun: floatThe objective function value at 'x'nfev : intThe number of function evaluations of the objective
functionnit : intThe number of iterations performedmaxcv : floatThe maximum constraint violation evaluated during
optimizationbest : listThe member of the population that had the lowest
objective value in the point set having the form
[f(x), x[0], x[1], ..., x[n-1]]worst : listThe member of the population that had the highest
objective value in the point set having the form
[f(x), x[0], x[1], ..., x[n-1]]final_error : floatThe optimization convergence value upon terminationpointset :  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][n-1]],
 [f(x[1]),   x[1][0],   x[1][1],   ..., x[1][n-1]],
 ...,
 [f(x[m-1]), x[m-1][0], x[m-1][1], ..., x[m-1][n-1]]
 ]where n is the number of decision variables and m
is the number of points in the search population.Example UsageThe 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$org(x) = -x^2 - y + 10 <= 0# test_lpfgopt.pyfromlpfgoptimportminimizeimportmatplotlib.pyplotasplt# set up the objective funciton,# constraint fuction and boundsf=lambdax:sum([i**2foriinx])g=lambdax:-x[0]**2+10-x[1]bounds=[[-5,5]foriinrange(2)]# run the optimizationsol=minimize(f,bounds,fconstraint=g)['x']print(f"Solution is:{sol}")# plot the results on a contour plotgg=lambdax:-x**2+10# for plotting purposesplt.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:Solutionis:[-3.0958051486911997,0.4159905027317925]As well as a plot that should look similar to the following image: