Skip to content

Commit

Permalink
some progress, but needs a little more work. mostly whitespace and va…
Browse files Browse the repository at this point in the history
…riable name changes to conform to pylint.
  • Loading branch information
Alex Olivas committed Jun 25, 2020
1 parent 27a0c27 commit 42942fa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
39 changes: 23 additions & 16 deletions voka/metrics/cvm.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
from math import log
from scipy.special import binom
'''
Module contains a function object that calculates
the Cramer-von-Mises test statistic between two sets.
'''

class CramerVonMises(object):

def __call__(self, v1, v2):
class CramerVonMises:
'''
Function object that calculates
the Cramer-von-Mises test statistic between two sets.
'''

def __call__(self, vector1, vector2):
r"""
Compare sequences v1, v2 with the Cramer-von-Mises test.
Compare sequences vector1, vector2 with the Cramer-von-Mises test.
"""
result = 0.
Nu = float(sum(v1))
Nv = float(sum(v2))
if Nu == 0 and Nv == 0:
return 0.
if not sum(vector1) and not sum(vector2):
return result

Nu = float(sum(vector1))
Nv = float(sum(vector2))

for i,uv in enumerate(zip(v1, v2)):
for i, uv in enumerate(zip(vector1, vector2)):
u = float(uv[0])
v = float(uv[1])
v = float(uv[1])
t = u + v
u_ecdf = sum([bn for bn in v1[:i]])/sum(v1)
v_ecdf = sum([bn for bn in v2[:i]])/sum(v2)
u_ecdf = sum([bn for bn in vector1[:i]])/sum(vector1)
v_ecdf = sum([bn for bn in vector2[:i]])/sum(vector2)
result += t*(u_ecdf - v_ecdf)**2
factor = Nu*Nv/(Nu+Nv)**2
T = factor * result
return T
result = factor * result
return result
55 changes: 26 additions & 29 deletions voka/metrics/llh.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from math import log
from scipy.special import binom

class LLHRatio(object):
def __call__(self, v1, v2):
class LLHRatio:

def __call__(self, vector1, vector2):
r"""
Compare sequences v1, v2 with the log likelihood ratio test.
Compare sequences vector1, vector2 with the log likelihood ratio test.
"""
result = 0.
Nu = float(sum(v1))
Nv = float(sum(v2))

if Nu == 0:
if Nv == 0:
return 1.
else:
return 0.

for u,v in zip(v1, v2):
if not vector1 and not vector2:
return result

Nu = float(sum(vector1))
Nv = float(sum(vector2))

for u, v in zip(vector1, vector2):
u = float(u)
v = float(v)
t = u + v
Expand All @@ -26,40 +23,40 @@ def __call__(self, v1, v2):
continue
if u == 0:
result += t*log(Nu/(Nu+Nv))
continue
continue
if v == 0:
result += t*log(Nv/(Nu+Nv))
continue
term1 = t*log((1+v/u)/(1+Nv/Nu))
term2 = v*log((Nv/Nu)*(u/v))
result += term1 + term2
T = -2*result
return T
return T

class LLHValue:

class LLHValue(object):

def __call__(self, v1, v2):
def __call__(self, vector1, vector2):

r"""
Compare histograms h1, h2 with the log likelihood value test.
FIXME: This is currently returning inf on occasion. It should
never do that. Taking it out of the rotation.
"""
result = 0.
Nu = float(sum(v1))
Nv = float(sum(v2))
if Nu == 0 and Nv == 0:
return 0.

for u,v in zip(v1, v2):
if not vector1 and not vector2:
return result

Nu = float(sum(vector1))
Nv = float(sum(vector2))

for u, v in zip(vector1, vector2):
u = float(u)
v = float(v)
v = float(v)
t = u + v
bn = binom(t,v)
bn = binom(t, v)
term1 = log(bn)
term2 = t*log(Nu/(Nu + Nv))
term3 = v*log(Nv/Nu)
result += term1 + term2 + term3
T = -result
return T

return T

0 comments on commit 42942fa

Please sign in to comment.