pyfastnbfit/pyfastnbfit.py
def fastfit_gamma(observed, s=None, tol=1e-3, max_iterations=10):
    """Estimate parameters of a Gamma distribution.

    Parameters
    ----------
    observed: array_like
              Observed values

    s: array_like
       Sufficient statistics. Default: None (inferred from the observations)

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    a, b: float
          alpha, beta parameters of Gamma Distribution
          https://en.wikipedia.org/wiki/Gamma_distribution#Characterization_using_shape_%CE%B1_and_rate_%CE%B2
    iterations: int
                Number of iterations before convergence
    """
    xbar = np.mean(observed)
    log_xbar = np.log(xbar)
    bar_logx = np.mean(np.log(observed))
    if s is None:
        s = log_xbar - bar_logx
    a = 0.5 / s

    a_old = np.inf
    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        #a, _ = inv_digamma(np.log(a) - s)
        sa = np.log(a) - s
        a = _digammainv(sa)# for x in sa]
        iteration += 1

    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        num = np.log(a) - s - digamma(a)
        denom = 1 / a - trigamma(a)
        a = 1 / (1 / a + num / (a ** 2 * denom))
        iteration += 1
    b = xbar / a
    return a, b, iteration
Estimate parameters of a Gamma distribution.

    Parameters
    ----------
    observed: array_like
              Observed values

    s: array_like
       Sufficient statistics. Default: None (inferred from the observations)

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    a, b: float
          alpha, beta parameters of Gamma Distribution
          https://en.wikipedia.org/wiki/Gamma_distribution#Characterization_using_shape_%CE%B1_and_rate_%CE%B2
    iterations: int
                Number of iterations before convergence
    
Estimate parameters of a Gamma distribution.
Parameters





float
Tolerance criterion for stopping
iterations when difference between sucessive estimates
drops below this value.

int
Maximum number of iterations.

Returns


Estimate parameters of a Gamma distribution . Parameters float Tolerance criterion for stopping iterations when difference between sucessive estimates drops below this value . int Maximum number of iterations . Returns
def fastfit_gamma(observed, s=None, tol=1e-3, max_iterations=10):
    xbar = np.mean(observed)
    log_xbar = np.log(xbar)
    bar_logx = np.mean(np.log(observed))
    if s is None:
        s = log_xbar - bar_logx
    a = 0.5 / s
    a_old = np.inf
    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        sa = np.log(a) - s
        a = _digammainv(sa)
        iteration += 1
    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        num = np.log(a) - s - digamma(a)
        denom = 1 / a - trigamma(a)
        a = 1 / (1 / a + num / (a ** 2 * denom))
        iteration += 1
    b = xbar / a
    return a, b, iteration
def fastfit_gamma ( observed , s = None , tol = 1e-3 , max_iterations = 10 ) : xbar = np . mean ( observed ) log_xbar = np . log ( xbar ) bar_logx = np . mean ( np . log ( observed ) ) if s is None : s = log_xbar - bar_logx a = 0.5 / s a_old = np . inf iteration = 0 while ( np . abs ( a_old - a ) > tol ) and ( iteration < max_iterations ) : a_old = a sa = np . log ( a ) - s a = _digammainv ( sa ) iteration += 1 iteration = 0 while ( np . abs ( a_old - a ) > tol ) and ( iteration < max_iterations ) : a_old = a num = np . log ( a ) - s - digamma ( a ) denom = 1 / a - trigamma ( a ) a = 1 / ( 1 / a + num / ( a ** 2 * denom ) ) iteration += 1 b = xbar / a return a , b , iteration
Estimate parameters of a Gamma distribution.
Estimate parameters of a Gamma distribution .
"""Estimate parameters of a Gamma distribution.

    Parameters
    ----------
    observed: array_like
              Observed values

    s: array_like
       Sufficient statistics. Default: None (inferred from the observations)

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    a, b: float
          alpha, beta parameters of Gamma Distribution
          https://en.wikipedia.org/wiki/Gamma_distribution#Characterization_using_shape_%CE%B1_and_rate_%CE%B2
    iterations: int
                Number of iterations before convergence
    """ #a, _ = inv_digamma(np.log(a) - s) # for x in sa]
observed
s
tol
max_iterations