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.14.tar.gz (205.0 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.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gp4c-0.0.14-cp312-cp312-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gp4c-0.0.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gp4c-0.0.14-cp311-cp311-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gp4c-0.0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

gp4c-0.0.14-cp310-cp310-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

gp4c-0.0.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

gp4c-0.0.14-cp39-cp39-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for gp4c-0.0.14.tar.gz
Algorithm Hash digest
SHA256 d2f8a0a2d0b5c61ed88646b72ef518fbee6a8508ffc5e2e5d217802622574190
MD5 bbc58e190525248184545b65483f1076
BLAKE2b-256 2c13fbea4d544a92d42aa37e6c96fa7200db72ba941fe30ffe1b8141c02b4173

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3335bc30bea332ad6ca6f9c84bf94458de9427082b8f1ffbaa3d901c13c780c
MD5 010fbd656b52890e1e642682c34712c4
BLAKE2b-256 cfffeed51cfdb0ce2abe37ea96a9d72180d365ad607e68de37c958e611284c3c

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 692df5984e5fb4bb519ca4597dbdc9ecce46a4c7ba3eb36a83f2a88ad2b9d8da
MD5 e1d57d15e7b5d65e7aecd06937d1542c
BLAKE2b-256 527b7e25de2c7605d84f978cdb4ef851d4f559013128f95c5b5a85418b4c0e7a

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 017fffa4071d5b82d4aebfad7ed21f972d1498063288fee407fa57409c4f0459
MD5 1d889bff031febbaea8760d711fd606e
BLAKE2b-256 03139bd47ede1491096334cfcb01388a621e8c9da0e5aeb10d8559c1b09a14e9

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84c09b3cabce6f556e7cdce23f4e222381864bcfaddd4560d8a67965b1c7161a
MD5 d0af25bd7280ef4c938f84b80ad227ef
BLAKE2b-256 ac08be498c707df963654928e95027da0f555bd098be041022d943a7467f0db3

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bd21a4bc87236c1516e1a1e016b7c80c795729a77ec34304eda422e91709095
MD5 0da53eba59e6bc3b5f08caa2e1d9635c
BLAKE2b-256 e150227611a020c4ad241e2f23cca00aae002a9d357a1ed5815e58c0534913b7

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b89eb4b3efd2c04fbb22c313e65acf79b8ca25225280adb2e3427f5810da6b25
MD5 b5c28dc0d7684a753722a28a542456ff
BLAKE2b-256 f298d564dc461b812ace701d02776296abdb47ecbaae7d3381805790a73f6a8d

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ed0b618eef641fb3b1f3aea0649a8e37999c59f211ba25ad08ae4e7f0b54a07
MD5 96fb5626396841c5541f0068327c7c82
BLAKE2b-256 f9396a2071c040bdfd79c10a711908d0103ce478d8c942ccb0b4725250d03768

See more details on using hashes here.

File details

Details for the file gp4c-0.0.14-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gp4c-0.0.14-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 778273184bad666ee8c9f02aed947c1f5768efdf73c373911bb44a63c2094aa6
MD5 990fdddfea1eab82755a8d4a7ac8dab5
BLAKE2b-256 053e739308db4604feced423202f1905160072c81bb429635bc3732b2465596e

See more details on using hashes here.

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