piscis.losses
=============

.. py:module:: piscis.losses


Attributes
----------

.. autoapisummary::

   piscis.losses.mean_smoothf1_loss
   piscis.losses.mean_masked_l2_loss


Functions
---------

.. autoapisummary::

   piscis.losses.smoothf1_loss
   piscis.losses.masked_l2_loss
   piscis.losses.reduce_loss
   piscis.losses.wrap_loss_fn


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

.. py:function:: smoothf1_loss(labels_pred: torch.Tensor, deltas_pred: torch.Tensor, deltas: torch.Tensor, p: torch.Tensor, max_distance: float = 3.0, kernel_size: Sequence[int] = (3, 3), temperature: float = 0.05, epsilon: float = 1e-07) -> torch.Tensor

   
   Compute the SmoothF1 loss.


   :Parameters:

       **labels_pred** : torch.Tensor
           Predicted labels.

       **deltas_pred** : torch.Tensor
           Predicted displacement vectors.

       **deltas** : torch.Tensor
           Ground truth displacement vectors.

       **p** : torch.Tensor
           Number of ground truth spots in each image.

       **max_distance** : float, optional
           Maximum distance for matching predicted and ground truth displacement vectors. Default is 3.

       **temperature** : float, optional
           Temperature parameter for softmax. Default is 0.05.

       **kernel_size** : Sequence[int], optional
           Kernel size of sum or max pooling operations. Default is (3, 3).

       **epsilon** : float, optional
           Small constant for numerical stability. Default is 1e-7.



   :Returns:

       **smoothf1** : torch.Tensor
           SmoothF1 loss.











   ..
       !! processed by numpydoc !!

.. py:function:: masked_l2_loss(input: torch.Tensor, target: torch.Tensor, mask: torch.Tensor, epsilon: float = 1e-07) -> torch.Tensor

   
   Compute the L2 loss over masked pixels.


   :Parameters:

       **input** : torch.Tensor
           Predicted values.

       **target** : torch.Tensor
           Ground truth values.

       **mask** : torch.Tensor
           Mask tensor where each pixel is a boolean for whether it should be included in the loss computation.

       **epsilon** : float, optional
           Small constant for numerical stability. Default is 1e-7.



   :Returns:

       **rmse** : jax.Array
           Masked root-mean-square error.











   ..
       !! processed by numpydoc !!

.. py:function:: reduce_loss(loss: torch.Tensor, reduction: Optional[str] = 'mean') -> torch.Tensor

   
   Reduce the loss.


   :Parameters:

       **loss** : torch.Tensor
           Loss tensor to be reduced.

       **reduction** : Optional[str], optional
           Loss reduction method. Supported methods are 'mean' and 'sum'. Default is 'mean'.



   :Returns:

       **loss** : torch.Tensor
           Reduced loss.




   :Raises:

       ValueError
           If the `reduction` method is not supported.







   ..
       !! processed by numpydoc !!

.. py:function:: wrap_loss_fn(loss_fn: Callable, axis: int = 0, reduction: Optional[str] = 'mean') -> Callable

   
   Wrap a loss function for vectorization and loss reduction.


   :Parameters:

       **loss_fn** : Callable
           Loss function.

       **axis** : int, optional
           Axis to vectorize over. Default is 0.

       **reduction** : Optional[str], optional
           Loss reduction method. Default is 'mean'.



   :Returns:

       **wrapped_loss_fn** : Callable
           Wrapped loss function.











   ..
       !! processed by numpydoc !!

.. py:data:: mean_smoothf1_loss

.. py:data:: mean_masked_l2_loss

