-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simple workflow under python #116
Comments
Yes, this almost exactly what I do with the C++ exe: opening a second shell allows to look at the plot while optimization is still running. Let's see how to do this with the python bindings, the first part is rather easy: import lcmaes
p = lcmaes.make_simple_parameters(x,sigma,lambda_,seed)
p.set_fplot(filename)
cmasols = lcmaes.pcmaes(some_function,p) The main difference I see between your example and using the libcmaes Python bindings is that at the moment the plot function is outside the bindings, so we cannot yet do In order to add the missing line: lcmaes.plot(filename) I need to add pure Python code into the Boost-python generated code. I did check and this appears possible with some work. Another simple though less elegant solution would be for me to refactor import lcmaesplt
lcmaesplt.plot(filename) I believe you would need a Another option could be based on #110, thus allowing to use your existing plotting script. Finally, at the moment you can run the optimization in Python using lcmaes and plot the results online with
My preference goes to adding the |
I have no objections to another import, so adding |
Regarding
I think the burden of setting I believe the last line of the example should read:
or
EDIT: |
I am still rooting for conversion to legacy format being available, as I have additional functionalities (e.g. |
OK, this is actually simpler (anything that doesn't require dealing with boost-python is simpler...)
Yes, and the Python behavior here differs from the C++ API one because I need to figure out how to pass default arguments with Boost-python. This is a pure engineering problem, and I've looked it up, so it is now a task. (links for my own ref, http://stackoverflow.com/questions/6050996/boost-python-overloaded-functions-with-default-arguments-problem and http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/overloads.html and http://boost.cppll.jp/HEAD/libs/python/doc/tutorial/doc/default_arguments.html ) |
I see, a simple solution would be that |
It already does this. I am working on using the boost python overload macros right now, but along with templates, this is not compiling for the most complicated cases for now... I've successfully tackled the make_simple_parameters function to be called as p = lcmaes.make_simple_parameters(x,sigma) or
|
…e_parameters in Python bindings, ref #116
The fix above allows support for default arguments to
I don't believe this is too problematic as in these cases |
FYI, my Python kernel dies when I use |
Yes, good point, this is in the lib, making a dedicated ticket. Also, is |
|
my curiosity is picked :) I thought of it with gradient a few months ago, as I was curious of how a particular run would do with the gradient offspring only. |
The main problem is step-size control. TPA needs two additional samples. Unmodified CSA produces probably far too small step-sizes. This can be fixed in some way or the other (and the famous 1/5th success rule is always available). |
Here is my current minimal Python workflow given the few additions and fixes (on 'dev' branch): import lcmaes
import cma_multiplt as lcmaplt
x = [10]*10
sigma = 0.1
p = lcmaes.make_simple_parameters(x,sigma)
p.set_str_algo("acmaes")
p.set_fplot('simple.dat')
# objective function.
def nfitfunc(x,n):
val = 0.0
for i in range(0,n):
val += x[i]*x[i]
return val
# pass the function and parameters to cmaes, run optimization and collect solution object.
cmasols = lcmaes.pcmaes(lcmaes.fitfunc_pbf.from_callable(nfitfunc),p)
lcmaplt.plot('simple.dat') Note that I've moved EDIT: the minimal workflow is now in |
Excellent, I also like a lot that the docs now appear in the Python objects! A small gimmick to further shorten the example: def nfitfunc(x, n):
assert len(x) == n # not necessary
return sum([y**2 for y in x]) or even nfitfunc = lambda x, n: sum([y**2 for y in x]) If you insist in using |
|
It is in |
You are right that somehow it isn't. Fixing it now. |
Not sure what happened, this should be fixed with 328bd00 |
I am sure that's a stupid problem, but I don't find a bottom to keep my fork up-to-date with your repo. |
Not sure what you mean. On branch |
Sorry, I mean my fork on github, operating from within the browser (not specifically related to the plotting script). But even from a local fork, I wouldn't know how to sync it with its origin. Maybe it's just not meant to work like this. |
Just merged the EDIT: I believe this should fulfill this ticket |
Conflicts: tests/cma_multiplt.py
My most common use-case when applying CMA-ES in Python or Octave looks something like this
If the optimization takes longer, I will open a second Python shell to do the plotting "online". This works, because
cma.plot()
reads in the output written on disc.cma.plot('cma_data_on_some_function')
would plot the respective data (cma.fmin
must have been called with the respective output filename option). Can we established a similar use-case withlcmaes
?The text was updated successfully, but these errors were encountered: