models.py (1627B)
1 import numpy as np 2 from scipy import stats 3 from scipy.special import erf 4 5 6 ### Probability Distribution Functions 7 # Single Gaussian Functions 8 def evalSingleGaussian(theta, x): 9 mu, sig = theta[0], theta[1] 10 normalisingTerm = (0.5*(1+erf((2-mu)/(sig*2**0.5)) - (1+erf((0.8-mu)/(sig*2**0.5))))) 11 return stats.norm(mu, sig).pdf(x) * 1.0/normalisingTerm 12 13 # Two Gaussian Functions 14 def evalTwoGaussian(theta, x): 15 mu1, mu2, sig1, sig2, alpha = theta 16 normalisingTerm1 = (0.5*(1+erf((2-mu1)/(sig1*2**0.5)) - (1+erf((0.8-mu1)/(sig1*2**0.5))))) 17 normalisingTerm2 = (0.5*(1+erf((2-mu2)/(sig2*2**0.5)) - (1+erf((0.8-mu2)/(sig2*2**0.5))))) 18 return alpha * stats.norm(mu1, sig1).pdf(x) * 1.0/normalisingTerm1 + (1-alpha) * stats.norm(mu2, sig2).pdf(x) * 1.0/normalisingTerm2 19 20 # Uniform Functions 21 def evalUniform(theta, x): 22 mMin, mMax = theta[0], theta[1] 23 return stats.uniform(mMin, mMax-mMin).pdf(x) 24 25 26 27 ### Model Information Dictionaries 28 singleGaussianModel = { 29 "name": "singleGaussian", 30 "pdf": evalSingleGaussian, 31 "ndim": 2, 32 "params": ['mu', 'sigma'] 33 } 34 35 twoGaussianModel = { 36 "name": "twoGaussian", 37 "pdf": evalTwoGaussian, 38 "ndim": 5, 39 "params": ['mu1', 'mu2', 'sigma1', 'sigma2', 'alpha'] 40 } 41 42 uniformModel = { 43 "name": "uniform", 44 "pdf": evalUniform, 45 "ndim": 2, 46 "params": ['mMin', 'mMax'] 47 } 48 49 50 singleGaussianList = ["singleGaussian", evalSingleGaussian, 2, [r'$\mu$', r'$\sigma$']] 51 twoGaussianList = ["twoGaussian", evalTwoGaussian, 5, [r'$\mu_1$', r'$\mu_2$', r'$\sigma_1$', r'$\sigma_2$', r'$\alpha$']] 52 uniformList = ["uniform", evalUniform, 2, [r'$m_l$', r'$m_u$']]