:py:mod:`pytomography.priors.smoothness`
========================================

.. py:module:: pytomography.priors.smoothness


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   pytomography.priors.smoothness.SmoothnessPrior
   pytomography.priors.smoothness.QuadraticPrior
   pytomography.priors.smoothness.LogCoshPrior




.. py:class:: SmoothnessPrior(beta, delta, phi, device = None)

   Bases: :py:obj:`pytomography.priors.prior.Prior`

   Implementation of priors with gradients of the form :math:`\frac{\partial V}{\partial f_r}=\frac{\beta}{\delta}\sum_{s}w_{r,s}\phi\left(\frac{f_r-f_s}{\delta}\right)` where :math:`V` is from the log-posterior probability :math:`\ln L (\tilde{f}, f) - \beta V(f)`.

   :param beta: Used to scale the weight of the prior
   :type beta: float
   :param phi: Function :math:`\phi` used in formula above
   :type phi: function
   :param delta: Parameter :math:`\delta` in equation above. Defaults to 1.
   :type delta: int, optional
   :param device: Pytorch device used for computation. Defaults to 'cpu'.
   :type device: str, optional

   .. py:method:: get_kernel()

      Obtains the kernel used to get :math:`\frac{\partial V}{\partial f_r}` (this is an array with the same dimensions as the object space image)

      :returns: Kernel used for convolution (number of output channels equal to number of :math:`s`), and array of weights :math:`w_s` used in expression for gradient.
      :rtype: (torch.nn.Conv3d, torch.tensor)


   .. py:method:: set_kernel(object_meta)

      Sets the kernel using  `get_kernel` and the corresponding object metadata.

      :param object_meta: _description_
      :type object_meta: _type_


   .. py:method:: forward()

      Computes the prior on self.object

      :returns: Tensor of shape [batch_size, Lx, Ly, Lz] representing :math:`\frac{\partial V}{\partial f_r}`
      :rtype: torch.tensor



.. py:class:: QuadraticPrior(beta, delta = 1, device = None)

   Bases: :py:obj:`SmoothnessPrior`

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

   :param beta: Used to scale the weight of the prior
   :type beta: float
   :param delta: Parameter :math:`\delta` in equation above. Defaults to 1.
   :type delta: int, optional
   :param device: Pytorch device used for computation. Defaults to 'cpu'.
   :type device: str, optional


.. py:class:: LogCoshPrior(beta, delta = 1, device = None)

   Bases: :py:obj:`SmoothnessPrior`

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

   :param beta: Used to scale the weight of the prior
   :type beta: float
   :param delta: Parameter :math:`\delta` in equation above. Defaults to 1.
   :type delta: int, optional
   :param device: Pytorch device used for computation. Defaults to 'cpu'.
   :type device: str, optional


