Skip to content

Commit

Permalink
transfer changes from #26 to updated env
Browse files Browse the repository at this point in the history
  • Loading branch information
rishasurana committed Jun 27, 2023
1 parent 5d0a86b commit 3ebe72e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/elexmodel/utils/math_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from scipy.stats import bootstrap
from scipy.stats.mstats import winsorize

LOG = logging.getLogger()

Expand All @@ -22,6 +23,15 @@ def sample_std(x, axis):
return np.std(x, ddof=1, axis=-1)


def winsorize_std(x, axis):
"""
Compute the winsorized standard deviation along the last axis. Limits
are used to trim 1% of the extreme values on both ends of the data.
"""
x_win = winsorize(x, limits=(0.01, 0.01), axis=-1).data
return np.std(x_win, ddof=1, axis=-1)


def weighted_median(x, weights):
"""
Compute weighted median. This function expectes weights to sum to 1.
Expand Down Expand Up @@ -55,6 +65,10 @@ def weighted_median(x, weights):
return x_sorted[median_index + 1]


def robust_sample_std(x, axis):
return winsorize_std(x, axis=-1)


def boot_sigma(data, conf, num_iterations=10000):
"""
Bootstrap standard deviation.
Expand Down

0 comments on commit 3ebe72e

Please sign in to comment.