An error occurred while loading the file. Please try again.
-
Le Roux Erwan authoredd5e81395
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import List
import numpy as np
import pandas as pd
class AbstractParams(object):
# Parameters
PARAM_NAMES = []
# Quantile
QUANTILE_10 = 'quantile 10'
QUANTILE_100 = 'quantile 100'
QUANTILE_1000 = 'quantile 1000'
QUANTILE_NAMES = [QUANTILE_10, QUANTILE_100, QUANTILE_1000][:-1]
QUANTILE_P_VALUES = [0.9, 0.99, 0.999]
# Summary
SUMMARY_NAMES = PARAM_NAMES + QUANTILE_NAMES
@classmethod
def from_dict(cls, params: dict):
return cls(**params)
# Parameters
@property
def param_values(self) -> List[float]:
raise NotImplementedError
def to_dict(self) -> dict:
assert len(self.PARAM_NAMES) == len(self.param_values)
return dict(zip(self.PARAM_NAMES, self.param_values))
def to_serie(self) -> pd.Series:
return pd.Series(self.to_dict(), index=self.PARAM_NAMES)
def to_array(self) -> np.ndarray:
return self.to_serie().values
# Quantile
def quantile(self, p) -> float:
raise NotImplementedError
@property
def quantile_name_to_p(self) -> dict:
return dict(zip(self.QUANTILE_NAMES, self.QUANTILE_P_VALUES))
@property
def quantile_name_to_value(self) -> dict:
return {quantile_name: self.quantile(p) for quantile_name, p in self.quantile_name_to_p.items()}
# Summary (i.e. parameters & quantiles)
@property
def summary_dict(self) -> dict:
return {**self.to_dict(), **self.quantile_name_to_value}
@property
def summary_serie(self) -> pd.Series:
return pd.Series(self.summary_dict, index=self.SUMMARY_NAMES)