GithubHelp home page GithubHelp logo

pyprob / pyprob_cpp Goto Github PK

View Code? Open in Web Editor NEW
12.0 9.0 5.0 162 KB

C++ front end for the pyprob probabilistic programming library

License: BSD 2-Clause "Simplified" License

CMake 5.59% C++ 93.72% Dockerfile 0.69%

pyprob_cpp's Introduction

pyprob_cpp Build Status

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.

Installation

Dependencies

Install from source

Please see the provided Dockerfile for more specific instructions on how to install the dependencies and configure the build environment.

git clone [email protected]:pyprob/pyprob_cpp.git
cd pyprob_cpp
mkdir build && cd build && cmake ../src && cmake --build . && make install

Docker

A Docker image with the latest passing commit is automatically pushed to pyprob/pyprob_cpp:latest

https://hub.docker.com/r/pyprob/pyprob_cpp/

Example models

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.pdf

xt::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;
}

License

pyprob_cpp is distributed under the BSD License.

pyprob_cpp's People

Contributors

gbaydin avatar lukasheinrich avatar schroederdewitt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.