-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
38 lines (30 loc) · 785 Bytes
/
utils.py
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
from typing import Optional, Tuple
import numpy as np
import pandas as pd
def gaussian_noise(
x: pd.Series,
sigma: float,
mu: Optional[float] = 0.,
) -> pd.Series:
x += np.random.normal(loc=mu, scale=sigma)
return x
def uniform_noise(
x: pd.Series,
lower: float,
higher: float,
) -> pd.Series:
x += np.random.uniform(lower, higher, len(x))
return x
def exponential_noise(
x: pd.Series,
beta: float,
) -> pd.Series:
x *= np.random.exponential(beta, len(x))
return x
def transform_nbinom(
mean: float,
var: float,
) -> Tuple[float, float]:
p = np.minimum(np.where(var > 0, mean / var, 1 - 1e-8), 1 - 1e-8)
n = np.where(var > 0, mean * p / (1 - p), 1)
return n, p