def calculate_cost(y_true, y_pred, threshold,  TP=0, FP=0, TN=0, FN=0):
    """
    Returns the cost given the truth, the predicted probabilities and the cost matrix
    """
    tp = ((y_pred > threshold) & (y_true > 0.5)).sum()
    tn = ((y_pred <= threshold) & (y_true <= 0.5)).sum()
    fp = ((y_pred > threshold) & (y_true <= 0.5)).sum()
    fn = ((y_pred <= threshold) & (y_true > 0.5)).sum()
    return tp*TP + tn*TN + fp*FP + fn*FN