Skip to content

Commit

Permalink
lnst.Common.Utils: use statistics in std_deviation
Browse files Browse the repository at this point in the history
This function was written back in 2015 when we couldn't use python3
yet and statistics module was added in 3.4.

At the same time, the formula used is "incorrect", this calculates the
POPULATION std deviation... whereas we really should be using a SAMPLE
standard deviation formula.

Signed-off-by: Ondrej Lichtner <[email protected]>
  • Loading branch information
olichtne committed Feb 8, 2024
1 parent 2d15587 commit 7646480
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lnst/Common/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import errno
import ast
import collections
import math
import statistics
import itertools
from collections.abc import Iterable, Callable
from contextlib import AbstractContextManager
Expand Down Expand Up @@ -287,10 +287,9 @@ def dict_to_dot(original_dict, prefix=""):
return return_list

def std_deviation(values):
if len(values) <= 0:
if len(values) <= 1:
return 0.0
avg = sum(values) / float(len(values))
return math.sqrt(sum([(float(i) - avg)**2 for i in values])/len(values))
return statistics.stdev(values)

def deprecated(func):
"""
Expand Down

0 comments on commit 7646480

Please sign in to comment.