igl.matryoshka
Truncation samplers and post-fit dimension-curve helpers.
igl.matryoshka.sampler.UniformSampler
Uniform sampler: k ~ Uniform{1, …, d_max}.
The simplest Matryoshka sampling strategy, and the default. It gives equal weight to all truncation levels and lets the encoder discover the true intrinsic dimension without prior bias.
igl.matryoshka.sampler.PowerLawSampler
Power-law sampler: P(k) ∝ k^{-α}.
Useful when prior knowledge suggests the effective dimension is small — biases sampling toward lower truncation levels so the encoder is more aggressively forced to compress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Exponent (must be positive). Larger |
1.0
|
igl.matryoshka.dimension_curve.eval_dimension_curve(module, x_val, y_val, *, loss, source_l2=0.001)
Evaluate the trained module at every truncation level k.
For each k, freshly solves the readout weights via lstsq using only the
first k latent dimensions, then computes the validation metric. Returns
a {k: metric} mapping. The mapping iterates k = 1, 2, …, d_max in
insertion order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
IGLModule | PrefixForward
|
Trained :class: |
required |
x_val
|
Tensor
|
Validation inputs |
required |
y_val
|
Tensor
|
Validation targets. |
required |
loss
|
LossStrategy
|
Loss strategy used to compute the per- |
required |
source_l2
|
float
|
Tikhonov regularisation forwarded to
:func: |
0.001
|
Returns:
| Type | Description |
|---|---|
DimensionCurve
|
A dict mapping |
DimensionCurve
|
|
DimensionCurve
|
|
DimensionCurve
|
The curve score is always lower-is-better so :func: |
DimensionCurve
|
can locate the knee. |
igl.matryoshka.dimension_curve.detect_elbow(curve, *, ratio=2.0)
Locate the elbow of a dimension/loss curve in log-space.
Operates on log(loss) so a 5× loss reduction has the same log-delta
whether it occurs at loss=0.1 or loss=0.001. Returns the largest
k whose log-reduction exceeds max_log_delta / ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
curve
|
DimensionCurve
|
|
required |
ratio
|
float
|
A reduction must be at least |
2.0
|
Returns:
| Type | Description |
|---|---|
int
|
The estimated intrinsic dimension |
Raises:
| Type | Description |
|---|---|
IGLConfigError
|
If |
igl.greedy_knockout(module, x_val, y_val, *, loss, source_l2=0.001, ratio=2.0)
Delete coordinates greedily, least-harmful first, refitting each time.
Scores use :meth:LossStrategy.curve_score (always lower-is-better:
error rate for classification, MSE for regression), so the certificate
is task-scored rather than reconstruction-scored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
IGLModule
|
Trained :class: |
required |
x_val
|
Tensor
|
Validation inputs |
required |
y_val
|
Tensor
|
Validation targets. |
required |
loss
|
LossStrategy
|
Loss strategy providing targets and the curve score. |
required |
source_l2
|
float
|
Tikhonov regularisation for the per-step readout refit. |
0.001
|
ratio
|
float
|
Knee threshold forwarded to :func: |
2.0
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
KnockoutResult
|
|
KnockoutResult
|
and the certified knee. |
igl.KnockoutResult
dataclass
Outcome of :func:greedy_knockout.
Attributes:
| Name | Type | Description |
|---|---|---|
curve |
dict[int, float]
|
|
removal_order |
list[int]
|
Coordinate indices in the order they were removed. |
knee |
int
|
The certified dimension, per :func: |
igl.detect_knockout_knee(curve, *, ratio=2.0)
Locate the smallest number of active coordinates before the score blows up.
Walking from few to many active coordinates, the knee is the first count
whose score is within ratio of the best score over the curve. A
single-point curve returns 1 only when it genuinely holds the best score
— the detector never fires unconditionally at n = 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
curve
|
dict[int, float]
|
|
required |
ratio
|
float
|
Blow-up threshold relative to the best score. |
2.0
|
Returns:
| Type | Description |
|---|---|
int
|
The certified dimension. |