.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "user/_auto_tutorials/1_basics.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_user__auto_tutorials_1_basics.py: 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 .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python import cuqi .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/CUQIpy/CUQIpy/cuqi/data/_data.py:1: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. import pkg_resources /home/runner/work/CUQIpy/CUQIpy/cuqi/likelihood/__init__.py:1: SyntaxWarning: invalid escape sequence '\p' """ /home/runner/work/CUQIpy/CUQIpy/cuqi/model/_model.py:17: SyntaxWarning: invalid escape sequence '\m' """Generic model defined by a forward operator. /home/runner/work/CUQIpy/CUQIpy/cuqi/geometry/_geometry.py:769: SyntaxWarning: invalid escape sequence '\s' """ /home/runner/work/CUQIpy/CUQIpy/cuqi/geometry/_geometry.py:938: SyntaxWarning: invalid escape sequence '\s' ''' /home/runner/work/CUQIpy/CUQIpy/cuqi/geometry/_product_geometry.py:5: SyntaxWarning: invalid escape sequence '\*' """ A class for representing a product geometry. A product geometry /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/_modified_half_normal.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:235: SyntaxWarning: invalid escape sequence '\m' """Wrapper for :meth:`scipy.optimize.lsq_linear`. /home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:799: SyntaxWarning: invalid escape sequence '\|' """ Preprocessing /home/runner/work/CUQIpy/CUQIpy/cuqi/solver/_solver.py:883: 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/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:1112: SyntaxWarning: invalid escape sequence '\m' """ .. GENERATED FROM PYTHON SOURCE LINES 21-43 Step 1: Deterministic model --------------------------- For the purpose of this tutorial we focus on a simple 1D deconvolution problem. Consider the deterministic inverse problem .. math:: \mathbf{y} = \mathbf{A} \mathbf{x} where :math:`\mathbf{A}` is a matrix representing a 1D convolution operation and :math:`\mathbf{y}` and :math:`\mathbf{x}` are the data and unknown (solution to the inverse problem) respectively. A linear forward model like :math:`\mathbf{A}` is represented by a :class:`~cuqi.model.LinearModel` and any data (like some observed data :math:`\mathbf{y}^\mathrm{obs}`) as a :class:`~cuqi.array.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. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python A, y_obs, info = cuqi.testproblem.Deconvolution1D().get_components() .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. todo:: Continue tutorial here. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.957 seconds) .. _sphx_glr_download_user__auto_tutorials_1_basics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 1_basics.ipynb <1_basics.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 1_basics.py <1_basics.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 1_basics.zip <1_basics.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_