From 884aeb9565e7b2f9eff477d2ef5a62930ab7875f Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 16 Jun 2014 15:19:19 +0200 Subject: [PATCH] attempted fix to issue #3. Not resolved. --- plfit/plfit.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plfit/plfit.py b/plfit/plfit.py index fcfb890..614b472 100644 --- a/plfit/plfit.py +++ b/plfit/plfit.py @@ -95,7 +95,7 @@ def alpha(xmin,x=x): return a return alpha - def kstest_(self,x): + def kstest_(self,x,unique=False,finite=False): """ Create a mappable function kstest to apply to each xmin in a list of xmins. @@ -107,12 +107,16 @@ def kstest_(self,x): The returned value is the "D" parameter in the ks test. """ def kstest(xmin,x=x): + if unique: + x = numpy.unique(x) x = x[x>=xmin] - n = float(len(x)) + n = len(x) if n == 0: return numpy.inf - a = float(n) / sum(log(x/xmin)) + a = 1+float(n) / sum(log(x/xmin)) + if finite: + a = a*(n-1.)/n+1./n cx = numpy.arange(n,dtype='float')/float(n) - cf = 1-(xmin/x)**a + cf = 1-(xmin/x)**(a-1) ks = max(abs(cf-cx)) return ks return kstest