DictionaryMatcher#
- class torchsim.DictionaryMatcher(acquisition=None, *, dictionary=None, parameters=None, query_chunk_size=4096, dictionary_chunk_size=16384, top_k=1, groups=None, prune=5e-3)[source]#
Bases:
EstimatorMatch signals using normalized complex inner products.
- Parameters:
acquisition (Simulator, optional) – The sequence being inverted: a simulator that ships with TorchSim, one written by subclassing
Simulator, or any otherSimulator. Every tissue property that is neither unknown nor measured separately is fixed on it beforehand, with the constructor orbind(). Leave it out to fit from signals handed tofit()directly.dictionary (torch.Tensor, optional) – Simulated atoms shaped
(n_atoms, n_contrasts). Leave it out and give anacquisitioninstead, and the atoms are simulated from it.parameters (torch.Tensor, optional) – Parameter values shaped
(n_atoms, n_parameters). If provided, a call returns parameter estimates; otherwise it returns atom indices.query_chunk_size (int, optional) – Maximum measured signals compared at once.
dictionary_chunk_size (int, optional) – Maximum dictionary atoms compared at once.
top_k (int, optional) – Number of candidates retained by
match(). The first is the conventional dictionary-matching estimate.groups (int, optional) – Cluster the dictionary into this many groups and match against their representative signals first, ruling out whole groups before any atom in them is scored. Read
groupingafterwards: itsconditionsays whether the representatives are still distinct enough to prune with, and itscompressionsays how much shorter an inner product inside a group is.prune (float, optional) – How far below its best group score a voxel still considers a group, as a fraction of that score. Larger keeps more groups and costs more. The default is the value Cauley et al. [1] tuned on 280 groups of 700 atoms; on a smaller dictionary or a coarser parameter grid it can rule out the group actually holding the match, which shows up as a handful of voxels landing several grid steps away. Widening it is the fix.
Notes
Compression comes first and is global: one temporal basis for the whole dictionary, which the signals are in too. Grouping then clusters within that basis, so the two savings multiply – the basis shortens every inner product, the grouping cuts how many are taken. State a
rankand the dictionary it matches against is compressed to(atoms, rank).The expensive operation is a matrix product. Torch therefore dispatches directly to the installed CPU BLAS or cuBLAS implementation; a separate C++ or Triton matrix-multiplication kernel would duplicate a faster vendor implementation. Chunking bounds the temporary score matrix.
References
Methods
fitFit the estimator over a sampling of the tissue it will meet.
from_coefficientsMap coefficients that are already in this estimator's basis.
mapEstimate the tissue a measurement came from.
Return the top matching atoms, scores, scales, and parameters.
training_setSimulate a training set: signals, unknowns, and knowns.
uncertainty_ofThe standard deviation the measurement noise leaves on each map.
- property fitted#
Whether the matcher holds a dictionary.
- property grouping#
How the dictionary was clustered, or
Noneif it was not.