plfit/plfit.py
def discrete_best_alpha(self, alpharangemults=(0.9,1.1), n_alpha=201,
                            approximate=True, verbose=True, finite=True):
        """
        Use the maximum likelihood to determine the most likely value of alpha

        *alpharangemults* [ 2-tuple ]
            Pair of values indicating multiplicative factors above and below the
            approximate alpha from the MLE alpha to use when determining the
            "exact" alpha (by directly maximizing the likelihood function)
        *n_alpha* [ int ]
            Number of alpha values to use when measuring.  Larger number is more accurate.
        *approximate* [ bool ]
            If False, try to "zoom-in" around the MLE alpha and get the exact
            best alpha value within some range around the approximate best
        *vebose* [ bool ]
        *finite* [ bool ]
            Correction for finite data?
        """

        data = self.data
        self._xmins = xmins = np.unique(data)
        if approximate:
            alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ]
        else:
            alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ]
            alpharanges = [(0.9*a,1.1*a) for a in alpha_approx]
            alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha)
                             for xmin,ar in zip(xmins,alpharanges) ]
        ksvalues = np.array([discrete_ksD(data, xmin, alpha)
                                for xmin,alpha in zip(xmins,alpha_of_xmin)
                               ])
        self._alpha_values = np.array(alpha_of_xmin)
        self._xmin_kstest = ksvalues

        ksvalues[np.isnan(ksvalues)] = np.inf

        best_index = argmin(ksvalues)
        self._alpha = best_alpha = alpha_of_xmin[best_index]
        self._xmin = best_xmin = xmins[best_index]
        self._ks = best_ks = ksvalues[best_index]
        self._likelihood = best_likelihood = discrete_likelihood(data, best_xmin, best_alpha)

        if finite:
            self._alpha = self._alpha*(n-1.)/n+1./n

        if verbose:
            print("alpha = %f   xmin = %f   ksD = %f   L = %f   (n<x) = %i  (n>=x) = %i" % (
                    best_alpha, best_xmin, best_ks, best_likelihood,
                    (data<best_xmin).sum(), (data>=best_xmin).sum()))


        self._ngtx = n = (self.data>=self._xmin).sum()
        self._alphaerr = (self._alpha-1.0)/np.sqrt(n)
        if scipyOK:
            self._ks_prob = scipy.stats.ksone.sf(self._ks, n)

        return best_alpha,best_xmin,best_ks,best_likelihood
def discrete_best_alpha(self, alpharangemults=(0.9,1.1), n_alpha=201,
                            approximate=True, verbose=True, finite=True):
        """
        Use the maximum likelihood to determine the most likely value of alpha

        *alpharangemults* [ 2-tuple ]
            Pair of values indicating multiplicative factors above and below the
            approximate alpha from the MLE alpha to use when determining the
            "exact" alpha (by directly maximizing the likelihood function)
        *n_alpha* [ int ]
            Number of alpha values to use when measuring.  Larger number is more accurate.
        *approximate* [ bool ]
            If False, try to "zoom-in" around the MLE alpha and get the exact
            best alpha value within some range around the approximate best
        *vebose* [ bool ]
        *finite* [ bool ]
            Correction for finite data?
        """

        data = self.data
        self._xmins = xmins = np.unique(data)
        if approximate:
            alpha_of_xmin = [ discrete_alpha_mle(data,xmin) for xmin in xmins ]
        else:
            alpha_approx = [ discrete_alpha_mle(data,xmin) for xmin in xmins ]
            alpharanges = [(0.9*a,1.1*a) for a in alpha_approx]
            alpha_of_xmin = [ most_likely_alpha(data,xmin,alpharange=ar,n_alpha=n_alpha)
                             for xmin,ar in zip(xmins,alpharanges) ]
        ksvalues = np.array([discrete_ksD(data, xmin, alpha)
                                for xmin,alpha in zip(xmins,alpha_of_xmin)
                               ])
        self._alpha_values = np.array(alpha_of_xmin)
        self._xmin_kstest = ksvalues

        ksvalues[np.isnan(ksvalues)] = np.inf

        best_index = argmin(ksvalues)
        self._alpha = best_alpha = alpha_of_xmin[best_index]
        self._xmin = best_xmin = xmins[best_index]
        self._ks = best_ks = ksvalues[best_index]
        self._likelihood = best_likelihood = discrete_likelihood(data, best_xmin, best_alpha)

        if finite:
            self._alpha = self._alpha*(n-1.)/n+1./n

        if verbose:
            print("alpha = %f   xmin = %f   ksD = %f   L = %f   (n<x) = %i  (n>=x) = %i" % (
                    best_alpha, best_xmin, best_ks, best_likelihood,
                    (data<best_xmin).sum(), (data>=best_xmin).sum()))


        self._ngtx = n = (self.data>=self._xmin).sum()
        self._alphaerr = (self._alpha-1.0)/np.sqrt(n)
        if scipyOK:
            self._ks_prob = scipy.stats.ksone.sf(self._ks, n)

        return best_alpha,best_xmin,best_ks,best_likelihood
Use the maximum likelihood to determine the most likely value of alpha

        *alpharangemults* [ 2-tuple ]
            Pair of values indicating multiplicative factors above and below the
            approximate alpha from the MLE alpha to use when determining the
            "exact" alpha (by directly maximizing the likelihood function)
        *n_alpha* [ int ]
            Number of alpha values to use when measuring.  Larger number is more accurate.
        *approximate* [ bool ]
            If False, try to "zoom-in" around the MLE alpha and get the exact
            best alpha value within some range around the approximate best
        *vebose* [ bool ]
        *finite* [ bool ]
            Correction for finite data?