Skip to content

Commit

Permalink
we only add a new value to the running stat if the value is between t…
Browse files Browse the repository at this point in the history
…he lower and upper bounds
  • Loading branch information
ChaoPang committed Sep 12, 2024
1 parent af2db54 commit e4c47c2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cehrbert/utils/stat_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
class RunningStatistics(OnlineStatistics):
def __init__(self, capacity=100, value_outlier_std=2.0):
super().__init__()
self.value_outlier_std = value_outlier_std
self.excluding_outlier_online_statistics = ExcludingOutlierOnlineStatistics(
capacity=capacity, value_outlier_std=value_outlier_std
)

def add(self, weight: float, value: float) -> None:
if self.excluding_outlier_online_statistics.is_full():
super().add(weight, value)
std = self.standard_deviation()
if self.current_mean - self.value_outlier_std * std <= self.current_mean + self.value_outlier_std * std:
super().add(weight, value)
else:
self.excluding_outlier_online_statistics.add(value)
if self.excluding_outlier_online_statistics.is_full():
Expand Down

0 comments on commit e4c47c2

Please sign in to comment.