Synthetic Data #
This module provides deterministic data generators used by examples and tests:
- 2D tabular grids (
cartesianGrid,linspace) - simple regression/classification sample builders
These helpers are in-memory. They keep example code focused on models and verification rather than data-loading infrastructure.
Domain-specific datasets belong in their own modules. The band-classification example, for
instance, lives in TorchLean.Data.Bands; this file contains only shape-independent generators.
Tabular 2D #
Affine function w₁x₁ + w₂x₂ + b for synthetic regression data.
Instances For
A length-1 float vector tensor.
Instances For
A length-2 float vector tensor.
Instances For
Cartesian product of two float vectors (batched tensor of points).
cartesianGrid 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
Casted version of singletonVectorFloat under an arbitrary scalar semantics α.
Instances For
Casted version of pointVectorFloat under an arbitrary scalar semantics α.
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 tensor-pack samples.
This is the common sample representation used by the training helpers.
Instances For
Convert (x, label) pairs into TorchLean tensor-pack samples with one-hot targets.