<jupyter_start><jupyter_text>Cross-in-Tray Function<jupyter_code>%%capture
obj = fx.crossintray
low, high = -6, 6
floor, ceiling = -2.0, -0.5
bounds = (np.array([low,low]),np.array([high,high]))
# Four possible solutions 
solutions = [(1.34941, 1.34941),(-1.34941, 1.34941),(1.34941, -1.34941),(-1.34941, -1.34941)]
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
closest = min([np.sqrt((s[0]-best_x)**2 + (s[1]-best_y)**2 ) for s in solutions])
print('Distance error: %.2f' % closest)
HTML(anim.to_html5_video())<jupyter_output>Final cost: -2.06
Distance error: 0.00<jupyter_text>Easom Function<jupyter_code>%%capture
obj = fx.easom
low, high = -5, 5
floor, ceiling = -1, 0.2
bounds = (np.array([low,low]),np.array([high,high]))
solution = (np.pi, np.pi)
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
print('Distance error: %.2f' % np.sqrt((solution[0]-best_x)**2 + (solution[1]-best_y)**2 ))
HTML(anim.to_html5_video())<jupyter_output>Final cost: -1.00
Distance error: 0.00<jupyter_text>Eggholder Function<jupyter_code>%%capture
obj = fx.eggholder
low, high = -512, 512
floor, ceiling = -1000, 1000
bounds = (np.array([low,low]),np.array([high,high]))
# Four possible solutions 
solution = (-512, 404.3219)
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=1)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
print('Distance error: %.2f' % np.sqrt((solution[0]-best_x)**2 + (solution[1]-best_y)**2 ))
HTML(anim.to_html5_video())<jupyter_output>Final cost: -894.58
Distance error: 49.90<jupyter_text>Himmelblau Function<jupyter_code>%%capture
obj = fx.himmelblau
low, high = -5, 5
floor, ceiling = -1.5, 1000
bounds = (np.array([low,low]),np.array([high,high]))
# Four possible solutions 
solutions = [(3.0,2.0),(-2.805118,3.131312),(-3.779310,-3.283186),(3.584428,-1.848126)]
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)])
m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=cm.bwr)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
closest = min([np.sqrt((s[0]-best_x)**2 + (s[1]-best_y)**2 ) for s in solutions])
print('Distance error: %.2f' % closest)
HTML(anim.to_html5_video())<jupyter_output>Final cost: 0.00
Distance error: 0.00<jupyter_text>Holder Table Function<jupyter_code>%%capture
obj = fx.holdertable
low, high = -10,10
floor, ceiling = -20, 0
bounds = (np.array([low,low]),np.array([high,high]))
# Four possible solutions 
solutions = [(8.05502, 9.6645),(-8.05502, 9.6645),(8.05502, -9.6645),(-8.05502, -9.6645)]
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
closest = min([np.sqrt((s[0]-best_x)**2 + (s[1]-best_y)**2 ) for s in solutions])
print('Distance error: %.2f' % closest)
HTML(anim.to_html5_video())<jupyter_output>Final cost: 0.00
Distance error: 12.58<jupyter_text>Sphere Function<jupyter_code>%%capture
obj = fx.sphere
low, high = -1,1
floor, ceiling = 0, 2
bounds = (np.array([low,low]),np.array([high,high])) 
solution = (0,0)
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
print('Distance error: %.2f' % np.sqrt((solution[0]-best_x)**2 + (solution[1]-best_y)**2 ))
HTML(anim.to_html5_video())<jupyter_output>Final cost: 0.00
Distance error: 0.00<jupyter_text>Three Hump Camel Function<jupyter_code>%%capture
obj = fx.threehump
low, high = -5, 5
floor, ceiling = 0, 2000
bounds = (np.array([low,low]),np.array([high,high]))
solution = (0,0)
options = {'c1':1.2, 'c2':1.7, 'w':0.3}

optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options, bounds=bounds)
cost, (best_x, best_y) = optimizer.optimize(obj, 100)

m = Mesher(func=obj, limits=[(low,high),(low,high)], delta=0.01)
d = Designer(limits=[(low,high),(low,high),(floor, ceiling)], colormap=dmap)
a = Animator(repeat=False, interval=150) # , repeat_delay=2000)
pos_history_3d = m.compute_history_3d(optimizer.pos_history[:50])
anim = plotters.plot_surface(pos_history_3d, mesher=m, designer=d, animator=a)
print('Final cost: %.2f' % cost)
print('Distance error: %.2f' % np.sqrt((solution[0]-best_x)**2 + (solution[1]-best_y)**2 ))
HTML(anim.to_html5_video())<jupyter_output>Final cost: 0.00
Distance error: 0.00
{'fraction_non_alphanumeric': 0.19926719278466742, 'fraction_numerical': 0.07032130777903044, 'mean_word_length': 7.300584795321638, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '167489', 'license': 'MIT', 'n_tokens_mistral': 3153, 'n_tokens_neox': 2874, 'n_words': 486, 'path': 'images/pyswarms/Objective Functions Demo.ipynb', 'repo_name': 'jayspeidell/jayspeidell.github.io', 'size': '7096'}