Implementation:Interpretml Interpret Tensor Hpp
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, EBM_Core |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
Declares the Tensor class which stores multi-dimensional score tensors representing EBM term updates and model weights.
Description
The Tensor.hpp header defines the Tensor class, the central data structure for storing EBM model scores across multi-dimensional feature spaces. A Tensor manages a multi-dimensional array of FloatScore values indexed by feature bin indices, along with per-dimension split point information. The class supports both expanded (fully materialized) and compressed (sliced) representations. In expanded mode, scores are directly addressable by bin indices; in compressed mode, only bins at split boundaries are stored. The header includes extensive design documentation for a planned restructuring to support efficient network transfer (for distributed/MPI environments) and GPU communication. Key internal structures include DimensionInfoStack (for traversal state), DimensionInfoStackExpand (for expansion operations), and DimensionInfo (for per-dimension metadata tracking split counts and capacities).
Usage
Used throughout the boosting process to store per-term model score updates. BoosterCore maintains arrays of Tensors for both the current and best models. Tensors are updated during GenerateTermUpdate and accessed during ApplyTermUpdate. They are also used to return model scores to the Python layer.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File: shared/libebm/Tensor.hpp
Signature
class Tensor final {
struct DimensionInfoStack final { ... };
struct DimensionInfoStackExpand final { ... };
struct DimensionInfo final {
size_t m_cSlices;
size_t m_cSliceCapacity;
UIntSplit* m_aSplits;
};
size_t m_cTensorScoreCapacity;
size_t m_cTensorScores;
FloatScore* m_aTensorScores;
size_t m_cDimensionsMax;
size_t m_cDimensions;
bool m_bExpanded;
// DimensionInfo m_aDimensions[]; // struct hack
static Tensor* Allocate(const size_t cDimensionsMax, const size_t cScores);
static void Free(Tensor* const pTensor);
ErrorEbm SetCountSlices(const size_t iDimension, const size_t cSlices);
ErrorEbm EnsureTensorScoreCapacity(const size_t cTensorScores);
void SetCountDimensions(const size_t cDimensions);
ErrorEbm Expand(const Term* const pTerm);
};
I/O Contract
| Field | Description |
|---|---|
| m_aTensorScores | Array of model score values |
| m_cTensorScores | Current number of scores in the tensor |
| m_cDimensions | Current number of dimensions |
| m_bExpanded | Whether tensor is in expanded (full) representation |
| DimensionInfo.m_aSplits | Per-dimension split point indices |
Usage Examples
# Called internally via native bindings
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier()
ebm.fit(X, y) # Tensor objects store per-term model scores internally