padaquad.IntegrationResult#
- class padaquad.IntegrationResult(*, integral, integral_error, mesh_init, mesh_final, nodes, h, y, mesh_quadratures, mesh_quadrature_errors, error_ratios, gradient_taken, y0, mesh_optimal=None, tracked_variables=None, loss=None, converged=None, n_start_steps=None, n_start_steps_split=None, max_split_depth=None)#
Result of an integration: the integral, its error estimate, the mesh and diagnostics.
Every field is required and passed by keyword (
kw_only=True), exceptmesh_optimal,tracked_variables,loss,converged,n_start_steps,n_start_steps_splitandmax_split_depth, which default toNone. Below,Nis the number of accepted subintervals,Cthe number of nodes per subinterval,P = C + (N - 1)(C - 1)the number of distinct nodes, andMthe number of mesh points (see The integrand contract).integral,integral_error,y0,mesh_optimal,mesh_initandmesh_finalare on the solver’s device; the other tensors are onresult_device(default"cpu").The solver also builds one result per batch of accepted subintervals and passes it to
loss_fxn. That result covers only the batch:integralis the batch’s contribution,y0is zero,mesh_optimal,loss,convergedand the split counts areNone, andnodes,yandtracked_variableskeep one row per subinterval (shapes[N, C, T],[N, C, D]and[N, C, ...]) instead of the flattened shapes below.- Attributes:
- integraltorch.Tensor
y0plus the integral offfrommesh_inittomesh_final. Shape[D].- integral_errortorch.Tensor
Sum of the subintervals’ signed error estimates. Shape
[D]. Withtake_gradient=False, subintervals accepted and later split again can leave it off by their error estimates. See Tolerances and error ratios.- mesh_optimaltorch.Tensor or None
Mesh to start the next integration of the same integrand from (with
same_f=True): the final mesh with low-error subintervals merged and failing ones split. Shape[M, T]. See The optimal mesh and the merge rule.- mesh_inittorch.Tensor
Lower integration bound. Shape
[T].- mesh_finaltorch.Tensor
Upper integration bound. Shape
[T].- nodestorch.Tensor
Nodes of all accepted subintervals in one non-decreasing sequence; the node shared by two neighbouring subintervals appears once. Shape
[P, T].- htorch.Tensor
Width of each accepted subinterval. Shape
[N, T].- ytorch.Tensor
Integrand values at
nodes. Shape[P, D].- tracked_variablestuple of torch.Tensor or None
Extra values the integrand returned beside its values, at
nodesand not integrated;Noneif it returned none. Each tensor is detached, with shape[P, ...]. See Tracked variables.- mesh_quadraturestorch.Tensor
Each subinterval’s contribution to the integral, \(h \sum_i b_i y_i\). Shape
[N, D].- mesh_quadrature_errorstorch.Tensor
Absolute value of each subinterval’s error estimate, \(|h \sum_i b^{\text{error}}_i y_i|\). Shape
[N, D].- error_ratiostorch.Tensor
Each subinterval’s error ratio when it was accepted, against the tolerance of that moment (with
error_norm="failure_fraction", the fraction of failing outputs instead). Shape[N].- losstorch.Tensor or None
Sum over batches of
loss_fxnapplied to the per-batch results; by default the integral withouty0. See Gradients.- gradient_takenbool
The call’s
take_gradient: whetherloss.backward()ran after each batch (it runs only when the loss requires a gradient).- y0torch.Tensor
The offset added to the integral, after conversion to the solver’s dtype and device. Shape
[D].- convergedbool or None
Trueif every accepted subinterval meets the tolerance judged against the final integral (in cumulative mode, the final running integral through it); otherwiseFalse, with a logged warning. See converged is False.- n_start_stepsint or None
Number of subintervals in the starting mesh (the given
mesh, the mesh stored bysame_f=True, or a new random one).- n_start_steps_splitint or None
Number of starting subintervals that were split at least once during the integration (splits made to build
mesh_optimaldo not count).- max_split_depthint or None
Largest number of times one starting subinterval was halved: 0 if none was split, at most
max_adaptive_splits.
Examples
>>> import torch >>> from padaquad import integrate >>> _ = torch.manual_seed(0) # the starting mesh is random >>> result = integrate( ... lambda t: torch.exp(t), ... atol=1e-10, ... rtol=1e-10, ... mesh_init=torch.tensor([0.0], dtype=torch.float64), ... mesh_final=torch.tensor([1.0], dtype=torch.float64), ... y0=torch.tensor([1.0], dtype=torch.float64), ... device="cpu", ... max_batch=10_000, ... ) >>> print(round(float(result.integral), 8)) # 1 + (e - 1) = e 2.71828183 >>> print(result.converged, abs(float(result.integral_error)) < 1e-10) True True >>> print(round(float(result.h.sum()), 8)) # the widths add up to 1 1.0
- __init__(*, integral, integral_error, mesh_init, mesh_final, nodes, h, y, mesh_quadratures, mesh_quadrature_errors, error_ratios, gradient_taken, y0, mesh_optimal=None, tracked_variables=None, loss=None, converged=None, n_start_steps=None, n_start_steps_split=None, max_split_depth=None)#
Methods
__init__(*, integral, integral_error, ...[, ...])Attributes
convergedlossmax_split_depthmesh_optimaln_start_stepsn_start_steps_splitpercent_start_steps_splitPercentage of the starting mesh's subintervals that were split at least once.
tracked_variablesintegralintegral_errormesh_initmesh_finalnodeshymesh_quadraturesmesh_quadrature_errorserror_ratiosgradient_takeny0