Benchmarking the Fractal Farmer algorithm

Sergio Hernández y Guillem Duran

Source code for the benchmarking process

In [2]:
from bug import *
from scipy import optimize
import numpy as np
import pandas as pd
In [3]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['double']
`%matplotlib` prevents importing * from pylab and numpy
In [4]:
def calc_fun(function,X,Y,Z):
    for i in np.arange(len(X[0])):
        for j in np.arange(len(X[1])):
            Z[i][j]=function(np.array([X[i][j],Y[i][j]])) 
    return Z.copy() 



def mccornick(x):
    return np.sin(x[0]+x[1])+(x[0]-x[1])**2-1.5*x[0]+2.5*x[1]+1


    
In [5]:
class MyBounds(object):
    def __init__(self, xmax=[513,513], xmin=[-513,-513] ):
        self.xmax = np.array(xmax)
        self.xmin = np.array(xmin)
            
    def __call__(self, **kwargs):
        x = kwargs["x_new"]
        tmax = bool(np.all(x <= self.xmax))
        tmin = bool(np.all(x >= self.xmin))
        return tmax and tmin
In [6]:
def run_benchmark(fun,x0,domain,nsa=100,nfa=100,nbh=100,maxticks=16,numbolts=1,seed=1):
        xmin=domain[0][0][0]
        xmax=domain[0][0][1]
        ymin=domain[1][0][0]
        ymax=domain[1][0][1]
        myopts = {
        'schedule'     : 'boltzmann',   # Non-default value.
        'maxfev'       : None,  # Default, formerly `maxeval`.
        'maxiter'      : nsa,   # Non-default value.
        'maxaccept'    : None,  # Default value.
        'ftol'         : 1e-6,  # Default, formerly `feps`.
        'T0'           : None,  # Default value.
        'Tf'           : 1e-6, # Default value.
        'boltzmann'    : 1.0,   # Default value.
        'learn_rate'   : 0.5,   # Default value.
        'quench'       : 1.0,   # Default value.
        'm'            : 1.0,   # Default value.
        'n'            : 1.0,   # Default value.
        'lower'        : -10,   # Non-default value.
        'upper'        : +10,   # Non-default value.
        'dwell'        : 250,   # Non-default value.
        'disp'         : True   # Default value.
        }
        
        cons = ({'type': 'ineq', 'fun': lambda x: -x[0] + xmin},
            {'type': 'ineq', 'fun': lambda x: x[0] + xmax},
            {'type': 'ineq', 'fun': lambda x: x[1] + ymax},
            {'type': 'ineq', 'fun': lambda x: -x[1] + ymin})
        np.random.seed(seed)  # Seeded to allow replication.
        anneal = optimize.minimize(fun, x0, method='Anneal', 
                                   options=myopts,constraints=cons)
        np.random.seed(seed)
        funcion=ObjFunc(fun,domain=domain)
        fa=Farmer(funcion,maxticks=maxticks,
                  numbolts=numbolts,speed=1,
                  minmax=-1.0,maxfails=11000,
                  maxepoch=nfa,sens=8)
        fa.optimize()
        
        np.random.seed(seed)
        mybounds = MyBounds(xmax=[xmax,ymax],xmin=[xmin,ymin])
        minimizer_kwargs = {"method": "BFGS"}
        bsh = optimize.basinhopping(fun, x0, 
                                    minimizer_kwargs=minimizer_kwargs,
                                    niter=6000,niter_success=nbh,accept_test=mybounds)
        return anneal,fa,bsh
In [7]:
def comparativa(sa,fa,bh,solution):
    logs=fa.logger.data
    fab=fa.best['val']
    faev=logs['ticks'].dropna().cumsum().tail(1).values[0]*len(fa.bolts)
    
    sab=sa.fun
    saev=sa.nfev
    
    bhb=bh.fun
    bhev=bh.nfev
    
    benchmark=pd.DataFrame(index=['Farmer','Simulated Annealing','Basin Hopping'],columns=['Evaluations','Minimum Found','Error'])
    benchmark['Evaluations']=np.array([faev,saev,bhev])
    benchmark['Minimum Found']=np.array([fab,sab,bhb])
    benchmark['Error']=np.array([solution-fab,solution-sab,solution-bhb])
    return benchmark
In [8]:
def create_index(samples,names):
    algos=np.array(names)
    tiled=np.tile(algos,samples)
    iters=np.repeat(np.arange(samples),len(algos))
    tuples=list(zip(iters,tiled))
    multiindex = pd.MultiIndex.from_tuples(tuples, names=['iter', 'algorithm'])
    return multiindex
In [9]:
names=['Farmer','Simulated Annealing','Basin Hopping']
def benchmark_df(samples,names):
    return pd.DataFrame(index=create_index(samples,names),columns=['Evaluations','Minimum Found','Error'])
In [10]:
def results_df():
     benchmark=pd.DataFrame(index=['Farmer','Simulated Annealing','Basin Hopping'],columns=['Evaluations','Minimum Found','Error'])
In [11]:
def record_benchmark(df,sa,fa,bh,solution,i):
    logs=fa.logger.data
    fab=fa.best['val']
    faev=logs['ticks'].dropna().cumsum().tail(1).values[0]*len(fa.bolts)
    
    sab=sa.fun
    saev=sa.nfev    
    bhb=bh.fun
    bhev=bh.nfev
    
    df.loc[i,'Farmer']['Evaluations']=faev
    df.loc[i,'Simulated Annealing']['Evaluations']=saev
    df.loc[i,'Basin Hopping']['Evaluations']=bhev
    
    df.loc[i,'Farmer']['Minimum Found']=fab
    df.loc[i,'Simulated Annealing']['Minimum Found']=sab
    df.loc[i,'Basin Hopping']['Minimum Found']=bhb
    
    df.loc[i,'Farmer']['Error']=fab-solution
    df.loc[i,'Simulated Annealing']['Error']=sab-solution
    df.loc[i,'Basin Hopping']['Error']=bhb-solution
In [12]:
def comparativa(df):
    return df.applymap(lambda x:float(x)).reset_index().drop('iter',axis=1).groupby('algorithm').describe()
In [13]:
from mpl_toolkits.mplot3d.axes3d import Axes3D
def make_plot(fun,domain,points=100):
    xmin=domain[0][0][0]
    xmax=domain[0][0][1]
    ymin=domain[1][0][0]
    ymax=domain[1][0][1]
    x = np.linspace(xmin, xmax, points)
    y = np.linspace(ymin, ymax, points)
    X,Y = np.meshgrid(x, y)
    Z=X.copy()
    Z=calc_fun(fun,X,Y,Z)
    

    # `ax` is a 3D-aware axis instance because of the projection='3d' keyword argument to add_subplot
    fig = plt.figure(figsize=(16,10))

    ax = fig.add_subplot(1,1,1, projection='3d')

    ax.plot_surface(X, Y, Z, rstride=4, cstride=4, alpha=0.25,cmap=cm.gist_rainbow)
    ax.set_xlabel(r'$x$', fontsize=18)
    ax.set_ylabel(r'$y$', fontsize=18)
    ax.set_xlim3d(xmin, xmax)
    ax.set_ylim3d(ymin, ymax)    
    return ax,fig
    
In [14]:
def random_in_domain(domain):
    xmin=domain[0][0][0]
    xmax=domain[0][0][1]
    ymin=domain[1][0][0]
    ymax=domain[1][0][1]
    return np.array([np.random.uniform(xmin,xmax),np.random.uniform(ymin,ymax)])

Benchmark

Schaffel function number 2

In [15]:
def schaffel2(X):
    x=X[0]
    y=X[1]
    return 0.5+(np.sin((x**2-y**2))**2-0.5)/(1+0.001*(x**2+y**2))**2
In [19]:
%%capture

dsc4=[[(-100,100)],[(-100,100)]]
runs=100
bm=benchmark_df(runs,names)
for i in range(runs):
    x0=random_in_domain(dsc4)
    sa,fa,bh=run_benchmark(schaffel2,x0,dsc4,nsa=500,nfa=30,nbh=50,maxticks=8,numbolts=10,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=0.0,i=i)
In [20]:
ax,fig=make_plot(schaffel2,dsc4,500)
p=ax.set_title(r'$Schaffel2$',fontsize=18)
comparativa(bm)
Out[20]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 1.000000e+02
mean 2.104025e-01 11480.070000 2.104025e-01
std 2.188639e-01 4868.032779 2.188639e-01
min 1.170175e-13 2856.000000 1.170175e-13
25% 7.945647e-11 7581.000000 7.945647e-11
50% 1.020581e-01 10712.000000 1.020581e-01
75% 4.600848e-01 14965.000000 4.600848e-01
max 4.948500e-01 27248.000000 4.948500e-01
Farmer count 1.000000e+02 100.000000 1.000000e+02
mean 1.601722e-08 915.000000 1.601722e-08
std 8.490559e-08 102.054650 8.490559e-08
min 0.000000e+00 580.000000 0.000000e+00
25% 0.000000e+00 867.500000 0.000000e+00
50% 0.000000e+00 960.000000 0.000000e+00
75% 8.403750e-09 990.000000 8.403750e-09
max 8.100000e-07 1030.000000 8.100000e-07
Simulated Annealing count 1.000000e+02 100.000000 1.000000e+02
mean 6.467489e-03 125301.000000 6.467489e-03
std 9.678121e-03 0.000000 9.678121e-03
min 2.267228e-07 125301.000000 2.267228e-07
25% 9.288691e-05 125301.000000 9.288691e-05
50% 1.666980e-03 125301.000000 1.666980e-03
75% 1.012242e-02 125301.000000 1.012242e-02
max 4.360897e-02 125301.000000 4.360897e-02

Schaffel function number 4

In [21]:
def schaffel4(X):
    x=X[0]
    y=X[1]
    return 0.5+(np.cos(np.sin(np.abs(x**2-y**2)))**2-0.5)/(1+0.001*(x**2+y**2))**2
In [22]:
%%capture
dsc4=[[(-100,100)],[(-100,100)]]
runs=100
bm=benchmark_df(runs,names)
for i in range(runs):
    x0=random_in_domain(dsc4)
    sa,fa,bh=run_benchmark(schaffel4,x0,dsc4,nsa=500,nfa=60,nbh=110,maxticks=8,numbolts=10,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=0.292579,i=i)
In [23]:
ax,fig=make_plot(schaffel4,dsc4,500)
p=ax.set_title(r'$Schaffel 4$',fontsize=18)
comparativa(bm)
Out[23]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 100.000000
mean 1.121666e-01 14413.370000 0.404746
std 8.720184e-02 7199.951049 0.087202
min -3.679640e-07 5028.000000 0.292579
25% -3.679615e-07 9283.000000 0.292579
50% 1.570780e-01 12118.000000 0.449657
75% 1.957180e-01 17297.000000 0.488297
max 2.048967e-01 43296.000000 0.497476
Farmer count 1.000000e+02 100.000000 100.000000
mean 2.068595e-05 2693.600000 0.292600
std 2.759781e-05 394.944108 0.000028
min -3.455718e-07 1200.000000 0.292579
25% 4.357988e-06 2750.000000 0.292583
50% 1.179427e-05 2780.000000 0.292591
75% 2.531250e-05 2862.500000 0.292604
max 1.524288e-04 3160.000000 0.292731
Simulated Annealing count 1.000000e+02 100.000000 100.000000
mean 2.880114e-03 125301.000000 0.295459
std 4.451486e-03 0.000000 0.004451
min 4.854072e-06 125301.000000 0.292584
25% 1.976816e-04 125301.000000 0.292777
50% 1.106782e-03 125301.000000 0.293686
75% 3.482585e-03 125301.000000 0.296062
max 2.235784e-02 125301.000000 0.314937

Test function from scipy optimize

In [24]:
params = (2, 3, 7, 8, 9, 10, 44, -1, 2, 26, 1, -2, 0.5)
def f1(z,):
     x, y = z
     a, b, c, d, e, f, g, h, i, j, k, l, scale = params
     return (a * x**2 + b * x * y + c * y**2 + d*x + e*y + f)
    
def f2(z,):
     x, y = z
     a, b, c, d, e, f, g, h, i, j, k, l, scale = params
     return (-g*np.exp(-((x-h)**2 + (y-i)**2) / scale))
    
def f3(z,):
     x, y = z
     a, b, c, d, e, f, g, h, i, j, k, l, scale = params
     return (-j*np.exp(-((x-k)**2 + (y-l)**2) / scale))   

def f(z,):
     x, y = z
     a, b, c, d, e, f, g, h, i, j, k, l, scale = params
     return f1(z) + f2(z) + f3(z) 
In [25]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dsc4=[[(-100,100)],[(-100,100)]]
for i in range(runs):
    x0=random_in_domain(dsc4)
    sa,fa,bh=run_benchmark(f,x0,dsc4,nsa=500,nfa=100,nbh=150,maxticks=8,numbolts=40,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=-3.409,i=i)
In [26]:
ax,fig=make_plot(f,dsc4,500)
#p=ax.set_title(r'$Schaffel 4$',fontsize=18)
comparativa(bm)
Out[26]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 100.000000 100.000000 100.000000
mean 2.261735 8696.000000 -1.147265
std 2.512574 2818.223984 2.512574
min 0.000418 4052.000000 -3.408582
25% 0.000418 6043.000000 -3.408582
50% 0.000418 8852.000000 -3.408582
75% 5.025566 10358.000000 1.616566
max 5.025566 16760.000000 1.616566
Farmer count 100.000000 100.000000 100.000000
mean 0.000789 21110.000000 -3.408211
std 0.000430 679.806865 0.000430
min 0.000418 19240.000000 -3.408582
25% 0.000515 20730.000000 -3.408485
50% 0.000636 21160.000000 -3.408364
75% 0.000897 21560.000000 -3.408103
max 0.003049 22520.000000 -3.405951
Simulated Annealing count 100.000000 100.000000 100.000000
mean 0.100790 125301.000000 -3.308210
std 0.071156 0.000000 0.071156
min 0.001177 125301.000000 -3.407823
25% 0.031448 125301.000000 -3.377552
50% 0.107805 125301.000000 -3.301195
75% 0.138780 125301.000000 -3.270220
max 0.305069 125301.000000 -3.103931

Easom Function

In [27]:
def easom(x):
    return -np.cos(x[0])*np.cos(x[1])*np.exp(-((x[0]-np.pi)**2+(x[1]-np.pi)**2))
In [28]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dsc4=[[(-100,100)],[(-100,100)]]
for i in range(runs):
    x0=random_in_domain(dsc4)
    sa,fa,bh=run_benchmark(easom,x0,dsc4,nsa=40,nfa=50,nbh=500,maxticks=8,numbolts=100,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=-1,i=i)
In [29]:
dplot=[[(-40,40)],[(-40,40)]]
ax,fig=make_plot(easom,dplot,500)
ax.set_title(r'$Easom function$',fontsize=18)
#p=ax.set_title(r'$Schaffel 4$',fontsize=18)
comparativa(bm)
Out[29]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 1.000000e+02
mean 9.600000e-01 2486.530000 -4.000000e-02
std 1.969464e-01 2311.798550 1.969464e-01
min 0.000000e+00 2008.000000 -1.000000e+00
25% 1.000000e+00 2008.000000 -0.000000e+00
50% 1.000000e+00 2008.000000 0.000000e+00
75% 1.000000e+00 2008.000000 0.000000e+00
max 1.000000e+00 23265.000000 -0.000000e+00
Farmer count 1.000000e+02 100.000000 1.000000e+02
mean 4.956140e-04 10226.000000 -9.995044e-01
std 7.396497e-04 144.683563 7.396497e-04
min 1.443862e-06 10200.000000 -9.999986e-01
25% 9.667748e-05 10200.000000 -9.999033e-01
50% 2.685658e-04 10200.000000 -9.997314e-01
75% 5.164475e-04 10200.000000 -9.994836e-01
max 4.219220e-03 11300.000000 -9.957808e-01
Simulated Annealing count 1.000000e+02 100.000000 1.000000e+02
mean 3.686524e-01 10201.000000 -6.313476e-01
std 4.523671e-01 1000.000000 4.523671e-01
min 4.470755e-09 301.000000 -1.000000e+00
25% 2.319474e-06 10301.000000 -9.999977e-01
50% 7.433029e-02 10301.000000 -9.256697e-01
75% 9.999189e-01 10301.000000 -8.108338e-05
max 1.000000e+00 10301.000000 -1.444226e-12

Eggholder

In [30]:
def eggholder(x):
    return -1*(x[1]+47)*np.sin(np.sqrt(np.abs(x[1]+x[0]/2.0+47.0)))-x[0]*np.sin(np.sqrt(np.abs(x[0]-(x[1]+47.0))))
In [31]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=[[(-512,512)],[(-512,512)]]
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(eggholder,x0,dom,nsa=2500,nfa=1000,nbh=3500,maxticks=8,numbolts=120,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=-959.6407,i=i)
In [32]:
ax,fig=make_plot(eggholder,dom,1000)
miau=ax.set_title(r'$Eggholder$',fontsize=18)
comparativa(bm)
Out[32]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 100.000000 100.000000 100.000000
mean 6.558007 351268.120000 -953.082693
std 291.829353 95357.663565 291.829353
min -2798.355490 98922.000000 -3757.996190
25% 2.722468 380542.250000 -956.918232
50% 4.385548 388444.500000 -955.255152
75% 24.302748 396579.750000 -935.337952
max 395.358681 418842.000000 -564.282019
Farmer count 100.000000 100.000000 100.000000
mean 0.584501 625447.200000 -959.056199
std 0.746574 261018.219814 0.746574
min 0.002446 278640.000000 -959.638254
25% 0.112017 332700.000000 -959.528683
50% 0.318692 665400.000000 -959.322008
75% 0.647193 905640.000000 -958.993507
max 2.724385 909360.000000 -956.916315
Simulated Annealing count 100.000000 100.000000 100.000000
mean 557.224499 625301.000000 -402.416201
std 117.554817 0.000000 117.554817
min 112.574731 625301.000000 -847.065969
25% 514.593218 625301.000000 -445.047482
50% 554.361541 625301.000000 -405.279159
75% 652.920338 625301.000000 -306.720362
max 752.943409 625301.000000 -206.697291

Trefethen function

In [33]:
def trefethen(X):
    x=X[0]
    y=X[1]
    return np.exp(np.sin(50.0*x))+np.sin(60.0*np.exp(y))+np.sin(70.0*np.sin(x))+np.sin(np.sin(80.0*y))-np.sin(10.0*(x+y))+0.25*(x**2+y**2)
In [34]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=dsc4
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(trefethen,x0,dsc4,nsa=1500,nfa=500,nbh=1500,maxticks=8,numbolts=40,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=-3.3068686474,i=i)
In [35]:
ax,fig=make_plot(trefethen,dsc4,600)
miau=ax.set_title(r'$Trefethen$',fontsize=18)
comparativa(bm)
Out[35]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 7.300000e+01 100.000000 7.300000e+01
mean 2.695998e+01 214272.660000 2.365311e+01
std 1.632895e+02 156941.623341 1.632895e+02
min -7.521672e-11 6172.000000 -3.306869e+00
25% -7.498180e-11 6172.000000 -3.306869e+00
50% -7.480949e-11 222801.000000 -3.306869e+00
75% -7.478951e-11 320923.750000 -3.306869e+00
max 1.124427e+03 567394.000000 1.121120e+03
Farmer count 1.000000e+02 100.000000 1.000000e+02
mean 5.258893e-07 147571.200000 -3.306868e+00
std 7.477985e-07 579.155219 7.485958e-07
min 6.997347e-09 146440.000000 -3.306869e+00
25% 1.004471e-07 147210.000000 -3.306869e+00
50% 2.174000e-07 147560.000000 -3.306868e+00
75% 6.499000e-07 147960.000000 -3.306868e+00
max 3.897400e-06 148920.000000 -3.306865e+00
Simulated Annealing count 1.000000e+02 100.000000 1.000000e+02
mean 1.879700e-01 375301.000000 -3.118899e+00
std 9.175537e-02 0.000000 9.175537e-02
min 4.745651e-03 375301.000000 -3.302123e+00
25% 1.241609e-01 375301.000000 -3.182708e+00
50% 1.661615e-01 375301.000000 -3.140707e+00
75% 2.607884e-01 375301.000000 -3.046080e+00
max 4.214797e-01 375301.000000 -2.885389e+00

Beale's Function

In [36]:
def beales(X):
    x=X[0]
    y=X[1]
    return (1.5-x+x*y)**2+(2.25-x+x*y**2)**2+(2.625-x+x*y**3)**2

dbeale=[[(-4.5,4.5)],[(-4.5,4.5)]]
In [37]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=dbeale
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(beales,x0,dbeale,nsa=500,nfa=100,nbh=1000,maxticks=8,numbolts=90,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=0,i=i)
In [38]:
ax,fig=make_plot(beales,dbeale,600)
miau=ax.set_title(r'$Beale$',fontsize=18)
comparativa(bm)
Out[38]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 1.000000e+02
mean 3.695901e-01 360997.000000 3.695901e-01
std 1.619122e+00 203688.180394 1.619122e+00
min 4.271768e-19 27464.000000 4.271768e-19
25% 5.294686e-17 172550.750000 5.294686e-17
50% 1.063693e-16 331146.500000 1.063693e-16
75% 2.508039e-16 565713.500000 2.508039e-16
max 7.399264e+00 734074.000000 7.399264e+00
Farmer count 1.000000e+02 100.000000 1.000000e+02
mean 3.355246e-06 38243.700000 3.355246e-06
std 4.226864e-06 4521.136814 4.226864e-06
min 2.000000e-08 20610.000000 2.000000e-08
25% 8.267337e-07 36810.000000 8.267337e-07
50% 1.815000e-06 38835.000000 1.815000e-06
75% 3.610000e-06 40995.000000 3.610000e-06
max 2.397000e-05 45090.000000 2.397000e-05
Simulated Annealing count 1.000000e+02 100.000000 1.000000e+02
mean 8.005326e-02 125301.000000 8.005326e-02
std 1.120617e-01 0.000000 1.120617e-01
min 5.653558e-04 125301.000000 5.653558e-04
25% 1.810908e-02 125301.000000 1.810908e-02
50% 3.791393e-02 125301.000000 3.791393e-02
75% 9.100665e-02 125301.000000 9.100665e-02
max 5.171038e-01 125301.000000 5.171038e-01

Goldstein-Price Function

In [39]:
def gprice(X):
    x=X[0]
    y=X[1]
    return (1+((x+y+1)**2)*(19-14*x+3*x**2-14*y+6*x*y+3*y**2))*(30+((2*x-3*y)**2)*(18-32*x+12*x**2+48*y-36*x*y+27*y**2))
dprice=[[(-2,2)],[(-2,2)]]
dpriceplot=[[(-2,1)],[(-2,1)]]
In [40]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=dprice
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(gprice,x0,dprice,nsa=500,nfa=200,nbh=100,maxticks=8,numbolts=50,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=3,i=i)
In [41]:
ax,fig=make_plot(gprice,dpriceplot,700)
miau=ax.set_title(r'$Goldstein-Price$',fontsize=18)
comparativa(bm)
Out[41]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 100.000000
mean -5.820677e-14 17422.330000 3.000000
std 8.420385e-15 6894.466892 0.000000
min -7.815970e-14 9114.000000 3.000000
25% -6.450396e-14 12726.250000 3.000000
50% -5.861978e-14 15635.000000 3.000000
75% -5.195844e-14 20433.000000 3.000000
max -3.508305e-14 48506.000000 3.000000
Farmer count 1.000000e+02 100.000000 100.000000
mean 8.430096e-06 54631.500000 3.000008
std 1.114397e-05 3348.726993 0.000011
min 2.573023e-08 33850.000000 3.000000
25% 1.692500e-06 53250.000000 3.000002
50% 5.210000e-06 55425.000000 3.000005
75% 1.145250e-05 56650.000000 3.000011
max 9.247367e-05 59550.000000 3.000092
Simulated Annealing count 1.000000e+02 100.000000 100.000000
mean 1.152638e+00 124323.500000 4.152638
std 2.755737e+00 9775.000000 2.755737
min 9.010734e-04 27551.000000 3.000901
25% 2.723642e-01 125301.000000 3.272364
50% 6.146259e-01 125301.000000 3.614626
75% 1.133861e+00 125301.000000 4.133861
max 2.687762e+01 125301.000000 29.877615

Matyas Function

In [42]:
def matyas(x):
    return 0.26*(x[0]**2+x[1]**2)-0.48*x[0]*x[1]
dmat=[[(-10,10)],[(-10,10)]]
In [43]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=dmat
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(matyas,x0,dmat,nsa=500,nfa=20,nbh=100,maxticks=8,numbolts=50,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=0,i=i)
In [44]:
ax,fig=make_plot(matyas,dmat,700)
miau=ax.set_title(r'$Matyas$',fontsize=18)
comparativa(bm)
Out[44]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 1.000000e+02 100.000000 1.000000e+02
mean 6.034837e-17 5128.600000 6.034837e-17
std 7.684060e-17 1811.664863 7.684060e-17
min 9.915984e-20 2844.000000 9.915984e-20
25% 8.199365e-18 3608.000000 8.199365e-18
50% 2.614786e-17 4754.000000 2.614786e-17
75% 8.328992e-17 6456.000000 8.328992e-17
max 3.117703e-16 10748.000000 3.117703e-16
Farmer count 1.000000e+02 100.000000 1.000000e+02
mean 1.814718e-06 3308.000000 1.814718e-06
std 3.088544e-06 419.578913 3.088544e-06
min 3.855696e-09 2300.000000 3.855696e-09
25% 3.200000e-07 3150.000000 3.200000e-07
50% 9.200000e-07 3300.000000 9.200000e-07
75% 2.142500e-06 3450.000000 2.142500e-06
max 2.575000e-05 5000.000000 2.575000e-05
Simulated Annealing count 1.000000e+02 100.000000 1.000000e+02
mean 1.539806e-04 125301.000000 1.539806e-04
std 1.435776e-04 0.000000 1.435776e-04
min 2.398465e-06 125301.000000 2.398465e-06
25% 4.663767e-05 125301.000000 4.663767e-05
50% 1.194390e-04 125301.000000 1.194390e-04
75% 2.066662e-04 125301.000000 2.066662e-04
max 7.029366e-04 125301.000000 7.029366e-04

Bukin Function number 6

In [45]:
def bukin6(X):
    x=X[0]
    y=X[1]
    return 100.0*np.sqrt(np.abs(y-0.01*x**2))+0.01*np.abs(x+10)
dbuk=[[(-15,5)],[(-3,3)]]
In [46]:
%%capture
runs=100
bm=benchmark_df(runs,names)
dom=dbuk
for i in range(runs):
    x0=random_in_domain(dom)
    sa,fa,bh=run_benchmark(bukin6,x0,dbuk,nsa=2500,nfa=400,nbh=5000,maxticks=8,numbolts=100,seed=i*10+1)
    record_benchmark(bm,sa,fa,bh,solution=0,i=i)
In [47]:
ax,fig=make_plot(bukin6,dbuk,700)
miau=ax.set_title(r'$Bukin6$',fontsize=18)
comparativa(bm)
Out[47]:
Error Evaluations Minimum Found
algorithm
Basin Hopping count 100.000000 100.000000 100.000000
mean 0.066295 686926.620000 0.066295
std 0.045132 32897.031314 0.045132
min 0.008447 640699.000000 0.008447
25% 0.026908 656879.500000 0.026908
50% 0.049903 679331.500000 0.049903
75% 0.108599 724850.000000 0.108599
max 0.152402 735149.000000 0.152402
Farmer count 100.000000 100.000000 100.000000
mean 0.098780 238266.000000 0.098780
std 0.023861 45621.457870 0.023861
min 0.028791 101000.000000 0.028791
25% 0.088563 229375.000000 0.088563
50% 0.104256 254550.000000 0.104256
75% 0.112314 268800.000000 0.112314
max 0.140246 283700.000000 0.140246
Simulated Annealing count 100.000000 100.000000 100.000000
mean 1.129800 625301.000000 1.129800
std 0.906916 0.000000 0.906916
min 0.182128 625301.000000 0.182128
25% 0.662732 625301.000000 0.662732
50% 0.919279 625301.000000 0.919279
75% 1.212323 625301.000000 1.212323
max 4.822966 625301.000000 4.822966
In [ ]: