The model is a class to make accessing log P(X) and grad log P(X) functions easier. Models contain caches for both log P(X) and the gradient. This is intended to be used when building new samplers, users won’t typically need this.

There are two models currently. Model expects separate log P(X) and gradient functions. SingleModel expects one function that returns both log P(x) and the gradient.

Example usage:

def logp(X):

model = init_model(logp)
x = some_state
logp_val = model.logp(x)
grad_val = model.grad(x)
logp_val, grad_val = model(x)
class model.Model

Convenience class for building models from log-priors and log-likelihood.


# Linear regression model
def logp(b, sig):
    model = Model()
    # Estimate from data and coefficients 
    y_hat =, b)
    # Add log-priors for coefficients and model error
    model.add(smp.uniform(b, lower=-100, upper=100),

    # Add log-likelihood
    model.add(smp.normal(y, mu=y_hat, sig=sig))

    return model()

Return log P(X) and grad log P(X) given a state X