-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfmath.py
More file actions
36 lines (19 loc) · 843 Bytes
/
Copy pathfmath.py
File metadata and controls
36 lines (19 loc) · 843 Bytes
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
# Useful math and helper functions
import numpy as np
from numpy import log, log10, exp, pi, sqrt, power, \
sin, cos, tan, arccos, arctan, arcsin, arctan2, heaviside, dot, cross
from scipy.integrate import quad, dblquad
from scipy.special import exp1, erf, erfinv, gamma
from scipy.stats import norm, chisquare, expon
def fastMC1D(func, a, b, n_samples, **kwargs):
# Fast 1D monte carlo, regenerating random variates each time
vars = np.random.uniform(a, b, n_samples)
return (b-a)*np.sum(func(vars, kwargs))/n_samples
# Fast 2d monte carlo
def fastMC2D(func, a, b, c, d, n_samples):
pass
def kallen_alplib(x, y, z):
return x*x + y*y + z*z - 2*x*y - 2*y*z - 2*z*x
def nu_integral(x, alpha, T_max=np.inf):
f = lambda t: np.power(x, t + alpha) / gamma(t + 1 + alpha)
return quad(f, 0.0, T_max)[0]