Subspace#

class torchsim.Subspace(basis, singular_values, dictionary=None, simulation=None)[source]#

Bases: object

A temporal basis fitted to a set of signals.

basis#

(contrasts, rank), orthonormal. Complex when the signals are.

Type:

torch.Tensor

singular_values#

Every singular value of the signals it was fitted from, not only the ones kept, so retained can be read and another rank costed.

Type:

torch.Tensor

dictionary#

(atoms, contrasts) – the signals the basis was fitted to, where they were simulated for the purpose. simulate_subspace() fills this in; fit() leaves it out, since the caller already holds them.

Type:

torch.Tensor, optional

simulation#

What that simulation recorded, with the labels that say which sample is which.

Type:

SimulationResult, optional

Methods

expand

Return subspace coefficients as contrasts again.

fit

Fit the leading rank directions of signals.

project

Return signals in the subspace: (..., contrasts) to (..., rank).

property rank#

How many directions the basis keeps.

property contrasts#

How many contrasts it was fitted over.

property retained#

The fraction of the fitted signals’ energy the basis keeps.

One minus this is the relative squared error of projecting those signals onto it and back, so it is the approximation, not a proxy for it.

property modes#

(rank, contrasts).

A reconstruction library’s subspace operator takes the basis this way round – mri-nufft’s MRISubspace, BART’s pics -B. It is a plain transpose and not a conjugate one: expanding coefficients back into contrasts is image_t = sum_k conj(modes[k, t]) c_k, which is what expand() does and what those operators do.

Type:

The basis with the rank axis first

project(signals)[source]#

Return signals in the subspace: (..., contrasts) to (..., rank).

A basis fitted to real signals is real, and a complex signal projected onto it keeps both its parts – the arithmetic is promoted to whichever of the two is wider, never narrowed to the basis. The basis follows the signals to whichever device they are on, rather than the other way round: a volume is large and a basis is not.

expand(coefficients)[source]#

Return subspace coefficients as contrasts again.

classmethod fit(signals, rank)[source]#

Fit the leading rank directions of signals.

Parameters:
  • signals – (..., contrasts). Every leading axis is flattened, so a simulated dictionary and a training set are the same input.

  • rank – How many directions to keep.

Return type:

Subspace

Raises:

ValueError – If rank is not positive, or exceeds what the signals span.