# LICENSE HEADER MANAGED BY add-license-header
#
# Copyright 2018 Kornia Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Score images, segmentations and distributions, or register images by mutual information.

A loss with a target takes the prediction first. Where a loss has a ``reduction``, its default and its output
shape differ between families: :ref:`Losses and metrics <losses-metrics-conventions>` tabulates them. The segmentation
losses take logits, the Hausdorff losses probabilities, and the mutual-information losses intensities of any range.

Which function to use, with the module form after the function:

- Image reconstruction: structural dissimilarity of two images, :func:`ssim_loss`, :class:`SSIMLoss`; of two volumes,
  :func:`ssim3d_loss`, :class:`SSIM3DLoss`; over several scales plus an L1 term, :class:`MS_SSIMLoss`; the negative
  PSNR, :func:`psnr_loss`, :class:`PSNRLoss`.
- Smoothness of one image or depth map: :func:`total_variation`, :class:`TotalVariation`; edge-aware smoothness of an
  inverse depth map, :func:`inverse_depth_smoothness_loss`, :class:`InverseDepthSmoothnessLoss`.
- Robust regression on tensors of any shape: linear for large residuals, :func:`charbonnier_loss`,
  :class:`CharbonnierLoss`; logarithmic, :func:`cauchy_loss`, :class:`CauchyLoss`; saturating at 2,
  :func:`geman_mcclure_loss`, :class:`GemanMcclureLoss`; saturating at 1, :func:`welsch_loss`, :class:`WelschLoss`.
- Segmentation by class overlap: the Dice overlap, :func:`dice_loss`, :class:`DiceLoss`; the Tversky index with its
  own false-positive and false-negative weights, :func:`tversky_loss`, :class:`TverskyLoss`; the IoU of one
  foreground, :func:`lovasz_hinge_loss`, :class:`LovaszHingeLoss`; the IoU of every class,
  :func:`lovasz_softmax_loss`, :class:`LovaszSoftmaxLoss`.
- Segmentation by per-pixel cross entropy that down-weights easy pixels: over exclusive classes, :func:`focal_loss`,
  :class:`FocalLoss`; over independent binary outputs, :func:`binary_focal_loss_with_logits`,
  :class:`BinaryFocalLossWithLogits`.
- One-hot encoding of a class-index map: :func:`one_hot`.
- Divergence between probability heatmaps: :func:`kl_div_loss_2d`, :func:`js_div_loss_2d`.
- Segmentation boundary distance: :class:`HausdorffERLoss`; of volumes, :class:`HausdorffERLoss3D`.
- Registration by mutual information: of flat signals, :func:`mutual_information_loss`, :class:`MILossFromRef`; of
  images, :func:`mutual_information_loss_2d`, :class:`MILossFromRef2D`; of volumes,
  :func:`mutual_information_loss_3d`, :class:`MILossFromRef3D`.
- Registration by normalized mutual information: of flat signals, :func:`normalized_mutual_information_loss`,
  :class:`NMILossFromRef`; of images, :func:`normalized_mutual_information_loss_2d`, :class:`NMILossFromRef2D`; of
  volumes, :func:`normalized_mutual_information_loss_3d`, :class:`NMILossFromRef3D`.
- The histogram kernel of the registration losses: :class:`MIKernel`.
"""

from __future__ import annotations

from .cauchy import CauchyLoss, cauchy_loss
from .charbonnier import CharbonnierLoss, charbonnier_loss
from .depth_smooth import InverseDepthSmoothnessLoss, inverse_depth_smoothness_loss
from .dice import DiceLoss, dice_loss
from .divergence import js_div_loss_2d, kl_div_loss_2d
from .focal import BinaryFocalLossWithLogits, FocalLoss, binary_focal_loss_with_logits, focal_loss
from .geman_mcclure import GemanMcclureLoss, geman_mcclure_loss
from .hausdorff import HausdorffERLoss, HausdorffERLoss3D
from .lovasz_hinge import LovaszHingeLoss, lovasz_hinge_loss
from .lovasz_softmax import LovaszSoftmaxLoss, lovasz_softmax_loss
from .ms_ssim import MS_SSIMLoss
from .mutual_information import (
    MIKernel,
    MILossFromRef,
    MILossFromRef2D,
    MILossFromRef3D,
    NMILossFromRef,
    NMILossFromRef2D,
    NMILossFromRef3D,
    mutual_information_loss,
    mutual_information_loss_2d,
    mutual_information_loss_3d,
    normalized_mutual_information_loss,
    normalized_mutual_information_loss_2d,
    normalized_mutual_information_loss_3d,
)
from .one_hot import one_hot
from .psnr import PSNRLoss, psnr_loss
from .ssim import SSIMLoss, ssim_loss
from .ssim3d import SSIM3DLoss, ssim3d_loss
from .total_variation import TotalVariation, total_variation
from .tversky import TverskyLoss, tversky_loss
from .welsch import WelschLoss, welsch_loss

__all__ = [
    "BinaryFocalLossWithLogits",
    "CauchyLoss",
    "CharbonnierLoss",
    "DiceLoss",
    "FocalLoss",
    "GemanMcclureLoss",
    "HausdorffERLoss",
    "HausdorffERLoss3D",
    "InverseDepthSmoothnessLoss",
    "LovaszHingeLoss",
    "LovaszSoftmaxLoss",
    "MIKernel",
    "MILossFromRef",
    "MILossFromRef2D",
    "MILossFromRef3D",
    "MS_SSIMLoss",
    "NMILossFromRef",
    "NMILossFromRef2D",
    "NMILossFromRef3D",
    "PSNRLoss",
    "SSIM3DLoss",
    "SSIMLoss",
    "TotalVariation",
    "TverskyLoss",
    "WelschLoss",
    "binary_focal_loss_with_logits",
    "cauchy_loss",
    "charbonnier_loss",
    "dice_loss",
    "focal_loss",
    "geman_mcclure_loss",
    "inverse_depth_smoothness_loss",
    "js_div_loss_2d",
    "kl_div_loss_2d",
    "lovasz_hinge_loss",
    "lovasz_softmax_loss",
    "mutual_information_loss",
    "mutual_information_loss_2d",
    "mutual_information_loss_3d",
    "normalized_mutual_information_loss",
    "normalized_mutual_information_loss_2d",
    "normalized_mutual_information_loss_3d",
    "one_hot",
    "psnr_loss",
    "ssim3d_loss",
    "ssim_loss",
    "total_variation",
    "tversky_loss",
    "welsch_loss",
]
