<jupyter_start><jupyter_text>todo: correlation between trap size and   Tuned Ackley<jupyter_code>ta = tuned_ackley()
ta.visualise3d(lim=20, n=50)
ta.visulise_gradient(lim=20, n=50)
class single_experiment:
    def set_objective(self, objective_func):
        self.objective_func = objective_func

    def set_optimise(self, optimizer):
        self.optimizer = optimizer

    def do(self):
        optimal, optimum, statistics = self.optimizer.optimise(self.objective_func)
        if np.linalg.norm(optimal - self.objective_func.get_optimal()) < 1e-1 \
        or np.linalg.norm(optimum - self.objective_func.get_optimum()) < 1e-1:
            statistics['status'] = 'global minimum'
        elif statistics['status'] != 'diverge':
            statistics['status'] = 'local minimum'
        print(statistics['status'])
        statistics['trail'] = np.array([x,y])
        self.analyser = post_analysis(statistics, self.objective_func)<jupyter_output><empty_output><jupyter_text>plot the domain edge of tuned ackley function<jupyter_code>r = 19
angle = np.linspace(0, 2*np.pi, 100)
x = np.cos(angle) * 19
y = np.sin(angle) * 19<jupyter_output><empty_output><jupyter_text>original CMA<jupyter_code>np.random.seed(134)

# setup objective function
ta = tuned_ackley()

# setup adjust function optimizer
default = do_nothing()

# setup optmizer
cma = cma_es()
paras = {'mean0':np.array([[19.193], [22.221]]), 'std':np.ones((2,)) * 3, 'tol':1e-5, 'adjust_func':default}
cma.set_parameters(paras)

# boil down to one expreiment
exp1 = single_experiment()
exp1.set_objective(ta)
exp1.set_optimise(cma)
exp1.do()
exp1.analyser.plot_distance()
exp1.analyser.animate_moving_cluster()<jupyter_output><empty_output><jupyter_text>line search CMA<jupyter_code>np.random.seed(134)

# setup objective function
ta = tuned_ackley()

# setup adjust function optimizer
line = line_search(alpha=1, beta=0.1)

# setup optmizer
cmal = cma_es()
paras = {'mean0':np.array([[19.193], [22.221]]), 'std':np.ones((2,)) * 3, 'tol':1e-5, 'adjust_func':line}
cmal.set_parameters(paras)

# boil down to one expreiment
exp2 = single_experiment()
exp2.set_objective(ta)
exp2.set_optimise(cmal)
exp2.do()
exp2.analyser.plot_distance()
exp2.analyser.animate_moving_cluster()<jupyter_output><empty_output><jupyter_text>egg holder objective line search CMA<jupyter_code>np.random.seed(134)

# setup objective function
eg = eggholder()

# setup adjust function optimizer
line = line_search(alpha=1, beta=0.1)

# setup optmizer
cmal = cma_es()
paras = {'mean0':np.array([[19.193], [22.221]]), 'std':np.ones((2,)) * 300, 'tol':1e-5, 'adjust_func':line}
cmal.set_parameters(paras)

# boil down to one expreiment
exp3 = single_experiment()
exp3.set_objective(eg)
exp3.set_optimise(cmal)
exp3.do()
eg.visualise3d(lim=650, n=100)
exp3.analyser.plot_distance()<jupyter_output><empty_output><jupyter_text>original CMA<jupyter_code>np.random.seed(134)

# setup objective function
eg = eggholder()

# setup adjust function optimizer

# setup optmizer
cmal = cma_es()
paras = {'mean0':np.array([[19.193], [22.221]]), 'std':np.ones((2,)) * 300, 'tol':1e-5, 'adjust_func':default}
cmal.set_parameters(paras)

# boil down to one expreiment
exp4 = single_experiment()
exp4.set_objective(eg)
exp4.set_optimise(cmal)
exp4.do()
exp4.analyser.plot_distance()<jupyter_output><empty_output><jupyter_text>contrast between line search and Adam<jupyter_code>ad = adam()
x0 = np.array([[13.193], [12.221]])
paras = {'x0':x0, 'alpha':0.01, 'beta_1':0.9, 'beta_2':0.999, 'epsilon':1e-8, 'max_iter':100000, 'tol':1e-2}
ad.set_parameters(paras)
%time minimum, cnt = ad.optimise(ta)
print("found minimum position:{}, minimum:{}, iteration counts:{}".format(minimum.ravel(), ta.func(minimum), cnt))
line = line_search()
x0 = np.array([[13.193], [12.221]])
paras = {'x0':x0, 'alpha':1, 'beta':0.1, 'max_iter':100, 'tol':1e-2}
line.set_parameters(paras)
%time minimum, cnt = line.optimise(ta)
print("found minimum position:{}, minimum:{}, iteration counts:{}".format(minimum.ravel(), ta.func(minimum), cnt))
np.random.seed(134)

# setup objective function
ta = tuned_ackley()

# setup adjust function optimizer
line = line_search(alpha=1, beta=0.1)

# setup optmizer
cmal = cma_es()
paras = {'mean0':np.array([[13.193], [12.221]]), 'std':np.ones((2,)) * 3, 'tol':1e-5, 'adjust_func':default}
cmal.set_parameters(paras)

# boil down to one expreiment
exp5 = single_experiment()
exp5.set_objective(ta)
exp5.set_optimise(cmal)
exp5.do()
exp5.analyser.plot_distance()
exp5.analyser.animate_scatterplot_distance()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup