projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix a bug in sanity check image.
[python_utils.git]
/
math_utils.py
diff --git
a/math_utils.py
b/math_utils.py
index 3a672da1caf406d3a842ae46923a88063743dbbd..156862a9c1b55eeec5515efef82f8f951d59b416 100644
(file)
--- a/
math_utils.py
+++ b/
math_utils.py
@@
-2,10
+2,13
@@
"""Mathematical helpers."""
"""Mathematical helpers."""
+import collections
import functools
import math
from heapq import heappop, heappush
import functools
import math
from heapq import heappop, heappush
-from typing import List, Optional
+from typing import Dict, List, Optional, Tuple
+
+import dict_utils
class NumericPopulation(object):
class NumericPopulation(object):
@@
-70,6
+73,14
@@
class NumericPopulation(object):
count = len(self.lowers) + len(self.highers)
return self.aggregate / count
count = len(self.lowers) + len(self.highers)
return self.aggregate / count
+ def get_mode(self) -> Tuple[float, int]:
+ count: Dict[float, int] = collections.defaultdict(int)
+ for n in self.lowers:
+ count[-n] += 1
+ for n in self.highers:
+ count[n] += 1
+ return dict_utils.item_with_max_value(count)
+
def get_stdev(self) -> float:
"""Returns the stdev so far in O(n) time."""
def get_stdev(self) -> float:
"""Returns the stdev so far in O(n) time."""