Skip to main content

pygeoinf

CI PyPI version License: BSD-3-Clause Documentation Status

Inference and inverse problems on Hilbert spaces, linear and nonlinear, written without coordinates. A model is a vector in a space with an inner product the problem chooses; a forward operator maps between such spaces, linear with its adjoint or nonlinear with its derivative and, where the code supplies one, its second derivative; a prior is a Gaussian measure on the model space; and the answer to an inverse problem comes in one of three kinds, each the same thing whatever the discretization:

  • a point: a least-squares, minimum-norm, maximum a posteriori or Backus-Gilbert estimate for a linear problem, and the maximum a posteriori model or Occam's inversion for a nonlinear one, found by Newton or quasi-Newton methods that work in the space's own metric;
  • a measure: the posterior, exactly for a linear problem and as a Laplace approximation at the mode otherwise, to be drawn from, pushed forward to a property, compared by its evidence, or hardened into a credible region;
  • a set: the models consistent with bounded errors and a bounded prior, and the range of any property over them, with no probability assumed at all; linearized about a model when the forward operator is nonlinear.

The same code runs on a function on a circle, a sphere, a disk or a ball, on a layered planet, on a finite element space, or on a vector type a C++ code owns, because nothing in it reaches past the space's own arithmetic. Refining the grid changes the answer only as the discretization does, not the number of iterations it takes.

Installation

pip install pygeoinf

Python 3.12 or later. The core needs NumPy, SciPy, Matplotlib, joblib and finufft. The extras add function spaces and backends:

extra what it brings
sphere functions on the two-sphere, with spherical harmonics and map plotting
planetmodel spaces on intervals, radial profiles, disks and balls whose correlation length varies, including layered planets
plot3d three-dimensional sets drawn as figures that can be turned by hand
osqp, clarabel alternative backends for the convex solvers
mfem PyMFEM, for the finite element mini-app, on Linux
pip install "pygeoinf[sphere,planetmodel]"

A first inversion

A function on a circle from fifteen noisy point values, under a smooth prior: the posterior is a measure on the function space, and its pointwise spread is read off it.

import numpy as np
from pygeoinf import GaussianMeasure, LinearForwardProblem, LinearGaussianInversion
from pygeoinf.symmetric_space.circle import Sobolev

rng = np.random.default_rng(7)
X = Sobolev(128, 2.0, 0.2)                      # H^2 functions on the circle
prior = X.heat_measure(0.3, pointwise_std=1.0)  # smooth, with unit spread

points = np.sort(rng.uniform(0.0, 2.0 * np.pi, 15))
forward = X.point_evaluation_operator(points)
noise = GaussianMeasure.from_standard_deviation(forward.codomain, 0.1)
problem = LinearForwardProblem(forward, error=noise)
truth, data = problem.synthetic_model_and_data(prior, rng=rng)

posterior = LinearGaussianInversion(problem, prior)(data)
mean = posterior.expectation
std = np.sqrt(X.pointwise_variance_at(posterior, X.grid_axes[0]))

Nothing above is a matrix: the forward operator is applied, its adjoint is derived, and the solve behind the posterior is conjugate gradients on the data space. The first tutorial continues from here and draws the result.

Where to go next

  • Tutorials: an ordered course of fourteen scripts, from the first inversion to nonlinear problems, coupled fields and writing a backend. Each runs top to bottom, opens as a notebook, and has a Colab badge.
  • Examples: thirty-six short scripts, one idea each, from spaces and operators to feasible sets and planet models.
  • Mini-apps: six complete inverse problems in the spirit of MFEM's, each a directory with real or realistic data, several features composed, and a run of a few minutes: a C++ vector backend, finite elements through MFEM, the Earth's radial density, a field on the sphere from ocean data, ray tomography in a layered planet, and acoustic waveform inversion with an MPI-split solver.
  • API reference: every public class and function, with the contract each keeps.

Development

git clone https://github.com/da380/pygeoinf.git
cd pygeoinf
poetry install --with dev --all-extras
poetry run pytest tests

The fast suite runs in about five minutes; -m slow adds the parity checks and Monte Carlo estimates that take minutes each. See CONTRIBUTING.md for the hooks and the release process.

Licence

BSD 3-Clause. Written by David Al-Attar, Dan Heathcote and Adrian Mag.

Metadata

Release files for pygeoinf 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygeoinf 2.0.0
File Size Uploaded Provenance Actions
pygeoinf-2.0.0.tar.gz 613.7 kB Without provenance Details for pygeoinf-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygeoinf 2.0.0
File Interpreter ABI Platform Actions
pygeoinf-2.0.0-py3-none-any.whl Python 3 none any Details for pygeoinf-2.0.0-py3-none-any.whl

Total release size: 1.3 MB

Release files / pygeoinf-2.0.0.tar.gz

Download URL pygeoinf-2.0.0.tar.gz
Size 613.7 kB
Tags Source
SHA-256 checksum
How to use checksums
79f7617fb91e250a202ba8f5e28da02a7799746ebe8f53ec5d891b086d8fb9ce
BLAKE2b-256 checksum
How to use checksums
c25004159da044cbf0e0266f52c5293d0a8dcfd7d7bef8824b056cccc90f1652
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

Release files / pygeoinf-2.0.0-py3-none-any.whl

Download URL pygeoinf-2.0.0-py3-none-any.whl
Size 676.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0aa855b7a15acbfec1c57276ca54235ec188c45374c83049b0ac3a5f83fb8a2
BLAKE2b-256 checksum
How to use checksums
7e8fc71d4711ef779d2549506e9d14af1af839c0ef09fc33bc49a0efead38c39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/7.0.0-1017-azure

Security for pygeoinf 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page