Loading...
Searching...
No Matches
Scalar surrogate and parameter search (ABI 1.26)

Functions

gpr_sgp_t gpr_sgp_create (int dimension, int kernel)
 Create a scalar surrogate with unit length scales, unit signal variance, a noise variance of 1e-8 and a zero mean.
void gpr_sgp_destroy (gpr_sgp_t sgp)
 Destroy a handle from gpr_sgp_create. Destroying NULL or a live handle clears gpr_last_status(); a destroyed handle is not touched and sets GPR_ERR_INVALID_ARG.
int gpr_sgp_n_observations (gpr_sgp_t sgp)
 Number of observed rows, or 0 for NULL or a dead handle.
int gpr_sgp_set_kernel (gpr_sgp_t sgp, int kernel)
 Select the radial shape. The observations and hyperparameters stay; the surrogate needs a new gpr_sgp_fit_checked before a prediction.
int gpr_sgp_set_mean_basis (gpr_sgp_t sgp, int basis)
 Select the mean with a gpr_bq_basis_t value: GPR_BQ_BASIS_NONE (zero, the default), GPR_BQ_BASIS_CONSTANT or GPR_BQ_BASIS_AFFINE (1 and every coordinate). The coefficients are fitted by generalized least squares together with the process at each fit.
int gpr_sgp_set_hyperparameters_checked (gpr_sgp_t sgp, const double *length_scales, size_t length_scales_len, double signal_variance, double noise_variance)
 Set the hyperparameters.
int gpr_sgp_get_hyperparameters_checked (gpr_sgp_t sgp, double *length_scales_out, size_t length_scales_len, double *signal_variance_out, double *noise_variance_out)
 Read the hyperparameters, as set or as the last fit left them.
int gpr_sgp_observe_checked (gpr_sgp_t sgp, const double *X, size_t X_len, const double *y, size_t y_len, const double *noise_var, size_t noise_var_len, int n_obs, int n_dims)
 Append observed rows.
int gpr_sgp_fit_checked (gpr_sgp_t sgp, int optimize, int n_starts, double *log_marginal_likelihood_out)
 Condition the surrogate on the observed rows.
int gpr_sgp_predict_checked (gpr_sgp_t sgp, const double *X_queries, size_t X_len, int n_queries, int n_dims, double query_noise_var, double *mean_out, size_t mean_len, double *std_out, size_t std_len)
 Predict mean and standard deviation at query rows.
gpr_psearch_t gpr_psearch_create (const double *lower, size_t lower_len, const double *upper, size_t upper_len, const int *axis_kind, size_t axis_kind_len, int dimension, int kernel, int noisy)
 Create a parameter search over a box.
void gpr_psearch_destroy (gpr_psearch_t search)
 Destroy a handle from gpr_psearch_create. Destroying NULL or a live handle clears gpr_last_status(); a destroyed handle is not touched and sets GPR_ERR_INVALID_ARG.
int gpr_psearch_set_allowed_values_checked (gpr_psearch_t search, int axis, const double *values, size_t values_len, int categorical)
 Restrict an axis to a list of values, such as the divisors of a core count. The list replaces the bounds and the kind of that axis.
int gpr_psearch_observe_checked (gpr_psearch_t search, const double *X, size_t X_len, const double *y, size_t y_len, const double *noise_var, size_t noise_var_len, const double *constraint, size_t constraint_len, int n_obs, int n_dims)
 Report evaluated rows.
int gpr_psearch_propose_checked (gpr_psearch_t search, int q, double *X_out, size_t X_len, int n_dims, int *n_proposed_out)
 Propose up to q parameter vectors to evaluate next.
int gpr_psearch_best_checked (gpr_psearch_t search, double *x_out, size_t x_len, double *loss_out)
 The incumbent: the feasible evaluated row with the smallest loss, or with the smallest posterior mean for a noisy search.

Detailed Description

A gpr_sgp_t is a Gaussian process on a dimension-dimensional parameter vector with one scalar output, for an oracle that returns a value and, optionally, the variance of its noise. The kernel is a radial shape of the scaled Euclidean distance with one length scale per coordinate. A gpr_psearch_t minimizes such an oracle over a box by ask and tell: the caller reports evaluated rows and receives the next batch to evaluate.

Kernel. Both handles take a gpr_bq_kernel_t value and accept GPR_BQ_KERNEL_SE, GPR_BQ_KERNEL_MATERN32_ISOTROPIC and GPR_BQ_KERNEL_MATERN52_ISOTROPIC. The product kernels are refused with GPR_ERR_UNSUPPORTED.

Noise. Rows are observed either all with a noise variance each or all without one. Without, every row shares the noise variance hyperparameter. A call that would mix the two returns GPR_ERR_INVALID_ARG.

Ownership. A create call returns a handle that the caller owns until it passes it to the matching destroy call. Every pointer argument is read or written during the call and stays with the caller. Arrays are row-major, one row per point, and every length counts elements.

Single writer. A handle has one writer at a time. A destroyed handle is refused: a second destroy sets GPR_ERR_INVALID_ARG in gpr_last_status(), and any other call returns GPR_ERR_NULL_HANDLE (gpr_sgp_n_observations returns 0).

Failure. Every function that returns int, except gpr_sgp_n_observations, returns GPR_SUCCESS (0) or a negative status, leaves its outputs unwritten on failure and keeps the previous state of the handle. GPR_ERR_CHOLESKY means a covariance did not factor, GPR_ERR_OPTIMIZER that no start of a hyperparameter fit had a finite likelihood, and GPR_ERR_NOT_TRAINED that the call needs observations, a fit or a feasible observation that the handle does not have yet.

Function Documentation

◆ gpr_psearch_best_checked()

int gpr_psearch_best_checked ( gpr_psearch_t search,
double * x_out,
size_t x_len,
double * loss_out )

The incumbent: the feasible evaluated row with the smallest loss, or with the smallest posterior mean for a noisy search.

Parameters
x_outdimension values.
loss_outOptional; that loss or posterior mean.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG; GPR_ERR_NOT_TRAINED without a feasible observation; GPR_ERR_CHOLESKY.

◆ gpr_psearch_create()

gpr_psearch_t gpr_psearch_create ( const double * lower,
size_t lower_len,
const double * upper,
size_t upper_len,
const int * axis_kind,
size_t axis_kind_len,
int dimension,
int kernel,
int noisy )

Create a parameter search over a box.

The search minimizes. Its surrogate is fitted to the standardized losses on the unit cube, and its hyperparameters are refitted by marginal likelihood before each proposal once there are max(2 * dimension + 2, 6) rows.

Parameters
lower,upperBounds of each axis, dimension values each, with upper > lower.
axis_kindOne gpr_psearch_axis_t value per axis, or NULL with length 0 for linear axes. A logarithmic axis needs a positive lower bound.
kernelA gpr_bq_kernel_t value, see the group description.
noisyNonzero for a noisy loss: the incumbent is then the smallest posterior mean at the evaluated points instead of the smallest observed loss, and an evaluated point may be proposed again.
Returns
A new handle owned by the caller, or NULL with the status in gpr_last_status(): GPR_ERR_INVALID_ARG or GPR_ERR_UNSUPPORTED.

◆ gpr_psearch_destroy()

void gpr_psearch_destroy ( gpr_psearch_t search)

Destroy a handle from gpr_psearch_create. Destroying NULL or a live handle clears gpr_last_status(); a destroyed handle is not touched and sets GPR_ERR_INVALID_ARG.

◆ gpr_psearch_observe_checked()

int gpr_psearch_observe_checked ( gpr_psearch_t search,
const double * X,
size_t X_len,
const double * y,
size_t y_len,
const double * noise_var,
size_t noise_var_len,
const double * constraint,
size_t constraint_len,
int n_obs,
int n_dims )

Report evaluated rows.

Parameters
Xn_obs x n_dims parameter vectors. A value off the lattice of a discrete axis is moved to the nearest lattice value; a value outside the box is clamped.
yn_obs losses. A row whose run produced no loss holds NaN and needs a positive constraint value.
noise_varn_obs noise variances, or NULL with length 0.
constraintn_obs constraint values, feasible at or below zero, or NULL with length 0. NaN marks a row without one. A caller that knows only the outcome passes -1 for a feasible row and +1 for an infeasible one. The feasibility model is a GP regression on these values, not a classifier, so with such labels the probability it yields is a ranking score.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG. On failure no row of the call is recorded.

◆ gpr_psearch_propose_checked()

int gpr_psearch_propose_checked ( gpr_psearch_t search,
int q,
double * X_out,
size_t X_len,
int n_dims,
int * n_proposed_out )

Propose up to q parameter vectors to evaluate next.

Without observations the rows are Halton points. Otherwise they maximize expected improvement, times the probability of feasibility when constraint values were reported, one after the other under the constant liar with the incumbent as the lie.

Parameters
qPositive batch size.
X_outq x n_dims values; the first *n_proposed_out rows are written.
n_proposed_outReceives the number of rows, which is below q when a discrete box has fewer unevaluated points.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG; GPR_ERR_CHOLESKY.

◆ gpr_psearch_set_allowed_values_checked()

int gpr_psearch_set_allowed_values_checked ( gpr_psearch_t search,
int axis,
const double * values,
size_t values_len,
int categorical )

Restrict an axis to a list of values, such as the divisors of a core count. The list replaces the bounds and the kind of that axis.

Parameters
axisZero-based axis index.
valuesDistinct finite values. Their order is the order the surrogate sees unless categorical is set.
categoricalNonzero: the values are unordered labels, compared only for equality.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for a bad axis, an empty, repeated or non-finite list, or a call after the first observation or proposal.

◆ gpr_sgp_create()

gpr_sgp_t gpr_sgp_create ( int dimension,
int kernel )

Create a scalar surrogate with unit length scales, unit signal variance, a noise variance of 1e-8 and a zero mean.

Parameters
dimensionNumber of coordinates, positive.
kernelA gpr_bq_kernel_t value, see the group description.
Returns
A new handle owned by the caller, or NULL with the status in gpr_last_status(): GPR_ERR_INVALID_ARG for a non-positive dimension or an unknown kernel value, GPR_ERR_UNSUPPORTED for a product kernel.

◆ gpr_sgp_destroy()

void gpr_sgp_destroy ( gpr_sgp_t sgp)

Destroy a handle from gpr_sgp_create. Destroying NULL or a live handle clears gpr_last_status(); a destroyed handle is not touched and sets GPR_ERR_INVALID_ARG.

◆ gpr_sgp_fit_checked()

int gpr_sgp_fit_checked ( gpr_sgp_t sgp,
int optimize,
int n_starts,
double * log_marginal_likelihood_out )

Condition the surrogate on the observed rows.

Parameters
optimizeNonzero: first maximize the log marginal likelihood over the length scales, the signal variance and, when the rows carry no variance of their own, the noise variance, by L-BFGS with an analytic gradient from n_starts starting points. The first start is the current hyperparameters.
n_startsPositive when optimize is nonzero; ignored otherwise.
log_marginal_likelihood_outOptional; receives the log marginal likelihood of the conditioned surrogate.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG; GPR_ERR_NOT_TRAINED without observations; GPR_ERR_CHOLESKY; GPR_ERR_OPTIMIZER.

◆ gpr_sgp_get_hyperparameters_checked()

int gpr_sgp_get_hyperparameters_checked ( gpr_sgp_t sgp,
double * length_scales_out,
size_t length_scales_len,
double * signal_variance_out,
double * noise_variance_out )

Read the hyperparameters, as set or as the last fit left them.

Parameters
length_scales_outReceives one value per coordinate.
length_scales_lenAt least the dimension.
signal_variance_outOptional.
noise_variance_outOptional.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for a NULL or short length_scales_out.

◆ gpr_sgp_n_observations()

int gpr_sgp_n_observations ( gpr_sgp_t sgp)

Number of observed rows, or 0 for NULL or a dead handle.

◆ gpr_sgp_observe_checked()

int gpr_sgp_observe_checked ( gpr_sgp_t sgp,
const double * X,
size_t X_len,
const double * y,
size_t y_len,
const double * noise_var,
size_t noise_var_len,
int n_obs,
int n_dims )

Append observed rows.

Parameters
Xn_obs x n_dims parameter vectors, row-major.
yn_obs values.
noise_varn_obs non-negative noise variances, or NULL with length 0 for rows that share the noise variance hyperparameter.
n_dimsMust equal the dimension of the handle.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for a short buffer, a non-finite value, a negative variance, a wrong n_dims, or rows with a variance after rows without one (or the reverse). The surrogate needs a new gpr_sgp_fit_checked.

◆ gpr_sgp_predict_checked()

int gpr_sgp_predict_checked ( gpr_sgp_t sgp,
const double * X_queries,
size_t X_len,
int n_queries,
int n_dims,
double query_noise_var,
double * mean_out,
size_t mean_len,
double * std_out,
size_t std_len )

Predict mean and standard deviation at query rows.

Parameters
X_queriesn_queries x n_dims parameter vectors.
query_noise_var0 for the standard deviation of the latent (noise-free) function; a positive value is added to the variance, which gives the spread of a new run with that noise variance.
mean_outn_queries values.
std_outn_queries values, or NULL with length 0.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG; GPR_ERR_NOT_TRAINED before a fit or after a change that needs a new one.

◆ gpr_sgp_set_hyperparameters_checked()

int gpr_sgp_set_hyperparameters_checked ( gpr_sgp_t sgp,
const double * length_scales,
size_t length_scales_len,
double signal_variance,
double noise_variance )

Set the hyperparameters.

Parameters
length_scalesOne positive value per coordinate, or a single value for every coordinate.
length_scales_len1 or the dimension.
signal_variancePositive prior variance k(x, x).
noise_varianceNon-negative shared noise variance. Rows observed with their own variance ignore it.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG.

◆ gpr_sgp_set_kernel()

int gpr_sgp_set_kernel ( gpr_sgp_t sgp,
int kernel )

Select the radial shape. The observations and hyperparameters stay; the surrogate needs a new gpr_sgp_fit_checked before a prediction.

Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for an unknown value; GPR_ERR_UNSUPPORTED for a product kernel.

◆ gpr_sgp_set_mean_basis()

int gpr_sgp_set_mean_basis ( gpr_sgp_t sgp,
int basis )

Select the mean with a gpr_bq_basis_t value: GPR_BQ_BASIS_NONE (zero, the default), GPR_BQ_BASIS_CONSTANT or GPR_BQ_BASIS_AFFINE (1 and every coordinate). The coefficients are fitted by generalized least squares together with the process at each fit.

Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for any other value, GPR_BQ_BASIS_FOLLOW_CONFIG included.