Skip to content

Commit e3254a2

Browse files
authored
(chore): small doc improvements (#177)
1 parent d3127e9 commit e3254a2

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

docs/source/tutorial.rst

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,32 @@ dimensions.
6262
At the time, *torchquad* offers the following integration methods for
6363
abritrary dimensionality.
6464

65-
+--------------+-------------------------------------------------+------------+
66-
| Name | How it works | Spacing |
67-
| | | |
68-
+==============+=================================================+============+
69-
| Trapezoid | Creates a linear interpolant between two |br| | Equal |
70-
| rule | neighbouring points | |
71-
+--------------+-------------------------------------------------+------------+
72-
| Simpson's | Creates a quadratic interpolant between |br| | Equal |
73-
| rule | three neighbouring point | |
74-
+--------------+-------------------------------------------------+------------+
75-
| Boole's | Creates a more complex interpolant between |br| | Equal |
76-
| rule | five neighbouring points | |
77-
+--------------+-------------------------------------------------+------------+
78-
| Monte Carlo | Randomly chooses points at which the |br| | Random |
79-
| | integrand is evaluated | |
80-
+--------------+-------------------------------------------------+------------+
81-
| VEGAS | Adaptive multidimensional Monte Carlo |br| | Stratified |
82-
| Enhanced | integration (VEGAS with adaptive stratified | |br| |
83-
| |br| (VEGAS+)| |br| sampling) | sampling |
84-
+--------------+-------------------------------------------------+------------+
65+
+--------------+----------------------------------------------------+------------+
66+
| Name | How it works | Spacing |
67+
| | | |
68+
+==============+====================================================+============+
69+
| Trapezoid | Creates a linear interpolant between two |br| | Equal |
70+
| rule | neighbouring points | |
71+
+--------------+----------------------------------------------------+------------+
72+
| Simpson's | Creates a quadratic interpolant between |br| | Equal |
73+
| rule | three neighbouring point | |
74+
+--------------+----------------------------------------------------+------------+
75+
| Boole's | Creates a more complex interpolant between |br| | Equal |
76+
| rule | five neighbouring points | |
77+
+--------------+----------------------------------------------------+------------+
78+
| Gaussian | Uses orthogonal polynomials to generate a grid | Unequal |
79+
| Quadrature | of sample points along with corresponding weights. | |
80+
| | A `GaussLegendre` implementation is provided | |
81+
| | as is a base `Gaussian` class that can be extended | |
82+
| | e.g., to other polynomials. | |
83+
+--------------+----------------------------------------------------+------------+
84+
| Monte Carlo | Randomly chooses points at which the |br| | Random |
85+
| | integrand is evaluated | |
86+
+--------------+----------------------------------------------------+------------+
87+
| VEGAS | Adaptive multidimensional Monte Carlo |br| | Stratified |
88+
| Enhanced | integration (VEGAS with adaptive stratified | |br| |
89+
| |br| (VEGAS+)| |br| sampling) | sampling |
90+
+--------------+----------------------------------------------------+------------+
8591

8692
.. |br| raw:: html
8793

@@ -100,6 +106,7 @@ the following way:
100106
4. Information on how to select a numerical backend
101107
5. Example showing how gradients can be obtained w.r.t. the integration domain with PyTorch
102108
6. Methods to speed up the integration
109+
7. Custom Integrators
103110

104111
Feel free to test the code on your own computer as we go along.
105112

@@ -586,7 +593,8 @@ Compiling the integrate method
586593
``````````````````````````````
587594

588595
To speed up the quadrature in situations where it is executed often with the
589-
same number of points ``N``, dimensionality ``dim``, and shape of the ``integrand``,
596+
same number of points ``N``, dimensionality ``dim``, and shape of the ``integrand``
597+
(see :ref:`the next section <multi_dim_integrand>` for more information on integrands),
590598
we can JIT-compile the performance-relevant parts of the integrate method:
591599

592600
.. code:: ipython3
@@ -724,6 +732,8 @@ sample points for both functions:
724732
725733
print(f"Quadrature results: {integral1}, {integral2}")
726734
735+
.. _multi_dim_integrand:
736+
727737
Multidimensional/Vectorized Integrands
728738
--------------------------------------
729739

@@ -756,6 +766,9 @@ Now let's see how to do this a bit more simply, and in a way that provides signf
756766
757767
torch.all(torch.isclose(result_vectorized, result)) # True!
758768
769+
.. note::
770+
VEGAS does not support multi-dimensional integrands. If you would like this, please consider opening an issue or PR.
771+
759772
Custom Integrators
760773
------------------
761774

torchquad/integration/gaussian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self):
2727
self._cache = {}
2828

2929
def integrate(self, fn, dim, N=8, integration_domain=None, backend=None):
30-
"""Integrates the passed function on the passed domain using Simpson's rule.
30+
"""Integrates the passed function on the passed domain using a Gaussian rule (Gauss-Legendre on [-1,1] as a default).
3131
3232
Args:
3333
fn (func): The function to integrate over.

torchquad/integration/monte_carlo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def integrate(
2727
2828
Args:
2929
fn (func): The function to integrate over.
30-
dim (int): Dimensionality of the function to integrate.
30+
dim (int): Dimensionality of the function's domain over which to integrate.
3131
N (int, optional): Number of sample points to use for the integration. Defaults to 1000.
3232
integration_domain (list or backend tensor, optional): Integration domain, e.g. [[-1,1],[0,1]]. Defaults to [-1,1]^dim. It can also determine the numerical backend.
3333
seed (int, optional): Random number generation seed to the sampling point creation, only set if provided. Defaults to None.

torchquad/integration/vegas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ def integrate(
4545
"""Integrates the passed function on the passed domain using VEGAS.
4646
4747
If the integrand output is far away from zero, i.e. lies within [b, b+c] for a constant b with large absolute value and small constant c, VEGAS does not adapt well to the integrand. Shifting the integrand so that it is close to zero may improve the accuracy of the calculated integral in this case.
48+
This method does not support multi-dimensional/vectorized integrands (i.e., integrating an integrand repeatedly over a grid of points).
4849
4950
Args:
5051
fn (func): The function to integrate over.
51-
dim (int): Dimensionality of the function to integrate.
52+
dim (int): Dimensionality of the function's domain over which to integrate.
5253
N (int, optional): Approximate maximum number of function evaluations to use for the integration. This value can be exceeded if the vegas stratification distributes evaluations per hypercube very unevenly. Defaults to 10000.
5354
integration_domain (list, optional): Integration domain, e.g. [[-1,1],[0,1]]. Defaults to [-1,1]^dim.
5455
seed (int, optional): Random number generation seed for the sampling point creation; only set if provided. Defaults to None.

torchquad/integration/vegas_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, N_intervals, dim, backend, dtype, alpha=0.5) -> None:
1616
1717
Args:
1818
N_intervals (int): Number of intervals per dimension to split the domain in.
19-
dim (int): Dimensionality of the integrand.
19+
dim (int): Dimensionality of the integration domain.
2020
backend (string): Numerical backend
2121
dtype (backend dtype): dtype used for the calculations
2222
alpha (float, optional): Alpha from the paper, EQ 19. Defaults to 0.5.

torchquad/integration/vegas_stratification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, N_increment, dim, rng, backend, dtype, beta=0.75):
1515
1616
Args:
1717
N_increment (int): Number of evaluations per iteration.
18-
dim (int): Dimensionality
18+
dim (int): Dimensionality of the integration domain
1919
rng (RNG): Random number generator
2020
backend (string): Numerical backend
2121
dtype (backend dtype): dtype used for the calculations

0 commit comments

Comments
 (0)