/gpcam:transformed-optimizers-advancedfrom gpcam
Provides LogGPOptimizer and LogitGPOptimizer for Gaussian process optimization under strictly positive or bounded observations. Fits GP in link space and transforms posterior back to constrained range.
Ships in gpcam. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Verified against gpCAM 8.7.0 / fvgp 4.11.1 — last checked 2026-10-28 (gpCAM a21385a).
Use this skill when measurements are guaranteed positive (y > 0) or bounded (y ∈ [a, b], default [0, 1]). A plain GP doesn't know about these constraints and will happily predict negative intensities or values outside [a, b]. The transformed optimizers fit the GP in an unconstrained "link" space (log or logit) and push the Gaussian posterior back through the inverse link via evaluate_posterior(x), so the original-scale predictions and credible intervals are guaranteed to respect the constraint.
| Observation type | Optimizer | Example domains |
|---|---|---|
Strictly positive, y > 0 | LogGPOptimizer | Intensities, rates, concentrations, fluxes, lifetimes |
Bounded, y ∈ [a, b] | LogitGPOptimizer(..., range=(a, b)) | Yields ([0, 100]%), probabilities, contrasts, transmittance, normalized intensities |
| Unconstrained / can be negative | plain GPOptimizer | Phase shifts, demeaned signals, temperatures in °C |
Both transformed classes are drop-in replacements for GPOptimizer in the single-task scalar case — the constructor, train, ask, tell, optimize, kernel / mean / noise hooks, and pickling are inherited unchanged. The transform is invisible to the rest of the workflow.
import numpy as np
from gpcam import LogGPOptimizer
# y_data must be > 0 — LogGPOptimizer raises ValueError otherwise
gpo = LogGPOptimizer(x_data, y_data)
gpo.train(hyperparameter_bounds=hp_bounds)
post = gpo.evaluate_posterior(x_grid)
# post["median"] -> exact (= exp of the latent GP mean)
# post["mean"] -> closed-form lognormal mean
# post["lower"], post["upper"] -> exact 95% credible band; both > 0
from gpcam import LogitGPOptimizer
# y_data must be in [0, 1]; boundary values are clipped to [eps, 1-eps] with a warning
gpo = LogitGPOptimizer(x_data, y_data, eps=1e-6, n_samples=10000)
gpo.train(hyperparameter_bounds=hp_bounds)
post = gpo.evaluate_posterior(x_grid)
# Same dict shape; mean/std are Monte-Carlo (logistic-normal has no closed form).
# All entries lie strictly inside (0, 1).
For observations bounded in an arbitrary closed interval [a, b] (yield in [0, 100]%,
transmittance in [0, 1], an angle in [0, 90], …), pass range=(a, b). The data is
linearly rescaled to [0, 1] before the logit transform, posterior outputs are mapped
back to [a, b], and predictions / credible bands stay strictly inside (a, b):
gpo = LogitGPOptimizer(x_data, y_data, range=(0.0, 100.0)) # yield in [0, 100]%
post = gpo.evaluate_posterior(x_grid)
# post["median"], post["lower"], post["upper"], post["samples"] -- all in (0, 100).
evaluate_posterior — the original-scale accessorThe inherited posterior_mean(x) / posterior_covariance(x) operate in the transformed (latent) space. Use evaluate_posterior(x) whenever you want the posterior on the original scale:
post = gpo.evaluate_posterior(x, level=0.95)
# returns: {"median", "mean", "std", "lower", "upper", "level"}
Because both links are monotone increasing, the median and the credible interval transform exactly. The mean/std are exact closed forms for LogGPOptimizer (lognormal) and Monte-Carlo estimates for LogitGPOptimizer.
Pass return_samples=True to also get an array of original-scale posterior draws of shape (n_points, n_samples):
post = gpo.evaluate_posterior(x_query, return_samples=True, n_samples=8000)
samples = post["samples"] # shape (len(x_query), 8000)
# Histogram at the first query point:
import matplotlib.pyplot as plt
plt.hist(samples[0], bins=50, density=True)
Distributions are: Gaussian for plain GPOptimizer, lognormal for LogGPOptimizer, logistic-normal for LogitGPOptimizer. Use samples to compute expectations of arbitrary functions: np.mean(g(samples), axis=1).
LogitGPOptimizer knobsrange (default (0.0, 1.0)): (lower, upper) bounds of the observation domain. Data is linearly rescaled to [0, 1] before the logit transform; predictions are mapped back to [lower, upper]. Raises ValueError if lower >= upper.eps (default 1e-6): clipping margin (in the rescaled [0, 1] space) so logit(0) / logit(1) don't blow up. Increase (e.g. 1e-4) for noisy boundary data at the cost of small bias; decrease for cleaner data.n_samples (default 10000): MC sample count for the closed-form-less mean / std (also the default for return_samples=True when no explicit n_samples is passed to evaluate_posterior). Higher is more accurate but slower.ask() and the inherited acquisition functions all run on the transformed GP. Both log and logit are monotone increasing, so ranking acquisitions ("variance", "ucb", "lcb", "maximum", "minimum") still pick the same locations as on the original scale.
Two cases that need care:
"target probability": pass already-transformed bounds (via GPOptimizer(..., args=...) or gpo.ask(..., args=...)). For LogGPOptimizer, use args={"a": np.log(a), "b": np.log(b)}. For LogitGPOptimizer with range=(lower, upper), first rescale a_norm = (a - lower) / (upper - lower) and b_norm = (b - lower) / (upper - lower), then pass args={"a": scipy.special.logit(a_norm), "b": scipy.special.logit(b_norm)}."expected improvement" / "probability of improvement": these compare against the best observed transformed value, which is also the best original value, so semantics carry over. The score magnitude differs from a plain GP fit but the ranking is consistent.Write them in latent space. The rule that makes this safe:
gpo.posterior_mean(),gpo.posterior_covariance(),gpo.x_data, andgpo.y_dataare all in the latent (transformed) space and are therefore mutually consistent.
So the recipes in the acquisition-functions skill — including
expected_improvement_minimize and probability_of_improvement, which take
np.min(gpo.y_data) / np.max(gpo.y_data) as the incumbent — work unchanged on
LogGPOptimizer and LogitGPOptimizer. Both sides of the comparison are log/logit
values; there is no unit mismatch.
Two things do need care:
Never mix in get_data()["original y data"]. That key is on the original
scale. Comparing it against posterior_mean() is a silent units bug — precisely
the mismatch that using gpo.y_data avoids.
Transform every absolute constant you hardcode. A threshold, target value, or forbidden output level written as a literal is interpreted in latent space:
def threshold_finder(x, gpo):
threshold = np.log(0.5) # LogGPOptimizer: transform the physical 0.5
mean = gpo.posterior_mean(x)["m(x)"]
std = np.sqrt(np.maximum(gpo.posterior_covariance(x, variance_only=True)["v(x)"], 1e-10))
eps = 0.01 * np.std(gpo.y_data) + 1e-12
return std / (np.abs(mean - threshold) + eps)
Constraints on inputs (x) need no transformation — only the output space is
transformed.
If you would rather reason on the original scale, call gpo.evaluate_posterior(x)
inside the acquisition function and use post["mean"] / post["std"]. This is
correct but noticeably slower for LogitGPOptimizer, where the moments are
Monte-Carlo estimates — and an acquisition function is evaluated many times per
ask(). Prefer latent space unless the score genuinely depends on original-scale
units (e.g. an absolute cost in counts).
get_data() returnsget_data()["y data"] is the transformed y stored on the GP. The transformed optimizers add a "original y data" key containing the inverse-transformed values for convenience:
data = gpo.get_data()
data["y data"] # log(y) or logit(y) -- in the GP's modeling space
data["original y data"] # y -- the observations as you provided them
When you provide noise_variances (observation noise) at construction or via tell(), they are transformed by the delta method (var_z ≈ (g'(y))² · var_y) before reaching the latent GP. Provide noise in the original scale; the optimizer handles the transform.
LogGPOptimizer and LogitGPOptimizer pickle the same way as GPOptimizer. LogitGPOptimizer's extra attributes (eps, n_samples, range) survive the round-trip.
See GPOptimizer_LogAndLogit.ipynb for a side-by-side visual tour — latent-space GP, back-transformed band, plain-GP comparison that violates the constraint, and posterior-sample histograms (lognormal vs. logistic-normal).
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub lbl-camera/gpcam --plugin gpcam11 skills in this plugin
/acquisition-functionsUse when choosing or writing an acquisition function for gpCAM — selecting a built-in criterion for exploration, optimization, batch, or multi-task runs, or implementing a custom callable for UCB/LCB, minimization EI, constraints, radical gradient, or threshold finding./cost-functionsUse when modeling the real expense of moving between gpCAM measurement points — motor travel time, settling, directional costs, sample damage, beam time, or zone-based penalties./experiment-designerUse for end-to-end autonomous experiment design with gpCAM. Translates a scientist's description of their measurement into a complete, runnable gpCAM script — useful for replacing raster scans with adaptive sampling, peak-finding, or parameter optimization.Other plugins' skills for the same job