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

Fixed line-too-long pylint message in probnum and probnum.problems subpackage #705

Merged
merged 8 commits into from
Apr 23, 2022
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
12 changes: 8 additions & 4 deletions src/probnum/_pnmethod/_stopping_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class StoppingCriterion(abc.ABC):
... def __call__(self, solver_state) -> bool:
... return solver_state.rtol < self.rtol

Now let's combine them by stopping when the solver has reached an absolute and relative tolerance, or a maximum number of iterations.
Now let's combine them by stopping when the solver has reached
an absolute and relative tolerance, or a maximum number of iterations.

>>> stopcrit = MaxIterations(maxiters=100) | (
... AbsoluteResidualTolerance(atol=1e-6)
Expand All @@ -57,7 +58,8 @@ class StoppingCriterion(abc.ABC):
>>> stopcrit(state)
False

Now let's modify the state such that the solver has reached a maximum number of iterations.
Now let's modify the state such that the solver has reached
a maximum number of iterations.

>>> state.iters = 1000
>>> stopcrit(state)
Expand All @@ -66,8 +68,10 @@ class StoppingCriterion(abc.ABC):
See Also
--------
LambdaStoppingCriterion : Stopping criterion defined via an anonymous function.
~probnum.linalg.solvers.stopping_criteria.LinearSolverStoppingCriterion : Stopping criterion of a probabilistic linear solver.
~probnum.filtsmooth.optim.FiltSmoothStoppingCriterion : Stopping criterion of filters and smoothers.
~probnum.linalg.solvers.stopping_criteria.LinearSolverStoppingCriterion : Stopping
criterion of a probabilistic linear solver.
~probnum.filtsmooth.optim.FiltSmoothStoppingCriterion : Stopping criterion of
filters and smoothers.
"""

@abc.abstractmethod
Expand Down
26 changes: 17 additions & 9 deletions src/probnum/problems/_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
class TimeSeriesRegressionProblem:
r"""Time series regression problem.

Fit a stochastic process to data, given a likelihood (realised by a :obj:`NonlinearGaussian` transition).
Fit a stochastic process to data, given a likelihood
(realised by a :obj:`NonlinearGaussian` transition).
Solved by filters and smoothers in :mod:`probnum.filtsmooth`.

Parameters
Expand All @@ -28,7 +29,8 @@ class TimeSeriesRegressionProblem:
measurement_models
Measurement models.
solution
Array containing solution to the problem at ``locations``. Used for testing and benchmarking.
Array containing solution to the problem at ``locations``.
Used for testing and benchmarking.

Examples
--------
Expand Down Expand Up @@ -70,7 +72,8 @@ class TimeSeriesRegressionProblem:
measurement_models: Union[Sequence, np.ndarray]

# For testing and benchmarking
# The solution here is a Sequence or array of the values of the truth at the location.
# The solution here is a Sequence or
# array of the values of the truth at the location.
solution: Optional[Union[Sequence, np.ndarray]] = None

def __post_init__(self):
Expand All @@ -81,8 +84,9 @@ def __post_init__(self):
2. Check that all inputs have the same length.
"""

# If a single measurement model has been provided, transform it into a list of models
# to ensure that there is a measurement model for every (t, y) combination.
# If a single measurement model has been provided,
# transform it into a list of models to ensure that
# there is a measurement model for every (t, y) combination.
if not isinstance(self.measurement_models, abc.Iterable):
self.measurement_models = [self.measurement_models] * len(self.locations)

Expand Down Expand Up @@ -135,11 +139,14 @@ class InitialValueProblem:
y0
Initial value of the solution.
df
Jacobian of the ODE vector-field :math:`f=f(t,y)` with respect to the :math:`y` variable.
Jacobian of the ODE vector-field :math:`f=f(t,y)`
with respect to the :math:`y` variable.
ddf
Hessian of the ODE vector-field :math:`f=f(t,y)` with respect to the :math:`y` variable.
Hessian of the ODE vector-field :math:`f=f(t,y)`
with respect to the :math:`y` variable.
solution
Closed form, analytic solution to the problem. Used for testing and benchmarking.
Closed form, analytic solution to the problem.
Used for testing and benchmarking.
dy0_all
All initial derivatives up to some order.

Expand Down Expand Up @@ -236,7 +243,8 @@ class QuadratureProblem:
output_dim
Output dimension of the integrand.
solution
Closed form, analytic solution to the problem. Used for testing and benchmarking.
Closed form, analytic solution to the problem.
Used for testing and benchmarking.

Examples
--------
Expand Down
40 changes: 25 additions & 15 deletions src/probnum/problems/zoo/diffeq/_ivp_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
def threebody(t0=0.0, tmax=17.0652165601579625588917206249, y0=None):
r"""Initial value problem (IVP) based on a three-body problem.

For the initial conditions :math:`y = (y_1, y_2, \dot{y}_1, \dot{y}_2)^T`, this function implements the second-order three-body problem as a system of
For the initial conditions :math:`y = (y_1, y_2, \dot{y}_1, \dot{y}_2)^T`,
this function implements the second-order three-body problem as a system of
first-order ODEs, which is defined as follows: [1]_

.. math::
Expand All @@ -39,21 +40,25 @@ def threebody(t0=0.0, tmax=17.0652165601579625588917206249, y0=None):
d_1 &= ((y_1 + \mu)^2 + y_2^2)^{\frac{3}{2}} \\
d_2 &= ((y_1 - (1 - \mu))^2 + y_2^2)^{\frac{3}{2}}

and a constant parameter :math:`\mu = 0.012277471` denoting the standardized moon mass.
and a constant parameter :math:`\mu = 0.012277471`
denoting the standardized moon mass.

Parameters
----------
t0
Initial time.
tmax
Final time. Default is ``17.0652165601579625588917206249`` which is the period of the solution.
Final time. Default is ``17.0652165601579625588917206249``
which is the period of the solution.
y0
*(shape=(4, ))* -- Initial value. Default is ``[0.994, 0, 0, -2.00158510637908252240537862224]``.
*(shape=(4, ))* -- Initial value.
Default is ``[0.994, 0, 0,-2.00158510637908252240537862224]``.

Returns
-------
InitialValueProblem
InitialValueProblem object describing a three-body problem IVP with the prescribed configuration.
InitialValueProblem object describing a three-body problem IVP
with the prescribed configuration.

References
----------
Expand Down Expand Up @@ -111,8 +116,8 @@ def vanderpol(t0=0.0, tmax=30, y0=None, params=1e1):
Returns
-------
InitialValueProblem
InitialValueProblem object describing the Van der Pol Oscillator IVP with the prescribed
configuration.
InitialValueProblem object describing the Van der Pol Oscillator
IVP with the prescribed configuration.
"""

if y0 is None:
Expand Down Expand Up @@ -170,8 +175,8 @@ def rigidbody(t0=0.0, tmax=20.0, y0=None, params=(-2.0, 1.25, -0.5)):
Returns
-------
InitialValueProblem
InitialValueProblem object describing the rigid body dynamics IVP with the prescribed
configuration.
InitialValueProblem object describing the rigid body dynamics IVP
with the prescribed configuration.
"""
if y0 is None:
y0 = np.array([1.0, 0.0, 0.9])
Expand Down Expand Up @@ -286,7 +291,8 @@ def fitzhughnagumo(t0=0.0, tmax=20.0, y0=None, params=(0.2, 0.2, 3.0, 1.0)):
Returns
-------
InitialValueProblem
InitialValueProblem object describing the FitzHugh-Nagumo model with the prescribed configuration.
InitialValueProblem object describing the FitzHugh-Nagumo model
with the prescribed configuration.
"""
if y0 is None:
y0 = np.array([1.0, -1.0])
Expand Down Expand Up @@ -335,7 +341,8 @@ def lotkavolterra(t0=0.0, tmax=20.0, y0=None, params=(0.5, 0.05, 0.5, 0.05)):
Returns
-------
InitialValueProblem
InitialValueProblem object describing the Lotka-Volterra system with the prescribed configuration.
InitialValueProblem object describing the Lotka-Volterra system
with the prescribed configuration.
"""
if y0 is None:
y0 = np.array([20.0, 20.0])
Expand Down Expand Up @@ -499,10 +506,12 @@ def lorenz96(t0=0.0, tmax=30.0, y0=None, num_variables=5, params=(8.0,)):
tmax
Final time.
y0
*(shape=(N, ))* -- Initial value. Default is ``[1/F, ..., 1/F]``. `N` is the number of variables in the model.
*(shape=(N, ))* -- Initial value. Default is ``[1/F, ..., 1/F]``.
`N` is the number of variables in the model.
num_variables
Number of variables in the model. If `y0` is specified, this argument is ignored
(and the number of variables is inferred from the dimension of the initial value).
Number of variables in the model. If `y0` is specified,
this argument is ignored (and the number of variables
is inferred from the dimension of the initial value).
params
Parameter(s) of the Lorenz96 model. Default is ``(8,)``.

Expand All @@ -521,7 +530,8 @@ def lorenz96(t0=0.0, tmax=30.0, y0=None, num_variables=5, params=(8.0,)):
y0 = np.ones(num_variables) * constant_forcing
elif len(y0) < 4:
raise ValueError(
"The number of variables (i.e. the length of the initial vector) must be at least 4."
"The number of variables (i.e. the length of the initial vector)",
"must be at least 4.",
)

def lorenz96_f_vec(t, y, c=constant_forcing):
Expand Down
6 changes: 4 additions & 2 deletions src/probnum/problems/zoo/diffeq/_ivp_examples_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def threebody_jax(tmax=17.0652165601579625588917206249):
d_1 &= ((y_1 + \mu)^2 + y_2^2)^{\frac{3}{2}} \\
d_2 &= ((y_1 - (1 - \mu))^2 + y_2^2)^{\frac{3}{2}}

and a constant parameter :math:`\mu = 0.012277471` denoting the standardized moon mass.
and a constant parameter :math:`\mu = 0.012277471`
denoting the standardized moon mass.

Parameters
----------
Expand Down Expand Up @@ -106,7 +107,8 @@ def _import_jax():


def vanderpol_jax(t0=0.0, tmax=30, y0=None, params=1e1):
r"""Initial value problem (IVP) based on the Van der Pol Oscillator, implemented in `jax`.
r"""Initial value problem (IVP) based on the Van der Pol Oscillator,
implemented in `jax`.

This function implements the second-order Van-der-Pol Oscillator as a system
of first-order ODEs.
Expand Down
12 changes: 7 additions & 5 deletions src/probnum/problems/zoo/filtsmooth/_filtsmooth_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,11 @@ def benes_daum(

Notes
-----
In order to generate observations for the returned ``TimeSeriesRegressionProblem`` object,
the non-linear Beneš SDE has to be linearized.
Here, a ``ContinuousEKFComponent`` is used, which corresponds to a first-order
linearization as used in the extended Kalman filter.
In order to generate observations for the returned
``TimeSeriesRegressionProblem`` object, the non-linear Beneš SDE
has to be linearized. Here, a ``ContinuousEKFComponent`` is used,
which corresponds to a first-order linearization as used
in the extended Kalman filter.
"""

def f(t, x):
Expand Down Expand Up @@ -538,7 +539,8 @@ def logistic_ode(
ek0_or_ek1
See :py:class:`probnum.diffeq.ODEFilter`
exclude_initial_condition
Whether the resulting regression problem should exclude (i.e. not contain) the initial condition of the ODE.
Whether the resulting regression problem should exclude
(i.e. not contain) the initial condition of the ODE.
Optional. Default is True, which means that the initial condition is omitted.
order
Order of integration for the Integrated Brownian Motion prior of the solver.
Expand Down
25 changes: 16 additions & 9 deletions src/probnum/problems/zoo/linalg/_random_linear_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ def random_linear_system(
) -> problems.LinearSystem:
"""Random linear system.

Generate a random linear system from a (random) matrix. If ``matrix`` is a callable instead of a matrix or
linear operator, the system matrix is sampled by passing the random generator instance ``rng``. The solution
of the linear system is set to a realization from ``solution_rv``. If ``None`` the solution is drawn from a
standard normal distribution with iid components.
Generate a random linear system from a (random) matrix.
If ``matrix`` is a callable instead of a matrix or linear operator,
the system matrix is sampled by passing the random generator
instance ``rng``. The solution of the linear system is set
to a realization from ``solution_rv``. If ``None`` the solution
is drawn from a standard normal distribution with iid components.

Parameters
----------
rng
Random number generator.
matrix
Matrix, linear operator or callable returning either for a given random number generator instance.
Matrix, linear operator or callable returning either
for a given random number generator instance.
solution_rv
Random variable from which the solution of the linear system is sampled.
kwargs
Expand All @@ -43,7 +46,8 @@ def random_linear_system(
See Also
--------
random_spd_matrix : Generate a random symmetric positive-definite matrix.
random_sparse_spd_matrix : Generate a random sparse symmetric positive-definite matrix.
random_sparse_spd_matrix : Generate a random sparse symmetric
positive-definite matrix.

Examples
--------
Expand All @@ -65,13 +69,15 @@ def random_linear_system(
>>> linsys_spd = random_linear_system(rng, random_spd_matrix, dim=2)
>>> linsys_spd
LinearSystem(A=array([[ 9.62543582, 3.14955953],
[ 3.14955953, 13.28720426]]), b=array([-2.7108139 , 1.10779288]), solution=array([-0.33488503, 0.16275307]))
[ 3.14955953, 13.28720426]]), b=array([-2.7108139 , 1.10779288]),
solution=array([-0.33488503, 0.16275307]))


Linear system with random sparse matrix.

>>> import scipy.sparse
>>> random_sparse_matrix = lambda rng,m,n: scipy.sparse.random(m=m, n=n, random_state=rng)
>>> random_sparse_matrix = lambda rng,m,n: scipy.sparse.random(m=m, n=n,\
random_state=rng)
>>> linsys_sparse = random_linear_system(rng, random_sparse_matrix, m=4, n=2)
>>> isinstance(linsys_sparse.A, scipy.sparse.spmatrix)
True
Expand All @@ -89,7 +95,8 @@ def random_linear_system(
else:
if A.shape[1] != solution_rv.shape[0]:
raise ValueError(
f"Shape of the system matrix: {A.shape} must match shape of the solution: {solution_rv.shape}."
f"Shape of the system matrix: {A.shape} must match shape \
of the solution: {solution_rv.shape}."
)
x = solution_rv.sample(size=(), rng=rng)

Expand Down
3 changes: 2 additions & 1 deletion src/probnum/problems/zoo/linalg/_random_spd_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def random_spd_matrix(

See Also
--------
random_sparse_spd_matrix : Generate a random sparse symmetric positive definite matrix.
random_sparse_spd_matrix : Generate a random
sparse symmetric positive definite matrix.

Examples
--------
Expand Down
17 changes: 12 additions & 5 deletions src/probnum/problems/zoo/linalg/_suitesparse_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def suitesparse_matrix(
import requests # pylint: disable=import-outside-toplevel
except ImportError as err:
raise ImportError(
"Cannot query SuiteSparse Matrix collection without optional dependency ",
"`requests`. Install ProbNum with optional dependencies for the problem zoo via",
" `pip install probnum[zoo]` or install requests directly: `pip install requests`.",
"Cannot query SuiteSparse Matrix collection without",
"optional dependency `requests`. Install ProbNum with",
"optional dependencies for the problem zoo via",
"`pip install probnum[zoo]` or install requests",
"directly: `pip install requests`.",
pnkraemer marked this conversation as resolved.
Show resolved Hide resolved
) from err
response = requests.get(SUITESPARSE_INDEX_URL, "r")
line_gen = response.iter_lines()
Expand Down Expand Up @@ -198,7 +200,11 @@ def _download(
import requests # pylint: disable=import-outside-toplevel
except ImportError as err:
raise ImportError(
"Cannot query SuiteSparse Matrix collection without optional dependency `requests`. Install ProbNum with optional dependencies for the problem zoo via `pip install probnum[zoo]` or install requests directly: `pip install requests`."
"Cannot query SuiteSparse Matrix collection without",
"optional dependency `requests`. Install ProbNum with",
"optional dependencies for the problem zoo via",
"`pip install probnum[zoo]` or install requests",
"directly: `pip install requests`.",
pnkraemer marked this conversation as resolved.
Show resolved Hide resolved
) from err

url = SUITESPARSE_ROOT_URL + f"/MM/{self.group}/{self.name}.tar.gz"
Expand Down Expand Up @@ -286,7 +292,8 @@ def _to_html_row(self) -> str:
f"{self.psym:.2}",
f"{self.nsym:.2}",
self.kind,
f'<img src="{SUITESPARSE_ROOT_URL}/files/{self.group}/{self.name}.png">',
f'<img src="{SUITESPARSE_ROOT_URL}/files/\
{self.group}/{self.name}.png">',
]
)
+ "</tr>"
Expand Down
Loading