-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstochastic.py
56 lines (43 loc) · 1.42 KB
/
stochastic.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
class Stochastic:
@staticmethod
def uniform_1(data):
"""Uniform distribution with bounds [d - sqrt(d), d + sqrt(d)].
d is a a deterministic duration d, i.e. uniformly adding or subtracting
sqrt(d) from d.
:param data:
:return:
"""
d = np.array(data)
return np.maximum((d > 0), data + np.random.uniform(-1, 1, size=d.shape) * np.sqrt(data))
@staticmethod
def uniform_2(data):
"""Uniform distribution with bounds [0, 2d] for a deterministic duration d.
:param data:
:return:
"""
d = np.array(data)
return np.maximum((d > 0), np.random.uniform(0, 2, size=d.shape) * data)
@staticmethod
def exponential(data):
"""Exponential distribution with expectation d for a deterministic duration d.
Note from the numpy doc: The scale parameter, β=1/λ
:param data:
:return:
"""
d = np.array(data)
return np.maximum((d > 0), np.random.exponential(d))
@staticmethod
def beta_1(data):
"""Beta distribution on [d/2, 2d] with variance d/3 for a deterministic duration d.
:param data:
:return:
"""
pass
@staticmethod
def beta_2(data):
"""Beta distribution on [d/2, 2d] with variance d²/3 for a deterministic duration d.
:param data:
:return:
"""
pass