Getting started


infergo benefits from modules introduced in Go 1.11, and relies on go/packages to import packages in a module-aware way, but will work with earlier versions of Go. Install Go. It is easier to build and use infergo with the make utility.


There are two installation options:

  1. If your Go project imports any of infergo packages and uses modules, infergo will be installed for you. deriv utility will be in $GOPATH/bin. As a side effect of providing examples with the main repository, the example binaries will also be installed in $GOPATH/bin. They are not needed there, you can remove them.

  2. Alternatively, you can clone the repository and build infergo from the cloned directory:

git clone
cd infergo
make install

This will install only deriv but not any example binaries. To build examples (and run each of them on the embedded self-check dataset), run

make examples

Hello world

The probabilistic “Hello world” example from the infergo repository shows a typical project layout and commands to build a Go program with an infergo model. Explore the example’s source code and Makefile. In a nutshell, one needs to:

  1. implement the model in a separate package,
  2. differentiate the model’s package with deriv,
  3. import the package with the differentiated model (ending in "ad/") in the file where inference is performed,
  4. build the project in the normal Go way.