Integrators¶
- class diffinytrace.integrators.Integrator[source]¶
Bases:
object- sample(num_points: int | list[int], method: IntegrationMethod) tuple[Tensor, Tensor][source]¶
Sample points and weights using the specified method. :param num_points: Number of points in each dimension. :type num_points: int or list :param method: The integration method to use. Options are ‘simpson’, ‘midpoint’, ‘monte_carlo’, ‘sobol’, and ‘sobol_pow2’. :type method: str
- Returns:
A tuple containing the sampled points and their corresponding weights.
- Return type:
tuple
- class diffinytrace.integrators.Cube(bounds)[source]¶
Bases:
IntegratorIntegrator for a multi-dimensional cube (hyperrectangle).
- Parameters:
bounds (array-like) – The bounds for each dimension of the cube. Should be a list or array of shape (n_dim, 2), where each row specifies [lower_bound, upper_bound] for a dimension.
Example
>>> cube = dit.integrators.Cube([[0, 1], [0, 1]]) >>> points, weights = cube.sample([10, 10], method=IntegrationMethod.MIDPOINT) >>> volume = cube.get_volume() >>> all_in_bounds = cube.in_bounds(points) >>> print("Sampled points:", points) >>> print("Integration weights:", weights) >>> print("Cube volume:", volume) >>> print("All points in bounds:", all_in_bounds)
- sample(num_points: int | list[int], method: IntegrationMethod = IntegrationMethod.MIDPOINT) tuple[Tensor, Tensor][source]¶
Sample points and weights using the specified method.
- Parameters:
num_points (int or list) – Number of points in each dimension.
method (str) – The integration method to use. Options are ‘simpson’, ‘midpoint’, ‘monte_carlo’, ‘sobol’, and ‘sobol_pow2’.
- Returns:
A tuple containing the sampled points and their corresponding weights.
- Return type:
tuple
- class diffinytrace.integrators.Disc(radius)[source]¶
Bases:
IntegratorIntegrator for a 2D disc (circle).
- Parameters:
radius (float) – The radius of the disc.
Example
>>> disc = dit.integrators.Disc(1.0) >>> points, weights = disc.sample(2**4, method="sobol_pow2") >>> volume = disc.get_volume() >>> all_in_bounds = disc.in_bounds(points) >>> print("Sampled points:", points) >>> print("Integration weights:", weights) >>> print("Disc area:", volume) >>> print("All points in bounds:", all_in_bounds)
- sample(num_points: int | list[int], method: IntegrationMethod = IntegrationMethod.SOBOL) tuple[Tensor, Tensor][source]¶
Sample points and weights using the specified method.
- Parameters:
num_points (int or list) – Number of points in each dimension.
method (str) – The integration method to use. Options are ‘simpson’, ‘midpoint’, ‘monte_carlo’, ‘sobol’, and ‘sobol_pow2’.
- Returns:
A tuple containing the sampled points and their corresponding weights.
- Return type:
tuple