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 neighbouring voxel to voxel \(r\), and \(w_{r,s}\) is a weight that adjusts for the Euclidean distance between the voxels (set to unity for neighbouring voxels). For all priors implemented here, the neighbouring voxels considered are those surrounding a given voxel, so \(\sum_s\) is a sum over 26 points.
Submodules#
Package Contents#
Classes#
Subclass of SmoothnessPrior where \(\phi(x)=x\) 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\) |
|
Subclass of SmoothnessPrior where \(\phi(x)=\tanh(x)\) corresponds to the logcosh prior \(V(f)=\sum_{r,s} w_{r,s} \log\cosh\left(\frac{f_r-f_s}{\delta}\right)\) |
|
Subclass of SmoothnessPrior where \(\phi(f_r-f_s,f_r+f_s) = \frac{4(f_r-f_s)(f_r+f_s)}{((f_r+f_s)+\gamma|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|}\) |
|
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 |
- class pytomography.priors.QuadraticPrior(beta, delta=1, device='cpu')#
Bases:
SmoothnessPrior
Subclass of SmoothnessPrior where \(\phi(x)=x\) 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 (int, optional) – Parameter \(\delta\) in equation above. Defaults to 1.
device (str, optional) – Pytorch device used for computation. Defaults to ‘cpu’.
- class pytomography.priors.LogCoshPrior(beta, delta=1, device='cpu')#
Bases:
SmoothnessPrior
Subclass of SmoothnessPrior where \(\phi(x)=\tanh(x)\) 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 (int, optional) – Parameter \(\delta\) in equation above. Defaults to 1.
device (str, optional) – Pytorch device used for computation. Defaults to ‘cpu’.
- class pytomography.priors.RelativeDifferencePrior(beta=1, gamma=1, device='cpu')#
Bases:
DiffAndSumSmoothnessPrior
Subclass of SmoothnessPrior where \(\phi(f_r-f_s,f_r+f_s) = \frac{4(f_r-f_s)(f_r+f_s)}{((f_r+f_s)+\gamma|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
phi (function) – Function $phi$ used in formula above
gamma (float, optional) – Parameter $gamma$ in equation above. Defaults to 1.
device (str, optional) – Pytorch device used for computation. Defaults to ‘cpu’.
- gradient(sum, diff, gamma, eps=1e-11)#
Gradient function.
- Parameters:
sum (torch.Tensor) – tensor of size [batch_size,Lx,Ly,Lz] representing \(f_r+f_s\)
diff (torch.Tensor) – tensor of size [batch_size,Lx,Ly,Lz] representing \(f_r-f_s\)
gamma (torch.Tensor) – hyperparameter \(\gamma\)
eps (float, optional) – Used to prevent division by 0. Defaults to 1e-11.
- Returns:
Returns \(\frac{(f_r-f_s)^2}{(f_r+f_s)+\gamma|f_r-f_s|}\) for a given \(r\) and \(s\).
- Return type:
torch.Tensor
- class pytomography.priors.Prior(beta, device='cpu')#
Bases:
torch.nn.Module
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
- set_device(device='cpu')#
Sets the pytorch computation device
- Parameters:
device (str) – sets device.
- Return type:
None
- abstract forward()#
Abstract method to compute prior based on the
self.object
attribute.