Note
Go to the end to download the full example code.
CUQIpy Basics#
In this tutorial, we will learn about the basic concepts of CUQIpy.
The aim of this tutorial is to help you get started with CUQIpy and start doing uncertainty quantification in five simple steps.
Step 1: Define deterministic model
Step 2: Define prior(s)
Step 3: Define likelihood
Step 4: Sample from the posterior
Step 5: Analyze the results
import cuqi
/home/runner/work/CUQIpy/CUQIpy/cuqi/likelihood/__init__.py:1: SyntaxWarning: invalid escape sequence '\p'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/model/_model.py:14: SyntaxWarning: invalid escape sequence '\m'
"""Generic model defined by a forward operator.
/home/runner/work/CUQIpy/CUQIpy/cuqi/geometry/_geometry.py:763: SyntaxWarning: invalid escape sequence '\s'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/geometry/_geometry.py:932: SyntaxWarning: invalid escape sequence '\s'
'''
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_beta.py:9: SyntaxWarning: invalid escape sequence '\G'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_cmrf.py:10: SyntaxWarning: invalid escape sequence '\s'
"""Cauchy distribution on the difference between neighboring nodes.
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_gamma.py:7: SyntaxWarning: invalid escape sequence '\G'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_modifiedhalfnormal.py:8: SyntaxWarning: invalid escape sequence '\p'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_gmrf.py:13: SyntaxWarning: invalid escape sequence '\s'
""" Gaussian Markov random field (GMRF).
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_inverse_gamma.py:8: SyntaxWarning: invalid escape sequence '\e'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_lmrf.py:8: SyntaxWarning: invalid escape sequence '\s'
"""Laplace distribution on the difference between neighboring nodes.
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_laplace.py:5: SyntaxWarning: invalid escape sequence '\e'
""" Laplace distribution.
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_smoothed_laplace.py:6: SyntaxWarning: invalid escape sequence '\e'
""" Smoothed Laplace distribution.
/home/runner/work/CUQIpy/CUQIpy/cuqi/distribution/_joint_distribution.py:12: SyntaxWarning: invalid escape sequence '\m'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:168: SyntaxWarning: invalid escape sequence '\m'
"""Wrapper for :meth:`scipy.optimize.least_squares`.
/home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:231: SyntaxWarning: invalid escape sequence '\m'
"""Wrapper for :meth:`scipy.optimize.lsq_linear`.
/home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:795: SyntaxWarning: invalid escape sequence '\|'
""" Preprocessing
/home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:879: SyntaxWarning: invalid escape sequence '\|'
"""(Euclidean) proximal operator of the \|x\|_1 norm.
/home/runner/work/CUQIpy/CUQIpy/cuqi/implicitprior/_restorator.py:101: SyntaxWarning: invalid escape sequence '\l'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/experimental/geometry/_productgeometry.py:5: SyntaxWarning: invalid escape sequence '\*'
""" A class for representing a product geometry. A product geometry
/home/runner/work/CUQIpy/CUQIpy/cuqi/problem/_problem.py:22: SyntaxWarning: invalid escape sequence '\m'
""" Representation of a Bayesian inverse problem defined by any number of densities (distributions and likelihoods), e.g.
/home/runner/work/CUQIpy/CUQIpy/cuqi/testproblem/_testproblem.py:145: SyntaxWarning: invalid escape sequence '\m'
"""
/home/runner/work/CUQIpy/CUQIpy/cuqi/testproblem/_testproblem.py:1113: SyntaxWarning: invalid escape sequence '\m'
"""
Step 1: Deterministic model#
For the purpose of this tutorial we focus on a simple 1D deconvolution problem.
Consider the deterministic inverse problem
where \(\mathbf{A}\) is a matrix representing a 1D convolution operation and \(\mathbf{y}\) and \(\mathbf{x}\) are the data and unknown (solution to the inverse problem) respectively.
A linear forward model like \(\mathbf{A}\) is represented by a LinearModel
and any data (like some observed data \(\mathbf{y}^\mathrm{obs}\)) as a CUQIarray
.
The easiest way to get these two components is to use the built-in testproblem module. If you are interested in defining your own model see the how-to guides on that.
Let us extract the model and data for a 1D deconvolution. In this case we use the default settings for the testproblem.
A, y_obs, info = cuqi.testproblem.Deconvolution1D().get_components()
Todo
Continue tutorial here.
Total running time of the script: (0 minutes 0.796 seconds)