Integration
Module for integrating functions in a consistent way in jaxspec
.
It mainly relies on tanh-sinh (or double exponential) quadrature to perform the integration.
References
- Takahasi and Mori (1974)
- Mori and Sugihara (2001)
- Tanh-sinh quadrature from Wikipedia
integrate_interval(integrand, n=51)
¶
Build a function which can compute the integral of the provided integrand over the interval \([a, b]\) using the tanh-sinh quadrature. Returns a function \(F(a, b, \pmb{\theta})\) which takes the limits of the interval and the parameters of \(f(x,\pmb{\theta})\) as inputs.
Example usage¶
pi = 4*integrate_interval(lambda x: 1/(1+x**2))(0, 1)
print(pi) # 3.1415927
Example where the limits of the integral are parameters¶
def erf(x):
def integrand(t):
return 2/jnp.sqrt(jnp.pi) * jnp.exp(-t**2)
return integrate_interval(integrand)(0, x)
print(erf(1)) # 0.84270084
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integrand
|
Callable
|
The function to integrate |
required |
n
|
int
|
The number of points to use for the quadrature |
51
|
Returns:
Type | Description |
---|---|
Callable
|
The integral of the provided integrand over the interval \([a, b]\) as a callable |
Source code in src/jaxspec/util/integrate.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
integrate_positive(integrand, n=51)
¶
Build a function which can compute the integral of the provided integrand over the positive real line using the tanh-sinh quadrature. Returns a function \(F(\pmb{\theta})\) which takes the parameters of the integrand \(f(x,\pmb{\theta})\) as inputs.
Example usage¶
gamma = integrate_positive(lambda t, z: t**(z-1) * jnp.exp(-t))
print(gamma(1/2)) # 1.7716383
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integrand
|
Callable
|
The function to integrate |
required |
n
|
int
|
The number of points to use for the quadrature |
51
|
Returns:
Type | Description |
---|---|
Callable
|
The integral of the provided integrand over the positive real line as a callable |
Source code in src/jaxspec/util/integrate.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
interval_weights(a, b, n)
¶
Return the weights for the tanh-sinh quadrature over the interval [a, b].
Source code in src/jaxspec/util/integrate.py
19 20 21 22 23 24 25 26 27 28 29 |
|
positive_weights(n)
¶
Return the weights for the tanh-sinh quadrature over the positive real line.
Source code in src/jaxspec/util/integrate.py
32 33 34 35 36 37 38 39 40 |
|