Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve pylint line-too-long messages in randprocs #681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
141 changes: 96 additions & 45 deletions src/probnum/randprocs/markov/_transition.py

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions src/probnum/randprocs/markov/continuous/_diffusions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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\{
Expand All @@ -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):
Expand All @@ -125,15 +130,17 @@ 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)
t_has_been_promoted = True
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
Expand All @@ -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]

Expand Down
18 changes: 12 additions & 6 deletions src/probnum/randprocs/markov/continuous/_linear_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/probnum/randprocs/markov/continuous/_lti_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
3 changes: 2 additions & 1 deletion src/probnum/randprocs/markov/continuous/_sde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
8 changes: 4 additions & 4 deletions src/probnum/randprocs/markov/discrete/_linear_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion src/probnum/randprocs/markov/discrete/_lti_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 14 additions & 7 deletions src/probnum/randprocs/markov/integrator/_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -73,17 +74,20 @@ 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
.. math:: (y_1, \dot y_1, \ddot y_1, y_2, \dot y_2, ..., y_d^{(\nu)})
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
--------
Expand All @@ -107,17 +111,20 @@ 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
.. math:: (y_1, \dot y_1, \ddot y_1, y_2, \dot y_2, ..., y_d^{(\nu)})
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
--------
Expand Down
32 changes: 21 additions & 11 deletions src/probnum/randprocs/markov/integrator/_ioup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -20,29 +21,34 @@ 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.
Optional. Default is :math:`d=1`.
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
------
Expand All @@ -66,7 +72,10 @@ class IntegratedOrnsteinUhlenbeckProcess(_markov_process.MarkovProcess):
>>> ioup4 = IntegratedOrnsteinUhlenbeckProcess(driftspeed=1.,initarg=0., num_derivatives=4, wiener_process_dimension=1)
>>> print(ioup4)
<IntegratedOrnsteinUhlenbeckProcess with input_shape=(), output_shape=(5,), dtype=float64>
"""
""" # 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.
pnkraemer marked this conversation as resolved.
Show resolved Hide resolved

def __init__(
self,
Expand All @@ -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:
Expand Down
32 changes: 21 additions & 11 deletions src/probnum/randprocs/markov/integrator/_iwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@
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.
Optional. Default is :math:`d=1`.
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
------
Expand All @@ -67,7 +73,10 @@ class IntegratedWienerProcess(_markov_process.MarkovProcess):
>>> iwp4 = IntegratedWienerProcess(initarg=0., num_derivatives=4, wiener_process_dimension=1)
>>> print(iwp4)
<IntegratedWienerProcess with input_shape=(), output_shape=(5,), dtype=float64>
"""
""" # 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.
pnkraemer marked this conversation as resolved.
Show resolved Hide resolved

def __init__(
self,
Expand All @@ -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:
Expand Down
Loading