# Inference¶

*Marginal inference* (or just *inference*) is the process of reifying
the distribution on return values implicitly represented by a
stochastic computation.

(In general, computing this distribution is intractable, so often the goal is to compute an approximation to it.)

This is achieved in WebPPL using the `Infer`

function, which takes a
function of zero arguments representing a stochastic computation and
returns the distribution on return values represented as a
distribution object. For example:

```
Infer({model: function() {
return flip() + flip();
}});
```

`Infer`

will perform inference using enumeration
by default, but several other implementations of marginal inference
are also built into WebPPL. Information about the individual methods
is available here:

## Factor¶

The `factor`

operator is a used *within* marginal inference to alter
the implicit distribution of a stochastic computation by arbitrarily
weighting particular executions.

Note that because `factor`

*interacts* with inference, it cannot be
used outside of `Infer`

. Attempting to do so will produce an error.

Marginal inference is often used to perform Bayesian inference. In
this setting, the stochastic computation represents the prior, the
`factor`

operator is used to introduce observations, and marginal
inference computes the posterior distribution. This common pattern is
aided by the helper function `condition`

.

See dippl.org and agentmodels.org for an introduction to these ideas.