From db2f22a520a31712623169a1b48ab18164f92f01 Mon Sep 17 00:00:00 2001 From: Nirmal Patel Date: Sat, 26 Mar 2022 18:14:05 -0400 Subject: [PATCH] Resolve pylint line-too-long messages in randprocs Some docstrings have long lines. Enabled pylint's line-too-long warning and fixed the resulting warnings. Signed-off-by: Nirmal Patel --- src/probnum/randprocs/markov/_transition.py | 141 ++++++++++++------ .../markov/continuous/_diffusions.py | 32 ++-- .../markov/continuous/_linear_sde.py | 18 ++- .../randprocs/markov/continuous/_lti_sde.py | 2 +- .../randprocs/markov/continuous/_sde.py | 3 +- .../markov/discrete/_linear_gaussian.py | 8 +- .../markov/discrete/_lti_gaussian.py | 3 +- .../markov/integrator/_integrator.py | 21 ++- .../randprocs/markov/integrator/_ioup.py | 32 ++-- .../randprocs/markov/integrator/_iwp.py | 32 ++-- .../randprocs/markov/integrator/_matern.py | 29 ++-- .../markov/integrator/_preconditioner.py | 7 +- .../markov/integrator/convert/_convert.py | 12 +- tox.ini | 2 +- 14 files changed, 225 insertions(+), 117 deletions(-) diff --git a/src/probnum/randprocs/markov/_transition.py b/src/probnum/randprocs/markov/_transition.py index ed0bbf253a..25c94f0040 100644 --- a/src/probnum/randprocs/markov/_transition.py +++ b/src/probnum/randprocs/markov/_transition.py @@ -15,7 +15,8 @@ class Transition(abc.ABC): .. math:: p(\mathcal{G}_t[x(t)] \,|\, x(t)) - for some operator :math:`\mathcal{G}: \mathbb{R}^d \rightarrow \mathbb{R}^m`, which are used to describe the evolution of Markov processes + for some operator :math:`\mathcal{G}: \mathbb{R}^d \rightarrow \mathbb{R}^m`, + which are used to describe the evolution of Markov processes .. math:: p(x(t+\Delta t) \,|\, x(t)) @@ -32,11 +33,13 @@ class Transition(abc.ABC): Sometimes, these can be equivalent. For example, linear, time-invariant SDEs have a mild solution that can be written as a discrete transition. - In ProbNum, we also use discrete-time transition objects to describe observation models, + In ProbNum, we also use discrete-time transition objects to describe + observation models, .. math:: z_k \,|\, x(t_k) \sim p(z_k \,|\, x(t_k)) - for some :math:`k=0,...,K`. All three building blocks are used heavily in filtering and smoothing, as well as solving ODEs. + for some :math:`k=0,...,K`. All three building blocks are used heavily in filtering + and smoothing, as well as solving ODEs. See Also -------- @@ -51,13 +54,15 @@ def __init__(self, input_dim: IntLike, output_dim: IntLike): self.output_dim = output_dim def __repr__(self): - return f"{self.__class__.__name__}(input_dim={self.input_dim}, output_dim={self.output_dim})" + classname = self.__class__.__name__ + return f"{classname}(input_dim={self.input_dim}, output_dim={self.output_dim})" @abc.abstractmethod def forward_rv( self, rv, t, dt=None, compute_gain=False, _diffusion=1.0, _linearise_at=None ): - r"""Forward-pass of a state, according to the transition. In other words, return a description of + r"""Forward-pass of a state, according to the transition. In other words, + return a description of .. math:: p(\mathcal{G}_t[x(t)] \,|\, x(t)), @@ -65,7 +70,8 @@ def forward_rv( .. math:: p(\mathcal{G}_t[x(t)] \,|\, x(t), z_{\leq t}), - for past observations :math:`z_{\leq t}`. (This perspective will be more interesting in light of :meth:`backward_rv`). + for past observations :math:`z_{\leq t}`. (This perspective will be more + interesting in light of :meth:`backward_rv`). Parameters @@ -77,19 +83,26 @@ def forward_rv( dt Increment :math:`\Delta t`. Ignored for discrete-time transitions. compute_gain - Flag that indicates whether the expected gain of the forward transition shall be computed. This is important if the forward-pass - is computed as part of a forward-backward pass, as it is for instance the case in a Kalman update. + Flag that indicates whether the expected gain of the forward transition + shall be computed. This is important if the forward-pass is computed as + part of a forward-backward pass, as it is for instance the case in a + Kalman update. _diffusion - Special diffusion of the driving stochastic process, which is used internally. + Special diffusion of the driving stochastic process, which is used + internally. _linearise_at - Specific point of linearisation for approximate forward passes (think: extended Kalman filtering). Used internally for iterated filtering and smoothing. + Specific point of linearisation for approximate forward passes + (think: extended Kalman filtering). Used internally for iterated filtering + and smoothing. Returns ------- RandomVariable New state, after applying the forward-pass. Dict - Information about the forward pass. Can for instance contain a `gain` key, if `compute_gain` was set to `True` (and if the transition supports this functionality). + Information about the forward pass. Can for instance contain a `gain` key, + if `compute_gain` was set to `True` (and if the transition supports this + functionality). """ raise NotImplementedError @@ -103,7 +116,8 @@ def forward_realization( _diffusion=1.0, _linearise_at=None, ): - r"""Forward-pass of a realization of a state, according to the transition. In other words, return a description of + r"""Forward-pass of a realization of a state, according to the transition. + In other words, return a description of .. math:: p(\mathcal{G}_t[x(t)] \,|\, x(t)=\xi), @@ -112,25 +126,33 @@ def forward_realization( Parameters ---------- realization - Realization :math:`\xi` of the random variable :math:`x(t)` that describes the current state. + Realization :math:`\xi` of the random variable :math:`x(t)` that describes + the current state. t Current time point. dt Increment :math:`\Delta t`. Ignored for discrete-time transitions. compute_gain - Flag that indicates whether the expected gain of the forward transition shall be computed. This is important if the forward-pass - is computed as part of a forward-backward pass, as it is for instance the case in a Kalman update. + Flag that indicates whether the expected gain of the forward transition + shall be computed. This is important if the forward-pass is computed as + part of a forward-backward pass, as it is for instance the case in a + Kalman update. _diffusion - Special diffusion of the driving stochastic process, which is used internally. + Special diffusion of the driving stochastic process, which is used + internally. _linearise_at - Specific point of linearisation for approximate forward passes (think: extended Kalman filtering). Used internally for iterated filtering and smoothing. + Specific point of linearisation for approximate forward passes (think: + extended Kalman filtering). Used internally for iterated filtering and + smoothing. Returns ------- RandomVariable New state, after applying the forward-pass. Dict - Information about the forward pass. Can for instance contain a `gain` key, if `compute_gain` was set to `True` (and if the transition supports this functionality). + Information about the forward pass. Can for instance contain a `gain` key, + if `compute_gain` was set to `True` (and if the transition supports this + functionality). """ raise NotImplementedError @@ -146,7 +168,8 @@ def backward_rv( _diffusion=1.0, _linearise_at=None, ): - r"""Backward-pass of a state, according to the transition. In other words, return a description of + r"""Backward-pass of a state, according to the transition. In other words, + return a description of .. math:: p(x(t) \,|\, z_{\mathcal{G}_t}) @@ -154,36 +177,49 @@ def backward_rv( p(\mathcal{G}_t(x(t)) \,|\, z_{\mathcal{G}_t})) d \mathcal{G}_t(x(t)), for observations :math:`z_{\mathcal{G}_t}` of :math:`{\mathcal{G}_t}(x(t))`. - For example, this function is called in a Rauch-Tung-Striebel smoothing step, which computes a Gaussian distribution + For example, this function is called in a Rauch-Tung-Striebel smoothing step, + which computes a Gaussian distribution .. math:: p(x(t) \,|\, z_{\leq t+\Delta t}) = \int p(x(t) \,|\, z_{\leq t+\Delta t}, x(t+\Delta t)) p(x(t+\Delta t) \,|\, z_{\leq t+\Delta t})) d x(t+\Delta t), - from filtering distribution :math:`p(x(t) \,|\, z_{\leq t})` and smoothing distribution :math:`p(x(t+\Delta t) \,|\, z_{\leq t+\Delta t})`, - where :math:`z_{\leq t + \Delta t}` contains both :math:`z_{\leq t}` and :math:`z_{t + \Delta t}`. + from filtering distribution :math:`p(x(t) \,|\, z_{\leq t})` and smoothing + distribution :math:`p(x(t+\Delta t) \,|\, z_{\leq t+\Delta t})`, + where :math:`z_{\leq t + \Delta t}` contains both :math:`z_{\leq t}` + and :math:`z_{t + \Delta t}`. Parameters ---------- rv_obtained - "Incoming" distribution (think: :math:`p(x(t+\Delta t) \,|\, z_{\leq t+\Delta t})`) as a RandomVariable. + "Incoming" distribution (think: + :math:`p(x(t+\Delta t) \,|\, z_{\leq t+\Delta t})`) as a RandomVariable. rv - "Current" distribution (think: :math:`p(x(t) \,|\, z_{\leq t})`) as a RandomVariable. + "Current" distribution (think: :math:`p(x(t) \,|\, z_{\leq t})`) as a + RandomVariable. rv_forwarded - "Forwarded" distribution (think: :math:`p(x(t+\Delta t) \,|\, z_{\leq t})`) as a RandomVariable. Optional. If provided (in conjunction with `gain`), computation might be more efficient, - because most backward passes require the solution of a forward pass. If `rv_forwarded` is not provided, :meth:`forward_rv` might be called internally (depending on the object) + "Forwarded" distribution (think: :math:`p(x(t+\Delta t) \,|\, z_{\leq t})`) + as a RandomVariable. Optional. If provided (in conjunction with `gain`), + computation might be more efficient, because most backward passes require + the solution of a forward pass. If `rv_forwarded` is not provided, + :meth:`forward_rv` might be called internally (depending on the object) which is skipped if `rv_forwarded` has been provided gain - Expected gain from "observing states at time :math:`t+\Delta t` from time :math:`t`). Optional. If provided (in conjunction with `rv_forwarded`), some additional computations may be avoided (depending on the object). + Expected gain from "observing states at time :math:`t+\Delta t` from time + :math:`t`). Optional. If provided (in conjunction with `rv_forwarded`), + some additional computations may be avoided (depending on the object). t Current time point. dt Increment :math:`\Delta t`. Ignored for discrete-time transitions. _diffusion - Special diffusion of the driving stochastic process, which is used internally. + Special diffusion of the driving stochastic process, which is used + internally. _linearise_at - Specific point of linearisation for approximate forward passes (think: extended Kalman filtering). Used internally for iterated filtering and smoothing. + Specific point of linearisation for approximate forward passes (think: + extended Kalman filtering). Used internally for iterated filtering and + smoothing. Returns ------- @@ -206,7 +242,8 @@ def backward_realization( _diffusion=1.0, _linearise_at=None, ): - r"""Backward-pass of a realisation of a state, according to the transition. In other words, return a description of + r"""Backward-pass of a realisation of a state, according to the transition. + In other words, return a description of .. math:: p(x(t) \,|\, {\mathcal{G}_t(x(t)) = \xi}) @@ -221,19 +258,26 @@ def backward_realization( rv "Current" distribution :math:`p(x(t))` as a RandomVariable. rv_forwarded - "Forwarded" distribution (think: :math:`p(\mathcal{G}_t(x(t)) \,|\, x(t))`) as a RandomVariable. Optional. If provided (in conjunction with `gain`), computation might be more efficient, - because most backward passes require the solution of a forward pass. If `rv_forwarded` is not provided, :meth:`forward_rv` might be called internally (depending on the object) + "Forwarded" distribution (think: :math:`p(\mathcal{G}_t(x(t)) \,|\, x(t))`) + as a RandomVariable. Optional. If provided (in conjunction with `gain`), + computation might be more efficient, because most backward passes require + the solution of a forward pass. If `rv_forwarded` is not provided, + :meth:`forward_rv` might be called internally (depending on the object) which is skipped if `rv_forwarded` has been provided gain - Expected gain. Optional. If provided (in conjunction with `rv_forwarded`), some additional computations may be avoided (depending on the object). + Expected gain. Optional. If provided (in conjunction with `rv_forwarded`), + some additional computations may be avoided (depending on the object). t Current time point. dt Increment :math:`\Delta t`. Ignored for discrete-time transitions. _diffusion - Special diffusion of the driving stochastic process, which is used internally. + Special diffusion of the driving stochastic process, which is used + internally. _linearise_at - Specific point of linearisation for approximate forward passes (think: extended Kalman filtering). Used internally for iterated filtering and smoothing. + Specific point of linearisation for approximate forward passes + (think: extended Kalman filtering). Used internally for iterated filtering + and smoothing. Returns ------- @@ -257,13 +301,16 @@ def smooth_list( rv_list : randvars._RandomVariableList List of random variables to be smoothed. locations : - Locations :math:`t` of the random variables in the time-domain. Used for continuous-time transitions. + Locations :math:`t` of the random variables in the time-domain. Used for + continuous-time transitions. _diffusion_list : List of diffusions that correspond to the intervals in the locations. - If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it contains one element less. + If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it + contains one element less. _previous_posterior : - Specify a previous posterior to improve linearisation in approximate backward passes. - Used in iterated smoothing based on posterior linearisation. + Specify a previous posterior to improve linearisation in approximate + backward passes. Used in iterated smoothing based on posterior + linearisation. Returns ------- @@ -311,15 +358,17 @@ def jointly_transform_base_measure_realization_list_backward( Parameters ---------- base_measure_realizations : - Base measure realizations (usually samples from a standard Normal distribution). - These are transformed into joint realizations of the random variable list. + Base measure realizations (usually samples from a standard Normal + distribution). These are transformed into joint realizations of the random + variable list. rv_list : List of random variables to be jointly sampled from. t : Locations of the random variables in the list. Assumed to be sorted. _diffusion_list : List of diffusions that correspond to the intervals in the locations. - If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it contains one element less. + If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it + contains one element less. _previous_posterior : Previous posterior. Used for iterative posterior linearisation. @@ -378,15 +427,17 @@ def jointly_transform_base_measure_realization_list_forward( Parameters ---------- base_measure_realizations : - Base measure realizations (usually samples from a standard Normal distribution). - These are transformed into joint realizations of the random variable list. + Base measure realizations (usually samples from a standard Normal + distribution). These are transformed into joint realizations of the random + variable list. initrv : Initial random variable. t : Locations of the random variables in the list. Assumed to be sorted. _diffusion_list : List of diffusions that correspond to the intervals in the locations. - If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it contains one element less. + If `locations=(t0, ..., tN)`, then `_diffusion_list=(d1, ..., dN)`, i.e. it + contains one element less. _previous_posterior : Previous posterior. Used for iterative posterior linearisation. diff --git a/src/probnum/randprocs/markov/continuous/_diffusions.py b/src/probnum/randprocs/markov/continuous/_diffusions.py index 99cc3bd334..065d1dfe76 100644 --- a/src/probnum/randprocs/markov/continuous/_diffusions.py +++ b/src/probnum/randprocs/markov/continuous/_diffusions.py @@ -12,7 +12,8 @@ class Diffusion(abc.ABC): - r"""Interface for diffusion models :math:`\sigma: \mathbb{R} \rightarrow \mathbb{R}^d` and their calibration.""" + r"""Interface for diffusion models + :math:`\sigma: \mathbb{R} \rightarrow \mathbb{R}^d` and their calibration.""" def __repr__(self): raise NotImplementedError @@ -58,14 +59,16 @@ def __repr__(self): def __call__(self, t: ArrayLike) -> Union[ArrayLike, np.ndarray]: if self.diffusion is None: raise NotImplementedError( - "No diffusions seen yet. Call estimate_locally_and_update_in_place first." + "No diffusions seen yet." + "Call estimate_locally_and_update_in_place first." ) return self.diffusion * np.ones_like(t) def __getitem__(self, idx: ArrayIndicesLike) -> Union[ArrayLike, np.ndarray]: if self.diffusion is None: raise NotImplementedError( - "No diffusions seen yet. Call estimate_locally_and_update_in_place first." + "No diffusions seen yet." + "Call estimate_locally_and_update_in_place first." ) return self.diffusion * np.ones_like(idx) @@ -93,8 +96,8 @@ def update_in_place(self, local_estimate, t): class PiecewiseConstantDiffusion(Diffusion): r"""Piecewise constant diffusion. - It is defined by a set of diffusions :math:`(\sigma_1, ..., \sigma_N)` and a set of locations :math:`(t_0, ..., t_N)` - through + It is defined by a set of diffusions :math:`(\sigma_1, ..., \sigma_N)` and a set of + locations :math:`(t_0, ..., t_N)` through .. math:: \sigma(t) = \left\{ @@ -105,14 +108,16 @@ class PiecewiseConstantDiffusion(Diffusion): \end{array} \right. - In other words, a tuple :math:`(t, \sigma)` always defines the diffusion *right* of :math:`t` as :math:`\sigma` (including the point :math:`t`), - except for the very first tuple :math:`(t_0, \sigma_0)` which *also* defines the diffusion *left* of :math:`t`. - This choice of piecewise constant function is continuous from the right. + In other words, a tuple :math:`(t, \sigma)` always defines the diffusion *right* of + :math:`t` as :math:`\sigma` (including the point :math:`t`), except for the very + first tuple :math:`(t_0, \sigma_0)` which *also* defines the diffusion *left* of + :math:`t`. This choice of piecewise constant function is continuous from the right. Parameters ---------- t0 - Initial time point. This is the leftmost time-point of the interval on which the diffusion is calibrated. + Initial time point. This is the leftmost time-point of the interval on which + the diffusion is calibrated. """ def __init__(self, t0): @@ -125,7 +130,8 @@ def __repr__(self): def __call__(self, t: ArrayLike) -> Union[ArrayLike, np.ndarray]: if len(self._locations) <= 1: raise NotImplementedError( - "No diffusions seen yet. Call estimate_locally_and_update_in_place first." + "No diffusions seen yet." + "Call estimate_locally_and_update_in_place first." ) if np.isscalar(t): t = np.atleast_1d(t) @@ -133,7 +139,8 @@ def __call__(self, t: ArrayLike) -> Union[ArrayLike, np.ndarray]: else: t_has_been_promoted = False - # The "-1" in here makes up for the fact that the locations contains one more element than the diffusions. + # The "-1" in here makes up for the fact that the locations contains one more + # element than the diffusions. indices = np.searchsorted(self.locations, t) - 1 indices[t < self.t0] = 0 indices[t > self.tmax] = -1 @@ -146,7 +153,8 @@ def __call__(self, t: ArrayLike) -> Union[ArrayLike, np.ndarray]: def __getitem__(self, idx: ArrayIndicesLike) -> Union[ArrayLike, np.ndarray]: if len(self._locations) <= 1: raise NotImplementedError( - "No diffusions seen yet. Call estimate_locally_and_update_in_place first." + "No diffusions seen yet." + "Call estimate_locally_and_update_in_place first." ) return self.diffusions[idx] diff --git a/src/probnum/randprocs/markov/continuous/_linear_sde.py b/src/probnum/randprocs/markov/continuous/_linear_sde.py index ed3b82e9f3..2e7f611f82 100644 --- a/src/probnum/randprocs/markov/continuous/_linear_sde.py +++ b/src/probnum/randprocs/markov/continuous/_linear_sde.py @@ -34,12 +34,16 @@ class LinearSDE(_sde.SDE): the dispersion(matrix) of the SDE. Returns np.ndarray with shape=(n, s) mde_atol - Absolute tolerance passed to the solver of the moment differential equations (MDEs). Optional. Default is 1e-6. + Absolute tolerance passed to the solver of the moment differential equations + (MDEs). Optional. Default is 1e-6. mde_rtol - Relative tolerance passed to the solver of the moment differential equations (MDEs). Optional. Default is 1e-6. + Relative tolerance passed to the solver of the moment differential equations + (MDEs). Optional. Default is 1e-6. mde_solver - Method that is chosen in `scipy.integrate.solve_ivp`. Any string that is compatible with ``solve_ivp(..., method=mde_solve,...)`` works here. - Usual candidates are ``[RK45, LSODA, Radau, BDF, RK23, DOP853]``. Optional. Default is LSODA. + Method that is chosen in `scipy.integrate.solve_ivp`. Any string that is + compatible with ``solve_ivp(..., method=mde_solve,...)`` works here. + Usual candidates are ``[RK45, LSODA, Radau, BDF, RK23, DOP853]``. + Optional. Default is LSODA. forward_implementation Implementation style for forward transitions. """ @@ -230,7 +234,8 @@ def _solve_mde_forward(self, mde, y0, t, dt, dim): ) y_end = sol.y[:, -1] new_mean = y_end[:dim] - # If forward_sqrt is used, new_cov_or_cov_cholesky is a Cholesky factor of the covariance + # If forward_sqrt is used, new_cov_or_cov_cholesky is a Cholesky factor of + # the covariance # If forward_classic is used, new_cov_or_cov_cholesky is the covariance new_cov_or_cov_cholesky = y_end[dim:].reshape((dim, dim)) @@ -316,7 +321,8 @@ def _setup_vectorized_mde_forward_sqrt(self, initrv, _diffusion=1.0): .. math:: \dot P(t) = G(t)P(t) + P(t)G^\top(t) + L(t)L^\top(t). - Let :math:`S(t)` be a square-root of :math:`P(t)`, :math:`P(t)` positive definite, then + Let :math:`S(t)` be a square-root of :math:`P(t)`, :math:`P(t)` + positive definite, then .. math:: P(t) = S(t)S^\top(t) diff --git a/src/probnum/randprocs/markov/continuous/_lti_sde.py b/src/probnum/randprocs/markov/continuous/_lti_sde.py index 558655a8f3..c90f3253b3 100644 --- a/src/probnum/randprocs/markov/continuous/_lti_sde.py +++ b/src/probnum/randprocs/markov/continuous/_lti_sde.py @@ -142,7 +142,7 @@ def discretise(self, dt): That is, matrices A(h) and Q(h) and vector s(h) such that the transition is - .. math:: x | x_\\text{old} \\sim \\mathcal{N}(A(h) x_\\text{old} + s(h), Q(h)) , + .. math:: x | x_\\text{old} \\sim \\mathcal{N}(A(h) x_\\text{old} + s(h), Q(h)), which is the transition of the mild solution to the LTI SDE. """ diff --git a/src/probnum/randprocs/markov/continuous/_sde.py b/src/probnum/randprocs/markov/continuous/_sde.py index 06896d10a2..0dd54a77a6 100644 --- a/src/probnum/randprocs/markov/continuous/_sde.py +++ b/src/probnum/randprocs/markov/continuous/_sde.py @@ -13,7 +13,8 @@ class SDE(_transition.Transition): .. math:: d x(t) = g(t, x(t)) d t + l(t, x(t)) d w(t), - driven by a Wiener process :math:`w` with isotropic diffusion :math:`\Gamma(t) = \gamma(t) I_d`. + driven by a Wiener process :math:`w` with isotropic diffusion + :math:`\Gamma(t) = \gamma(t) I_d`. """ def __init__( diff --git a/src/probnum/randprocs/markov/discrete/_linear_gaussian.py b/src/probnum/randprocs/markov/discrete/_linear_gaussian.py index db63a0bfc4..150d095c7a 100644 --- a/src/probnum/randprocs/markov/discrete/_linear_gaussian.py +++ b/src/probnum/randprocs/markov/discrete/_linear_gaussian.py @@ -233,8 +233,8 @@ def _backward_rv_sqrt( # Smoothing updates need the gain, but # filtering updates "compute their own". - # Thus, if we are doing smoothing (|cov_obtained|>0) an the gain is not provided, - # make an extra prediction to compute the gain. + # Thus, if we are doing smoothing (|cov_obtained|>0) an the gain is not + # provided, make an extra prediction to compute the gain. if gain is None: if np.linalg.norm(rv_obtained.cov) > 0: rv_forwarded, info_forwarded = self.forward_rv( @@ -271,8 +271,8 @@ def _backward_rv_sqrt( ] # If no initial gain was provided, compute it from the QR-results - # This is required in the Kalman update, where, other than in the smoothing update, - # no initial gain was provided. + # This is required in the Kalman update, where, other than in the smoothing + # update, no initial gain was provided. # Recall that above, gain was set to zero in this setting. if np.linalg.norm(gain) == 0.0: R1 = big_triu[:output_dim, :output_dim] diff --git a/src/probnum/randprocs/markov/discrete/_lti_gaussian.py b/src/probnum/randprocs/markov/discrete/_lti_gaussian.py index c2c3b22c79..1971b27694 100644 --- a/src/probnum/randprocs/markov/discrete/_lti_gaussian.py +++ b/src/probnum/randprocs/markov/discrete/_lti_gaussian.py @@ -72,7 +72,8 @@ def from_linop( """Turn a linear operator (or numpy array) into a noise-free transition.""" # Currently, this is only a numpy array. - # In the future, once linops are more widely adopted here, this will become a linop. + # In the future, once linops are more widely adopted here, this will become + # a linop. if transition_matrix.ndim != 2: raise ValueError return cls( diff --git a/src/probnum/randprocs/markov/integrator/_integrator.py b/src/probnum/randprocs/markov/integrator/_integrator.py index 79923e0508..22c23e9ecc 100644 --- a/src/probnum/randprocs/markov/integrator/_integrator.py +++ b/src/probnum/randprocs/markov/integrator/_integrator.py @@ -16,7 +16,8 @@ class IntegratorTransition: For instances, this includes integrated Wiener processes or Matern processes. In ProbNum, integrators are always driven by :math:`d` dimensional Wiener processes. - We compute the transitions usually in a preconditioned state (Nordsieck-like coordinates). + We compute the transitions usually in a preconditioned state (Nordsieck-like + coordinates). """ def __init__(self, num_derivatives, wiener_process_dimension): @@ -73,7 +74,8 @@ def proj2coord(self, coord: int) -> np.ndarray: @property def _derivwise2coordwise_projmat(self) -> np.ndarray: - r"""Projection matrix to change the ordering of the state representation in an :class:`Integrator` from coordinate-wise to derivative-wise representation. + r"""Projection matrix to change the ordering of the state representation in an + :class:`Integrator` from coordinate-wise to derivative-wise representation. A coordinate-wise ordering is @@ -81,9 +83,11 @@ def _derivwise2coordwise_projmat(self) -> np.ndarray: and a derivative-wise ordering is - .. math:: (y_1, y_2, ..., y_d, \dot y_1, \dot y_2, ..., \dot y_d, \ddot y_1, ..., y_d^{(\nu)}). + .. math:: (y_1, y_2, ..., y_d, \dot y_1, \dot y_2, ..., + \dot y_d, \ddot y_1, ..., y_d^{(\nu)}). - Default representation in an :class:`Integrator` is coordinate-wise ordering, but sometimes, derivative-wise ordering is more convenient. + Default representation in an :class:`Integrator` is coordinate-wise ordering, + but sometimes, derivative-wise ordering is more convenient. See Also -------- @@ -107,7 +111,8 @@ def _derivwise2coordwise_projmat(self) -> np.ndarray: @property def _coordwise2derivwise_projmat(self) -> np.ndarray: - r"""Projection matrix to change the ordering of the state representation in an :class:`Integrator` from derivative-wise to coordinate-wise representation. + r"""Projection matrix to change the ordering of the state representation in an + :class:`Integrator` from derivative-wise to coordinate-wise representation. A coordinate-wise ordering is @@ -115,9 +120,11 @@ def _coordwise2derivwise_projmat(self) -> np.ndarray: and a derivative-wise ordering is - .. math:: (y_1, y_2, ..., y_d, \dot y_1, \dot y_2, ..., \dot y_d, \ddot y_1, ..., y_d^{(\nu)}). + .. math:: (y_1, y_2, ..., y_d, \dot y_1, \dot y_2, ..., + \dot y_d, \ddot y_1, ..., y_d^{(\nu)}). - Default representation in an :class:`Integrator` is coordinate-wise ordering, but sometimes, derivative-wise ordering is more convenient. + Default representation in an :class:`Integrator` is coordinate-wise ordering, + but sometimes, derivative-wise ordering is more convenient. See Also -------- diff --git a/src/probnum/randprocs/markov/integrator/_ioup.py b/src/probnum/randprocs/markov/integrator/_ioup.py index b16fb56466..49c3f0a1cf 100644 --- a/src/probnum/randprocs/markov/integrator/_ioup.py +++ b/src/probnum/randprocs/markov/integrator/_ioup.py @@ -11,7 +11,8 @@ class IntegratedOrnsteinUhlenbeckProcess(_markov_process.MarkovProcess): r"""Integrated Ornstein-Uhlenbeck process. - Convenience access to :math:`\nu` times integrated (:math:`d` dimensional) Ornstein-Uhlenbeck processes. + Convenience access to :math:`\nu` times integrated (:math:`d` dimensional) + Ornstein-Uhlenbeck processes. Parameters ---------- @@ -20,7 +21,8 @@ class IntegratedOrnsteinUhlenbeckProcess(_markov_process.MarkovProcess): initarg Initial time point. num_derivatives - Number of modelled derivatives of the integrated process (''order'', ''number of integrations''). + Number of modelled derivatives of the integrated process (''order'', + ''number of integrations''). Optional. Default is :math:`\nu=1`. wiener_process_dimension Dimension of the underlying Wiener process. @@ -28,21 +30,25 @@ class IntegratedOrnsteinUhlenbeckProcess(_markov_process.MarkovProcess): The dimension of the integrated Wiener process itself is :math:`d(\nu + 1)`. initrv Law of the integrated Wiener process at the initial time point. - Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal distribution. + Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal + distribution. diffuse - Whether to instantiate a diffuse prior. A diffuse prior has large initial variances. + Whether to instantiate a diffuse prior. A diffuse prior has large initial + variances. Optional. Default is `False`. - If `True`, and if an initial random variable is not passed, an initial random variable is created, - where the initial covariance is of the form :math:`\kappa I_{d(\nu + 1)}` - with :math:`\kappa=10^6`. + If `True`, and if an initial random variable is not passed, an initial random + variable is created, where the initial covariance is of the form + :math:`\kappa I_{d(\nu + 1)}` with :math:`\kappa=10^6`. Diffuse priors are used when initial distributions are not known. They are common for filtering-based probabilistic ODE solvers. forward_implementation Implementation of the forward-propagation in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. backward_implementation Implementation of the backward-conditioning in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. Raises ------ @@ -66,7 +72,10 @@ class IntegratedOrnsteinUhlenbeckProcess(_markov_process.MarkovProcess): >>> ioup4 = IntegratedOrnsteinUhlenbeckProcess(driftspeed=1.,initarg=0., num_derivatives=4, wiener_process_dimension=1) >>> print(ioup4) - """ + """ # pylint: disable=line-too-long + # Doctest/Example blocks in the docstring above cannot be made to comply with line + # length rule because adding newlines in them will cause rendered page to have + # unwanted newlines. def __init__( self, @@ -88,7 +97,8 @@ def __init__( ) if initrv is not None and diffuse: warnings.warn( - "Parameter `diffuse` has no effect, because an `initrv` has been provided." + "Parameter `diffuse` has no effect," + "because an `initrv` has been provided." ) if initrv is None: if diffuse: diff --git a/src/probnum/randprocs/markov/integrator/_iwp.py b/src/probnum/randprocs/markov/integrator/_iwp.py index ab613e5ba9..6a89192cff 100644 --- a/src/probnum/randprocs/markov/integrator/_iwp.py +++ b/src/probnum/randprocs/markov/integrator/_iwp.py @@ -14,14 +14,16 @@ class IntegratedWienerProcess(_markov_process.MarkovProcess): r"""Integrated Wiener process. - Convenience access to :math:`\nu` times integrated (:math:`d` dimensional) Wiener processes. + Convenience access to :math:`\nu` times integrated (:math:`d` dimensional) + Wiener processes. Parameters ---------- initarg Initial time point. num_derivatives - Number of modelled derivatives of the integrated process (''order'', ''number of integrations''). + Number of modelled derivatives of the integrated process (''order'', + ''number of integrations''). Optional. Default is :math:`\nu=1`. wiener_process_dimension Dimension of the underlying Wiener process. @@ -29,21 +31,25 @@ class IntegratedWienerProcess(_markov_process.MarkovProcess): The dimension of the integrated Wiener process itself is :math:`d(\nu + 1)`. initrv Law of the integrated Wiener process at the initial time point. - Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal distribution. + Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal + distribution. diffuse - Whether to instantiate a diffuse prior. A diffuse prior has large initial variances. + Whether to instantiate a diffuse prior. A diffuse prior has large initial + variances. Optional. Default is `False`. - If `True`, and if an initial random variable is not passed, an initial random variable is created, - where the initial covariance is of the form :math:`\kappa I_{d(\nu + 1)}` - with :math:`\kappa=10^6`. + If `True`, and if an initial random variable is not passed, an initial + random variable is created, where the initial covariance is of the form + :math:`\kappa I_{d(\nu + 1)}` with :math:`\kappa=10^6`. Diffuse priors are used when initial distributions are not known. They are common for filtering-based probabilistic ODE solvers. forward_implementation Implementation of the forward-propagation in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. backward_implementation Implementation of the backward-conditioning in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. Raises ------ @@ -67,7 +73,10 @@ class IntegratedWienerProcess(_markov_process.MarkovProcess): >>> iwp4 = IntegratedWienerProcess(initarg=0., num_derivatives=4, wiener_process_dimension=1) >>> print(iwp4) - """ + """ # pylint: disable=line-too-long + # Doctest/Example blocks in the docstring above cannot be made to comply with line + # length rule because adding newlines in them will cause rendered page to have + # unwanted newlines. def __init__( self, @@ -87,7 +96,8 @@ def __init__( ) if initrv is not None and diffuse: warnings.warn( - "Parameter `diffuse` has no effect, because an `initrv` has been provided." + "Parameter `diffuse` has no effect," + "because an `initrv` has been provided." ) if initrv is None: if diffuse: diff --git a/src/probnum/randprocs/markov/integrator/_matern.py b/src/probnum/randprocs/markov/integrator/_matern.py index 1842eb27cf..807ba06a87 100644 --- a/src/probnum/randprocs/markov/integrator/_matern.py +++ b/src/probnum/randprocs/markov/integrator/_matern.py @@ -21,7 +21,8 @@ class MaternProcess(_markov_process.MarkovProcess): initarg Initial time point. num_derivatives - Number of modelled derivatives of the integrated process (''order'', ''number of integrations''). + Number of modelled derivatives of the integrated process (''order'', + ''number of integrations''). Optional. Default is :math:`\nu=1`. wiener_process_dimension Dimension of the underlying Wiener process. @@ -29,21 +30,25 @@ class MaternProcess(_markov_process.MarkovProcess): The dimension of the integrated Wiener process itself is :math:`d(\nu + 1)`. initrv Law of the integrated Wiener process at the initial time point. - Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal distribution. + Optional. Default is a :math:`d(\nu + 1)` dimensional standard-normal + distribution. diffuse - Whether to instantiate a diffuse prior. A diffuse prior has large initial variances. + Whether to instantiate a diffuse prior. A diffuse prior has large initial + variances. Optional. Default is `False`. - If `True`, and if an initial random variable is not passed, an initial random variable is created, - where the initial covariance is of the form :math:`\kappa I_{d(\nu + 1)}` - with :math:`\kappa=10^6`. + If `True`, and if an initial random variable is not passed, an initial random + variable is created, where the initial covariance is of the form + :math:`\kappa I_{d(\nu + 1)}` with :math:`\kappa=10^6`. Diffuse priors are used when initial distributions are not known. They are common for filtering-based probabilistic ODE solvers. forward_implementation Implementation of the forward-propagation in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. backward_implementation Implementation of the backward-conditioning in the underlying transitions. - Optional. Default is `classic`. `sqrt` implementation is more computationally expensive, but also more stable. + Optional. Default is `classic`. `sqrt` implementation is more computationally + expensive, but also more stable. Raises ------ @@ -67,7 +72,10 @@ class MaternProcess(_markov_process.MarkovProcess): >>> matern4 = MaternProcess(lengthscale=1.,initarg=0., num_derivatives=4, wiener_process_dimension=1) >>> print(matern4) - """ + """ # pylint: disable=line-too-long + # Doctest/Example blocks in the docstring above cannot be made to comply with line + # length rule because adding newlines in them will cause rendered page to have + # unwanted newlines. def __init__( self, @@ -89,7 +97,8 @@ def __init__( ) if initrv is not None and diffuse: warnings.warn( - "Parameter `diffuse` has no effect, because an `initrv` has been provided." + "Parameter `diffuse` has no effect," + "because an `initrv` has been provided." ) if initrv is None: if diffuse: diff --git a/src/probnum/randprocs/markov/integrator/_preconditioner.py b/src/probnum/randprocs/markov/integrator/_preconditioner.py index 7f1f645b4e..3be0a88596 100644 --- a/src/probnum/randprocs/markov/integrator/_preconditioner.py +++ b/src/probnum/randprocs/markov/integrator/_preconditioner.py @@ -14,7 +14,8 @@ def apply_precon(precon, rv): # but not exposed to the 'randprocs' namespace # (i.e. not imported in any __init__.py). - # There is no way of checking whether `rv` has its Cholesky factor computed already or not. + # There is no way of checking whether `rv` has its Cholesky factor computed already + # or not. # Therefore, since we need to update the Cholesky factor for square-root filtering, # we also update the Cholesky factor for non-square-root algorithms here, # which implies additional cost. @@ -49,8 +50,8 @@ class NordsieckLikeCoordinates(Preconditioner): """Nordsieck-like coordinates. Similar to Nordsieck coordinates (which store the Taylor coefficients instead of the - derivatives), but better for ODE filtering and smoothing. Used in integrator-transitions, e.g. in - :class:`IntegratedWienerTransition`. + derivatives), but better for ODE filtering and smoothing. Used in + integrator-transitions, e.g. in :class:`IntegratedWienerTransition`. """ def __init__(self, powers, scales, dimension): diff --git a/src/probnum/randprocs/markov/integrator/convert/_convert.py b/src/probnum/randprocs/markov/integrator/convert/_convert.py index 97fa440dfc..5e4240e1ac 100644 --- a/src/probnum/randprocs/markov/integrator/convert/_convert.py +++ b/src/probnum/randprocs/markov/integrator/convert/_convert.py @@ -18,9 +18,11 @@ def convert_derivwise_to_coordwise( state: State to be converted. Assumed to be in coordinate-wise representation. num_derivatives: - Order of the integrator-state. Usually, this is the order of the highest derivative in the state. + Order of the integrator-state. Usually, this is the order of the highest + derivative in the state. wiener_process_dimension: - Spatial dimension of the integrator. Usually, this is the number of states associated with each derivative. + Spatial dimension of the integrator. Usually, this is the number of states + associated with each derivative. """ projmat = _integrator.IntegratorTransition( num_derivatives, wiener_process_dimension @@ -40,9 +42,11 @@ def convert_coordwise_to_derivwise( state: State to be converted. Assumed to be in derivative-wise representation. num_derivatives: - Order of the integrator-state. Usually, this is the order of the highest derivative in the state. + Order of the integrator-state. Usually, this is the order of the highest + derivative in the state. wiener_process_dimension: - Spatial dimension of the integrator. Usually, this is the number of states associated with each derivative. + Spatial dimension of the integrator. Usually, this is the number of states + associated with each derivative. """ projmat = _integrator.IntegratorTransition( num_derivatives, wiener_process_dimension diff --git a/tox.ini b/tox.ini index 5373b15525..a80bb3655c 100644 --- a/tox.ini +++ b/tox.ini @@ -72,7 +72,7 @@ commands = pylint src/probnum/linops --disable="too-many-instance-attributes,too-many-arguments,too-many-locals,protected-access,no-else-return,no-else-raise,else-if-used,line-too-long,missing-class-docstring,missing-function-docstring,missing-raises-doc,duplicate-code" --jobs=0 pylint src/probnum/problems --disable="too-many-arguments,too-many-locals,unused-variable,unused-argument,else-if-used,consider-using-from-import,duplicate-code,line-too-long,missing-module-docstring,missing-function-docstring,missing-param-doc,missing-type-doc,missing-raises-doc" --jobs=0 pylint src/probnum/quad --disable="too-many-arguments,missing-module-docstring" --jobs=0 - pylint src/probnum/randprocs --disable="arguments-differ,arguments-renamed,too-many-instance-attributes,too-many-arguments,too-many-locals,protected-access,unused-argument,no-else-return,duplicate-code,line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring,missing-type-doc,missing-raises-doc,useless-param-doc,useless-type-doc,missing-return-type-doc" --jobs=0 + pylint src/probnum/randprocs --disable="arguments-differ,arguments-renamed,too-many-instance-attributes,too-many-arguments,too-many-locals,protected-access,unused-argument,no-else-return,duplicate-code,missing-module-docstring,missing-class-docstring,missing-function-docstring,missing-type-doc,missing-raises-doc,useless-param-doc,useless-type-doc,missing-return-type-doc" --jobs=0 pylint src/probnum/randprocs/kernels --disable="duplicate-code" --jobs=0 pylint src/probnum/randvars --disable="too-many-arguments,too-many-locals,too-many-branches,too-few-public-methods,protected-access,unused-argument,no-else-return,duplicate-code,line-too-long,missing-function-docstring,missing-raises-doc" --jobs=0 pylint src/probnum/utils --disable="no-else-return,else-if-used,line-too-long,missing-raises-doc,missing-return-type-doc" --jobs=0