Implementation:Interpretml Interpret InteractionCore
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, EBM_Core |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
InteractionCore is a C++ module that manages the creation, initialization, and lifecycle of the interaction detection engine in the EBM framework.
Description
This module implements the core interaction detection functionality through the InteractionCore class. Interaction detection evaluates how strongly pairs (or higher-order tuples) of features interact, which informs which feature interactions should be included in the EBM model.
Key responsibilities include:
InteractionCore::Create: Factory method that allocates and initializes the interaction core. It processes the shared dataset to extract feature metadata (bin counts, missing/unseen/nominal flags), resolves the objective function, validates targets, checks SIMD and numeric restrictions, unpacks the bag, and initializes the interaction dataset.
InteractionCore::Free: Thread-safe reference-counted deallocation usingstd::atomicwith proper memory ordering (release on decrement, acquire fence before delete).
InteractionCore::InitializeInteractionGradientsAndHessians: Computes initial gradients and hessians for all training samples by applying a zero-valued update through the objective function. This reuses the same code path as boosting to generate gradients from initial scores. For classification, it handles both multiclass (with per-class targets stored as unsigned integers) and binary targets. For regression, targets are stored as floats. After gradient computation, it optionally multiplies gradients and hessians by sample weights as an optimization.
CheckInteractionRestrictions: Validates that bin sizes and index ranges fit within the numeric types used for SIMD processing, checking bothUIntBigandUIntSmallvariants.
Usage
This module is instantiated when the user calls interaction detection methods. It creates the interaction dataset, initializes gradients, and then serves as the context for all subsequent interaction scoring calls.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
shared/libebm/InteractionCore.cpp
Signature
// Factory method
static ErrorEbm InteractionCore::Create(
const unsigned char* const pDataSetShared,
const size_t cSamples,
const size_t cFeatures,
const size_t cWeights,
const BagEbm* const aBag,
const CreateInteractionFlags flags,
const AccelerationFlags acceleration,
const char* const sObjective,
const double* const experimentalParams,
InteractionCore** const ppInteractionCoreOut);
// Reference-counted destructor
static void InteractionCore::Free(
InteractionCore* const pInteractionCore);
// Gradient/Hessian initialization
ErrorEbm InteractionCore::InitializeInteractionGradientsAndHessians(
const unsigned char* const pDataSetShared,
const size_t cWeights,
const double* const aIntercept,
const BagEbm* const aBag,
const double* const aInitScores);
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pDataSetShared | const unsigned char* | Yes | Shared dataset binary blob |
| cSamples | size_t | Yes | Total number of samples |
| cFeatures | size_t | Yes | Number of features |
| cWeights | size_t | Yes | Number of weight columns (0 or 1) |
| aBag | const BagEbm* | No | Bag replication array for train/validation split |
| flags | CreateInteractionFlags | Yes | Configuration flags (UseApprox, DifferentialPrivacy, BinaryAsMulticlass) |
| sObjective | const char* | Yes | Objective function name string |
| aIntercept | const double* | No | Initial intercept values per score |
| aInitScores | const double* | No | Initial score values per sample |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | ErrorEbm | Error code (Error_None on success) |
| ppInteractionCoreOut | InteractionCore** | Pointer to the created InteractionCore instance |
Usage Examples
Pipeline Context
# This C++ module is called internally via the native bindings
# during interaction detection to score feature interactions
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier(interactions=10)
ebm.fit(X, y) # Internally creates InteractionCore for interaction scoring