Skip to main content

Fast joint GP sampling with integral and derivative relationships

Project description

logo High-performance C implementation with Python bindings for sampling from joint Gaussian Processes with integral and derivative relationships.

Overview

Sample from joint GP $(f, g, h)$ where:

  • $f(x) \sim \mathcal{GP}(0, k_f)$ — original process with RBF kernel
  • $g(x) = \int_0^x f(t) dt$ — integrated process
  • $h(x) = f'(x)$ — derivative process

All three are correlated through proper cross-covariance structures.

Key Features

  • Fast C implementation using GSL (GNU Scientific Library)
  • Zero-copy Cython wrapper for seamless NumPy integration
  • Three-way joint sampling of function, integral, and derivative
  • Posterior sampling conditioned on observed data
  • Mixed observations — observe f, predict h, or any combination
  • Multiple kernels — RBF, Matérn 5/2, Matérn 3/2, periodic, locally-periodic
  • Hyperparameter optimization via fit() — maximize log marginal likelihood
  • Mathematically rigorous covariance structure
  • Fully tested with comprehensive unit tests

Quick Install

Prerequisites

Install GSL first:

# macOS
brew install gsl

# Ubuntu/Debian
sudo apt-get install libgsl-dev

# Fedora/RHEL
sudo dnf install gsl-devel

Install Package

pip install -e .

Quick Start

import numpy as np
from gp4c import sample_prior, SamplingSpec

x = np.linspace(0, 5, 100)
spec = SamplingSpec(x_f=x, x_g=x)
result = sample_prior(
    spec,
    sigma2=1.0,
    ell=0.5,
    n_samples=5,
    seed=42
)
# result.f contains f samples, result.g contains integral samples

Documentation

Full documentation is available at: https://rcalderonb6.github.io/gp4c

Or build locally:

pip install mkdocs-material
mkdocs serve

Quick Links

Examples

Basic usage:

# Sample f and its derivative h
from gp4c import sample_prior, SamplingSpec

spec = SamplingSpec(x_f=x, x_h=x)
result = sample_prior(spec, sigma2=1.0, ell=0.5, n_samples=5)

Posterior sampling:

# Condition on observations
from gp4c import sample_posterior, Observations, SamplingSpec

x_train = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
y_train = np.sin(x_train)
obs = Observations(x_f=x_train, y_f=y_train, noise_f=0.01)

x_test = np.linspace(0, 5, 100)
spec = SamplingSpec(x_f=x_test)

result = sample_posterior(obs, spec, ell=1.0, n_samples=10)

Hyperparameter optimization:

# Automatically find the best kernel parameters
import gp4c
import numpy as np

x = np.linspace(0, 10, 50)
y = np.sin(x) + np.random.default_rng(0).normal(0, 0.1, len(x))
obs = gp4c.Observations(x_f=x, y_f=y, noise_f=0.01)

result = gp4c.fit(obs, kernel='rbf')
print(f"sigma2={result.sigma2:.3f}, ell={result.ell:.3f}")
# Use result.sigma2 and result.ell directly in sample_posterior

See the examples/ directory and documentation for more.

Testing

pytest tests/ -v

C Library

The core can be used directly in C/C++ projects. See C Integration Guide.

Quick install as system library:

./install_library.sh        # System-wide (requires sudo)
./install_library.sh --user # User install (no sudo)

Project Structure

gp4c/
├── gp4c/                # Python package
│   ├── gp4c.c           # C implementation
│   ├── gp4c.h           # C headers and constants
│   ├── _core.pyx        # Cython wrapper
│   ├── types.py         # Type definitions
│   ├── optimize.py      # Hyperparameter optimization
│   └── cli.py           # CLI commands (gp4c install, etc.)
├── docs/                # MkDocs documentation
├── tests/               # Test suite
├── examples/            # Example scripts
├── notebooks/           # Jupyter notebooks
└── mkdocs.yml           # Documentation config

Contributing

Contributions welcome! See Contributing Guide.

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

License

MIT License - see LICENSE file for details.

Citation

If you use this package in your research, please cite:

@software{gp4c,
  title = {gp4c: Fast Joint Gaussian Process Sampling with integral and derivative information},
  author = {Calderón, Rodrigo},
  year = {2026},
  url = {https://github.com/rcalderonb6/gp4c}
}

References

  1. Solak et al. (2003) - Derivative observations in Gaussian process models
  2. Rasmussen & Williams (2006) - Gaussian Processes for Machine Learning
  3. GSL Manual - https://www.gnu.org/software/gsl/doc/html/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gp4c-0.0.20.tar.gz (205.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gp4c-0.0.20-cp312-cp312-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

gp4c-0.0.20-cp312-cp312-macosx_14_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

gp4c-0.0.20-cp312-cp312-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

gp4c-0.0.20-cp311-cp311-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

gp4c-0.0.20-cp311-cp311-macosx_14_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

gp4c-0.0.20-cp311-cp311-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

gp4c-0.0.20-cp310-cp310-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

gp4c-0.0.20-cp310-cp310-macosx_14_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 14.0+ x86-64

gp4c-0.0.20-cp310-cp310-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

gp4c-0.0.20-cp39-cp39-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

gp4c-0.0.20-cp39-cp39-macosx_14_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9macOS 14.0+ x86-64

gp4c-0.0.20-cp39-cp39-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file gp4c-0.0.20.tar.gz.

File metadata

  • Download URL: gp4c-0.0.20.tar.gz
  • Upload date:
  • Size: 205.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gp4c-0.0.20.tar.gz
Algorithm Hash digest
SHA256 95306182563b4ed2fe1f8cd265fee1f817b7d651aaf3136743938832a13cbfd1
MD5 084ec8ed2dbe1eb12e17140b74f091e5
BLAKE2b-256 7b1e31a36e062a4edca28c24d6390e31b8cb4750f7936d2ef4da264f8b3b5dda

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20.tar.gz:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 241174095d0bbd829f296a57a12e1905bdea567532a040293b1e165ce7151470
MD5 93a2d5360245d544ee1016aaf331a6b9
BLAKE2b-256 c586d915dd97803aee7ffc7eb1243f46c86054d122f7fe92e2d906f002b869aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 16d389bc7d10db6c6036ef44a2a7ca50a2b9bc38529704f5ec33d4de2d32b096
MD5 6334334cb477a9c8a51663ff3c041442
BLAKE2b-256 459dcc416ec6e556dade98c59768295b4f8740c7470b7bad667c1ffd037565c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp312-cp312-macosx_14_0_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c24e8e4afbd0de8924b708f6f8f38efec91bed70977f3aa4fd019ed977c54934
MD5 4ed6c9cc350ac100b686c4d6f03e269b
BLAKE2b-256 6ba1ea0ddb0601a149d80da5e3af530345b1d255d2fc4fb5efd6e951a0aec30b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd5fa563d2880846f5721b80ae2df51bc4b7b498a88737ce8bfd68e773b2671d
MD5 79d8758ac434f4435b25a510ce57605d
BLAKE2b-256 29aa467e73a6766fdcc7a379cfe72feab2ecb8ec584262ef898ede70ea9ba243

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 1ead6df6a01cc0e47c75688c767e4f55add3106518c7ac47a05d46f18719ff8b
MD5 4308095900706517863be967b14a77f4
BLAKE2b-256 d80be3ab503d93f5bfc05e3bbab2d1c6c803636ab1396a728a7cb2d53bd38fe6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp311-cp311-macosx_14_0_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b8e0870370264ceb3e7f739158cca8083de209ff9c0802e1219f9c2aaef1edb2
MD5 63dec72d7a10141de9abb4aff0cebd14
BLAKE2b-256 9374447db8217bdf402a2c01fffd153116da38f65fa5daabe980415e8ec1690a

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 53f7fb6cb48058ed2526a9c4fed8be199566c82bf907c316d0ba43efb8e929bb
MD5 8f2348d724840155194b169045f21a4c
BLAKE2b-256 d3d8d83cc04cc349158c135fbc7f051f185b2c6729dac22ba20f9d572f318d06

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 d33f6045b87a40b3e9ba807af662b35aca38de7f2e936b93ddc170758c8acddf
MD5 e870669265f5d85215922bfb80a504ec
BLAKE2b-256 c1bb7f6b463658233410b65fb391f00527f1039b4133e15ca6ffb21efac2e9dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp310-cp310-macosx_14_0_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e5e04f101178133200ede9bcb4323721771498686b3bd53624487f9379b9ae13
MD5 92be3a68cb4c7c040dd8056bb2084766
BLAKE2b-256 a2b75f8cc47aa8e51fe70009cc9f273c1cb8cf9a777e6a2f8a0e4731d838bba0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a528969451575ee478d52321140fc0b94fc3c15fc1e3f20cbde765e85b477033
MD5 64463f45ee7473a0595116a6e547a9d1
BLAKE2b-256 f03d2a852ea515859b1c87a1cfa2d16c4f5a3550a2103746b77b5a927eefa93f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp39-cp39-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp39-cp39-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.20-cp39-cp39-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 8da93cc4558c34b92e4e17a5e89b44dc7d02e04e81565b955ea4e5a1b9cabd35
MD5 0bde60461c408d70b32071600d60b7e4
BLAKE2b-256 374011e8587cebef88508a71fd5a1f05191dc70cda358b7c0519803763e7713b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp39-cp39-macosx_14_0_x86_64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gp4c-0.0.20-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

  • Download URL: gp4c-0.0.20-cp39-cp39-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.9, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gp4c-0.0.20-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2bf2066d88bc622ae90d538fc3cf4d9cfc567105855e4fc514d047ab12e2749d
MD5 a4dd2e6a690bd8086ac832418d67dd97
BLAKE2b-256 6dec5111b5ae8b3d92786d80ff5109affaa6506d5c4eb7d392169d46ca783cf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.20-cp39-cp39-macosx_14_0_arm64.whl:

Publisher: publish.yml on rcalderonb6/gp4c

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page