Subspace#
- class torchsim.Subspace(basis, singular_values, dictionary=None, simulation=None)[source]#
Bases:
objectA 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
retainedcan 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
Return subspace coefficients as contrasts again.
Fit the leading
rankdirections ofsignals.Return
signalsin 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’spics -B. It is a plain transpose and not a conjugate one: expanding coefficients back into contrasts isimage_t = sum_k conj(modes[k, t]) c_k, which is whatexpand()does and what those operators do.- Type:
The basis with the rank axis first
- project(signals)[source]#
Return
signalsin 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.
- classmethod fit(signals, rank)[source]#
Fit the leading
rankdirections ofsignals.- 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:
- Raises:
ValueError – If
rankis not positive, or exceeds what the signals span.