def beta(**kwds):
    """Return the parameters of the beta distribution (alpha, beta) given the
    mean and variance."""
    mean = kwds['mean']
    var = kwds['variance']

    alpha = -(mean*var + mean**3 - mean**2) / var
    beta = ((mean-1)*var + mean**3 - 2*mean**2 + mean) / var
    return alpha, beta