Subspace#

class blochsim.Subspace[source]#

Bases: object

Orthonormal temporal basis of a set of signals, for subspace reconstruction.

The basis holds the leading left singular vectors of a dictionary of simulated signals (for example an MR fingerprinting dictionary), so that a series of contrasts images is described by rank coefficient images. fit() builds one from signals; project() and expand() move between the contrast and coefficient domains. Instances are immutable.

Parameters:
  • basis (torch.Tensor) – Orthonormal basis of shape (contrasts, rank); complex when the signals are.

  • singular_values (torch.Tensor) – All singular values of the fitted signals, including those not kept.

  • dictionary (torch.Tensor, default=None) – Signals the basis was fitted to, of shape (atoms, contrasts). Set by blochsim.sequence.simulate_subspace, not by fit().

  • simulation (SimulationResult, default=None) – The recorded simulation the dictionary came from, with its sample labels. Set by blochsim.sequence.simulate_subspace.

Methods

expand

Expand coefficients to contrasts, giving coefficients @ basis.mT.

fit

Fit the leading rank singular directions of signals.

project

Project signals onto the basis, giving signals @ basis.conj().

property rank#

Number of basis directions kept.

property contrasts#

Number of contrasts, the length of the time axis the basis spans.

property retained#

Fraction of the fitted signals’ energy the basis keeps.

One minus this is the relative squared error of projecting the fitted signals onto the basis and back.

property modes#

mri-nufft’s MRISubspace layout.

MRISubspace expands image_t = sum_k conj(modes[k, t]) c_k and projects c_k = sum_t modes[k, t] image_t, which are expand() and project(). BART’s pics -B and bartorch’s basis= contract without the conjugate, image_t = sum_k B[k, t] c_k, so they take basis.mT; for a real basis the two are the same.

Type:

The basis conjugate-transposed, (rank, contrasts)

project()[source]#

Project signals onto the basis, giving signals @ basis.conj().

The coefficients are the inner products of each signal with the basis vectors, \(c_k = \langle b_k, s \rangle = \sum_t \overline{b_{tk}} s_t\), so expand() returns a signal of the span unchanged.

Parameters:

signals (torch.Tensor) – Signals of shape (..., contrasts). The result is computed in the wider of the signals’ and the basis’s dtypes, on the signals’ device.

Returns:

(..., rank) coefficients.

Return type:

torch.Tensor

expand()[source]#

Expand coefficients to contrasts, giving coefficients @ basis.mT.

\(s_t = \sum_k b_{tk} c_k\), the inverse of project() on the span of the basis.

Parameters:

coefficients (torch.Tensor) – (..., rank).

Returns:

(..., contrasts), on the coefficients’ device.

Return type:

torch.Tensor

classmethod fit()[source]#

Fit the leading rank singular directions of signals.

The basis is the first rank left singular vectors of the matrix whose columns are the signals; no mean is removed.

Parameters:
  • signals (torch.Tensor) – Signals of shape (..., contrasts); leading axes are flattened into atoms.

  • rank (int) – Number of directions to keep.

Returns:

The fitted basis.

Return type:

Subspace

Raises:

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