Commit dbb4f61f authored by Jason Rhinelander's avatar Jason Rhinelander

Add reset(); fix predict_generic overload

parent 38fe2cc9
#include "pyeris/learning/BayesianLinear.hpp"
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
using namespace Eigen;
using namespace eris::learning;
......@@ -21,8 +22,8 @@ void bind_BL(py::module &m) {
"prior"_a, "y"_a, "X"_a, "sd_scale"_a = 1.0,
"Constructs a new belief distribution by combining the given prior with the given observations. sd_scale allows adjustment of the prior's variance to weakning (> 1) or strengthen (< 1) the prior relative to the new observations (the variance is multiplied by the square of `sd_scale`)")
.def(py::init<const BayesianLinear&, double>(),
"prior"_a, "sd_scale"_a,
"Constructs a new belief distribution by weakening (sd_scale > 1) or strengthening (sd_scale < 1) the variance of the belief")
"prior"_a, "sd_scale"_a = 1,
"Constructs a new belief distribution by copying an existing one. The variance of the resulting belief can be weakened (sd_scale > 1) or, less commonly, strengthened (sd_scale < 1). If `sd_scale == 1` (the default if omitted) the resulting distribution will have the same distribution as the original.")
.def("fixed_model_size", &BayesianLinear::fixedModelSize, "This method can be overridden by a subclass to return a non-zero number of parameters to indicate that the class supports only the given number of parameters; this will be checked during class construction. If it returns 0 (the default), the number of parameters is determined from the constructor parameters")
.def_property_readonly("noninformative", &BayesianLinear::noninformative, "Returns True if this model is noninformative (because it has not yet had sufficient data incorporated from an initial noninformative prior)")
......@@ -44,6 +45,7 @@ void bind_BL(py::module &m) {
"Single-function version of predict_generic: this takes just one function instead of a list of functions")
.def("discard", &BayesianLinear::discard, "Discards any previously obtained prediction draws. The next prediction will take new draws from the posterior distribution")
.def("reset", &PyBL<>::reset, "Resets the internal object state. The default implementation clears the last draw value, and calls discard()")
.def("draw", &BayesianLinear::draw, "Draws a set of beta and s^2 values according to the posterior and returns them in a column vector; elements 0 through K-1 are the drawn beta values, element K is the s^2 value. This method is used for prediction and can be overridden to affect the distribution of drawn values")
.def_property_readonly("last_draw", &BayesianLinear::lastDraw, "Accesses the last draw returned by draw(). The first K elements are the drawn beta values; the K+1th element is the drawn s^2 value")
......
......@@ -9,6 +9,7 @@ namespace pyeris { namespace learning {
template <class Base = BayesianLinear>
class PyBL : public Base {
public:
using Base::Base;
// Virtual methods:
......@@ -22,8 +23,9 @@ class PyBL : public Base {
return Base::draw();
}
MatrixXd predictGeneric(const Ref<const MatrixXd> &X, const std::vector<std::function<double(double y)>> &g, unsigned int draws = 0) override {
PYBIND11_OVERLOAD_NAME(MatrixXd, BayesianLinear, "predict_generic", predictGeneric, X, g, draws);
PYBIND11_OVERLOAD_NAME(MatrixXd, Base, "predict_generic", predictGeneric, X, g, draws);
}
void reset() override { PYBIND11_OVERLOAD(void, Base, reset); }
protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment