A mathematical and practical guide to probabilistic decision trees, Density Estimation Trees (DET), Diffusion-guided Decision Trees (Forest-Diffusion), and Python implementation for tabular data synthesis.
Traditional decision trees—such as CART, ID3, and C4.5—are strictly discriminative models. Given an input feature vector x ∈ ℝd, they partition the feature space into axis-aligned hyper-rectangles to approximate the conditional target distribution P(Y ∣ X = x). While extraordinarily effective for classification and regression, standard decision trees cannot natively generate new synthetic feature samples xnew ∼ P(X).
Generative Decision Trees invert this paradigm. Instead of optimizing splits solely to separate target labels, generative tree architectures model the joint probability density P(X, Y) or the marginal feature distribution P(X). Because tabular datasets exhibit irregular boundaries, mixed continuous-categorical features, and non-Gaussian multimodality, tree-based generative models frequently outperform deep neural architectures (such as GANs and VAEs) on structured tabular synthesis.
This article explores the mathematical mechanics of generative decision trees, contrasts major algorithmic paradigms, and demonstrates synthetic tabular generation in Python.
1. Discriminative vs. Generative Tree Architectures
Let D = {(x1, y1), …, (xn, yn)} represent a dataset with n observations across d features. A decision tree recursively partitions the input space 𝒳 into M disjoint terminal leaf regions R1, R2, …, RM.
| Dimension | Discriminative Decision Tree (CART) | Generative Decision Tree (DET / Forest-Flow) |
|---|---|---|
| Objective Function | Models conditional P(Y ∣ X) | Models joint P(X, Y) or marginal P(X) |
| Split Criterion | Minimizes Gini Impurity, Entropy, or MSE of Y | Minimizes Integrated Squared Error (ISE) of density or score-matching loss |
| Leaf Representation | Scalar class probability or conditional mean ȳm | Piecewise-constant density p̂m, local Gaussian, or velocity vector field |
| Primary Output | Point prediction ŷ for a given x | Novel synthetic samples x̃ ∼ P̂(X) and exact log-likelihoods |
2. Core Mathematical Paradigms of Generative Decision Trees
Paradigm A: Density Estimation Trees (DET)
Introduced by Ram and Gray (2011), a Density Estimation Tree (DET) constructs a piecewise-constant approximation of the underlying probability density function f(x) across the hyper-rectangles defined by the tree leaves.
For any leaf node m covering a hyper-rectangle Rm ⊆ ℝd with hyper-volume V(Rm) = ∏j=1d (bm,j − am,j) and containing Nm out of N total training points, the estimated probability density inside leaf m is constant:
f̂(x) = (Nm / N) ⋅ (1 / V(Rm)), ∀ x ∈ Rm
The Integrated Squared Error (ISE) Split Criterion
To find the optimal feature j and split threshold t, DET minimizes the Integrated Squared Error between the true density f(x) and the tree estimate f̂(x):
ISE(f̂) = ∫𝒳 (f(x) − f̂(x))2 dx = ∫𝒳 f(x)2 dx − 2 ∫𝒳 f̂(x)f(x) dx + ∫𝒳 f̂(x)2 dx
Because the first term ∫ f(x)2 dx does not depend on the tree structure, minimizing ISE is equivalent to minimizing the empirical risk functional R̂(T) across all leaves m = 1, …, M:
R̂(T) = − ∑m=1M [ (Nm / N)2 ⋅ (1 / V(Rm)) ]
Once trained, ancestral sampling generates new synthetic data in two steps:
- Sample a leaf index m from the categorical distribution with probabilities pm = Nm / N.
- Draw a synthetic vector x̃ uniformly inside the bounding box of leaf Rm: x̃j ∼ Uniform(am,j, bm,j) for each feature j = 1, …, d.
Paradigm B: Tree-Based Diffusion & Flow Matching (Forest-Diffusion)
While single DETs struggle in high dimensions due to hyper-volume sparsity, modern generative decision trees leverage Score-Based Diffusion and Conditional Flow Matching (e.g., Jolicoeur-Martineau et al., 2024).
Instead of estimating static leaf volumes, an ensemble of gradient-boosted decision trees (such as XGBoost or LightGBM) learns the time-dependent drift or velocity field vθ(xt, t) that transports a simple base Gaussian distribution x0 ∼ 𝒩(0, I) into the complex target tabular distribution x1 ∼ Pdata(X) over continuous time t ∈ [0, 1]:
dxt / dt = vθ(xt, t)
Using linear interpolation paths xt = (1 − t)x0 + tx1, decision trees are trained via standard squared-error regression to predict the conditional vector field (x1 − x0) at discretized noise levels tk. Synthetic rows are then generated by integrating the learned tree vector field forward using Euler or Runge-Kutta ODE solvers.
Paradigm C: Autoregressive Conditional Trees (ARF / Synthpop)
By applying the probability chain rule, any d-dimensional joint distribution factorizes into a product of one-dimensional conditionals:
P(X1, X2, …, Xd) = P(X1) ⋅ P(X2 ∣ X1) ⋅ ∏j=3d P(Xj ∣ X1, …, Xj−1)
In sequential CART synthesis or Adversarial Random Forests (ARF), a dedicated decision tree is trained for each column Xj conditioned on preceding columns, sampling sequentially from the empirical leaf distributions to preserve exact conditional dependencies and mixed data types.
3. Python Implementation: Generative Density Estimation Tree
The following self-contained Python script builds a recursive Generative Density Estimation Tree (DET) using the Integrated Squared Error (ISE) criterion and generates synthetic multimodal data:
import numpy as np
class GenerativeDensityTree:
"""
Piecewise-constant Density Estimation Tree (DET) minimizing
Integrated Squared Error (ISE) for tabular data generation.
"""
def __init__(self, max_depth=5, min_samples_leaf=15):
self.max_depth = max_depth
self.min_samples_leaf = min_samples_leaf
self.leaves = []
def _volume(self, bounds):
# Compute hyper-rectangle volume: prod(upper_j - lower_j)
widths = np.maximum(bounds[:, 1] - bounds[:, 0], 1e-12)
return np.prod(widths)
def _ise_score(self, n_samples, total_n, bounds):
# Negative empirical ISE contribution: -(N_m / N)^2 / V(R_m)
if n_samples == 0:
return 0.0
vol = self._volume(bounds)
return -((n_samples / total_n) ** 2) / vol
def _build(self, X, bounds, depth, total_n):
n_samples, n_features = X.shape
if depth >= self.max_depth or n_samples < 2 * self.min_samples_leaf:
self.leaves.append({
"bounds": bounds.copy(),
"weight": n_samples / total_n,
"density": (n_samples / total_n) / self._volume(bounds)
})
return
best_gain = 0.0
best_split = None
parent_score = self._ise_score(n_samples, total_n, bounds)
# Evaluate candidate axis-aligned splits across features
for j in range(n_features):
thresholds = np.quantile(X[:, j], np.linspace(0.1, 0.9, 17))
for t in np.unique(thresholds):
left_mask = X[:, j] <= t
n_left = np.sum(left_mask)
n_right = n_samples - n_left
if n_left < self.min_samples_leaf or n_right < self.min_samples_leaf:
continue
left_bounds = bounds.copy()
left_bounds[j, 1] = t
right_bounds = bounds.copy()
right_bounds[j, 0] = t
children_score = (
self._ise_score(n_left, total_n, left_bounds) +
self._ise_score(n_right, total_n, right_bounds)
)
gain = parent_score - children_score
if gain > best_gain:
best_gain = gain
best_split = (j, t, left_mask, left_bounds, right_bounds)
if best_split is None:
self.leaves.append({
"bounds": bounds.copy(),
"weight": n_samples / total_n,
"density": (n_samples / total_n) / self._volume(bounds)
})
return
j, t, left_mask, left_bounds, right_bounds = best_split
self._build(X[left_mask], left_bounds, depth + 1, total_n)
self._build(X[~left_mask], right_bounds, depth + 1, total_n)
def fit(self, X):
self.leaves = []
# Define outer domain bounding box with slight padding
mins = X.min(axis=0) - 1e-3
maxs = X.max(axis=0) + 1e-3
bounds = np.column_stack([mins, maxs])
self._build(X, bounds, depth=0, total_n=len(X))
return self
def sample(self, n_synthetic, random_state=42):
rng = np.random.default_rng(random_state)
weights = np.array([leaf["weight"] for leaf in self.leaves])
weights /= weights.sum()
# 1. Sample leaf indices proportional to empirical leaf mass
chosen_indices = rng.choice(len(self.leaves), size=n_synthetic, p=weights)
synthetic_X = np.zeros((n_synthetic, self.leaves[0]["bounds"].shape[0]))
# 2. Sample uniformly inside each chosen leaf's hyper-rectangle
for idx, leaf_idx in enumerate(chosen_indices):
b = self.leaves[leaf_idx]["bounds"]
synthetic_X[idx] = rng.uniform(b[:, 0], b[:, 1])
return synthetic_X
# Demonstration on a 2D multimodal Gaussian mixture
rng = np.random.default_rng(42)
cluster_1 = rng.normal(loc=[-3.0, 2.0], scale=0.6, size=(300, 2))
cluster_2 = rng.normal(loc=[3.0, -1.5], scale=0.8, size=(300, 2))
X_real = np.vstack([cluster_1, cluster_2])
det = GenerativeDensityTree(max_depth=6, min_samples_leaf=15).fit(X_real)
X_synth = det.sample(n_synthetic=600)
print(f"Learned Terminal Leaves : {len(det.leaves)}")
print(f"Real Data Mean : {X_real.mean(axis=0).round(3)}")
print(f"Synthetic Data Mean : {X_synth.mean(axis=0).round(3)}")
print(f"Real Data Std : {X_real.std(axis=0).round(3)}")
print(f"Synthetic Data Std : {X_synth.std(axis=0).round(3)}")
4. Advantages and Practical Limitations
- Native Handling of Mixed Tabular Types: Unlike neural generators that require one-hot encoding and continuous relaxations (such as Gumbel-Softmax), generative trees naturally partition integer counts, skewed continuous columns, and categorical levels without distortion.
- Zero Mode Collapse & Fast Training: Because tree splits optimize deterministic density or regression objectives rather than unstable minimax adversarial games, generative decision trees train in seconds on CPU without suffering from mode collapse.
- Curse of Dimensionality in Pure Volume Trees: Single Density Estimation Trees rely on hyper-volume calculations V(Rm) that suffer from boundary sparsity when d > 20. For high-dimensional tabular datasets, ensemble score-matching trees (Forest-Diffusion) or Adversarial Random Forests (ARF) are strongly preferred over single DETs.
No comments:
Post a Comment