Skip to content

Commit

Permalink
removed redundant options in lci.pcmaes call by detecting parameter o…
Browse files Browse the repository at this point in the history
…bject type + example use file, ref #125 #116
  • Loading branch information
Emmanuel Benazera committed Feb 20, 2015
1 parent 5daa2e2 commit 50dfc28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/lcmaes_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def to_params(x0, sigma0, str_algo=b'acmaes', fplot=None, lbounds=None, ubounds=
getattr(p, setter)(val) # call setter with value
return p

def pcmaes(fitfunc,p,has_bounds=False,has_scaling=False):
def pcmaes(fitfunc,p):
has_bounds = isinstance(p,lcmaes.CMAParametersPB) or isinstance(p,lcmaes.CMAParametersPBS)
has_scaling = isinstance(p,lcmaes.CMAParametersNBS) or isinstance(p,lcmaes.CMAParametersPBS)
print(has_bounds)
print(has_scaling)
if not has_bounds:
if not has_scaling:
return lcmaes.pcmaes(fitfunc,p)
Expand Down
17 changes: 17 additions & 0 deletions python/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import lcmaes_interface as lci

# setup input parameters
myfun = lambda x: sum([xi**2 for xi in x]) # myfun accepts a list of numbers as input
x0 = [2.1] * 10
sigma0 = 0.1
mlbounds = [-4]*10
mubounds = [4]*10

# run optimization via lci
res = lci.pcmaes(lci.to_fitfunc(myfun),
lci.to_params(x0, sigma0,
str_algo=b'abipop',quiet=True, # b=bytes, unicode fails
lbounds=mlbounds,ubounds=mubounds,
scaling=False,
restarts=2))
lci.plot() # plot from file set in lci.to_params

0 comments on commit 50dfc28

Please sign in to comment.