stats: fixed the computation of variance when it is equal to 0
This commit is contained in:
@ -119,9 +119,12 @@ def mean(values, options):
|
||||
|
||||
def variance(v):
|
||||
if len(v)==1:
|
||||
return 0
|
||||
return 0
|
||||
s = reduce(lambda x,y:(x[0]+y,x[1]+y**2),v,(0.,0.))
|
||||
return s[1]/(len(v)-1) - s[0]**2/len(v)/(len(v)-1)
|
||||
var = round(s[1]/(len(v)-1) - s[0]**2/len(v)/(len(v)-1), 5) # round to go around shady python rounding stuff when var is actually 0
|
||||
if var == -0.0: # then fix -0 to +0 if was rounded to -0
|
||||
var = 0.0
|
||||
return var
|
||||
|
||||
|
||||
def varpop(values, options):
|
||||
|
Reference in New Issue
Block a user