No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
e2a46b0
... +1 ...
c9957f3
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
5 | 5 | import numpy as np |
|
6 | 6 | import scipy.stats |
|
7 | 7 | ||
8 | - | from probnum import _function, randvars, utils |
|
8 | + | from probnum import functions, randvars, utils |
|
9 | 9 | from probnum.randprocs import _random_process, kernels |
|
10 | 10 | from probnum.randprocs.markov import _transition, continuous, discrete |
|
11 | 11 | from probnum.typing import ShapeLike |
31 | 31 | input_shape=input_shape, |
|
32 | 32 | output_shape=output_shape, |
|
33 | 33 | dtype=np.dtype(np.float_), |
|
34 | - | mean=_function.LambdaFunction( |
|
34 | + | mean=functions.LambdaFunction( |
|
35 | 35 | lambda x: self.__call__(args=x).mean, |
|
36 | 36 | input_shape=input_shape, |
|
37 | 37 | output_shape=output_shape, |
3 | 3 | from __future__ import annotations |
|
4 | 4 | ||
5 | 5 | import abc |
|
6 | + | import functools |
|
6 | 7 | from typing import Callable |
|
7 | 8 | ||
8 | 9 | import numpy as np |
|
9 | 10 | ||
10 | - | from . import utils |
|
11 | - | from .typing import ArrayLike, ShapeLike, ShapeType |
|
11 | + | from probnum import utils |
|
12 | + | from probnum.typing import ArrayLike, ShapeLike, ShapeType |
|
12 | 13 | ||
13 | 14 | ||
14 | 15 | class Function(abc.ABC): |
17 | 18 | This class represents a, uni- or multivariate, scalar- or tensor-valued, |
|
18 | 19 | mathematical function. Hence, the call method should not have any observable |
|
19 | 20 | side-effects. |
|
21 | + | Instances of this class can be added and multiplied by a scalar, which means that |
|
22 | + | they are elements of a vector space. |
|
20 | 23 | ||
21 | 24 | Parameters |
|
22 | 25 | ---------- |
29 | 32 | See Also |
|
30 | 33 | -------- |
|
31 | 34 | LambdaFunction : Define a :class:`Function` from an anonymous function. |
|
32 | - | ~probnum.randprocs.mean_fns.Zero : Zero mean function of a random process. |
|
35 | + | ~probnum.functions.Zero : Zero function. |
|
33 | 36 | """ |
|
34 | 37 | ||
35 | 38 | def __init__(self, input_shape: ShapeLike, output_shape: ShapeLike = ()) -> None: |
112 | 115 | def _evaluate(self, x: np.ndarray) -> np.ndarray: |
|
113 | 116 | pass |
|
114 | 117 | ||
118 | + | def __neg__(self): |
|
119 | + | return -1.0 * self |
|
120 | + | ||
121 | + | @functools.singledispatchmethod |
|
122 | + | def __add__(self, other): |
|
123 | + | return NotImplemented |
|
124 | + | ||
125 | + | @functools.singledispatchmethod |
|
126 | + | def __sub__(self, other): |
|
127 | + | return NotImplemented |
|
128 | + | ||
129 | + | @functools.singledispatchmethod |
|
130 | + | def __mul__(self, other): |
|
131 | + | if np.ndim(other) == 0: |
|
132 | + | from ._algebra_fallbacks import ( # pylint: disable=import-outside-toplevel |
|
133 | + | ScaledFunction, |
|
134 | + | ) |
|
135 | + | ||
136 | + | return ScaledFunction(function=self, scalar=other) |
|
137 | + | ||
138 | + | return NotImplemented |
|
139 | + | ||
140 | + | @functools.singledispatchmethod |
|
141 | + | def __rmul__(self, other): |
|
142 | + | if np.ndim(other) == 0: |
|
143 | + | from ._algebra_fallbacks import ( # pylint: disable=import-outside-toplevel |
|
144 | + | ScaledFunction, |
|
145 | + | ) |
|
146 | + | ||
147 | + | return ScaledFunction(function=self, scalar=other) |
|
148 | + | ||
149 | + | return NotImplemented |
|
150 | + | ||
115 | 151 | ||
116 | 152 | class LambdaFunction(Function): |
|
117 | 153 | """Define a :class:`Function` from a given :class:`callable`. |
131 | 167 | Examples |
|
132 | 168 | -------- |
|
133 | 169 | >>> import numpy as np |
|
134 | - | >>> from probnum import LambdaFunction |
|
170 | + | >>> from probnum.functions import LambdaFunction |
|
135 | 171 | >>> fn = LambdaFunction(fn=lambda x: 2 * x + 1, input_shape=(2,), output_shape=(2,)) |
|
136 | 172 | >>> fn(np.array([[1, 2], [4, 5]])) |
|
137 | 173 | array([[ 3, 5], |
7 | 7 | ||
8 | 8 | import numpy as np |
|
9 | 9 | ||
10 | - | from probnum import _function, randvars, utils as _utils |
|
10 | + | from probnum import functions, randvars, utils as _utils |
|
11 | 11 | from probnum.randprocs import kernels |
|
12 | 12 | from probnum.typing import DTypeLike, ShapeLike, ShapeType |
|
13 | 13 |
56 | 56 | input_shape: ShapeLike, |
|
57 | 57 | output_shape: ShapeLike, |
|
58 | 58 | dtype: DTypeLike, |
|
59 | - | mean: Optional[_function.Function] = None, |
|
59 | + | mean: Optional[functions.Function] = None, |
|
60 | 60 | cov: Optional[kernels.Kernel] = None, |
|
61 | 61 | ): |
|
62 | 62 | self._input_shape = _utils.as_shape(input_shape) |
75 | 75 | ||
76 | 76 | # Mean function |
|
77 | 77 | if mean is not None: |
|
78 | - | if not isinstance(mean, _function.Function): |
|
78 | + | if not isinstance(mean, functions.Function): |
|
79 | 79 | raise TypeError("The mean function must have type `probnum.Function`.") |
|
80 | 80 | ||
81 | 81 | if mean.input_shape != self._input_shape: |
177 | 177 | raise NotImplementedError |
|
178 | 178 | ||
179 | 179 | @property |
|
180 | - | def mean(self) -> _function.Function: |
|
180 | + | def mean(self) -> functions.Function: |
|
181 | 181 | r"""Mean function :math:`m(x) := \mathbb{E}[f(x)]` of the random process.""" |
|
182 | 182 | if self._mean is None: |
|
183 | 183 | raise NotImplementedError |
Learn more Showing 7 files with coverage changes found.
src/probnum/linops/_kronecker.py
src/probnum/linops/_linear_operator.py
src/probnum/functions/_algebra_fallbacks.py
src/probnum/functions/_algebra.py
src/probnum/functions/__init__.py
src/probnum/linops/_arithmetic.py
src/probnum/randvars/_arithmetic.py
Files | Coverage |
---|---|
src/probnum | 0.15% 90.28% |
Project Totals (197 files) | 90.28% |
c9957f3
798c23a
e2a46b0