Yelp / MOE

A global, black box optimization engine for real world metric optimization.
Other
1.31k stars 140 forks source link

[C++] Make covariance objects constructible from Python #378

Open suntzu86 opened 10 years ago

suntzu86 commented 10 years ago

Right now, the boost C++/Python interface assumes the user wants SquareExponential. Operations that require covariance classes currently just accept a vector of hyperparameters, and then they always construct the sqexp object. So far, this hasn't been a limitation for our use cases.

But the C++ has several more covariance options but they are not available through the python interface (without recompilation, yuck).

Instead, we should...

  1. Expose covariance objects to Python via class_. These objects should come with the ability to get the number of hyperparameters and get/set hyperparameters at a minimum. It'd be nice if they could also compute covariance and its various derivatives. This would be easier with #159 done so we wouldn't need a ton of wrapper functions.
  2. Set up SquareExponential in python/cpp_wrappers/covariance.py to construct the object from step 1.
  3. For the functions exposed to python, instead of:

    foo(double * hyperparameters, ...) {
    SquareExponential cov(hyperparameters);
    do_stuff(cov, ...);
    }

    We should now do:

    foo(CovarianceInterface& cov, ...) {
    do_stuff(cov, ...);
    }

    and in Python, change calls to foo(cov, ...) where cov is one of the objects constructed from step 2 instead of just passing hyperparams around.

C++ covariance functions all inherit (virtually) from CovarianceInterface, so no modification outside of the gpp_python_* files will be necessary.