Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c3a2c57
adding base class for initial designs for bq
mmahsereci Nov 21, 2022
73ea344
adding info to kernel embeddings docs
mmahsereci Nov 21, 2022
414283b
Merge branch 'mm-quad-kernel-embddings-doc' into mm-quad-init-designs
mmahsereci Nov 21, 2022
e577f20
small change
mmahsereci Nov 21, 2022
f195687
resolving one of the pylint errors
mmahsereci Nov 21, 2022
0461fd2
Merge branch 'mm-quad-kernel-embddings-doc' into mm-quad-init-designs
mmahsereci Nov 21, 2022
4136b41
consistent file structure
mmahsereci Nov 21, 2022
de253b6
formatting
mmahsereci Nov 21, 2022
cca1865
adding an options dict
mmahsereci Nov 21, 2022
e76f412
fixing tests
mmahsereci Nov 21, 2022
32e48c2
stateless policy
mmahsereci Nov 21, 2022
825c063
making policies stateless
mmahsereci Nov 21, 2022
dbedd41
better table
mmahsereci Nov 21, 2022
d6a553c
stateless policy
mmahsereci Nov 21, 2022
9b4f2fd
small change
mmahsereci Nov 21, 2022
546189c
small fix
mmahsereci Nov 22, 2022
f7a2592
small fix
mmahsereci Nov 22, 2022
bbc3148
fix tests
mmahsereci Nov 22, 2022
31b488a
some tests for initial designs
mmahsereci Nov 22, 2022
18ae4d4
small fix
mmahsereci Nov 22, 2022
272d2d9
small change
mmahsereci Nov 22, 2022
a07fa07
adding shape tests for policies
mmahsereci Nov 22, 2022
92cf89c
tests for policies
mmahsereci Nov 22, 2022
3877df7
tests for bq output
mmahsereci Nov 22, 2022
2cb2f24
adding a comment
mmahsereci Nov 22, 2022
14f3219
resolving merge conflicts
mmahsereci Nov 23, 2022
0898beb
parametrize policy tests
mmahsereci Nov 23, 2022
33bb4a6
resolving one pylint error
mmahsereci Nov 23, 2022
eb84d0e
fixing interface
mmahsereci Nov 23, 2022
00334ef
resolving merge conflicts
mmahsereci Nov 23, 2022
8ab844c
api fix
mmahsereci Nov 23, 2022
0e1008d
fix type annotation rendering
mmahsereci Nov 23, 2022
0673cd3
Merge branch 'mm-quad-stateless-policy' into mm-quad-init-designs
mmahsereci Nov 23, 2022
8003323
fix tests
mmahsereci Nov 23, 2022
1911bb2
add reference
mmahsereci Nov 23, 2022
328ac52
addressing pr comments
mmahsereci Nov 24, 2022
7f5ba9d
small change
mmahsereci Nov 24, 2022
956ccb0
small change
mmahsereci Nov 24, 2022
d1cf99a
resolvig merge conflicts
mmahsereci Nov 24, 2022
67229a2
fixing tests
mmahsereci Nov 24, 2022
ff55b10
fing tests
mmahsereci Nov 24, 2022
6543761
fixing doctest
mmahsereci Nov 24, 2022
63de434
fixig pylint
mmahsereci Nov 24, 2022
9e97f24
adding rng property
mmahsereci Nov 24, 2022
90d61ab
add Todos
mmahsereci Nov 24, 2022
41ad6c0
resolve merge conflict
mmahsereci Nov 24, 2022
df0574f
fixing docstring
mmahsereci Nov 25, 2022
018c20d
some changes in docs
mmahsereci Nov 25, 2022
42d579d
undo unwanted change
mmahsereci Nov 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/api/quad/solvers.initial_designs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Initial Designs
---------------
.. automodapi:: probnum.quad.solvers.initial_designs
:no-heading:
:headings: "*"
5 changes: 5 additions & 0 deletions docs/source/api/quad/solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ probnum.quad.solvers
:hidden:

solvers.stopping_criteria

.. toctree::
:hidden:

solvers.initial_designs
128 changes: 73 additions & 55 deletions src/probnum/quad/_bayesquad.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@
from probnum.quad.typing import DomainLike, DomainType
from probnum.randprocs.kernels import Kernel
from probnum.randvars import Normal
from probnum.typing import FloatLike, IntLike
from probnum.typing import IntLike


def bayesquad(
fun: Callable,
input_dim: int,
input_dim: IntLike,
kernel: Optional[Kernel] = None,
domain: Optional[DomainLike] = None,
measure: Optional[IntegrationMeasure] = None,
domain: Optional[DomainLike] = None,
policy: Optional[str] = "bmc",
scale_estimation: Optional[str] = "mle",
max_evals: Optional[IntLike] = None,
var_tol: Optional[FloatLike] = None,
rel_tol: Optional[FloatLike] = None,
batch_size: IntLike = 1,
initial_design: Optional[str] = None,
rng: Optional[np.random.Generator] = None,
jitter: FloatLike = 1.0e-8,
options: Optional[dict] = None,
) -> Tuple[Normal, BQIterInfo]:
r"""Infer the solution of the uni- or multivariate integral
:math:`\int_\Omega f(x) d \mu(x)`
Expand Down Expand Up @@ -66,44 +62,56 @@ def bayesquad(
Input dimension of the integration problem.
kernel
The kernel used for the GP model. Defaults to the ``ExpQuad`` kernel.
measure
The integration measure. Defaults to the Lebesgue measure on ``domain``.
domain
The integration domain. Contains lower and upper bound as scalar or
``np.ndarray``. Obsolete if ``measure`` is given.
measure
The integration measure. Defaults to the Lebesgue measure on ``domain``.
policy
Type of acquisition strategy to use. Defaults to 'bmc'. Options are

========================== =======
Bayesian Monte Carlo [2]_ ``bmc``
========================== =======

========================== =======
van Der Corput points ``vdc``
========================== =======

scale_estimation
Estimation method to use to compute the scale parameter. Defaults to 'mle'.
Options are

============================== =======
Maximum likelihood estimation ``mle``
============================== =======

max_evals
Maximum number of function evaluations.
var_tol
Tolerance on the variance of the integral.
rel_tol
Tolerance on consecutive updates of the integral mean.
batch_size
Number of new observations at each update. Defaults to 1.
initial_design
The type of initial design to use. If ``None`` is given, no initial design is
used. Options are

========================== =========
Samples from measure ``mc``
Latin hypercube [3]_ ``latin``
========================== =========

rng
Random number generator. Used by Bayesian Monte Carlo other random sampling
policies.
jitter
Non-negative jitter to numerically stabilise kernel matrix inversion.
Defaults to 1e-8.
The random number generator used for random methods.

options
A dictionary with the following optional solver settings

scale_estimation : Optional[str]
Estimation method to use to compute the scale parameter. Defaults
to 'mle'. Options are

============================== =======
Maximum likelihood estimation ``mle``
============================== =======

max_evals : Optional[IntLike]
Maximum number of function evaluations.
var_tol : Optional[FloatLike]
Tolerance on the variance of the integral.
rel_tol : Optional[FloatLike]
Tolerance on consecutive updates of the integral mean.
jitter : Optional[FloatLike]
Non-negative jitter to numerically stabilise kernel matrix
inversion. Defaults to 1e-8.
batch_size : Optional[IntLike]
Number of new observations at each update. Defaults to 1.
num_initial_design_nodes : Optional[IntLike]
The number of nodes created by the initial design. Defaults to
``input_dim * 5`` if an initial design is given.

Returns
-------
Expand All @@ -119,7 +127,8 @@ def bayesquad(

Warns
-----
When ``domain`` is given but not used.
UserWarning
When ``domain`` is given but not used.

Notes
-----
Expand All @@ -138,6 +147,8 @@ def bayesquad(
computation?, *Statistical Science 34.1*, 2019, 1-22, 2019
.. [2] Rasmussen, C. E., and Z. Ghahramani, Bayesian Monte Carlo, *Advances in
Neural Information Processing Systems*, 2003, 505-512.
.. [3] Mckay et al., A Comparison of Three Methods for Selecting Values of Input
Variables in the Analysis of Output from a Computer Code, *Technometrics*, 1979.

Examples
--------
Expand All @@ -162,12 +173,8 @@ def bayesquad(
measure=measure,
domain=domain,
policy=policy,
scale_estimation=scale_estimation,
max_evals=max_evals,
var_tol=var_tol,
rel_tol=rel_tol,
batch_size=batch_size,
jitter=jitter,
initial_design=initial_design,
options=options,
)

# Integrate
Expand All @@ -182,10 +189,9 @@ def bayesquad_from_data(
nodes: np.ndarray,
fun_evals: np.ndarray,
kernel: Optional[Kernel] = None,
domain: Optional[DomainLike] = None,
measure: Optional[IntegrationMeasure] = None,
scale_estimation: Optional[str] = "mle",
jitter: FloatLike = 1.0e-8,
domain: Optional[DomainLike] = None,
options: Optional[dict] = None,
) -> Tuple[Normal, BQIterInfo]:
r"""Infer the value of an integral from a given set of nodes and function
evaluations.
Expand All @@ -199,16 +205,25 @@ def bayesquad_from_data(
*shape=(n_eval,)* -- Function evaluations at ``nodes``.
kernel
The kernel used for the GP model. Defaults to the ``ExpQuad`` kernel.
measure
The integration measure. Defaults to the Lebesgue measure.
domain
The integration domain. Contains lower and upper bound as scalar or
``np.ndarray``. Obsolete if ``measure`` is given.
measure
The integration measure. Defaults to the Lebesgue measure.
scale_estimation
Estimation method to use to compute the scale parameter. Defaults to 'mle'.
jitter
Non-negative jitter to numerically stabilise kernel matrix inversion.
Defaults to 1e-8.
options
A dictionary with the following optional solver settings

scale_estimation : Optional[str]
Estimation method to use to compute the scale parameter. Defaults
to 'mle'. Options are

============================== =======
Maximum likelihood estimation ``mle``
============================== =======

jitter : Optional[FloatLike]
Non-negative jitter to numerically stabilise kernel matrix
inversion. Defaults to 1e-8.

Returns
-------
Expand All @@ -224,7 +239,8 @@ def bayesquad_from_data(

Warns
-----
When ``domain`` is given but not used.
UserWarning
When ``domain`` is given but not used.

See Also
--------
Expand Down Expand Up @@ -256,8 +272,8 @@ def bayesquad_from_data(
measure=measure,
domain=domain,
policy=None,
scale_estimation=scale_estimation,
jitter=jitter,
initial_design=None,
options=options,
)

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

input_dim = int(input_dim)

# Neither domain nor measure given
if domain is None and measure is None:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion src/probnum/quad/solvers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Bayesian quadrature methods and their components."""

from . import belief_updates, policies, stopping_criteria
from . import belief_updates, initial_designs, policies, stopping_criteria
from ._bayesian_quadrature import BayesianQuadrature
from ._bq_state import BQIterInfo, BQState

Expand Down
Loading