jax_cosmo.scipy package

jax_cosmo.scipy.integrate module

jax_cosmo.scipy.integrate.romb(function, a, b, args=(), divmax=6, return_error=False)[source]

Romberg integration of a callable function or method. Returns the integral of function (a function of one variable) over the interval (a, b). If show is 1, the triangular array of the intermediate results will be printed. If vec_func is True (default is False), then function is assumed to support vector arguments. :param function: Function to be integrated. :type function: callable :param a: Lower limit of integration. :type a: float :param b: Upper limit of integration. :type b: float

Returns:

results – Result of the integration.

Return type:

float

Other Parameters:
 
  • args (tuple, optional) – Extra arguments to pass to function. Each element of args will be passed as a single argument to func. Default is to pass no extra arguments.
  • divmax (int, optional) – Maximum order of extrapolation. Default is 10.

See also

fixed_quad()
Fixed-order Gaussian quadrature.
quad()
Adaptive quadrature using QUADPACK.
dblquad()
Double integrals.
tplquad()
Triple integrals.
romb()
Integrators for sampled data.
simps()
Integrators for sampled data.
cumtrapz()
Cumulative integration for sampled data.
ode()
ODE integrator.
odeint()
ODE integrator.

References

[1]‘Romberg’s method’ http://en.wikipedia.org/wiki/Romberg%27s_method

Examples

Integrate a gaussian from 0 to 1 and compare to the error function. >>> from scipy import integrate >>> from scipy.special import erf >>> gaussian = lambda x: 1/np.sqrt(np.pi) * np.exp(-x**2) >>> result = integrate.romberg(gaussian, 0, 1, show=True) Romberg integration of <function vfunc at …> from [0, 1]

Steps  StepSize  Results
    1  1.000000  0.385872
    2  0.500000  0.412631  0.421551
    4  0.250000  0.419184  0.421368  0.421356
    8  0.125000  0.420810  0.421352  0.421350  0.421350
   16  0.062500  0.421215  0.421350  0.421350  0.421350  0.421350
   32  0.031250  0.421317  0.421350  0.421350  0.421350  0.421350  0.421350

The final result is 0.421350396475 after 33 function evaluations. >>> print(“%g %g” % (2*result, erf(1))) 0.842701 0.842701

jax_cosmo.scipy.integrate.simps(f, a, b, N=128)[source]

Approximate the integral of f(x) from a to b by Simpson’s rule.

Simpson’s rule approximates the integral int_a^b f(x) dx by the sum: (dx/3) sum_{k=1}^{N/2} (f(x_{2i-2} + 4f(x_{2i-1}) + f(x_{2i})) where x_i = a + i*dx and dx = (b - a)/N.

Parameters:
  • f (function) – Vectorized function of a single variable
  • , b (a) – Interval of integration [a,b]
  • N ((even) integer) – Number of subintervals of [a,b]
Returns:

Approximation of the integral of f(x) from a to b using Simpson’s rule with N subintervals of equal length.

Return type:

float

Examples

>>> simps(lambda x : 3*x**2,0,1,10)
1.0

Stolen from: https://www.math.ubc.ca/~pwalls/math-python/integration/simpsons-rule/

jax_cosmo.scipy.interpolate module

jax_cosmo.scipy.interpolate.interp(x, xp, fp)[source]

Vectorized version of interp. Takes similar arguments as interp but with additional array axes over which interp is mapped.

Original documentation:

Simple equivalent of np.interp that compute a linear interpolation.

We are not doing any checks, so make sure your query points are lying inside the array.

TODO: Implement proper interpolation!

x, xp, fp need to be 1d arrays

jax_cosmo.scipy.ode module

jax_cosmo.scipy.ode.odeint(fn, y0, t)[source]

My dead-simple rk4 ODE solver. with no custom gradients