fredipy


Namefredipy JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryInverting Fredholm Integrals with Python
upload_time2024-03-08 15:35:14
maintainer
docs_urlNone
author
requires_python>=3.10
licenseMIT License Copyright (c) 2024 Jonas Turnwald, Julian M. Urban, Nicolas Wink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords gaussian-process fredholm inverse-problem
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # _fredipy_: Fredholm Inversion in Python

This package implements constrained Gaussian process regression for linear inverse problems, with a focus on inverting Fredholm integral equations of the first kind.

## Introduction

Linear inverse problems are ubiquitous in science. A particular instance of this class of problems is finding solutions $\rho(\omega)$ to Fredholm integral equations of the form

$$G(p) = \int \mathrm{d}\omega\ K(p,\omega) \rho(\omega)\ ,$$

where the function $K(p, \omega)$ is known. The left-hand side, $G(p)$, is typically available in the form of discrete observations with finite measurement uncertainty. Further prior knowledge about the solution $\rho(\omega)$ is often provided in terms of linear equality constraints. Discretizing the convolution on the right-hand side can result in heavily ill-conditioned systems of linear equations in need of regularization.

Extending standard Gaussian process regression to inference with indirect observations (which are related to the desired data by a linear transformation) offers a powerful non-parametric approach to the probabilistic treatment of Fredholm inversion problems. Moreover, the ansatz naturally admits the incorporation of further linear equality constraints with essentially arbitrary linear operators, treated in the same way as the main problem statement itself.

This package provides a python implementation of the method. To the best of our knowledge, the full algorithm was first described by Valentine and Sambridge, 2019 [[1]](#1) in the context of geostatistics. We are primarily interested in its application to the spectral reconstruction of correlation functions in computational quantum field theory [[2-4]](#2). Nevertheless, the software is largely problem-agnostic and generally applicable in a wide variety of similar settings.

We recommend [[1]](#1) and [[2]](#2) for an introduction to the method, while the textbook by Rasmussen and Wiliams [[5]](#5) is an excellent general introdution to Gaussian Processes.

In the current framework, it is not possible to include global inequality constraints, most relevant to reconstruct a strictily positive function. This makes reconstructing sharp peaks that swiftly approach zero at the tails one of the hardest reconstruction problems with this technique. Currently, we are looking into several possibilites to provide such a feature in the future.

Note, that we use custom integration routines for two reasons: Firstly, this lets us write the integration as a fast matrix multiplication. Secondly, using integration schemes that do not have a fixed set of grid points, can lead to numerical instabilities in the reconstruction. The consistency of the result in the different integration procedures during the reconstruction is very important and we therefore explicitly require this.

## Installation

To install _fredipy_ from PyPi, use

```
pip install fredipy
```

## Usage

See [examples](https://github.com/JonasTurnwald/fredipy/tree/main/examples/), for in depth examples of the package usage. Specifically, [this notebook](https://github.com/JonasTurnwald/fredipy/tree/main/examples/basic_breit_wigner.ipynb) covers the most important basic options.

A simple example for the reconstruction of a single Breit-Wigner peak, showcasing the basic structure.

```python
import fredipy as fp
import numpy as np

# define breit wigner peak
def get_BW(p, a, m, g):
    return a / (m ** 2 + (np.sqrt(p**2) + g) ** 2)

# define the associates spectral function rho
def get_rho(w, a, m, g):
    return (4 * a * g * w) / (4 * g ** 2 * w ** 2 + (g ** 2 + m ** 2 - w ** 2) ** 2)

# ... and the källen lehmann kernel, that is integrated over
def kl_kernel(p, w):
    return w / (w**2 + p**2) / np.pi

# prepare the data arrays

w_pred = np.arange(0.1, 10, 0.1)
p = np.linspace(0, 20, 100)

a = 1.6
m = 1
g = 0.8

# the example spectral function
rho = get_rho(w_pred, a, m, g) 

# ... and the associated correlator
G = get_BW(p, a, m, g)

# put some noise on the data
err = 1e-5
G_err = G + err * np.random.randn(len(G))

data = {
    'x': p,
    'y': G_err,
    'dy': err * np.ones_like(G)}

# use the RBF kernel
kernel = fp.kernels.RadialBasisFunction(variance=0.3, lengthscale=0.4)
# define the integrator method to use, with upper and lower bounds and number of points
integrator = fp.integrators.Riemann_1D(w_min=0, w_max=100, int_n=1000)

# ... and define the operator, the integration with the källen lehmann kernel
integral_op = fp.operators.Integral(kl_kernel, integrator)

# ... and define the full constraint using the date we genrated before
constraints = [fp.constraints.LinearEquality(integral_op, data)]

# now we can define the model using the contraints and the GP kernel
model = fp.models.GaussianProcess(kernel, constraints)

# ... and do a prediction on the points w_pred
_rho, _rho_err = model.predict(w_pred)
```

## Authors & Citing

This package is written and maintained by Jonas Turnwald, Julian M. Urban and Nicolas Wink.

If you use this package in scientific work, please cite this repository.

## References

<a id="1">[1]</a>
A. P. Valentine and M. Sambridge, Gaussian process models—I. A framework for probabilistic continuous inverse theory, [Geophysical Journal International 220, 1632 (2020)](https://academic.oup.com/gji/article/220/3/1632/5632112).

<a id="2">[2]</a>
J. Horak, J. M. Pawlowski, J. Rodríguez-Quintero, J. Turnwald, J. M. Urban, N. Wink, and S. Zafeiropoulos, Reconstructing QCD spectral functions with Gaussian processes, [Phys. Rev. D 105, 036014 (2022), arXiv:2107.13464 [hep-ph]](https://arxiv.org/abs/2107.13464).

<a id="3">[3]</a>
J. M. Pawlowski, C. S. Schneider, J. Turnwald, J. M. Urban, and N. Wink, Yang-Mills glueball masses from spectral reconstruction, [Phys. Rev. D 108, 076018 (2023), arXiv:2212.01113 [hep-ph]](https://arxiv.org/abs/2212.01113).

<a id="4">[4]</a>
J. Horak, J. M. Pawlowski, J. Turnwald, J. M. Urban, N. Wink, and S. Zafeiropoulos, Nonperturbative strong coupling at timelike momenta, [Phys. Rev. D 107, 076019 (2023), arXiv:2301.07785 [hep-ph]](https://arxiv.org/abs/2301.07785).

<a id="5">[5]</a>
C. Rasmussen and C. Williams, [Gaussian Processes for Machine Learning, The MIT Press, 2005](https://doi.org/10.7551/mitpress/3206.001.0001).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fredipy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "gaussian-process,fredholm,inverse-problem",
    "author": "",
    "author_email": "Jonas Turnwald <j.turnwald@theorie.ikp.physik.tu-darmstadt.de>, \"Julian M. Urban\" <tbd@tbd.com>, Nicolas Wink <tbd@tbd.com>",
    "download_url": "https://files.pythonhosted.org/packages/c7/1f/fe6023aeaeb3aeecae874cba2dbc42a4ae0f13e414736791215b20b3c2bf/fredipy-0.1.0.tar.gz",
    "platform": null,
    "description": "# _fredipy_: Fredholm Inversion in Python\n\nThis package implements constrained Gaussian process regression for linear inverse problems, with a focus on inverting Fredholm integral equations of the first kind.\n\n## Introduction\n\nLinear inverse problems are ubiquitous in science. A particular instance of this class of problems is finding solutions $\\rho(\\omega)$ to Fredholm integral equations of the form\n\n$$G(p) = \\int \\mathrm{d}\\omega\\ K(p,\\omega) \\rho(\\omega)\\ ,$$\n\nwhere the function $K(p, \\omega)$ is known. The left-hand side, $G(p)$, is typically available in the form of discrete observations with finite measurement uncertainty. Further prior knowledge about the solution $\\rho(\\omega)$ is often provided in terms of linear equality constraints. Discretizing the convolution on the right-hand side can result in heavily ill-conditioned systems of linear equations in need of regularization.\n\nExtending standard Gaussian process regression to inference with indirect observations (which are related to the desired data by a linear transformation) offers a powerful non-parametric approach to the probabilistic treatment of Fredholm inversion problems. Moreover, the ansatz naturally admits the incorporation of further linear equality constraints with essentially arbitrary linear operators, treated in the same way as the main problem statement itself.\n\nThis package provides a python implementation of the method. To the best of our knowledge, the full algorithm was first described by Valentine and Sambridge, 2019 [[1]](#1) in the context of geostatistics. We are primarily interested in its application to the spectral reconstruction of correlation functions in computational quantum field theory [[2-4]](#2). Nevertheless, the software is largely problem-agnostic and generally applicable in a wide variety of similar settings.\n\nWe recommend [[1]](#1) and [[2]](#2) for an introduction to the method, while the textbook by Rasmussen and Wiliams [[5]](#5) is an excellent general introdution to Gaussian Processes.\n\nIn the current framework, it is not possible to include global inequality constraints, most relevant to reconstruct a strictily positive function. This makes reconstructing sharp peaks that swiftly approach zero at the tails one of the hardest reconstruction problems with this technique. Currently, we are looking into several possibilites to provide such a feature in the future.\n\nNote, that we use custom integration routines for two reasons: Firstly, this lets us write the integration as a fast matrix multiplication. Secondly, using integration schemes that do not have a fixed set of grid points, can lead to numerical instabilities in the reconstruction. The consistency of the result in the different integration procedures during the reconstruction is very important and we therefore explicitly require this.\n\n## Installation\n\nTo install _fredipy_ from PyPi, use\n\n```\npip install fredipy\n```\n\n## Usage\n\nSee [examples](https://github.com/JonasTurnwald/fredipy/tree/main/examples/), for in depth examples of the package usage. Specifically, [this notebook](https://github.com/JonasTurnwald/fredipy/tree/main/examples/basic_breit_wigner.ipynb) covers the most important basic options.\n\nA simple example for the reconstruction of a single Breit-Wigner peak, showcasing the basic structure.\n\n```python\nimport fredipy as fp\nimport numpy as np\n\n# define breit wigner peak\ndef get_BW(p, a, m, g):\n    return a / (m ** 2 + (np.sqrt(p**2) + g) ** 2)\n\n# define the associates spectral function rho\ndef get_rho(w, a, m, g):\n    return (4 * a * g * w) / (4 * g ** 2 * w ** 2 + (g ** 2 + m ** 2 - w ** 2) ** 2)\n\n# ... and the k\u00e4llen lehmann kernel, that is integrated over\ndef kl_kernel(p, w):\n    return w / (w**2 + p**2) / np.pi\n\n# prepare the data arrays\n\nw_pred = np.arange(0.1, 10, 0.1)\np = np.linspace(0, 20, 100)\n\na = 1.6\nm = 1\ng = 0.8\n\n# the example spectral function\nrho = get_rho(w_pred, a, m, g) \n\n# ... and the associated correlator\nG = get_BW(p, a, m, g)\n\n# put some noise on the data\nerr = 1e-5\nG_err = G + err * np.random.randn(len(G))\n\ndata = {\n    'x': p,\n    'y': G_err,\n    'dy': err * np.ones_like(G)}\n\n# use the RBF kernel\nkernel = fp.kernels.RadialBasisFunction(variance=0.3, lengthscale=0.4)\n# define the integrator method to use, with upper and lower bounds and number of points\nintegrator = fp.integrators.Riemann_1D(w_min=0, w_max=100, int_n=1000)\n\n# ... and define the operator, the integration with the k\u00e4llen lehmann kernel\nintegral_op = fp.operators.Integral(kl_kernel, integrator)\n\n# ... and define the full constraint using the date we genrated before\nconstraints = [fp.constraints.LinearEquality(integral_op, data)]\n\n# now we can define the model using the contraints and the GP kernel\nmodel = fp.models.GaussianProcess(kernel, constraints)\n\n# ... and do a prediction on the points w_pred\n_rho, _rho_err = model.predict(w_pred)\n```\n\n## Authors & Citing\n\nThis package is written and maintained by Jonas Turnwald, Julian M. Urban and Nicolas Wink.\n\nIf you use this package in scientific work, please cite this repository.\n\n## References\n\n<a id=\"1\">[1]</a>\nA. P. Valentine and M. Sambridge, Gaussian process models\u2014I. A framework for probabilistic continuous inverse theory, [Geophysical Journal International 220, 1632 (2020)](https://academic.oup.com/gji/article/220/3/1632/5632112).\n\n<a id=\"2\">[2]</a>\nJ. Horak, J. M. Pawlowski, J. Rodr\u00edguez-Quintero, J. Turnwald, J. M. Urban, N. Wink, and S. Zafeiropoulos, Reconstructing QCD spectral functions with Gaussian processes, [Phys. Rev. D 105, 036014 (2022), arXiv:2107.13464 [hep-ph]](https://arxiv.org/abs/2107.13464).\n\n<a id=\"3\">[3]</a>\nJ. M. Pawlowski, C. S. Schneider, J. Turnwald, J. M. Urban, and N. Wink, Yang-Mills glueball masses from spectral reconstruction, [Phys. Rev. D 108, 076018 (2023), arXiv:2212.01113 [hep-ph]](https://arxiv.org/abs/2212.01113).\n\n<a id=\"4\">[4]</a>\nJ. Horak, J. M. Pawlowski, J. Turnwald, J. M. Urban, N. Wink, and S. Zafeiropoulos, Nonperturbative strong coupling at timelike momenta, [Phys. Rev. D 107, 076019 (2023), arXiv:2301.07785 [hep-ph]](https://arxiv.org/abs/2301.07785).\n\n<a id=\"5\">[5]</a>\nC. Rasmussen and C. Williams, [Gaussian Processes for Machine Learning, The MIT Press, 2005](https://doi.org/10.7551/mitpress/3206.001.0001).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Jonas Turnwald, Julian M. Urban, Nicolas Wink  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Inverting Fredholm Integrals with Python",
    "version": "0.1.0",
    "project_urls": {
        "Repository": "https://github.com/JonasTurnwald/fredipy"
    },
    "split_keywords": [
        "gaussian-process",
        "fredholm",
        "inverse-problem"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e4fd46bbab22badcdbdcc136c7d55ff6969d522ada1abc209cb96d6d529ea541",
                "md5": "002a68b952b23baba69b3b7583e90896",
                "sha256": "2098ead7c9fb7c1a3a12506c361f30e848ea7ba0ef41cf514ecae16d408012d1"
            },
            "downloads": -1,
            "filename": "fredipy-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "002a68b952b23baba69b3b7583e90896",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 15710,
            "upload_time": "2024-03-08T15:35:13",
            "upload_time_iso_8601": "2024-03-08T15:35:13.203953Z",
            "url": "https://files.pythonhosted.org/packages/e4/fd/46bbab22badcdbdcc136c7d55ff6969d522ada1abc209cb96d6d529ea541/fredipy-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c71ffe6023aeaeb3aeecae874cba2dbc42a4ae0f13e414736791215b20b3c2bf",
                "md5": "404775912cec8fd461955062d822e9d0",
                "sha256": "9780a84aae5134d9ede3e71cbc9e102c9458ca2d1fc74bcd22e9562735c4e167"
            },
            "downloads": -1,
            "filename": "fredipy-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "404775912cec8fd461955062d822e9d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 19701,
            "upload_time": "2024-03-08T15:35:14",
            "upload_time_iso_8601": "2024-03-08T15:35:14.920107Z",
            "url": "https://files.pythonhosted.org/packages/c7/1f/fe6023aeaeb3aeecae874cba2dbc42a4ae0f13e414736791215b20b3c2bf/fredipy-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-08 15:35:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JonasTurnwald",
    "github_project": "fredipy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fredipy"
}
        
Elapsed time: 0.22897s