neural_trees.HardRoutedExperts#

class neural_trees.HardRoutedExperts(gate_weights, expert_weights, classes, n_features_in, depth, branching_factor)[source]#

Bases: object

A trained mixture of experts with its gates read as hard routing decisions.

Each gating node sends a sample to its highest-weighted child, and the expert reached at the leaf produces the prediction. Everything runs in numpy; no PyTorch is involved.

Built by HierarchicalMixtureOfExperts.to_hard_router() rather than directly.

Attributes:
depthint
branching_factorint
classes_ndarray of shape (n_classes,)
n_features_in_int
gate_weights_list of (W1, b1, W2, b2)

One two-layer gating network per internal node, in breadth-first order.

expert_weights_list of (W1, b1, W2, b2)

One two-layer expert network per leaf.

export_text(feature_names=None, max_features=3, decimals=3) str[source]#

Render the routing tree, showing which features drive each gate.

A gating node is a two-layer network, not a single hyperplane, so there is no exact rule to print. What is shown is each gate’s input-layer sensitivity per feature, summed over hidden units, which says what the gate is looking at.

predict(X) ndarray[source]#

Predicted class labels, shape (n_samples,).

predict_proba(X) ndarray[source]#

Class probabilities from the single expert each sample reaches.

route_counts(X) ndarray[source]#

How many samples reach each expert, shape (n_experts,).

A mixture spreads every sample over all experts, so this is the first thing the export makes visible: whether the tree actually partitions the input or leans on one branch.

score(X, y) float[source]#

Mean accuracy on the given data.