@@ -45,7 +45,8 @@
Loading
45 45
        Returns
46 46
        -------
47 47
        updated_belief :
48 -
            Gaussian integral belief after conditioning on the new nodes and evaluations.
48 +
            Gaussian integral belief after conditioning on the new nodes and
49 +
            evaluations.
49 50
        updated_state :
50 51
            Updated version of ``bq_state`` that contains all updated quantities.
51 52
        """
@@ -110,7 +111,7 @@
Loading
110 111
111 112
        Returns
112 113
        -------
113 -
        x:
114 +
        x :
114 115
            The solution to the linear system :math:`K x = b`
115 116
        """
116 117
        jitter = 1.0e-6

@@ -9,7 +9,7 @@
Loading
9 9
from probnum.randprocs.kernels import Kernel
10 10
from probnum.randvars import Normal
11 11
12 -
# pylint: disable=too-few-public-methods, too-many-instance-attributes, too-many-arguments
12 +
# pylint: disable=too-few-public-methods,too-many-instance-attributes,too-many-arguments
13 13
14 14
15 15
class BQInfo:
@@ -128,6 +128,11 @@
Loading
128 128
            The Gram matrix of the given nodes.
129 129
        kernel_means :
130 130
            The kernel means at the given nodes.
131 +
132 +
        Returns
133 +
        -------
134 +
        bq_state :
135 +
            An instance of this class.
131 136
        """
132 137
        return cls(
133 138
            measure=prev_state.measure,

@@ -10,7 +10,8 @@
Loading
10 10
class BQStoppingCriterion(StoppingCriterion):
11 11
    r"""Stopping criterion of a Bayesian quadrature method.
12 12
13 -
    Checks whether quantities tracked by the :class:`~probnum.quad.solvers.BQState` meet a desired terminal condition.
13 +
    Checks whether quantities tracked by the :class:`~probnum.quad.solvers.BQState`
14 +
    meet a desired terminal condition.
14 15
15 16
    See Also
16 17
    --------

@@ -45,7 +45,8 @@
Loading
45 45
    ----------
46 46
    sample_func :
47 47
        The sample function. Needs to have the following interface:
48 -
        `sample_func(batch_size: int, rng: np.random.Generator)` and return an array of shape (batch_size, n_dim).
48 +
        `sample_func(batch_size: int, rng: np.random.Generator)` and return an array of
49 +
        shape (batch_size, n_dim).
49 50
    batch_size :
50 51
        Size of batch of nodes when calling the policy once.
51 52
    """

@@ -1,7 +1,7 @@
Loading
1 1
"""Kernel embedding of exponentiated quadratic kernel with Lebesgue integration
2 2
measure."""
3 3
4 -
# pylint: disable=no-name-in-module, invalid-name
4 +
# pylint: disable=no-name-in-module
5 5
6 6
import numpy as np
7 7
from scipy.special import erf
@@ -19,7 +19,8 @@
Loading
19 19
    Parameters
20 20
    ----------
21 21
    x :
22 -
        *shape (n_eval, input_dim)* -- n_eval locations where to evaluate the kernel mean.
22 +
        *shape (n_eval, input_dim)* -- n_eval locations where to evaluate the kernel
23 +
        mean.
23 24
    kernel :
24 25
        Instance of an ExpQuad kernel.
25 26
    measure :
@@ -27,9 +28,9 @@
Loading
27 28
28 29
    Returns
29 30
    -------
30 -
    k_mean :
31 +
    kernel_mean :
31 32
        *shape=(n_eval,)* -- The kernel integrated w.r.t. its first argument,
32 -
        evaluated at locations x.
33 +
        evaluated at locations ``x``.
33 34
    """
34 35
    input_dim = kernel.input_dim
35 36
@@ -59,7 +60,7 @@
Loading
59 60
60 61
    Returns
61 62
    -------
62 -
    k_var :
63 +
    kernel_variance :
63 64
        The kernel integrated w.r.t. both arguments.
64 65
    """
65 66

@@ -8,10 +8,11 @@
Loading
8 8
"""
9 9
10 10
import warnings
11 -
from typing import Callable, Dict, Optional, Tuple, Union
11 +
from typing import Callable, Optional, Tuple, Union
12 12
13 13
import numpy as np
14 14
15 +
from probnum.quad.solvers.bq_state import BQInfo
15 16
from probnum.randprocs.kernels import Kernel
16 17
from probnum.randvars import Normal
17 18
from probnum.typing import FloatLike, IntLike
@@ -20,7 +21,6 @@
Loading
20 21
from .solvers import BayesianQuadrature
21 22
22 23
23 -
# pylint: disable=too-many-arguments, no-else-raise
24 24
def bayesquad(
25 25
    fun: Callable,
26 26
    input_dim: int,
@@ -35,8 +35,9 @@
Loading
35 35
    rel_tol: Optional[FloatLike] = None,
36 36
    batch_size: Optional[IntLike] = 1,
37 37
    rng: Optional[np.random.Generator] = np.random.default_rng(),
38 -
) -> Tuple[Normal, Dict]:
39 -
    r"""Infer the solution of the uni- or multivariate integral :math:`\int_\Omega f(x) d \mu(x)`
38 +
) -> Tuple[Normal, BQInfo]:
39 +
    r"""Infer the solution of the uni- or multivariate integral
40 +
    :math:`\int_\Omega f(x) d \mu(x)`
40 41
    on a hyper-rectangle :math:`\Omega = [a_1, b_1] \times \cdots \times [a_D, b_D]`.
41 42
42 43
    Bayesian quadrature (BQ) infers integrals of the form
@@ -47,12 +48,12 @@
Loading
47 48
    :math:`\Omega \subset \mathbb{R}^D` against a measure :math:`\mu: \mathbb{R}^D
48 49
    \mapsto \mathbb{R}`.
49 50
50 -
    Bayesian quadrature methods return a probability distribution over the solution :math:`F` with
51 -
    uncertainty arising from finite computation (here a finite number of function evaluations).
52 -
    They start out with a random process encoding the prior belief about the function :math:`f`
53 -
    to be integrated. Conditioned on either existing or acquired function evaluations according to a
54 -
    policy, they update the belief on :math:`f`, which is translated into a posterior measure over
55 -
    the integral :math:`F`.
51 +
    Bayesian quadrature methods return a probability distribution over the solution
52 +
    :math:`F` with uncertainty arising from finite computation (here a finite number
53 +
    of function evaluations). They start out with a random process encoding the prior
54 +
    belief about the function :math:`f` to be integrated. Conditioned on either existing
55 +
    or acquired function evaluations according to a policy, they update the belief on
56 +
    :math:`f`, which is translated into a posterior measure over the integral :math:`F`.
56 57
    See Briol et al. [1]_ for a review on Bayesian quadrature.
57 58
58 59
    Parameters
@@ -132,7 +133,7 @@
Loading
132 133
    if domain is not None:
133 134
        if isinstance(measure, GaussianMeasure):
134 135
            raise ValueError("GaussianMeasure cannot be used with finite bounds.")
135 -
        elif isinstance(measure, LebesgueMeasure):
136 +
        if isinstance(measure, LebesgueMeasure):
136 137
            warnings.warn(
137 138
                "Both domain and a LebesgueMeasure are specified. The domain "
138 139
                "information will be ignored."
@@ -165,7 +166,7 @@
Loading
165 166
        Tuple[Union[np.ndarray, FloatLike], Union[np.ndarray, FloatLike]]
166 167
    ] = None,
167 168
    measure: Optional[IntegrationMeasure] = None,
168 -
) -> Tuple[Normal, Dict]:
169 +
) -> Tuple[Normal, BQInfo]:
169 170
    r"""Infer the value of an integral from a given set of nodes and function
170 171
    evaluations.
171 172
@@ -219,7 +220,7 @@
Loading
219 220
    if domain is not None:
220 221
        if isinstance(measure, GaussianMeasure):
221 222
            raise ValueError("GaussianMeasure cannot be used with finite bounds.")
222 -
        elif isinstance(measure, LebesgueMeasure):
223 +
        if isinstance(measure, LebesgueMeasure):
223 224
            warnings.warn(
224 225
                "Both domain and a LebesgueMeasure are specified. The domain "
225 226
                "information will be ignored."

@@ -1,4 +1,5 @@
Loading
1 -
"""Stopping criterion based on the relative change of the successive integral estimators."""
1 +
"""Stopping criterion based on the relative change of the successive integral
2 +
estimators."""
2 3
3 4
import numpy as np
4 5
@@ -13,9 +14,11 @@
Loading
13 14
    """Stop once the relative change of consecutive integral estimates are smaller than
14 15
    a tolerance.
15 16
16 -
    The stopping criterion is: :math:`|\\hat{F}_{c} - \\hat{F}_{p}|/ |\\hat{F}_{c}| \\leq r`
17 -
    where :math:`\\hat{F}_{c}` and :math:`\\hat{F}_{p}` are the integral estimates of the current and previous iteration
18 -
    respectively, and :math:`r` is the relative tolerance.
17 +
    The stopping criterion is:
18 +
    :math:`|\\hat{F}_{c} - \\hat{F}_{p}|/ |\\hat{F}_{c}| \\leq r` where
19 +
    :math:`\\hat{F}_{c}` and :math:`\\hat{F}_{p}` are the integral estimates of the
20 +
    current and previous iteration respectively, and :math:`r` is the relative
21 +
    tolerance.
19 22
20 23
    Parameters
21 24
    ----------

@@ -98,6 +98,19 @@
Loading
98 98
            Batch size used in node acquisition.
99 99
        rng :
100 100
            The random number generator.
101 +
102 +
        Returns
103 +
        -------
104 +
        BayesianQuadrature
105 +
            An instance of this class.
106 +
107 +
        Raises
108 +
        ------
109 +
        ValueError
110 +
            If Bayesian Monte Carlo ('bmc') is selected as ``policy`` and no random
111 +
            number generator (``rng``) is given.
112 +
        NotImplementedError
113 +
            If an unknown ``policy`` is given.
101 114
        """
102 115
        # Set up integration measure
103 116
        if measure is None:
@@ -125,8 +138,8 @@
Loading
125 138
                "Policies other than random sampling are not available at the moment."
126 139
            )
127 140
128 -
        # Set stopping criteria
129 -
        # If multiple stopping criteria are given, BQ stops once the first criterion is fulfilled.
141 +
        # Set stopping criteria: If multiple stopping criteria are given, BQ stops
142 +
        # once the first criterion is fulfilled.
130 143
        def _stopcrit_or(sc1, sc2):
131 144
            if sc1 is None:
132 145
                return sc2
@@ -147,7 +160,8 @@
Loading
147 160
                _stopping_criterion, RelativeMeanChange(rel_tol)
148 161
            )
149 162
150 -
        # If no stopping criteria are given, use some default values (these are arbitrary values)
163 +
        # If no stopping criteria are given, use some default values
164 +
        # (these are arbitrary values)
151 165
        if _stopping_criterion is None:
152 166
            _stopping_criterion = IntegralVarianceTolerance(var_tol=1e-6) | MaxNevals(
153 167
                max_nevals=input_dim * 25
@@ -167,13 +181,13 @@
Loading
167 181
        Parameters
168 182
        ----------
169 183
        bq_state:
170 -
            State of the Bayesian quadrature methods. Contains all necessary information about the
171 -
            problem and the computation.
184 +
            State of the Bayesian quadrature methods. Contains all necessary
185 +
            information about the problem and the computation.
172 186
173 187
        Returns
174 188
        -------
175 -
        has_converged:
176 -
            Whether or not the solver has converged.
189 +
        has_converged :
190 +
            Whether the solver has converged.
177 191
        """
178 192
179 193
        _has_converged = self.stopping_criterion(bq_state)
@@ -192,7 +206,8 @@
Loading
192 206
    ) -> Tuple[Normal, np.ndarray, np.ndarray, BQState]:
193 207
        """Generator that implements the iteration of the BQ method.
194 208
195 -
        This function exposes the state of the BQ method one step at a time while running the loop.
209 +
        This function exposes the state of the BQ method one step at a time while
210 +
        running the loop.
196 211
197 212
        Parameters
198 213
        ----------
@@ -208,23 +223,22 @@
Loading
208 223
        integral_belief:
209 224
            Current belief about the integral.
210 225
        bq_state:
211 -
            State of the Bayesian quadrature methods. Contains all necessary information about the
212 -
            problem and the computation.
226 +
            State of the Bayesian quadrature methods. Contains all necessary information
227 +
            about the problem and the computation.
213 228
214 -
        Returns
215 -
        -------
216 -
        integral_belief:
229 +
        Yields
230 +
        ------
231 +
        new_integral_belief :
217 232
            Updated belief about the integral.
218 -
        new_nodes:
233 +
        new_nodes :
219 234
            *shape=(n_new_eval, input_dim)* -- The new location(s) at which
220 235
            ``new_fun_evals`` are available found during the iteration.
221 -
        new_fun_evals:
236 +
        new_fun_evals :
222 237
            *shape=(n_new_eval,)* -- The function evaluations at the new locations
223 238
            ``new_nodes``.
224 -
        bq_state:
239 +
        new_bq_state :
225 240
            Updated state of the Bayesian quadrature methods.
226 241
        """
227 -
        # pylint: disable=missing-yield-doc
228 242
229 243
        # Setup
230 244
        if bq_state is None:
@@ -293,8 +307,9 @@
Loading
293 307
    ) -> Tuple[Normal, BQState]:
294 308
        """Integrate the function ``fun``.
295 309
296 -
        ``fun`` may be analytically given, or numerically in terms of ``fun_evals`` at fixed nodes.
297 -
        This function calls the generator ``bq_iterator`` until the first stopping criterion is met.
310 +
        ``fun`` may be analytically given, or numerically in terms of ``fun_evals`` at
311 +
        fixed nodes. This function calls the generator ``bq_iterator`` until the first
312 +
        stopping criterion is met.
298 313
299 314
        Parameters
300 315
        ----------
@@ -310,10 +325,16 @@
Loading
310 325
311 326
        Returns
312 327
        -------
313 -
        integral_belief:
328 +
        integral_belief :
314 329
            Posterior belief about the integral.
315 -
        bq_state:
330 +
        bq_state :
316 331
            Final state of the Bayesian quadrature method.
332 +
333 +
        Raises
334 +
        ------
335 +
        ValueError
336 +
            If neither the integrand function (``fun``) nor integrand evaluations
337 +
            (``fun_evals``) are given.
317 338
        """
318 339
        if fun is None and fun_evals is None:
319 340
            raise ValueError("You need to provide a function to be integrated!")

@@ -8,8 +8,6 @@
Loading
8 8
from probnum.quad._integration_measures import GaussianMeasure
9 9
from probnum.randprocs.kernels import ExpQuad
10 10
11 -
# pylint: disable=invalid-name
12 -
13 11
14 12
def _kernel_mean_expquad_gauss(
15 13
    x: np.ndarray, kernel: ExpQuad, measure: GaussianMeasure
@@ -20,7 +18,8 @@
Loading
20 18
    Parameters
21 19
    ----------
22 20
    x :
23 -
        *shape=(n_eval, input_dim)* -- n_eval locations where to evaluate the kernel mean.
21 +
        *shape=(n_eval, input_dim)* -- n_eval locations where to evaluate the kernel
22 +
        mean.
24 23
    kernel :
25 24
        Instance of an ExpQuad kernel.
26 25
    measure :
@@ -28,9 +27,9 @@
Loading
28 27
29 28
    Returns
30 29
    -------
31 -
    k_mean :
30 +
    kernel_mean :
32 31
        *shape (n_eval,)* -- The kernel integrated w.r.t. its first argument,
33 -
        evaluated at locations x.
32 +
        evaluated at locations ``x``.
34 33
    """
35 34
    input_dim = kernel.input_dim
36 35
@@ -66,7 +65,7 @@
Loading
66 65
67 66
    Returns
68 67
    -------
69 -
    k_var :
68 +
    kernel_variance :
70 69
        The kernel integrated w.r.t. both arguments.
71 70
    """
72 71
    input_dim = kernel.input_dim

@@ -27,6 +27,12 @@
Loading
27 27
        Instance of a kernel.
28 28
    measure:
29 29
        Instance of an integration measure.
30 +
31 +
    Raises
32 +
    ------
33 +
    ValueError
34 +
        If the input dimension of the kernel does not match the input dimension of the
35 +
        measure.
30 36
    """
31 37
32 38
    def __init__(self, kernel: Kernel, measure: IntegrationMeasure) -> None:
@@ -45,20 +51,20 @@
Loading
45 51
            kernel=self.kernel, measure=self.measure
46 52
        )
47 53
48 -
    # pylint: disable=invalid-name
49 54
    def kernel_mean(self, x: np.ndarray) -> np.ndarray:
50 55
        """Kernel mean w.r.t. its first argument against the integration measure.
51 56
52 57
        Parameters
53 58
        ----------
54 59
        x :
55 -
            *shape=(n_eval, input_dim)* -- n_eval locations where to evaluate the kernel mean.
60 +
            *shape=(n_eval, input_dim)* -- n_eval locations where to evaluate the
61 +
            kernel mean.
56 62
57 63
        Returns
58 64
        -------
59 -
        k_mean :
65 +
        kernel_mean :
60 66
            *shape=(n_eval,)* -- The kernel integrated w.r.t. its first argument,
61 -
            evaluated at locations x.
67 +
            evaluated at locations ``x``.
62 68
        """
63 69
        return self._kmean(x=x, kernel=self.kernel, measure=self.measure)
64 70
@@ -67,7 +73,7 @@
Loading
67 73
68 74
        Returns
69 75
        -------
70 -
        k_var :
76 +
        kernel_variance :
71 77
            The kernel integrated w.r.t. both arguments.
72 78
        """
73 79
        return self._kvar(kernel=self.kernel, measure=self.measure)
@@ -87,15 +93,24 @@
Loading
87 93
88 94
    Returns
89 95
    -------
90 -
        An instance of _KernelEmbedding.
96 +
    kernel_mean :
97 +
        The kernel mean function.
98 +
    kernel_variance :
99 +
        The kernel variance function.
100 +
101 +
    Raises
102 +
    ------
103 +
    NotImplementedError
104 +
        If the given kernel is unknown.
105 +
    NotImplementedError
106 +
        If the kernel embedding of the kernel-measure pair is unknown.
91 107
    """
92 108
93 109
    # Exponentiated quadratic kernel
94 110
    if isinstance(kernel, ExpQuad):
95 -
        # pylint: disable=no-else-return
96 111
        if isinstance(measure, GaussianMeasure):
97 112
            return _kernel_mean_expquad_gauss, _kernel_variance_expquad_gauss
98 -
        elif isinstance(measure, LebesgueMeasure):
113 +
        if isinstance(measure, LebesgueMeasure):
99 114
            return _kernel_mean_expquad_lebesgue, _kernel_variance_expquad_lebesgue
100 115
        raise NotImplementedError
101 116
Files Coverage
src/probnum 89.40%
Project Totals (181 files) 89.40%
1
coverage:
2
  precision: 2
3
  status:
4
    project:
5
      default:
6
        target: auto
7
        threshold: 1%
8
    patch:
9
      default:
10
        target: 90%
11
        threshold: 1%
12

13
comment:
14
  layout: "reach, diff, files"
15
  behavior: default
16
  require_changes: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading