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, u)$ 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
  • $u(x) = f''(x)$ — second derivative process

All 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
  • Four-way joint sampling of function, integral, derivative, and second derivative
  • Posterior sampling conditioned on observed data
  • Mixed observations — observe f, predict h or u, 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)

Second derivative sampling:

# Sample f and its second derivative u = f''
from gp4c import sample_prior, SamplingSpec

spec = SamplingSpec(x_f=x, x_u=x)
result = sample_prior(spec, sigma2=1.0, ell=0.5, n_samples=5)
# result.f contains f samples, result.u contains f'' samples

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.21.tar.gz (220.9 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.21-cp312-cp312-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

gp4c-0.0.21-cp311-cp311-manylinux_2_28_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

gp4c-0.0.21-cp310-cp310-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10macOS 14.0+ x86-64

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

Uploaded CPython 3.10macOS 14.0+ ARM64

gp4c-0.0.21-cp39-cp39-manylinux_2_28_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.9macOS 14.0+ x86-64

gp4c-0.0.21-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.21.tar.gz.

File metadata

  • Download URL: gp4c-0.0.21.tar.gz
  • Upload date:
  • Size: 220.9 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.21.tar.gz
Algorithm Hash digest
SHA256 bca4c44e62e10667d3f70de422c3c94e471ab72bb05c639459932e8a839262a5
MD5 c95b5503252ca657448d8c06a4d732fc
BLAKE2b-256 28c24a0ddbb69b7b8ed3195448cce4b8a5bc55cfc8eecbb53f206dc052a20280

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21.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.21-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cf846fad54ada1dd6d250dbdacc705aca204a0170b0bcd9ba29cc59811fdaf7
MD5 dcd228ac88d0e196e176ac53756d84ca
BLAKE2b-256 5d818103586cc4c9be2c244164d337cd5a7503a429ab08e6c77578a54b97533e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 7ad703510eb61e7205826a68b81079e0df32fecdc4a86031dcba348f78c636b8
MD5 1ee2ff3633f8b21abe6d7a1bd5d89074
BLAKE2b-256 ec29e87db467891c17390da92a50bb2816cc536803e0769083b975c495241c6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7618823a7150bdf4544bfbae013e8df42736c85d22f52780f9085032fe75fa7a
MD5 c0558bc38fc15eb7f4de7d1924bf6b16
BLAKE2b-256 c9152c71cb1f53648d8e1a54a5cf82b6a2eff739a5c5b692961c6c4b86679917

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c8755b84d386cf412893fbbc73bb37faecd7f963cdf033410dceae2d19a4d59
MD5 dea2f1b9c8d1ae16a94b42314b0d8327
BLAKE2b-256 a241c66950388963c7faff9348dce7472499c05ee88b1a488a3e60c75c810e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 ef5d3ed75120854927df30ae189744f2acf1e3af40518c80db97341a13c00474
MD5 122534095803159c1cfa8a1c2e2188dd
BLAKE2b-256 148973aad2fa22b7a87133edce2c3f5c9bda5acfd638d4004531643308593f13

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3bbbe46ef93efb83710f9d3c5f11a2bc1044e7ea620f04e6ecba523bc03f658b
MD5 902eacffd2f7f01141aba4253b0b9cd2
BLAKE2b-256 a95e58c452ee95b416c20e4e00efc8159935bb6c612b1b5f112676498a0c45ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e3c8ccdb574072cbb7a123a58320d14a01d6b8a8f0803c6b560c54597f8971ef
MD5 387751623e16ba30ade20713efd54d28
BLAKE2b-256 774c0e7099f25418625103a1d45928e008090aa1a892b0ffa67580e5675b2c1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 252d93e1903b47c96dce8714527020f0c01d3952ad005088d2be8c8036829465
MD5 4993e1c418d0767c21b56bf045b1a9a3
BLAKE2b-256 e5f6c3a5a86076f586d54d487af3c6914c260fbb7f382c3b93c17efcd78285ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1999ee8d36018aa544db09e67a696ac42b4fd8b446b5deb4e707f8363aa698e5
MD5 61e5d7e6c82fb5bb5ef30529c96dbfbc
BLAKE2b-256 33b004f4b8a6f47e61f93056f06e80d82aa7207f578f518d41be1f5535f175cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f1ca1847f4ebf491a93d254fcc498da05c55014e42519d50b44a2cebaf9fe791
MD5 39724756cb92f7aaaab23f308490af34
BLAKE2b-256 4dd69609a12bb844463e2ebbb0c4eb041fad4885f9495fb9c3bbf84251f88ea0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp39-cp39-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.21-cp39-cp39-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 47f8b68e8a1ccaaace77b3dc6e10acbb213b9c0d1bd84c6199b71d5b71c78450
MD5 3986ed6b2e0451fce8e661fc0d8a2db9
BLAKE2b-256 8d0e71b653f5539e42787a79a2af3e91ca0750c6467752e32812d8c9641be63d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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.21-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

  • Download URL: gp4c-0.0.21-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.21-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 13810d02d0bb649f043d98729fef9ccf2b26759bc6af0cea6dd11c0aadc9b2be
MD5 9480bbf32dea54e010c2548eb4f11d89
BLAKE2b-256 54732cfb69886c065297c150ab7338dca194ae0093616fdb9bfc5a335a1a0313

See more details on using hashes here.

Provenance

The following attestation bundles were made for gp4c-0.0.21-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