-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
52 lines (41 loc) · 1.59 KB
/
models.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
import numpy as np
from scipy import stats
from scipy.special import erf
### Probability Distribution Functions
# Single Gaussian Functions
def evalSingleGaussian(theta, x):
mu, sig = theta[0], theta[1]
normalisingTerm = (0.5*(1+erf((2-mu)/(sig*2**0.5)) - (1+erf((0.8-mu)/(sig*2**0.5)))))
return stats.norm(mu, sig).pdf(x) * 1.0/normalisingTerm
# Two Gaussian Functions
def evalTwoGaussian(theta, x):
mu1, mu2, sig1, sig2, alpha = theta
normalisingTerm1 = (0.5*(1+erf((2-mu1)/(sig1*2**0.5)) - (1+erf((0.8-mu1)/(sig1*2**0.5)))))
normalisingTerm2 = (0.5*(1+erf((2-mu2)/(sig2*2**0.5)) - (1+erf((0.8-mu2)/(sig2*2**0.5)))))
return alpha * stats.norm(mu1, sig1).pdf(x) * 1.0/normalisingTerm1 + (1-alpha) * stats.norm(mu2, sig2).pdf(x) * 1.0/normalisingTerm2
# Uniform Functions
def evalUniform(theta, x):
mMin, mMax = theta[0], theta[1]
return stats.uniform(mMin, mMax-mMin).pdf(x)
### Model Information Dictionaries
singleGaussianModel = {
"name": "singleGaussian",
"pdf": evalSingleGaussian,
"ndim": 2,
"params": ['mu', 'sigma']
}
twoGaussianModel = {
"name": "twoGaussian",
"pdf": evalTwoGaussian,
"ndim": 5,
"params": ['mu1', 'mu2', 'sigma1', 'sigma2', 'alpha']
}
uniformModel = {
"name": "uniform",
"pdf": evalUniform,
"ndim": 2,
"params": ['mMin', 'mMax']
}
singleGaussianList = ["singleGaussian", evalSingleGaussian, 2, [r'$\mu$', r'$\sigma$']]
twoGaussianList = ["twoGaussian", evalTwoGaussian, 5, [r'$\mu_1$', r'$\mu_2$', r'$\sigma_1$', r'$\sigma_2$', r'$\alpha$']]
uniformList = ["uniform", evalUniform, 2, [r'$m_l$', r'$m_u$']]