pyprob_cpp is a C++ library providing a lightweight interface to the pyprob probabilistic programming library implemented in Python. The two components communicate through the PPX
interface that allows execution of models and inference engines in
separate programming languages, processes, and machines connected over a
network.
Please see the main pyprob documentation for more information.
Several example models in C++ are provided in this repository, under the src/pyprob_cpp/test folder.
These mirror the Python test cases in the main pyprob repository and are used as continuous integration tests ensuring that pyprob and pyprob_cpp work seamlessly together.
Here is how a simple model looks like:
#include <pyprob_cpp.h>// Gaussian with unkown mean// http://www.robots.ox.ac.uk/~fwood/assets/pdf/Wood-AISTATS-2014.pdfxt::xarray<double> forward(xt::xarray<double> observation)
{ auto prior_mean = 1; auto prior_stddev = std::sqrt(5); auto likelihood_stddev = std::sqrt(2); auto prior = pyprob_cpp::distributions::Normal(prior_mean, prior_stddev); auto mu = pyprob_cpp::sample(prior); auto likelihood = pyprob_cpp::distributions::Normal(mu, likelihood_stddev); for (auto & o : observation)
{ pyprob_cpp::observe(likelihood, o);
} return mu;
}int main(int argc, char *argv[])
{ auto serverAddress = (argc > 1) ? argv[1] : "tcp://*:5555";
pyprob_cpp::Model model = pyprob_cpp::Model(forward, xt::xarray<double> {}, "Gaussian with unknown mean C++");
model.startServer(serverAddress); return 0;
}