Skip to content

Commit

Permalink
minor bugfix in randomsearch with new util.score
Browse files Browse the repository at this point in the history
  • Loading branch information
claesenm committed Apr 22, 2015
1 parent 1e788b5 commit e40c0ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bin/examples/python/parabola.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
optima = dict([(s, []) for s in solvers])

# we run experiments a number of times to estimate each solver's variance
particle_details = None
for i in range(200):
xoff = random.random()
yoff = random.random()
Expand All @@ -22,6 +23,7 @@ def f(x, y):
optima[solver].append(details.optimum)
logs[solver] = np.array([details.call_log['args']['x'],
details.call_log['args']['y']])
if solver == 'particle swarm': particle_details = details

# plot results
print('plotting results')
Expand All @@ -36,6 +38,7 @@ def f(x, y):

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
plt.figure(1)
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10, alpha=0.5)
for i, solver in enumerate(solvers):
Expand All @@ -45,9 +48,9 @@ def f(x, y):
plt.ylim([-5, 5])
plt.axis('equal')
plt.legend(solvers)
plt.show()
plt.draw()
#plt.savefig('parabola_solver_traces.png', transparant=True)
plt.clf()
#plt.clf()

from collections import OrderedDict
log_optima = OrderedDict()
Expand All @@ -58,9 +61,22 @@ def f(x, y):
means[k] = sum(log_optima[k]) / len(v)
std[k] = np.std(log_optima[k])

plt.figure(2)
plt.barh(np.arange(len(means)), means.values(), height=0.8, xerr=std.values(), alpha=0.5)
plt.xlabel('number of correct digits')
plt.yticks(np.arange(len(means))+0.4, list(means.keys()))
plt.tight_layout()
plt.show()
#plt.savefig('parabola_solver_precision.png', transparant=True)




num_evals = len(particle_details.call_log['values'])
best_fitness = [min(particle_details.call_log['values'][:x]) for x in range(1, 1 + num_evals)]
avg_fitness = [sum(particle_details.call_log['values'][:x]) / x for x in range(1, 1 + num_evals)]

plt.figure(3)
plt.plot(range(num_evals), best_fitness, 'b')
plt.plot(range(num_evals), avg_fitness, 'r')
plt.show()
1 change: 1 addition & 0 deletions optunity/solvers/RandomSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ..functions import static_key_order
from .solver_registry import register_solver
from .util import Solver, _copydoc, shrink_bounds, uniform_in_bounds
import util

@register_solver('random search',
'random parameter tuples sampled uniformly within box constraints',
Expand Down

0 comments on commit e40c0ee

Please sign in to comment.