Quick Start¶
Sample f and its Integral g¶
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, # Kernel variance
ell=0.5, # Length scale
n_samples=5,
seed=42
)
print(result.f.shape) # (5, 100) - function samples
print(result.g.shape) # (5, 100) - integral samples
Sample f and its Derivative h¶
from gp4c import sample_prior, SamplingSpec
x = np.linspace(0, 5, 100)
spec = SamplingSpec(x_f=x, x_h=x)
result = sample_prior(spec, sigma2=1.0, ell=0.5, n_samples=5)
print(result.f.shape) # (5, 100) - function samples
print(result.h.shape) # (5, 100) - derivative samples
Posterior Sampling¶
Condition on observations and predict:
from gp4c import sample_posterior, Observations, SamplingSpec
# Observe f at sparse points
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)
# Predict at dense points
x_test = np.linspace(0, 5, 100)
spec = SamplingSpec(x_f=x_test)
result = sample_posterior(obs, spec, ell=1.0, n_samples=10)
print(result.f_mean.shape) # (100,) - posterior mean
print(result.f.shape) # (10, 100) - posterior samples
What's Next?¶
- Basic Usage Tutorial - Detailed examples
- Posterior Sampling - Conditioning on data
- API Reference - Complete documentation