Skip to content

Commit

Permalink
AIS now throws an error when a hard factor statement is encountered.
Browse files Browse the repository at this point in the history
  • Loading branch information
null-a committed Jul 30, 2018
1 parent 017b63b commit 50b8a98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
21 changes: 16 additions & 5 deletions docs/functions/other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,29 @@ Other
``model``. This is not an unbiased estimator, rather it is a
stochastic lower bound. [grosse16]_

The sequence of intermediate distributions used by AIS is obtained
by scaling the contribution to the overall score made by the
``factor`` statements in ``model``.

When a model includes hard factors (e.g. ``factor(-Infinity)``,
``condition(bool)``) this approach does not produce an estimate of
the expected quantity. Hence, to avoid confusion, an error is
generated by ``AIS`` if a hard factor is encountered in the model.

The length of the sequence of distributions is given by the
``steps`` option. At step ``k`` the score given by each ``factor``
is scaled by ``k / steps``.


The MCMC transition operator used is based on the :ref:`MH kernel
<mh>`.


The following options are supported:

.. describe:: steps

The length of the sequence of intermediate distributions used by
AIS. This sequence is obtained by scaling the contribution to
the overall score made by the ``factor`` statements in
``model``. At step ``k`` the score given by each ``factor`` is
scaled by ``k / steps``.
The length of the sequence of intermediate distributions.

Default: ``20``

Expand Down
5 changes: 4 additions & 1 deletion src/inference/ais.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ module.exports = function(env){
var mhStepKernel = function(k, trace) {
weight += increment * trace.scoreAllFactors();
curStep += 1;
return MHKernel(k, trace, {factorCoeff: curStep * increment});
return MHKernel(k, trace, {
factorCoeff: curStep * increment,
allowHardFactors: false
});
};

var mhChainKernel = kernels.repeat(options.steps, mhStepKernel);
Expand Down
7 changes: 6 additions & 1 deletion src/inference/mhkernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ module.exports = function(env) {
runOpts = util.mergeDefaults(runOpts, {
proposalBoundary: 0,
exitFactor: 0,
factorCoeff: 1
factorCoeff: 1,
allowHardFactors: true
});

this.proposalBoundary = runOpts.proposalBoundary;
this.exitFactor = runOpts.exitFactor;

this.factorCoeff = runOpts.factorCoeff;
assert.ok(0 <= this.factorCoeff && this.factorCoeff <= 1);
this.allowHardFactors = runOpts.allowHardFactors;

this.cont = cont;
this.oldTrace = oldTrace;
Expand All @@ -65,6 +67,9 @@ module.exports = function(env) {
MHKernel.prototype.factor = function(s, k, a, score) {
// Optimization: Bail early if we know acceptProb will be zero.
if (ad.value(score) === -Infinity) {
if (!this.allowHardFactors) {
throw new Error('Hard factor statements are not allowed.');
}
return this.finish(this.oldTrace, false);
}
this.trace.numFactors += 1;
Expand Down

0 comments on commit 50b8a98

Please sign in to comment.