compileml.runtime — primitives

contributions_half_micro

def contributions_half_micro(model: dict, x: collections.abc.Sequence[float], baseline: collections.abc.Sequence[float]) -> tuple[list[int], int, int, int]

from compileml.runtime import contributions_half_micro

Per-feature contributions in half-micro units.

Returns (c2, full, fbase, residual2) where all values are integers, c2[j] is twice the micro-unit contribution of feature j, and residual2 satisfies the spec §7.4 identity exactly.

Computed per tree. A tree that does not split on feature j contributes nothing to j's main effect, because baselining j cannot change which leaf the row reaches. The same cancellation is sharper for pairs: the interaction term t(x) - t(x_i) - t(x_j) + t(x_ij) vanishes unless the tree splits on **both** i and j. So each tree only needs its own features enumerated, and the total is independent of how many features the model has.

Parameters#

NameTypeDefaultKind
modeldictrequiredpositional
xcollections.abc.Sequence[float]requiredpositional
baselinecollections.abc.Sequence[float]requiredpositional

Returns#

tuple[list[int], int, int, int]