pdft.training.train_basis_exact#
- pdft.training.train_basis_exact(basis, *, dataset, k, sweeps, passes=1, frozen_indices=None, precision='double', callback=None)[source]#
Train a separable circuit basis by exact block-coordinate descent on its sparsity.
- Parameters:
dataset (Sequence[Array]) – Images in the basis’s frame and of its
image_size. They are summed as they are; normalise them first for each to weigh the same.k (int | Sequence[int]) – The coefficient budget, or several, whose objectives are averaged.
sweeps (int) – Rounds of the alternation: the codes, then every block’s gates.
passes (int) – Visits to every gate of a block per sweep, its codes held fixed.
frozen_indices (Sequence[int] | None) – Indices into
basis.tensorsthat are not updated.precision (str) –
"double"or"single": the precision of everything the size of an image (the images, the transforms, the codes, each image’s part ofM, each block’s unitary and its gradient) for every basis and whatever the tensors’ precision, including the bases whoseforward_transformcasts to double (CLAUDE.md 13)."single"halves the memory these take.Mis summed in double precision and each update is computed in double precision from its environment either way; the tensors come back in the dtype they came in with, unitary to its rounding.callback (Callable[[int, object, float], None] | None) –
callback(sweep, basis, loss)after every sweep: the basis as the sweep left it, and the objective the sweep started from.
- Returns:
TrainingResult – Its
loss_historyholds, per sweep, the objective at its start: the energy outside the topksummed over the images (the mean over the budgets). No sweep raises it in exact arithmetic; once it has converged, rounding can, by about1e-15of it when the working precision and the tensors are both double,1e-7when either is single.- Raises:
ValueError – If a gate couples the two registers (
separable_blocks), the dataset orkis empty, an image is not(2**m, 2**n)or not finite, a budget,sweepsorpassesis below 1, a frozen index is not one of the basis’s tensors, orprecisionis neither"double"nor"single".TypeError – For a basis with no circuit of its own (a
BlockedBasis), or a budget,sweepsorpassesthat is not an integer.
- Return type:
Notes
When every image and every tensor is exactly real, as for a
RealRichBasison real images, each environment is exactly real and the updates are computed in real arithmetic: the basis stays exactly real. One complex tensor makes every update complex, as under the gradient trainers.Where the data leave a gate’s best value open (several score the same, as when the images are zero or their codes already exact), the gate takes the one of them nearest its value, and is left as it is when its environment is zero; zero here means below the rounding of the working precision, next to the block’s
M.The top
kisMSELoss’s, with no tie band (CLAUDE.md 14): where coefficients tie in magnitude, as conjugate pairs of a real image do at the Fourier start, rounding decides which is kept, and the CPU and the GPU, or the two precisions, can follow different trajectories.