bartz.mcmcstep.Forest¶
- class bartz.mcmcstep.Forest(var_tree, split_tree, affluence_tree, leaf_tree, leaf_unit, offset, grow_prop_count, prune_prop_count, grow_acc_count, prune_acc_count, max_split, blocked_vars, p_nonterminal, p_propose_grow, leaf_indices, to_prune, move_node, count_tree, prec_tree, min_points_per_decision_node, min_points_per_leaf, log_trans_prior, log_likelihood, leaf_prior_cov_inv, log_s, theta, a, b, rho)[source]¶
Represents the MCMC state of a sum of trees.
- var_tree: UInt[Array, '*chains num_trees half_tree_size']¶
Variables/predictors/axes of decision rules.
- split_tree: UInt[Array, '*chains num_trees half_tree_size']¶
Cutpoints/boundaries of decision rules.
- affluence_tree: Bool[Array, '*chains num_trees half_tree_size']¶
Marks leaves that can be grown.
- leaf_tree: Float[Array, '*chains num_trees 2*half_tree_size'] | Float[Array, '*chains num_trees k 2*half_tree_size']¶
The leaf values, in units of
leaf_unit. The function computed by the forest isoffset + leaf_unit * (sum of leaves).
- leaf_unit: Float32[Array, ''] | Float32[Array, 'k']¶
The storage unit of the leaves. Keeps the stored values O(1) whatever the data units, so they do not under/overflow narrow
leaf_treedtypes. Set to the marginal prior standard deviation of a leaf, rounded to a power of two so converting to and from data units is exact.
- offset: Float32[Array, ''] | Float32[Array, 'k']¶
Constant shift added to the scaled sum of trees, see
leaf_tree.
- grow_prop_count: Int32[Array, '*chains']¶
The number of grow proposals made during the last MCMC step.
- prune_prop_count: Int32[Array, '*chains']¶
The number of prune proposals made during the last MCMC step.
- grow_acc_count: Int32[Array, '*chains']¶
The number of grow moves accepted during the last MCMC step.
- prune_acc_count: Int32[Array, '*chains']¶
The number of prune moves accepted during the last MCMC step.
- max_split: UInt[Array, 'p']¶
The maximum split index for each predictor.
- blocked_vars: UInt[Array, 'q'] | None¶
Indices of not to be used variables/predictors. This shall include at least all the
ithat yieldmax_split[i] == 0, otherwise behavior is undefined.
- p_nonterminal: Float32[Array, '2*half_tree_size']¶
The prior probability of each node being nonterminal (conditional on its ancestors leaving at least one available decision rule). Includes the nodes at maximum depth which shall be set to 0.
- p_propose_grow: Float32[Array, 'half_tree_size']¶
The unnormalized probability of picking a leaf for a grow proposal.
- leaf_indices: UInt[Array, '*chains num_trees n']¶
The index of the leaf each datapoint falls into, for each tree, in the largest version of the tree compatible with the last moves.
A pending prune (accepted prune or rejected grow, marked per-tree by
to_prune) is not yet applied to the indices;stepfolds it in at the beginning of the next iteration. Evaluating the trees at these indices is correct anyway becauseleaf_treemirrors the value of a pruned node onto its dangling children.
- to_prune: Bool[Array, '*chains num_trees']¶
Whether the last move on each tree ended in a prune (accepted prune or rejected grow) whose application to
leaf_indicesis still pending.
- move_node: Int32[Array, '*chains num_trees']¶
The node the last move on each tree operated on (the leaf to grow or the node to prune). Meaningful only where
to_pruneis set.
- count_tree: UInt32[Array, '*chains num_trees 2*half_tree_size'] | None¶
The number of datapoints per leaf. Valid at the leaves and at the nodes involved in the latest moves, dirty elsewhere.
Noneif there are per-datapoint error scales and no minimum-points-per-node constraints, which makes the counts unused.
- prec_tree: Float32[Array, '*chains num_trees 2*half_tree_size'] | Float32[Array, '*chains num_trees k k 2*half_tree_size'] | None¶
The sum of
State.prec_scaleover the datapoints in each leaf, in the same units; valid/dirty likecount_tree.Noneif there are no per-datapoint error scales, in which casecount_treetakes its place.
- min_points_per_decision_node: Int32[Array, ''] | None¶
The minimum number of data points in a decision node.
- log_trans_prior: Float32[Array, '*chains num_trees'] | None¶
The log transition and prior Metropolis-Hastings ratio for the proposed move on each tree.
- leaf_prior_cov_inv: Float32[Array, ''] | Float32[Array, 'k k'] | None¶
The prior precision matrix of a leaf, conditional on the tree structure (a scalar inverse variance for univariate). The prior mean of a leaf is zero; the prior covariance of the sum of trees is
num_trees * leaf_prior_cov_inv^-1.
- log_s: Float32[Array, '*chains p'] | None¶
The logarithm of the prior probability for choosing a variable to split along in a decision rule. Not normalized. Variables that do not have any available decision rule at a given node are masked away. If
None, use a uniform distribution.
- theta: Float32[Array, '*chains'] | None¶
The concentration parameter for the Dirichlet prior on the variable distribution
s. If not set,log_sis left constant.