bartz.debug.sample_prior

bartz.debug.sample_prior(key, state)[source]

Draw the parameters of the model from their prior.

The prior is the one defined by the hyperparameters in state. Replaces the trees and the leaves, and, where they have a prior, the leaf and error precisions and the variable selection parameters. The data is left unchanged, and the fields derived from the parameters are updated to match.

Parameters:
  • key (Key[Array, '']) – A jax random key.

  • state (StateT) – A BART MCMC state, as created by bartz.mcmcstep.init.

Returns:

StateT – The state with new parameters.

Raises:

NotImplementedError – If the minimum number of points per node is set together with a prior on the variable selection probabilities, or if the data is sharded.

Notes

The minimum number of points per node restricts the prior support to the trees that satisfy the constraints on the data State.X. The trees are sampled exactly by rejection. This does not work with a random Sparsity.log_s, because then the constraints also change its marginal distribution.

The memory of the input state is re-used for the output state, so the input state can not be used any more, like with bartz.mcmcstep.step.