Synthetic Samples and Small Datasets #
This module provides small deterministic data generators used by examples and tests:
- 2D tabular grids (
grid2,linspace) - simple regression/classification sample builders
- a small "band image" generator (2D patterns) for CHW examples
These helpers are simple and in-memory. They keep tutorial code focused on models and verification rather than data-loading infrastructure.
Tabular 2D #
2D affine synthetic target function generator (re-exported from the runtime helper module).
Instances For
A length-1 float vector tensor.
Instances For
Cartesian product of two float vectors (batched tensor of points).
grid2 xs ys produces a tensor X : (m*n, 2) containing all pairs (x, y) with:
xtaken fromxs : (m,)ytaken fromys : (n,)
Ordering is row-major: for each x in xs (outer loop), we sweep all y in ys (inner loop).
PyTorch analogue: torch.cartesian_prod(xs, ys) (up to shape).
Instances For
Linearly spaced points including endpoints.
linspace lo hi count returns a vector tensor of shape (count,):
- empty if
count = 0 [lo]ifcount = 1- otherwise
countpoints fromlotohi(inclusive).
PyTorch analogue: torch.linspace.
Instances For
Rectangular grid over [xLo, xHi] x [yLo, yHi].
Instances For
Square grid over [lo, hi] x [lo, hi].
Instances For
Compute 2D→1D regression targets for a batched grid.
Input X has shape (n,2) and the output Y has shape (n,1).
Instances For
Image 2D (Synthetic CHW Pixels) #
Which axis a synthetic "band" varies along.
We use this to build small labeled image datasets without depending on any external image format.
Instances For
Human-readable axis name (useful in example titles / sample names).
Instances For
Render a CHW c h w image tensor from a pixel function.
The pixel function is indexed by Fin indices that are guaranteed to be in-bounds.
Instances For
Binary image tensor renderer in CHW layout.
Pixels satisfying on c row col get onValue; the rest get offValue.
Instances For
Render a thick horizontal or vertical band into an h x w image tensor.
This is used to create small classification datasets where the label is "horizontal" vs "vertical".
Returns a single-channel CHW 1 h w image tensor (channel-first, PyTorch style).
Instances For
Convenience constructor for a "vertical band" class.
Instances For
Convenience constructor for a "horizontal band" class.
Instances For
Generate labeled band samples for a list of classes and offsets.
This produces a list of (x, label) pairs where x is a typed CHW 1 h w tensor.
Instances For
Like bandDatasetCHWFloat, but keep a human-readable name for each sample.
Each entry is (name, x, label) where x is a typed CHW 1 h w tensor.
Instances For
Labels and Packing #
One-hot encode a label as a float vector of shape Vec classes.
Instances For
Casted version of oneHotFloat.
Instances For
Convert (x, label) pairs into (x, oneHot(label)) pairs.
This is a pure preprocessing step that keeps the data in-memory.
Instances For
Pack (x, y) tensor pairs into TorchLean supervised TList samples.
This is the common sample representation used by the training helpers.
Instances For
Convert (x, label) pairs into TorchLean TList samples with one-hot targets.
Instances For
CHW Parsing #
Interpret a flat list of floats as an image tensor of shape CHW c h w.
Fails if xs.length ≠ c*h*w.
Instances For
Casted version of imageCHWFloat.