def calculate_rates(TP, TN, FP, FN):
    """
    Calculates the True and False Positive and Negative rates of the supplied reference and test data
    
    For TPR and TNR, if the denominator is 0, the result is defined as 1, as there were no false positive/negatives
    
    Input:
        ref: Numpy boolean array of the reference data, of size [n_samples, ]
        test: Numpy boolean array of the test data, of size [n_samples, ]
        
    Output:
        TPR: The True Positive Rate (also known as Sensitivity)
        TNR: The True Negative Rate (also known as Specificity)
        FPR: The False Positive Rate (equal to 1 - Specificity)
        FNR: The False Negative Rate (equal to 1 - Sensitivity)
    """
    
    
    if (TP + FN) > 0:
        TPR = TP / (TP + FN)  # Sensitivity
    else: 
        TPR = 1
    
    if (TN + FP) > 0:
        TNR = TN / (TN + FP) # Specificity
    else:
        TNR = 1
        
    FPR = 1 - TNR
    FNR = 1 - TPR
    
    return TPR, TNR, FPR, FNR