ShapeRelationDiscovery
Helpers & Utilities · AiDotNet.NeuralNetworks
Recovers a layer’s symbolic shape relation by RUNNING it on probe shapes and fitting the simplest relation that reproduces every observation.
How It Works
Hand-writing an IShapeContract for every layer type does not scale and is not what
“automatic” means: this codebase has ~199 layer types and only 6 had even the coarse relation kind
declared, so annotation-only coverage would sit near zero indefinitely and each new layer would start
uncovered. Discovery inverts that — every layer is covered the moment it exists, and a layer that
changes its shape behaviour is caught without anyone remembering to update a declaration.
PROBES MUST VARY ONE AXIS AT A TIME or the fit is ambiguous rather than wrong. If every probe has
Height equal to Width, Same(Height) and Same(Width) reproduce the observations equally
well and there is no evidence to choose between them; the fitted relation would then be right on the
probes and wrong on the first non-square input. ProbeShapes generates a discriminating
set, and an axis that stays ambiguous is reported as such instead of being guessed.
A FIT IS EVIDENCE, NOT PROOF. Simplest-that-explains is an inductive step: a layer could follow the
window formula on every probe and something else beyond them. That is exactly why discovery does not
replace IShapeContract — where a layer declares one, the declaration is authoritative
and discovery becomes an independent check on it. Where none is declared, a discovered relation is
strictly better than the nothing that was there before.
Methods
| Method | Summary |
|---|---|
IReadOnlyList<AxisFinding> Fit(IReadOnlyList<TensorAxis> inputAxes, IReadOnlyList<TensorAxis> outputAxes, IReadOnlyList<ValueTuple<int[], int[]>> observations) |
Fits a relation for every output axis from observed (input shape, output shape) pairs. |
IReadOnlyList<int[]> ProbeShapes(IReadOnlyList<int> baseShape) |
Generates probe shapes that vary each axis independently, so fits are discriminating. |