pytomography.priors#

Under the modification \(L(\tilde{f}, f) \to L(\tilde{f}, f)e^{-\beta V(f)}\), the log-liklihood becomes \(\ln L(\tilde{f},f) - \beta V(f)\). Typically, the prior has a form \(V(f) = \sum_{r,s} w_{r,s} \phi(f_r,f_s)\). In this expression, \(r\) represents a voxel in the object, \(s\) represents a voxel nearby to voxel \(r\), and \(w_{r,s}\) is a weight that adjusts for the Euclidean distance between the voxels.

Submodules#

Package Contents#

Classes#

Prior

Abstract class for implementation of prior \(V(f)\) where \(V\) is from the log-posterior probability \(\ln L(\tilde{f}, f) - \beta V(f)\). Any function inheriting from this class should implement a foward method that computes the tensor \(\frac{\partial V}{\partial f_r}\) where \(f\) is an object tensor.

NearestNeighbourPrior

Implementation of priors where gradients depend on summation over nearest neighbours \(s\) to voxel \(r\) given by : \(\frac{\partial V}{\partial f_r}=\beta\sum_{r,s}w_{r,s}\phi(f_r, f_s)\) where \(V\) is from the log-posterior probability \(\ln L (\tilde{f}, f) - \beta V(f)\).

QuadraticPrior

Subclass of NearestNeighbourPrior where \(\phi(f_r, f_s)= (f_r-f_s)/\delta\) corresponds to a quadratic prior \(V(f)=\frac{1}{4}\sum_{r,s} w_{r,s} \left(\frac{f_r-f_s}{\delta}\right)^2\)

LogCoshPrior

Subclass of NearestNeighbourPrior where \(\phi(f_r,f_s)=\tanh((f_r-f_s)/\delta)\) corresponds to the logcosh prior \(V(f)=\sum_{r,s} w_{r,s} \log\cosh\left(\frac{f_r-f_s}{\delta}\right)\)

RelativeDifferencePrior

Subclass of NearestNeighbourPrior where \(\phi(f_r,f_s)=\frac{2(f_r-f_s)(\gamma|f_r-f_s|+3f_s + f_r)}{(\gamma|f_r-f_s|+f_r+f_s)^2}\) corresponds to the relative difference prior \(V(f)=\sum_{r,s} w_{r,s} \frac{(f_r-f_s)^2}{f_r+f_s+\gamma|f_r-f_s|}\)

class pytomography.priors.Prior(beta)[source]#

Abstract class for implementation of prior \(V(f)\) where \(V\) is from the log-posterior probability \(\ln L(\tilde{f}, f) - \beta V(f)\). Any function inheriting from this class should implement a foward method that computes the tensor \(\frac{\partial V}{\partial f_r}\) where \(f\) is an object tensor.

Parameters:
  • beta (float) – Used to scale the weight of the prior

  • device (float) – Pytorch device used for computation. Defaults to ‘cpu’.

set_object_meta(object_meta)#

Sets object metadata parameters.

Parameters:

object_meta (ObjectMeta) – Object metadata describing the system.

Return type:

None

set_beta_scale(factor)#

Sets \(\beta\)

Parameters:

factor (float) – Value of \(\beta\)

Return type:

None

set_object(object)#

Sets the object \(f_r\) used to compute \(\frac{\partial V}{\partial f_r}\)

Parameters:

object (torch.tensor) – Tensor of size [batch_size, Lx, Ly, Lz] representing \(f_r\).

Return type:

None

abstract __call__()#

Abstract method to compute prior based on the self.object attribute.

class pytomography.priors.NearestNeighbourPrior(beta, phi, **kwargs)[source]#

Bases: pytomography.priors.prior.Prior

Implementation of priors where gradients depend on summation over nearest neighbours \(s\) to voxel \(r\) given by : \(\frac{\partial V}{\partial f_r}=\beta\sum_{r,s}w_{r,s}\phi(f_r, f_s)\) where \(V\) is from the log-posterior probability \(\ln L (\tilde{f}, f) - \beta V(f)\).

Parameters:
  • beta (float) – Used to scale the weight of the prior

  • phi (function) – Function \(\phi\) used in formula above. Input arguments should be \(f_r\), \(f_s\), and any kwargs passed to this initialization function.

  • device (str, optional) – Pytorch device used for computation. Defaults to ‘cpu’.

__call__()#

Computes the prior on self.object

Returns:

Tensor of shape [batch_size, Lx, Ly, Lz] representing \(\frac{\partial V}{\partial f_r}\)

Return type:

torch.tensor

class pytomography.priors.QuadraticPrior(beta, delta=1)[source]#

Bases: NearestNeighbourPrior

Subclass of NearestNeighbourPrior where \(\phi(f_r, f_s)= (f_r-f_s)/\delta\) corresponds to a quadratic prior \(V(f)=\frac{1}{4}\sum_{r,s} w_{r,s} \left(\frac{f_r-f_s}{\delta}\right)^2\)

Parameters:
  • beta (float) – Used to scale the weight of the prior

  • delta (float, optional) – Parameter \(\delta\) in equation above. Defaults to 1.

class pytomography.priors.LogCoshPrior(beta, delta=1)[source]#

Bases: NearestNeighbourPrior

Subclass of NearestNeighbourPrior where \(\phi(f_r,f_s)=\tanh((f_r-f_s)/\delta)\) corresponds to the logcosh prior \(V(f)=\sum_{r,s} w_{r,s} \log\cosh\left(\frac{f_r-f_s}{\delta}\right)\)

Parameters:
  • beta (float) – Used to scale the weight of the prior

  • delta (float, optional) – Parameter \(\delta\) in equation above. Defaults to 1.

class pytomography.priors.RelativeDifferencePrior(beta=1, gamma=1, epsilon=1e-08)[source]#

Bases: NearestNeighbourPrior

Subclass of NearestNeighbourPrior where \(\phi(f_r,f_s)=\frac{2(f_r-f_s)(\gamma|f_r-f_s|+3f_s + f_r)}{(\gamma|f_r-f_s|+f_r+f_s)^2}\) corresponds to the relative difference prior \(V(f)=\sum_{r,s} w_{r,s} \frac{(f_r-f_s)^2}{f_r+f_s+\gamma|f_r-f_s|}\)

Parameters:
  • beta (float) – Used to scale the weight of the prior

  • gamma (float, optional) – Parameter \(\gamma\) in equation above. Defaults to 1.

  • epsilon (float, optional) – Prevent division by 0, Defaults to 1e-8.