CMA-ES / libcmaes

libcmaes is a multithreaded C++11 library with Python bindings for high performance blackbox stochastic optimization using the CMA-ES algorithm for Covariance Matrix Adaptation Evolution Strategy
Other
321 stars 78 forks source link

python docs on classes are lacking help for instantiation #126

Open nikohansen opened 9 years ago

nikohansen commented 9 years ago

For example,

import lcmaes
help(lcmaes.CMAParametersPB)

yields

Help on class CMAParametersPB in module lcmaes:

class CMAParametersPB(Boost.Python.instance)
 |  CMAParameters object for problems with bounded parameters
 |  
 |  Method resolution order:
 |      CMAParametersPB
 |      Boost.Python.instance
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  __init__(...)
 |      __init__( (object)arg1) -> None
 |  
 |  __reduce__ = <unnamed Boost.Python function>(...)
 |  
 |  dim(...)
 |      dim( (CMAParametersPB)arg1) -> int :
[...]

which is not particularly helpful to find out how to instantiate the CMAParametersPB class. At the moment I don't see a way how I could figure this out within Python.

beniz commented 9 years ago

This is because there's no constructor for CMAParametersPB for the Python object (nor is there for CMAParametersNB, etc...), and thus no custom __init__ function. The current reason for this is that at least one of the useful constructors in C++ requires a C++ vector of double. Boost python supports binding C++ to Python constructors but I couldn't find how pass non basic types such as vectors. My current understanding is that these types need to be transformed into Python types (such as C++ vector to Python array), and this is what make_parameters_pwqb, make_simple_parameters and other methods do.

So in summary, the constructor for CMAParameterPB is make_parameters_pwqb at the moment.

I am not happy with the current solution, and I have been looking at it one more time briefly, but I don't yet see how to do this simply on the Boost python side.

Maybe in pure Python on top of the lcmaes module ?

nikohansen commented 9 years ago

I agree, it shouldn't be too difficult to rebuild the desired interface in Python instead.

beniz commented 9 years ago

I believe a pure Python slight encapsulation of CMAParameter class could take place in the lcmaes_interface of #125, once accepted.