pytomography.likelihoods#
Submodules#
Package Contents#
Classes#
Negative mean squared error likelihood function \(L(g|f) = -\frac{1}{2} \alpha \sum_i \left(g_i-(Hf)_i\right)^2\) where \(g\) is the acquired data, \(H\) is the system matrix, \(f\) is the object being reconstructed, and \(\alpha\) is the scaling constant. The negative is taken so that the it works in gradient ascent (as opposed to descent) algorithms |
|
Generic likelihood class in PyTomography. Subclasses may implement specific likelihoods with methods to compute the likelihood itself as well as particular gradients of the likelihood |
|
The log-likelihood function for Poisson random variables. The likelihood is given by \(L(g|f) = \sum_i g_i [\ln(Hf)]_i - [Hf]_i - ...\). The \(...\) contains terms that are not dependent on \(f\). |
|
Adapated Poisson log likelihood for Monte Carlo hybrid SPECT system matrix. |
|
Generic likelihood class in PyTomography. Subclasses may implement specific likelihoods with methods to compute the likelihood itself as well as particular gradients of the likelihood |
- class pytomography.likelihoods.NegativeMSELikelihood(system_matrix, projections=None, additive_term=None, scaling_constant=1.0)[source]#
Bases:
pytomography.likelihoods.likelihood.LikelihoodNegative mean squared error likelihood function \(L(g|f) = -\frac{1}{2} \alpha \sum_i \left(g_i-(Hf)_i\right)^2\) where \(g\) is the acquired data, \(H\) is the system matrix, \(f\) is the object being reconstructed, and \(\alpha\) is the scaling constant. The negative is taken so that the it works in gradient ascent (as opposed to descent) algorithms
- Parameters:
system_matrix (SystemMatrix) – The system matrix modeling the particular system whereby the projections were obtained
projections (torch.Tensor) – Acquired data
additive_term (torch.Tensor, optional) – Additional term added after forward projection by the system matrix. This term might include things like scatter and randoms. Defaults to None.
additive_term_variance_estimate (torch.tensor, optional) – Variance estimate of the additive term. If none, then uncertainty estimation does not include contribution from the additive term. Defaults to None.
scaling_constant (float) –
- compute_gradient(object, subset_idx=None, norm_BP_subset_method='subset_specific')[source]#
Computes the gradient for the mean squared error objective function given by \(\nabla_f L(g|f) = H^T \left(g-Hf\right)\).
- Parameters:
object (torch.Tensor) – Object \(f\) on which the likelihood is computed
subset_idx (int | None, optional) – Specifies the subset for forward/back projection. If none, then forward/back projection is done over all subsets, and the entire projections \(g\) are used. Defaults to None.
norm_BP_subset_method (str, optional) – Specifies how \(H^T 1\) is calculated when subsets are used. If ‘subset_specific’, then uses \(H_m^T 1\). If average_of_subsets, then uses the average of all :math:`H_m^T 1`s for any given subset (scaled to the relative size of the subset if subsets are not equal size). Defaults to ‘subset_specific’.
- Returns:
The gradient of the Poisson likelihood.
- Return type:
torch.Tensor
- class pytomography.likelihoods.SARTWeightedNegativeMSELikelihood(system_matrix, projections, additive_term=None)[source]#
Bases:
pytomography.likelihoods.likelihood.LikelihoodGeneric likelihood class in PyTomography. Subclasses may implement specific likelihoods with methods to compute the likelihood itself as well as particular gradients of the likelihood
- Parameters:
system_matrix (SystemMatrix) – The system matrix modeling the particular system whereby the projections were obtained
projections (torch.Tensor | None) – Acquired data. If listmode, then this argument need not be provided, and it is set to a tensor of ones. Defaults to None.
additive_term (torch.Tensor, optional) – Additional term added after forward projection by the system matrix. This term might include things like scatter and randoms. Defaults to None.
additive_term_variance_estimate (Callable, optional) – Operator for variance estimate of additive term. If none, then uncertainty estimation does not include contribution from the additive term. Defaults to None.
- compute_gradient(object, subset_idx=None, norm_BP_subset_method='subset_specific')[source]#
Computes the gradient for the mean squared error objective function given by \(\nabla_f L(g|f) = H^T \left(g-Hf\right)\).
- Parameters:
object (torch.Tensor) – Object \(f\) on which the likelihood is computed
subset_idx (int | None, optional) – Specifies the subset for forward/back projection. If none, then forward/back projection is done over all subsets, and the entire projections \(g\) are used. Defaults to None.
norm_BP_subset_method (str, optional) – Specifies how \(H^T 1\) is calculated when subsets are used. If ‘subset_specific’, then uses \(H_m^T 1\). If average_of_subsets, then uses the average of all :math:`H_m^T 1`s for any given subset (scaled to the relative size of the subset if subsets are not equal size). Defaults to ‘subset_specific’.
- Returns:
The gradient of the Poisson likelihood.
- Return type:
torch.Tensor
- class pytomography.likelihoods.PoissonLogLikelihood(system_matrix, projections=None, additive_term=None, additive_term_variance_estimate=None)[source]#
Bases:
pytomography.likelihoods.likelihood.LikelihoodThe log-likelihood function for Poisson random variables. The likelihood is given by \(L(g|f) = \sum_i g_i [\ln(Hf)]_i - [Hf]_i - ...\). The \(...\) contains terms that are not dependent on \(f\).
- Parameters:
system_matrix (SystemMatrix) – The system matrix \(H\) modeling the particular system whereby the projections were obtained
projections (torch.Tensor) – Acquired data (assumed to have Poisson statistics).
additive_term (torch.Tensor, optional) – Additional term added after forward projection by the system matrix. This term might include things like scatter and randoms. Defaults to None.
additive_term_variance_estimate (collections.abc.Callable | None) –
- compute_gradient(object, subset_idx=None, norm_BP_subset_method='subset_specific')[source]#
Computes the gradient for the Poisson log likelihood given by \(\nabla_f L(g|f) = H^T (g / Hf) - H^T 1\).
- Parameters:
object (torch.Tensor) – Object \(f\) on which the likelihood is computed
subset_idx (int | None, optional) – Specifies the subset for forward/back projection. If none, then forward/back projection is done over all subsets, and the entire projections \(g\) are used. Defaults to None.
norm_BP_subset_method (str, optional) – Specifies how \(H^T 1\) is calculated when subsets are used. If ‘subset_specific’, then uses \(H_m^T 1\). If average_of_subsets, then uses the average of all :math:`H_m^T 1`s for any given subset (scaled to the relative size of the subset if subsets are not equal size). Defaults to ‘subset_specific’.
- Returns:
The gradient of the Poisson likelihood.
- Return type:
torch.Tensor
- compute_gradient_ff(object, precomputed_forward_projection=None, subset_idx=None)[source]#
Computes the second order derivative \(\nabla_{ff} L(g|f) = -H^T (g/(Hf+s)^2) H\).
- Parameters:
object (torch.Tensor) – Object \(f\) used in computation.
precomputed_forward_projection (torch.Tensor | None, optional) – The quantity \(Hf\). If this value is None, then the forward projection is recomputed. Defaults to None.
subset_idx (int, optional) – Specifies the subset for all computations. Defaults to None.
- Returns:
The operator given by the second order derivative.
- Return type:
Callable
- compute_gradient_gf(object, precomputed_forward_projection=None, subset_idx=None)[source]#
Computes the second order derivative \(\nabla_{gf} L(g|f) = 1/(Hf+s) H\).
- Parameters:
object (torch.Tensor) – Object \(f\) used in computation.
precomputed_forward_projection (torch.Tensor | None, optional) – The quantity \(Hf\). If this value is None, then the forward projection is recomputed. Defaults to None.
subset_idx (int, optional) – Specifies the subset for all computations. Defaults to None.
- Returns:
The operator given by the second order derivative.
- Return type:
Callable
- compute_gradient_sf(object, precomputed_forward_projection=None, subset_idx=None)[source]#
Computes the second order derivative \(\nabla_{sf} L(g|f,s) = -g/(Hf+s)^2 H\) where \(s\) is an additive term representative of scatter.
- Parameters:
object (torch.Tensor) – Object \(f\) used in computation.
precomputed_forward_projection (torch.Tensor | None, optional) – The quantity \(Hf\). If this value is None, then the forward projection is recomputed. Defaults to None.
subset_idx (int, optional) – Specifies the subset for all computations. Defaults to None.
- Returns:
The operator given by the second order derivative.
- Return type:
Callable
- class pytomography.likelihoods.MonteCarloHybridSPECTPoissonLogLikelihood(system_matrix, projections=None, additive_term=None, additive_term_variance_estimate=None)[source]#
Bases:
PoissonLogLikelihoodAdapated Poisson log likelihood for Monte Carlo hybrid SPECT system matrix.
- Parameters:
system_matrix (pytomography.projectors.SystemMatrix) –
projections (torch.Tensor | None) –
additive_term (torch.Tensor) –
additive_term_variance_estimate (collections.abc.Callable | None) –
- compute_gradient(object, subset_idx=None, norm_BP_subset_method='subset_specific')[source]#
Returns the gradient of the log likelihood with respect to the object. :param object: Object to simulate :type object: torch.Tensor :param subset_idx: Index of the subset to use. If None, then all projections are used. Defaults to None. :type subset_idx: int | None, optional :param norm_BP_subset_method: Method to use for normalizing the back projection. Defaults to ‘subset_specific’. :type norm_BP_subset_method: str, optional
- Returns:
Gradient of the log likelihood with respect to the object
- Return type:
torch.Tensor
- Parameters:
object (torch.Tensor) –
subset_idx (int | None) –
norm_BP_subset_method (str) –
- class pytomography.likelihoods.Likelihood(system_matrix, projections=None, additive_term=None, additive_term_variance_estimate=None)[source]#
Generic likelihood class in PyTomography. Subclasses may implement specific likelihoods with methods to compute the likelihood itself as well as particular gradients of the likelihood
- Parameters:
system_matrix (SystemMatrix) – The system matrix modeling the particular system whereby the projections were obtained
projections (torch.Tensor | None) – Acquired data. If listmode, then this argument need not be provided, and it is set to a tensor of ones. Defaults to None.
additive_term (torch.Tensor, optional) – Additional term added after forward projection by the system matrix. This term might include things like scatter and randoms. Defaults to None.
additive_term_variance_estimate (Callable, optional) – Operator for variance estimate of additive term. If none, then uncertainty estimation does not include contribution from the additive term. Defaults to None.
- _set_n_subsets(n_subsets)[source]#
Sets the number of subsets to be used when computing the likelihood
- Parameters:
n_subsets (int) – Number of subsets
- Return type:
None
- _get_projection_subset(projections, subset_idx=None)[source]#
Method for getting projection subset corresponding to given subset index
- Parameters:
projections (torch.Tensor) – Projection data
subset_idx (int) – Subset index
- Returns:
Subset projection data
- Return type:
torch.Tensor
- _get_normBP(subset_idx, return_sum=False)[source]#
Gets normalization factor (back projection of ones)
- Parameters:
subset_idx (int) – Subset index
return_sum (bool, optional) – Sum normalization factor from all subsets. Defaults to False.
- Returns:
Normalization factor
- Return type:
torch.Tensor
- abstract compute_gradient(*args, **kwargs)[source]#
Function used to compute the gradient of the likelihood \(\nabla_{f} L(g|f)\)
- Raises:
NotImplementedError – Must be implemented by sub classes
- abstract compute_gradient_ff(*args, **kwargs)[source]#
Function used to compute the second order gradient (with respect to the object twice) of the likelihood \(\nabla_{ff} L(g|f)\)
- Raises:
NotImplementedError – Must be implemented by sub classes