Skip to content

Commit 4f434ca

Browse files
authored
Initial designs for quad (#745)
1 parent 8dde541 commit 4f434ca

File tree

14 files changed

+679
-188
lines changed

14 files changed

+679
-188
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Initial Designs
2+
---------------
3+
.. automodapi:: probnum.quad.solvers.initial_designs
4+
:no-heading:
5+
:headings: "*"

docs/source/api/quad/solvers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ probnum.quad.solvers
1919
:hidden:
2020

2121
solvers.stopping_criteria
22+
23+
.. toctree::
24+
:hidden:
25+
26+
solvers.initial_designs

src/probnum/quad/_bayesquad.py

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,19 @@
1818
from probnum.quad.typing import DomainLike, DomainType
1919
from probnum.randprocs.kernels import Kernel
2020
from probnum.randvars import Normal
21-
from probnum.typing import FloatLike, IntLike
21+
from probnum.typing import IntLike
2222

2323

2424
def bayesquad(
2525
fun: Callable,
26-
input_dim: int,
26+
input_dim: IntLike,
2727
kernel: Optional[Kernel] = None,
28-
domain: Optional[DomainLike] = None,
2928
measure: Optional[IntegrationMeasure] = None,
29+
domain: Optional[DomainLike] = None,
3030
policy: Optional[str] = "bmc",
31-
scale_estimation: Optional[str] = "mle",
32-
max_evals: Optional[IntLike] = None,
33-
var_tol: Optional[FloatLike] = None,
34-
rel_tol: Optional[FloatLike] = None,
35-
batch_size: IntLike = 1,
31+
initial_design: Optional[str] = None,
3632
rng: Optional[np.random.Generator] = None,
37-
jitter: FloatLike = 1.0e-8,
33+
options: Optional[dict] = None,
3834
) -> Tuple[Normal, BQIterInfo]:
3935
r"""Infer the solution of the uni- or multivariate integral
4036
:math:`\int_\Omega f(x) d \mu(x)`
@@ -66,44 +62,56 @@ def bayesquad(
6662
Input dimension of the integration problem.
6763
kernel
6864
The kernel used for the GP model. Defaults to the ``ExpQuad`` kernel.
65+
measure
66+
The integration measure. Defaults to the Lebesgue measure on ``domain``.
6967
domain
7068
The integration domain. Contains lower and upper bound as scalar or
7169
``np.ndarray``. Obsolete if ``measure`` is given.
72-
measure
73-
The integration measure. Defaults to the Lebesgue measure on ``domain``.
7470
policy
7571
Type of acquisition strategy to use. Defaults to 'bmc'. Options are
7672
7773
========================== =======
7874
Bayesian Monte Carlo [2]_ ``bmc``
79-
========================== =======
80-
81-
========================== =======
8275
van Der Corput points ``vdc``
8376
========================== =======
8477
85-
scale_estimation
86-
Estimation method to use to compute the scale parameter. Defaults to 'mle'.
87-
Options are
88-
89-
============================== =======
90-
Maximum likelihood estimation ``mle``
91-
============================== =======
92-
93-
max_evals
94-
Maximum number of function evaluations.
95-
var_tol
96-
Tolerance on the variance of the integral.
97-
rel_tol
98-
Tolerance on consecutive updates of the integral mean.
99-
batch_size
100-
Number of new observations at each update. Defaults to 1.
78+
initial_design
79+
The type of initial design to use. If ``None`` is given, no initial design is
80+
used. Options are
81+
82+
========================== =========
83+
Samples from measure ``mc``
84+
Latin hypercube [3]_ ``latin``
85+
========================== =========
86+
10187
rng
102-
Random number generator. Used by Bayesian Monte Carlo other random sampling
103-
policies.
104-
jitter
105-
Non-negative jitter to numerically stabilise kernel matrix inversion.
106-
Defaults to 1e-8.
88+
The random number generator used for random methods.
89+
90+
options
91+
A dictionary with the following optional solver settings
92+
93+
scale_estimation : Optional[str]
94+
Estimation method to use to compute the scale parameter. Defaults
95+
to 'mle'. Options are
96+
97+
============================== =======
98+
Maximum likelihood estimation ``mle``
99+
============================== =======
100+
101+
max_evals : Optional[IntLike]
102+
Maximum number of function evaluations.
103+
var_tol : Optional[FloatLike]
104+
Tolerance on the variance of the integral.
105+
rel_tol : Optional[FloatLike]
106+
Tolerance on consecutive updates of the integral mean.
107+
jitter : Optional[FloatLike]
108+
Non-negative jitter to numerically stabilise kernel matrix
109+
inversion. Defaults to 1e-8.
110+
batch_size : Optional[IntLike]
111+
Number of new observations at each update. Defaults to 1.
112+
num_initial_design_nodes : Optional[IntLike]
113+
The number of nodes created by the initial design. Defaults to
114+
``input_dim * 5`` if an initial design is given.
107115
108116
Returns
109117
-------
@@ -119,7 +127,8 @@ def bayesquad(
119127
120128
Warns
121129
-----
122-
When ``domain`` is given but not used.
130+
UserWarning
131+
When ``domain`` is given but not used.
123132
124133
Notes
125134
-----
@@ -138,6 +147,8 @@ def bayesquad(
138147
computation?, *Statistical Science 34.1*, 2019, 1-22, 2019
139148
.. [2] Rasmussen, C. E., and Z. Ghahramani, Bayesian Monte Carlo, *Advances in
140149
Neural Information Processing Systems*, 2003, 505-512.
150+
.. [3] Mckay et al., A Comparison of Three Methods for Selecting Values of Input
151+
Variables in the Analysis of Output from a Computer Code, *Technometrics*, 1979.
141152
142153
Examples
143154
--------
@@ -162,12 +173,8 @@ def bayesquad(
162173
measure=measure,
163174
domain=domain,
164175
policy=policy,
165-
scale_estimation=scale_estimation,
166-
max_evals=max_evals,
167-
var_tol=var_tol,
168-
rel_tol=rel_tol,
169-
batch_size=batch_size,
170-
jitter=jitter,
176+
initial_design=initial_design,
177+
options=options,
171178
)
172179

173180
# Integrate
@@ -182,10 +189,9 @@ def bayesquad_from_data(
182189
nodes: np.ndarray,
183190
fun_evals: np.ndarray,
184191
kernel: Optional[Kernel] = None,
185-
domain: Optional[DomainLike] = None,
186192
measure: Optional[IntegrationMeasure] = None,
187-
scale_estimation: Optional[str] = "mle",
188-
jitter: FloatLike = 1.0e-8,
193+
domain: Optional[DomainLike] = None,
194+
options: Optional[dict] = None,
189195
) -> Tuple[Normal, BQIterInfo]:
190196
r"""Infer the value of an integral from a given set of nodes and function
191197
evaluations.
@@ -199,16 +205,25 @@ def bayesquad_from_data(
199205
*shape=(n_eval,)* -- Function evaluations at ``nodes``.
200206
kernel
201207
The kernel used for the GP model. Defaults to the ``ExpQuad`` kernel.
208+
measure
209+
The integration measure. Defaults to the Lebesgue measure.
202210
domain
203211
The integration domain. Contains lower and upper bound as scalar or
204212
``np.ndarray``. Obsolete if ``measure`` is given.
205-
measure
206-
The integration measure. Defaults to the Lebesgue measure.
207-
scale_estimation
208-
Estimation method to use to compute the scale parameter. Defaults to 'mle'.
209-
jitter
210-
Non-negative jitter to numerically stabilise kernel matrix inversion.
211-
Defaults to 1e-8.
213+
options
214+
A dictionary with the following optional solver settings
215+
216+
scale_estimation : Optional[str]
217+
Estimation method to use to compute the scale parameter. Defaults
218+
to 'mle'. Options are
219+
220+
============================== =======
221+
Maximum likelihood estimation ``mle``
222+
============================== =======
223+
224+
jitter : Optional[FloatLike]
225+
Non-negative jitter to numerically stabilise kernel matrix
226+
inversion. Defaults to 1e-8.
212227
213228
Returns
214229
-------
@@ -224,7 +239,8 @@ def bayesquad_from_data(
224239
225240
Warns
226241
-----
227-
When ``domain`` is given but not used.
242+
UserWarning
243+
When ``domain`` is given but not used.
228244
229245
See Also
230246
--------
@@ -256,8 +272,8 @@ def bayesquad_from_data(
256272
measure=measure,
257273
domain=domain,
258274
policy=None,
259-
scale_estimation=scale_estimation,
260-
jitter=jitter,
275+
initial_design=None,
276+
options=options,
261277
)
262278

263279
# Integrate
@@ -274,6 +290,8 @@ def _check_domain_measure_compatibility(
274290
measure: Optional[IntegrationMeasure],
275291
) -> Tuple[int, Optional[DomainType], IntegrationMeasure]:
276292

293+
input_dim = int(input_dim)
294+
277295
# Neither domain nor measure given
278296
if domain is None and measure is None:
279297
raise ValueError(

src/probnum/quad/solvers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Bayesian quadrature methods and their components."""
22

3-
from . import belief_updates, policies, stopping_criteria
3+
from . import belief_updates, initial_designs, policies, stopping_criteria
44
from ._bayesian_quadrature import BayesianQuadrature
55
from ._bq_state import BQIterInfo, BQState
66

0 commit comments

Comments
 (0)