Subspace#
- class blochsim.Subspace[source]#
Bases:
objectOrthonormal 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
contrastsimages is described byrankcoefficient images.fit()builds one from signals;project()andexpand()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 byblochsim.sequence.simulate_subspace, not byfit().simulation (SimulationResult, default=None) – The recorded simulation the dictionary came from, with its sample labels. Set by
blochsim.sequence.simulate_subspace.
Methods
Expand coefficients to contrasts, giving
coefficients @ basis.mT.Fit the leading
ranksingular directions ofsignals.Project
signalsonto the basis, givingsignals @ 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
MRISubspacelayout.MRISubspaceexpandsimage_t = sum_k conj(modes[k, t]) c_kand projectsc_k = sum_t modes[k, t] image_t, which areexpand()andproject(). BART’spics -Band bartorch’sbasis=contract without the conjugate,image_t = sum_k B[k, t] c_k, so they takebasis.mT; for a real basis the two are the same.- Type:
The basis conjugate-transposed,
(rank, contrasts)
- project()[source]#
Project
signalsonto the basis, givingsignals @ 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
ranksingular directions ofsignals.The basis is the first
rankleft 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:
- Raises:
ValueError – If
rankis not positive, or exceeds what the signals span.