class probnum.linalg.solvers.ProbabilisticLinearSolver(policy, information_op, belief_update, stopping_criterion)

Bases: ProbabilisticNumericalMethod[LinearSystem, LinearSystemBelief]

Compose a custom probabilistic linear solver.

Class implementing probabilistic linear solvers. Such (iterative) solvers infer solutions to problems of the form


where \(A \in \mathbb{R}^{n \times n}\) and \(b \in \mathbb{R}^{n}\). They return a probability measure which quantifies uncertainty in the output arising from finite computational resources or stochastic input. This class unifies and generalizes probabilistic linear solvers as described in the literature. [1] [2] [3] [4]

  • policy – Policy returning actions taken by the solver.

  • information_op – Information operator defining how information about the linear system is obtained given an action.

  • belief_update – Belief update defining how to update the QoI beliefs given new observations.

  • stopping_criterion – Stopping criterion determining when a desired terminal condition is met.


See also


Solve linear systems in a Bayesian framework.


Solve linear systems with prior information on the solution.


Define a linear system.

>>> import numpy as np
>>> from probnum.problems import LinearSystem
>>> from probnum.problems.zoo.linalg import random_spd_matrix
>>> rng = np.random.default_rng(42)
>>> n = 100
>>> A = random_spd_matrix(rng=rng, dim=n)
>>> b = rng.standard_normal(size=(n,))
>>> linsys = LinearSystem(A=A, b=b)

Create a custom probabilistic linear solver from pre-defined components.

>>> from probnum.linalg.solvers import (
...     ProbabilisticLinearSolver,
...     belief_updates,
...     beliefs,
...     information_ops,
...     policies,
...     stopping_criteria,
... )
>>> pls = ProbabilisticLinearSolver(
...     policy=policies.ConjugateGradientPolicy(),
...     information_op=information_ops.ProjectedResidualInformationOp(),
...     belief_update=belief_updates.solution_based.ProjectedResidualBeliefUpdate(),
...     stopping_criterion=(
...         stopping_criteria.MaxIterationsStoppingCriterion(100)
...         | stopping_criteria.ResidualNormStoppingCriterion(atol=1e-5, rtol=1e-5)
...     ),
... )

Define a prior over the solution.

>>> from probnum import linops, randvars
>>> prior = beliefs.LinearSystemBelief(
...     x=randvars.Normal(
...         mean=np.zeros((n,)),
...         cov=np.eye(n),
...     ),
... )

Solve the linear system using the custom solver.

>>> belief, solver_state = pls.solve(prior=prior, problem=linsys)
>>> np.linalg.norm(linsys.A @ belief.x.mean - linsys.b) / np.linalg.norm(linsys.b)

Methods Summary

solve(prior, problem[, rng])

Solve the linear system.

solve_iterator(prior, problem[, rng])

Generator implementing the solver iteration.

Methods Documentation

solve(prior, problem, rng=None)[source]

Solve the linear system.

  • prior (LinearSystemBelief) – Prior belief about the quantities of interest \((x, A, A^{-1}, b)\) of the linear system.

  • problem (LinearSystem) – Linear system to be solved.

  • rng (Generator | None) – Random number generator.


  • belief – Posterior belief \((\mathsf{x}, \mathsf{A}, \mathsf{H}, \mathsf{b})\) over the solution \(x\), the system matrix \(A\), its (pseudo-)inverse \(H=A^\dagger\) and the right hand side \(b\).

  • solver_state – Final state of the solver.

Return type:

Tuple[LinearSystemBelief, LinearSolverState]

solve_iterator(prior, problem, rng=None)[source]

Generator implementing the solver iteration.

This function allows stepping through the solver iteration one step at a time and exposes the internal solver state.

  • prior (LinearSystemBelief) – Prior belief about the quantities of interest \((x, A, A^{-1}, b)\) of the linear system.

  • problem (LinearSystem) – Linear system to be solved.

  • rng (Generator | None) – Random number generator.


solver_state – State of the probabilistic linear solver.

Return type:

Generator[LinearSolverState, None, None]