[M] Mode experiment scripts
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@dataclass
|
||||
class Statistics:
|
||||
mean: float
|
||||
median: float
|
||||
lower_quartile: float
|
||||
upper_quartile: float
|
||||
iqr: float
|
||||
minimum: float
|
||||
maximum: float
|
||||
count: int
|
||||
total: float
|
||||
stddev: float
|
||||
|
||||
def get_metric_6(self) -> tuple[float, float, float, float, float, float]:
|
||||
return self.mean, self.median, self.minimum, self.maximum, self.lower_quartile, self.upper_quartile
|
||||
|
||||
def print(self, dec: int = 2):
|
||||
print(f'> Mean: {round(self.mean, dec)}, Median: {round(self.median, dec)}')
|
||||
print(f'> Min: {round(self.minimum, dec)}, Max: {round(self.maximum, dec)}')
|
||||
print(f'> Q1: {round(self.lower_quartile, dec)}, Q3: {round(self.upper_quartile, dec)}')
|
||||
print(f'> StdDev: {round(self.stddev, dec)}, IQR: {round(self.iqr, dec)}')
|
||||
print(f'> N: {self.count}')
|
||||
|
||||
|
||||
def _calc_col_stats_helper(col: np.ndarray) -> tuple[float, float, float, float, float, float, float, int, float, float]:
|
||||
q1 = np.quantile(col, 0.25)
|
||||
q3 = np.quantile(col, 0.75)
|
||||
return (
|
||||
float(np.mean(col)),
|
||||
float(np.median(col)),
|
||||
float(q1),
|
||||
float(q3),
|
||||
float(q3 - q1),
|
||||
float(np.min(col)),
|
||||
float(np.max(col)),
|
||||
len(col),
|
||||
float(np.sum(col)),
|
||||
float(np.std(col))
|
||||
)
|
||||
|
||||
|
||||
def calc_col_stats(col: np.ndarray | list) -> Statistics:
|
||||
"""
|
||||
Compute statistics for a data column
|
||||
:param col: Input column (tested on 1D array)
|
||||
:return: Statistics
|
||||
"""
|
||||
if isinstance(col, list):
|
||||
col = np.array(col)
|
||||
return Statistics(*_calc_col_stats_helper(col))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
txt = Path('action-sizes.log').read_text('utf-8').split('\n')
|
||||
nums = [int(line) for line in txt if line.isnumeric()]
|
||||
# print(nums)
|
||||
|
||||
calc_col_stats(nums).print()
|
||||
plt.hist(nums, bins=50)
|
||||
plt.show()
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
,Date,Number of Patches
|
||||
0,2017-03-01,3149
|
||||
1,2017-06-01,3150
|
||||
2,2017-09-01,3146
|
||||
3,2017-12-01,3139
|
||||
4,2018-03-01,3146
|
||||
5,2018-04-01,3146
|
||||
6,2018-06-01,3148
|
||||
7,2018-07-01,3153
|
||||
8,2018-09-01,3148
|
||||
9,2018-10-01,3142
|
||||
10,2018-12-01,3142
|
||||
11,2019-01-01,3149
|
||||
12,2019-03-01,3147
|
||||
13,2019-04-01,3151
|
||||
14,2019-06-01,3148
|
||||
15,2019-07-01,3147
|
||||
16,2019-09-01,3152
|
||||
17,2019-10-01,3148
|
||||
18,2019-12-01,3146
|
||||
19,2020-01-01,3148
|
||||
20,2020-03-01,3146
|
||||
21,2020-04-01,3147
|
||||
22,2020-06-01,3146
|
||||
23,2020-07-01,3149
|
||||
24,2020-09-01,3140
|
||||
25,2020-10-01,3152
|
||||
26,2020-12-01,3136
|
||||
27,2021-01-01,3149
|
||||
28,2021-03-01,3146
|
||||
29,2021-04-01,3146
|
||||
30,2021-06-01,3148
|
||||
31,2021-07-01,3150
|
||||
32,2021-09-01,3138
|
||||
33,2021-10-01,3146
|
||||
34,2021-12-01,3148
|
||||
35,2022-01-01,3148
|
||||
36,2022-03-01,3142
|
||||
37,2022-04-01,3152
|
||||
38,2022-06-01,3151
|
||||
|
Reference in New Issue
Block a user