def get_criterion_by_name(name, reduction='mean',
                          bce_weight=None):
    """
    Get criterion by name

    Parameters
    ----------
    name : str
        Loss function name. Available functions: 'mse', 'mae', 'bce'.
        See https://pytorch.org/docs/stable/nn.html#loss-functions for details.

    reduction : str, optional (default='mean')
        Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
        'none': no reduction will be applied, 
        'mean': the sum of the output will be divided by the number of elements in the output, 
        'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, 
            and in the meantime, specifying either of those two args will override reduction. Default: 'mean'
        See https://pytorch.org/docs/stable/nn.html#loss-functions for details.

    bce_weight : torch.Tensor, optional (default=None)
        A manual rescaling weight given to the loss of each batch element.
        See https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html#torch.nn.BCELoss for details.

    Returns
    -------
    criterion : torch.nn.Module
        Criterion module.
    """
    criterion_dict = {
        'mse': nn.MSELoss(reduction=reduction),
        'mae': nn.L1Loss(reduction=reduction),
        'bce': nn.BCELoss(reduction=reduction, weight=bce_weight)
    }

    if name in criterion_dict.keys():
        return criterion_dict[name]

    else:
        raise ValueError(f"{name} is not a valid criterion.")

    Get criterion by name

    Parameters
    ----------
    name : str
        Loss function name. Available functions: 'mse', 'mae', 'bce'.
        See https://pytorch.org/docs/stable/nn.html#loss-functions for details.

    reduction : str, optional (default='mean')
        Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
        'none': no reduction will be applied, 
        'mean': the sum of the output will be divided by the number of elements in the output, 
        'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, 
            and in the meantime, specifying either of those two args will override reduction. Default: 'mean'
        See https://pytorch.org/docs/stable/nn.html#loss-functions for details.

    bce_weight : torch.Tensor, optional (default=None)
        A manual rescaling weight given to the loss of each batch element.
        See https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html#torch.nn.BCELoss for details.

    Returns
    -------
    criterion : torch.nn.Module
        Criterion module.
    
pyod/utils/torch_utility.py