TorchLean API

NN.API.Data.Synthetic

Synthetic Data #

This module provides deterministic data generators used by examples and tests:

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 #

def TorchLean.Data.Synthetic.affinePlane (w₁ w₂ b x₁ x₂ : Float) :

Affine function w₁x₁ + w₂x₂ + b for synthetic regression data.

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:

      • x taken from xs : (m,)
      • y taken from ys : (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] if count = 1
        • otherwise count points from lo to hi (inclusive).

        PyTorch analogue: torch.linspace.

        Instances For
          def TorchLean.Data.Synthetic.rectangularGrid (xLo xHi yLo yHi : Float) (xCount yCount : ) :

          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
                      def TorchLean.Data.Synthetic.oneHot {α : Type} [Context α] (cast : Floatα) (classes label : ) :

                      Casted version of oneHotFloat.

                      Instances For
                        def TorchLean.Data.Synthetic.classification {α : Type} [Context α] {σ : Shape} (cast : Floatα) (classes : ) (xs : List (Spec.Tensor Float σ × )) :

                        Convert (x, label) pairs into (x, oneHot(label)) pairs.

                        This is a pure preprocessing step that keeps the data in-memory.

                        Instances For
                          def TorchLean.Data.Synthetic.supervised {α : Type} [Context α] {σ τ : Shape} (cast : Floatα) (xs : List (Spec.Tensor Float σ × Spec.Tensor Float τ)) :
                          List (TensorPack α [σ, τ])

                          Pack (x, y) tensor pairs into TorchLean supervised tensor-pack samples.

                          This is the common sample representation used by the training helpers.

                          Instances For
                            def TorchLean.Data.Synthetic.labeled {α : Type} [Context α] {σ : Shape} (cast : Floatα) (classes : ) (xs : List (Spec.Tensor Float σ × )) :

                            Convert (x, label) pairs into TorchLean tensor-pack samples with one-hot targets.

                            Instances For