diff options
| author | J08nY | 2019-02-22 10:29:28 +0100 |
|---|---|---|
| committer | J08nY | 2019-02-22 10:29:28 +0100 |
| commit | b6daaef0a884bd154a848bdb73919b3b82d0df98 (patch) | |
| tree | 7a4034a9862324b0988050cfe9f13c66d633daec /util/utils.py | |
| parent | 687a09baf6fd858d393b8f284cfe7236b52d7457 (diff) | |
| parent | fea5c7b1cbd539b105b42c4bde65d0b9b6f0b8fc (diff) | |
| download | ECTester-b6daaef0a884bd154a848bdb73919b3b82d0df98.tar.gz ECTester-b6daaef0a884bd154a848bdb73919b3b82d0df98.tar.zst ECTester-b6daaef0a884bd154a848bdb73919b3b82d0df98.zip | |
Diffstat (limited to 'util/utils.py')
| -rw-r--r-- | util/utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/util/utils.py b/util/utils.py new file mode 100644 index 0000000..bddfc35 --- /dev/null +++ b/util/utils.py @@ -0,0 +1,34 @@ +import numpy as np +from matplotlib import ticker + + +def hw(i): + res = 0 + while i: + res += 1 + i &= i - 1 + return res + + +def moving_average(a, n) : + ret = np.cumsum(a, dtype=float) + ret[n:] = ret[n:] - ret[:-n] + return ret[n - 1:] / n + + +def plot_hist(axes, data, xlabel=None, log=False): + time_max = max(data) + time_min = min(data) + time_avg = np.average(data) + time_median = np.median(data) + axes.hist(data, bins=time_max - time_min, log=log) + axes.axvline(x=time_avg, alpha=0.7, linestyle="dotted", color="blue", label="avg = {}".format(time_avg)) + axes.axvline(x=time_median, alpha=0.7, linestyle="dotted", color="green", label="median = {}".format(time_median)) + axes.set_ylabel("count" + ("\n(log)" if log else "")) + axes.set_xlabel("time" if xlabel is None else xlabel) + axes.xaxis.set_major_locator(ticker.MaxNLocator()) + axes.legend(loc="best") + + +def miller_correction(entropy, samples, bins): + return entropy + (bins - 1)/(2*samples) |
