bartz.mcmcstep.Forest¶
- class bartz.mcmcstep.Forest(var_tree, split_tree, affluence_tree, leaf_tree, leaf_unit, offset, used_trees, 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, tree_life, count_tree, prec_tree, min_points_per_decision_node, min_points_per_leaf, log_trans_prior, log_likelihood, sum_trees_prior_cov_inv, sparsity)[source]¶
Represents the MCMC state of a sum of trees.
- var_tree: UInt[Array, '*chains num_trees max_num_leaves']¶
Variables/predictors/axes of decision rules.
- split_tree: UInt[Array, '*chains num_trees max_num_leaves']¶
Cutpoints/boundaries of decision rules.
- affluence_tree: Bool[Array, '*chains num_trees max_num_leaves']¶
Marks leaves that can be grown.
- leaf_tree: Float[Array, '*chains num_trees max_num_leaves'] | Float[Array, '*chains num_trees k max_num_leaves']¶
The leaf values, in units of
leaf_unit, laid out as inbartz.grove.TreeHeaps. 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 with all the trees in use, 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.
- used_trees: Int32[Array, '*chains'] | None¶
The number of trees in use,
Noneif all the trees are always in use. Only the firstused_treestrees in the arrays are part of the model;stepskips the others in the sequential accept/reject loop and, on gpu or with few trees in use, in the update ofleaf_indices. The other trees shall be lone roots with zero leaves, asstepkeeps them, such that the function computed by the forest is the sum of all the trees anyway.
- 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. The predictors with 0 are ignored, as if they did not exist.
- blocked_vars: UInt[Array, 'q'] | None¶
The indices of the predictors with
max_split == 0, padded with values >= p, orNoneif there are none. Redundant withmax_split, it speeds up proposing moves.
- p_nonterminal: Float32[Array, '2*max_num_leaves']¶
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, 'max_num_leaves']¶
The unnormalized probability of picking a leaf for a grow proposal.
- leaf_indices: UInt[Array, '*chains num_trees n']¶
The index in
leaf_treeof 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 right child, while the left one shares its index.
- 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.
- tree_life: Int32[Array, '*chains num_trees']¶
The number of MCMC steps since each tree was last pruned to a lone root, or since the start.
- count_tree: UInt32[Array, '*chains num_trees max_num_leaves'] | None¶
The number of datapoints at each index in
leaf_indices, so in the same version of each tree: with a pending prune, the children are still counted apart.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 max_num_leaves'] | Float32[Array, '*chains num_trees k k max_num_leaves'] | None¶
The sum of
State.prec_scaleover the datapoints at each index inleaf_indices, in the same units.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. Arbitrary for a tree without an allowed move, like those not in use.
- log_likelihood: Float32[Array, '*chains num_trees'] | None¶
The log likelihood ratio, dirty like
log_trans_prior.
- sum_trees_prior_cov_inv: Wishart¶
The prior precision matrix of the sum of trees (a scalar inverse variance for univariate), with its Wishart prior. Conditional on the tree structures, the leaves of the trees in use have zero mean and precision
used_trees * sum_trees_prior_cov_inv.value(num_treesifused_treesis not set), such that the prior covariance of the sum of trees does not depend on the number of trees. IfWishart.nuisNone, the precision is held fixed.