o
    _{j  ã                   @   sN   d dl Z d dlmZ ddlmZ 			ddd„Ze ¡ G d	d
„ d
ejƒƒZdS )é    Né   )ÚLOSSESç      à?©gÍÌÌÌÌÌð?é   çñhãˆµøä>c                 C   sÈ   |  d¡ | j¡}|  ¡   d¡} ||k ¡  | j¡}tt |¡dƒ}t|ƒ}|| }t	t||d ƒ|d ƒ}d| |d  }	d| }
|
| t 
| | ¡ |	d|  t 
d|  | ¡  }t |¡ }|S )z Binary Logistic Regression Loss.éÿÿÿÿé   r   r   g      ð?)ÚviewÚtoÚdeviceÚ
contiguousÚfloatÚmaxÚtorchÚsumÚlenÚminÚlogÚmean)Ú	reg_scoreÚlabelÚ	thresholdÚratio_rangeÚepsZpmaskÚnum_positiveZnum_entriesÚratioZcoef_0Zcoef_1Úloss© r   úL/root/disk_3tb/HAC/mmaction/models/losses/binary_logistic_regression_loss.pyÚbinary_logistic_regression_loss   s    ÿÿr    c                   @   s    e Zd ZdZ			ddd„ZdS )	ÚBinaryLogisticRegressionLossz{Binary Logistic Regression Loss.

    It will calculate binary logistic regression loss given reg_score and
    label.
    r   r   r   c                 C   s   t |||||ƒS )a/  Calculate Binary Logistic Regression Loss.

        Args:
                reg_score (torch.Tensor): Predicted score by model.
                label (torch.Tensor): Groundtruth labels.
                threshold (float): Threshold for positive instances.
                    Default: 0.5.
                ratio_range (tuple): Lower bound and upper bound for ratio.
                    Default: (1.05, 21)
                eps (float): Epsilon for small value. Default: 1e-5.

        Returns:
                torch.Tensor: Returned binary logistic loss.
        )r    )Úselfr   r   r   r   r   r   r   r   Úforward'   s   ÿz$BinaryLogisticRegressionLoss.forwardN©r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r   r   r   r   r!      s    	ûr!   r$   )	r   Útorch.nnÚnnÚregistryr   r    Úregister_moduleÚModuler!   r   r   r   r   Ú<module>   s    
ü