def fit_beta_mean_uncertainty(mean, var):
    """
    Compute parameters from the mean and variance following this parameterization:
    https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_variance
    """
    EPSILON = 1E-2
    mean = EPSILON if mean==0 else 1-EPSILON if mean==1 else mean
    nu = -1 + (mean * (1 - mean)) / var
    alpha = mean * nu
    beta = (1 - mean) * nu
    if alpha < 0 or beta < 0:
        pass
    return alpha, beta