def check_consistency(p=p, extra_par={}): old_p = p.copy() p.update(extra_par) wJ = sqrt(p["mJ"] / p["DJ"]) wA = sqrt(p["mA"] / p["DA"]) assert p["r"] >= 1.0 assert 1.0 / p["r"] * (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) <= 1.0 p.update(old_p)
def G(l, p=p, extra_par={}): old_p = p.copy() p.update(extra_par) wJ = sqrt((p["mJ"] + l) / p["DJ"]) wA = sqrt((p["mA"] + l) / p["DA"]) result = exp(l * p["t1"]) * (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) p.update(old_p) return result
def daubechis(N): # make polynomial q_y = [sm.binomial(N-1+k,k) for k in reversed(range(N))] # get polynomial roots y[k] y = sm.mp.polyroots(q_y, maxsteps=200, extraprec=64) z = [] for yk in y: # subustitute y = -1/4z + 1/2 - 1/4/z to factor f(y) = y - y[k] f = [sm.mpf('-1/4'), sm.mpf('1/2') - yk, sm.mpf('-1/4')] # get polynomial roots z[k] z += sm.mp.polyroots(f) # make polynomial using the roots within unit circle h0z = sm.sqrt('2') for zk in z: if sm.fabs(zk) < 1: h0z *= sympy.sympify('(z-zk)/(1-zk)').subs('zk',zk) # adapt vanising moments hz = (sympy.sympify('(1+z)/2')**N*h0z).expand() # get scaling coefficients return [sympy.re(hz.coeff('z',k)) for k in reversed(range(N*2))]
def intA(p=p, extra_par={}): old_p = p.copy() p.update(extra_par) wJ = sqrt((p["mJ"]) / p["DJ"]) wA = sqrt((p["mA"]) / p["DA"]) result = ( sinh(wA * p["d"]) / wA / cosh(wA * p["d"]) * ( 1 / (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) - 1.0 / (p["r"] * p["d"] * exp(-p["a"] * p["L1"])) ) ) p.update(old_p) return result
def J(x, p=p, extra_par={}): old_p = p.copy() p.update(extra_par) assert x >= 0 assert x <= p["L1"] wJ = sqrt((p["mJ"]) / p["DJ"]) wA = sqrt((p["mA"]) / p["DA"]) result = p["K"] * exp(wJ * (x - p["L1"])) / 2.0 * (1 - wA / wJ * tanh(wA * p["d"])) * ( 1 / (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) - 1.0 / (p["r"] * p["d"] * exp(-p["a"] * p["L1"])) ) + p["K"] * exp(-wJ * (x - p["L1"])) / 2.0 * (1 + wA / wJ * tanh(wA * p["d"])) * ( 1 / (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) - 1.0 / (p["r"] * p["d"] * exp(-p["a"] * p["L1"])) ) p.update(old_p) return result
def A(x, p=p, extra_par={}): old_p = p.copy() p.update(extra_par) assert x >= p["L1"] assert x <= p["L1"] + p["d"] wJ = sqrt((p["mJ"]) / p["DJ"]) wA = sqrt((p["mA"]) / p["DA"]) result = ( cosh(wA * (p["L1"] + p["d"] - x)) / cosh(wA * p["d"]) * ( 1 / (cosh(wJ * p["L1"]) + wA / wJ * tanh(wA * p["d"]) * sinh(wJ * p["L1"])) - 1.0 / (p["r"] * p["d"] * exp(-p["a"] * p["L1"])) ) ) p.update(old_p) return result
def test_norms(): # matrix norms A = matrix([[1, -2], [-3, -1], [2, 1]]) assert mnorm_1(A) == 6 assert mnorm_oo(A) == 4 assert mnorm_F(A) == sqrt(20) # vector norms x = [1, -2, 7, -12] assert norm_p(x, 1) == 22 assert round(norm_p(x, 2), 10) == 14.0712472795 assert round(norm_p(x, 10), 10) == 12.0054633727 assert norm_p(x, inf) == 12
def calc_fnu_mp(nu_M, a=0.707, p=0.3, A=1): """ Find f(nu) using equation A19 from Zhu et al. A19 is used to get the mass function, f(nu). Find A using int_0^inf fnu dnu = 1. They find 0.129. We find A=0.322? # need to integrate fnu from 0 -> inf and set equal to 1, which sets A. res2,_ = scipy.integrate.quad(calc_fnu, 0, np.inf) print res2 """ # normalization constant is A, assume 1 for now. an2 = a*nu_M return A*mp.sqrt(2 * an2 / pi) * (1 + an2**-p) * mp.exp(-0.5*an2)
def cramerVonMises(x, y): try: x = sorted(x); y = sorted(y); pool = x + y; ps, pr = _sortRank(pool) rx = array ( [ pr[ind] for ind in [ ps.index(element) for element in x ] ] ) ry = array ( [ pr[ind] for ind in [ ps.index(element) for element in y ] ] ) n = len(x) m = len(y) i = array(range(1, n+1)) j = array(range(1, m+1)) u = n * sum ( power( (rx - i), 2 ) ) + m * sum ( power((ry - j), 2) ) t = u / (n*m*(n+m)) - (4*n*m-1) / (6 * (n+m)) Tmu = 1/6 + 1 / (6*(n+m)) Tvar = 1/45 * ( (m+n+1) / power((m+n),2) ) * (4*m*n*(m+n) - 3*(power(m,2) + power(n,2)) - 2*m*n) / (4*m*n) t = (t - Tmu) / power(45*Tvar, 0.5) + 1/6 if t < 0: return -1 elif t <= 12: a = 1-mp.nsum(lambda x : ( mp.gamma(x+0.5) / ( mp.gamma(0.5) * mp.fac(x) ) ) * mp.power( 4*x + 1, 0.5 ) * mp.exp ( - mp.power(4*x + 1, 2) / (16*t) ) * mp.besselk(0.25 , mp.power(4*x + 1, 2) / (16*t) ), [0,100] ) / (mp.pi*mp.sqrt(t)) return float(mp.nstr(a,3)) else: return 0 except Exception as e: print e return -1
def N(x, l, p=p): '''Incomplete!!''' return 2. * mp.sinh(sqrt((p['mJ'] + l)/p['DJ']) * p['L1']) \ * (mp.exp(mp.sqrt((p['mA'] + l)/p['DA']) * x) + \ mp.exp(mp.sqrt((p['mA'] + l)/p['DA']) * (2*p['L2'] - x)))
def M(x, l, p=p): return mp.exp(mp.sqrt((p['mJ'] + l)/p['DJ']) * x) + \ ((1 - p['b'] * mp.exp(-x * p['t2'])) * mp.exp(x * p['t1']) - p['a'] * mp.exp(mp.sqrt((p['mJ'] + l)/p['DJ']) * p['L1'])) / \ ((1 - p['b'] * mp.exp(-x * p['t2'])) * mp.exp(x * p['t1']) - p['a'] * mp.exp(- mp.sqrt((p['mJ'] + l)/p['DJ']) * p['L1'])) \ * mp.exp(- mp.sqrt((p['mJ'] + l)/p['DJ']) * x)
def F(x, p=p): return (1 - p['b'] * mp.exp(-x * p['t2'])) * mp.exp(x * p['t1']) \ * (mp.cosh(mp.sqrt((p['mJ'] + x)/p['DJ']) * p['L1']) \ + mp.sinh(mp.sqrt((p['mJ'] + x)/p['DJ']) * p['L1']) \ * mp.sqrt((p['mJ'] + x)/p['DJ']) / mp.sqrt((p['mA'] + x)/p['DA']) \ * mp.coth(mp.sqrt((p['mA'] + x)/p['DA']) * p['d'])) - p['a']