From gpcam
Designs custom noise models for gpCAM experiments with non-uniform or structured noise, including position-dependent, count-rate-dependent, and learnable noise functions.
How this skill is triggered — by the user, by Claude, or both
Slash command
/gpcam:noise-functionsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Design custom noise models for experiments with non-uniform or structured noise.
Design custom noise models for experiments with non-uniform or structured noise.
def my_noise(x, hyperparameters):
"""
Parameters
----------
x : np.ndarray, shape (N, D)
Input positions.
hyperparameters : np.ndarray, 1D
The FULL hyperparameter vector (shared with kernel and mean).
Returns
-------
noise : np.ndarray
Either shape (N,) for diagonal noise (independent per point),
or shape (N, N) for full noise covariance matrix.
"""
| Scenario | Approach |
|---|---|
| Known, uniform noise | Use noise_variances=np.full(N, sigma**2) — no noise function needed |
| Known per-point noise | Use noise_variances=my_array — no noise function needed |
| Unknown uniform noise | Use a noise function with a learnable hyperparameter |
| Position-dependent noise | Use a noise function that depends on x |
| No noise info at all | Don't provide either — gpCAM defaults to `(0.01 * mean |
The noise level is a hyperparameter that gets optimized:
def learnable_noise(x, hps):
"""hps[K] = noise standard deviation (learned)."""
K = 3 # INDEX WHERE NOISE HP STARTS — adjust for your kernel
return np.full(len(x), hps[K]**2) # return VARIANCE, not std
More noise at edges of the measurement range:
def edge_noise(x, hps):
"""Higher noise near boundaries."""
K = 3
base_noise = hps[K]**2
# Increase noise near edges (within 10% of range)
center = np.mean(parameter_bounds, axis=1)
half_range = (parameter_bounds[:, 1] - parameter_bounds[:, 0]) / 2
dist_from_center = np.abs(x - center) / half_range # 0 at center, 1 at edge
edge_factor = 1.0 + 5.0 * np.max(dist_from_center, axis=1)**2
return base_noise * edge_factor
Common in photon-counting detectors:
def poisson_noise(x, hps):
"""
Noise proportional to sqrt of expected signal.
Uses the GP posterior mean as estimate of signal.
NOTE: This creates a feedback loop — use carefully.
hps[K] = noise scale factor
"""
K = 3
# Can't call posterior_mean here directly (circular dependency)
# Instead, use a fixed estimate or pass through args
# Simple version: just scale with position
return np.full(len(x), hps[K]**2)
def two_detector_noise(x, hps):
"""
Different noise for two measurement modes.
Assumes last dimension of x encodes the mode (0 or 1).
"""
K = 3
noise = np.empty(len(x))
mode_0 = x[:, -1] < 0.5
mode_1 = ~mode_0
noise[mode_0] = hps[K]**2 # detector 1
noise[mode_1] = hps[K+1]**2 # detector 2
return noise
Noise function hyperparameters come from the same vector as kernel and mean hyperparameters.
# Example layout:
# hps[0] = signal variance (kernel)
# hps[1:3] = length scales (kernel)
# hps[3] = noise std dev (noise function) ← YOUR NOISE HP
#
# Total: 4 hyperparameters
hp_bounds = np.array([
[0.001, 100.0], # signal variance
[0.01, 50.0], # length scale dim 0
[0.01, 50.0], # length scale dim 1
[0.001, 10.0], # noise std dev
])
0.001 minimum (prevents singular matrices)10 * std(y_data) — noise shouldn't be larger than the signal0.01 * mean(|y_data|) (gpCAM's own default)Do not provide both. Use one or the other:
# Option A: fixed known noise
gpo = GPOptimizer(x_data, y_data, noise_variances=np.full(N, 0.01))
# Option B: learnable noise function
gpo = GPOptimizer(x_data, y_data, noise_function=learnable_noise)
noise_variances AND noise_function — pick one.hyperparameter_bounds array.(N,) for independent noise, (N, N) for correlated.npx claudepluginhub lbl-camera/gpcam --plugin gpcamDesigns custom kernel (covariance) functions for gpCAM that encode domain knowledge like smoothness, periodicity, symmetry, anisotropy, or non-Euclidean input spaces.
Optimizes multi-objective problems using pymoo (NSGA-II/III, MOEA/D) with Pareto-front computation, constraint handling, and standard benchmarks (ZDT, DTLZ).
Builds Bayesian models with PyMC v5+, specifies priors, runs MCMC inference via nutpie, diagnoses convergence, and compares models using ArviZ.