import math


def explicit_mcc(golds, preds):
    """This is the way to calculate MCC directly from a confusion matrix as described here:
        "https://en.wikipedia.org/wiki/Matthews_correlation_coefficient
    """
    TP, TN, FP, FN = 0, 0, 0, 0
    for g, p in zip(golds, preds):
        if g == p and g == 0:
            TP += 1
        elif g == p and p == 1:
            TN += 1
        elif g != p and p == 0:
            FP += 1
        elif g != p and p == 1:
            FN += 1
    num = TP * TN - FP * FN
    denom = float(math.sqrt((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)))
    denom = denom if denom != 0.0 else 1.0
    return num / denom