Skip to content

Major Interface Changes in v0.7

null-a edited this page May 26, 2016 · 3 revisions

ERPs replaced with Distributions

A primitive distribution is now represented as a Distribution object rather than an ERP and an array of parameters.

Each ERP is replaced with a function to create a corresponding Distribution. These functions take an object containing named parameters as their only argument.

Sampling

As a result, the sample primitive now takes a Distribution as its only argument.

An example makes this clearer:

// previously
sample(gaussianERP, [0, 1])
// now
sample(Gaussian({mu: 0, sigma: 1}))

The sampling helper functions still exist:

gaussian(0, 1) // still works
gaussian({mu: 0, sigma: 1}) // also works

Scoring

The score (log probability) of a value under a Distribution can be computed like so:

// previously
gaussianERP.score([0, 1], x)
// now
Gaussian({mu: 0, sigma: 1}).score(x)

Computing the score of a value under a marginal distribution is a special case of this:

var marginal = Enumerate(flip)
// previously
marginal.score([], x)
// now
marginal.score(x)

categoricalERP & deltaERP

Previously deltaERP and categoricalERP were not ERPs, they were functions that returned ERPs. This inconsistency has been remove -- Categorical and Delta are each represented as a Distribution.

// sampling
// previously
sample(categoricalERP([.5, .5], [a, b]), [])
// now
sample(Categorical({ps: [.5, .5], vs: [a, b]}))

// scoring
// previously
categoricalERP([.5, .5], [a, b]).score([], a)
// now
Categorical({ps: [.5, .5], vs: [a, b]}).score(a)

// sampling
// previously
sample(deltaERP(val), [])
// now
sample(Delta({v: val}))

// scoring
// previously
deltaERP(val).score([], x)
// now
Delta({v: val}).score(x)

Misc

  • multiplexERP has been removed.

Unified Inference Interface

The Infer function now provides a unified interface for computing marginals/performing inference. For example:

// previously
MCMC(function() {
  // some code
  //
}, {samples: 1})

// now
Infer({method: 'MCMC', samples: 1}, function() {
  // some code
  //
})