def corr_to_coef(v_x, v_e, cov_xe, cor):
    b2 = v_x ** 2 * (cor ** 2 - 1)
    b1 = 2 * cov_xe * v_x * (cor ** 2 - 1)
    b0 = cor ** 2 * v_x * v_e - cov_xe ** 2
    delta = b1 ** 2 - 4 * b2 * b0
    sol1 = (-b1 - np.sqrt(delta)) / (2 * b2)
    sol2 = (-b1 + np.sqrt(delta)) / (2 * b2)

    return np.max([sol1, sol2]) if cor >= 0 else np.min([sol1, sol2])


############################################################################
## utils


############################################################################
## Objects classes
In a linear model y = bx + e. Calculate b such cor(bx + e, x) = cor.
dataset/ETHPy150Open neurospin/pylearn-parsimony/parsimony/datasets/utils.py/corr_to_coef