def explained_variance_1d(ypred, y):
    assert y.ndim == 1 and ypred.ndim == 1
    vary = np.var(y)
    if np.isclose(vary, 0):
        if np.var(ypred) > 0:
            return 0
        else:
            return 1
    if abs(1 - np.var(y - ypred) / (vary + 1e-8)) > 1e5:
        import ipdb; ipdb.set_trace()
    return 1 - np.var(y - ypred) / (vary + 1e-8)
dataset/ETHPy150Open rllab/rllab/rllab/misc/special.py/explained_variance_1d/original