Loading...
Searching...
No Matches
Free-energy surrogate (ABI 1.23)

Classes

struct  gpr_fes_config_t
 Free-energy surrogate configuration (ABI 1.23). More...
struct  gpr_fes_rate_config_t
 Posterior-sampled Kramers rate configuration (ABI 1.23). More...
struct  gpr_fes_rate_report_t
 Summary of the accepted posterior rate draws (ABI 1.23). More...

Functions

int gpr_fes_config_init (gpr_fes_config_t *out, size_t out_size)
 Write the default gpr_fes_config_t (squared exponential, shared length scale) into the first min(out_size, sizeof) bytes of out.
gpr_fes_t gpr_fes_create (int dimension, const gpr_model_config_t *model_config, const gpr_fes_config_t *fes_config, const double *grad_noise_var, size_t grad_noise_var_len)
 Create an untrained free-energy surrogate.
void gpr_fes_destroy (gpr_fes_t fes)
 Destroy a handle from gpr_fes_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_fes_dimension (gpr_fes_t fes)
 Collective-variable dimension, or 0 for NULL or a dead handle.
int gpr_fes_n_observations (gpr_fes_t fes)
 Number of training points, or 0 before training, for NULL or for a dead handle.
int gpr_fes_noise_from_weights_checked (const double *weights, size_t weights_len, double reference_variance, double min_relative_weight, double *noise_var_out, size_t noise_var_len, int n_obs)
 Noise variances from relative sample weights: noise[i] = reference_variance * max(w) / max(w[i], min_relative_weight * max(w)). The result is unchanged when every weight is scaled by the same factor, and min_relative_weight caps the largest noise at reference_variance / min_relative_weight.
int gpr_fes_train_checked (gpr_fes_t fes, const double *s, size_t s_len, const double *F, size_t F_len, const double *F_noise_var, size_t F_noise_var_len, const double *grad_F, size_t grad_F_len, const double *grad_noise_var, size_t grad_noise_var_len, const uint8_t *grad_present, size_t grad_present_len, int n_obs, int dimension)
 Replace the training data and fit the hyperparameters.
int gpr_fes_predict_batch_checked (gpr_fes_t fes, const double *s_query, size_t s_query_len, double *F_out, size_t F_len, double *grad_F_out, size_t grad_F_len, double *var_F_out, size_t var_F_len, int n_queries, int dimension)
 Posterior mean of F at each query point, with its gradient and the latent posterior variance of F when requested.
int gpr_fes_rate_config_init (gpr_fes_rate_config_t *out, size_t out_size)
 Write the default gpr_fes_rate_config_t into the first min(out_size, sizeof) bytes of out.
int gpr_fes_rate_path_checked (gpr_fes_t fes, const double *path, size_t path_len, int n_path, int dimension, int reactant_index, int product_index, const double *diffusion, size_t diffusion_len, const gpr_fes_rate_config_t *config, gpr_fes_rate_report_t *report)
 Overdamped Kramers-Langer rate from path point reactant_index to product_index, with its uncertainty from joint posterior function draws.

Detailed Description

A gpr_fes_t holds a Gaussian process over a free energy F(s) on a dimension-dimensional collective-variable space. It observes F at points s, each with its own noise variance, and optionally the gradient of F at some of those points. The prior is the squared-exponential kernel of the scaled distance (one length scale, or one per coordinate when ard is set) around a constant mean equal to the arithmetic mean of the observed F. F must be a free energy: a bias potential, or a biased histogram that has not been reweighted, is not one.

Ownership. gpr_fes_create returns a handle that the caller owns until it passes it to gpr_fes_destroy. Every pointer argument is read or written during the call and stays with the caller; the library copies what it keeps, including both configurations. Arrays are row-major, one row per point, and every length counts elements, not bytes.

Single writer. A gpr_fes_t has one writer at a time: gpr_fes_train_checked and gpr_fes_destroy must not overlap any other call on the same handle. A destroyed handle is refused: a second gpr_fes_destroy sets GPR_ERR_INVALID_ARG in gpr_last_status(), and any other call returns GPR_ERR_NULL_HANDLE (the query functions return 0).

Failure. Every function that returns int returns GPR_SUCCESS (0) or a negative status and leaves its outputs unwritten on failure. A train call that fails keeps the previous posterior. GPR_ERR_CHOLESKY means the training covariance does not factor at the fitted hyperparameters; GPR_ERR_OPTIMIZER means hyperparameter inference diverged.

Size-prefixed structures. gpr_fes_config_t, gpr_fes_rate_config_t and gpr_fes_rate_report_t begin with struct_size. An init function writes the first min(out_size, sizeof) bytes of the defaults and sets struct_size to that count; a call reads or writes only the first struct_size bytes, so a caller compiled against an older, shorter structure keeps working when fields are appended. Fields past struct_size take their defaults.

Function Documentation

◆ gpr_fes_config_init()

int gpr_fes_config_init ( gpr_fes_config_t * out,
size_t out_size )

Write the default gpr_fes_config_t (squared exponential, shared length scale) into the first min(out_size, sizeof) bytes of out.

Returns
GPR_SUCCESS, or GPR_ERR_INVALID_ARG for a NULL out or an out_size smaller than struct_size.

◆ gpr_fes_create()

gpr_fes_t gpr_fes_create ( int dimension,
const gpr_model_config_t * model_config,
const gpr_fes_config_t * fes_config,
const double * grad_noise_var,
size_t grad_noise_var_len )

Create an untrained free-energy surrogate.

Parameters
model_configCopied; NULL selects gpr_model_config_defaults(). sigma2 and jitter_sigma2 are added to the noise variance of every F observation, in the unit of F squared, and never to a gradient observation; magn_sigma2 > 0 fixes the signal variance and 0 fits it; max_iter, tol_func, tol_sol and report_level (in [0, 255]) drive the SCG fit of the signal variance and length scales, which minimises the negative log marginal likelihood plus a MAP penalty: a half-Cauchy prior on the signal standard deviation, a half-Student-t prior on each length scale over the standard deviation of the points along its coordinates, and a log barrier below a data-set ceiling on a fitted signal variance, the priors and barrier weighted by min(1e-4 + 1e-3 n, 0.5) for n training rows. max_iter 0 keeps the initial values: length scales at the standard deviation of the points along each coordinate (with ard) or the root mean of their variances (without), and the signal variance at the larger of the variance of F and the mean squared gradient component times its squared length scale. optim_alg must be GPR_OPT_SCG. const_sigma2, use_zbl_prior_mean and use_ff_prior_mean must be zero. prior_mu, prior_nu, prior_s2 and the tp_hyperprior fields are not read: the prior mean is the mean of the observed F.
fes_configCopied; NULL selects gpr_fes_config_init().
grad_noise_vardimension non-negative variances, copied; entry k is added to component k of every observed gradient, in the unit of F squared per unit of coordinate k squared. NULL with length 0 selects (sigma2 + jitter_sigma2) / spread_k^2 at each train, with spread_k the standard deviation of the training points along k, so rescaling a coordinate rescales its gradient noise with it.
dimensionNumber of collective variables; must be positive.
grad_noise_var_lenLength of grad_noise_var in elements.
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, an invalid field or a grad_noise_var whose length is not dimension or that holds a negative or non-finite entry, GPR_ERR_UNSUPPORTED for a kernel other than GPR_BQ_KERNEL_SE or a model option the surrogate does not implement.

◆ gpr_fes_destroy()

void gpr_fes_destroy ( gpr_fes_t fes)

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

◆ gpr_fes_dimension()

int gpr_fes_dimension ( gpr_fes_t fes)

Collective-variable dimension, or 0 for NULL or a dead handle.

◆ gpr_fes_n_observations()

int gpr_fes_n_observations ( gpr_fes_t fes)

Number of training points, or 0 before training, for NULL or for a dead handle.

◆ gpr_fes_noise_from_weights_checked()

int gpr_fes_noise_from_weights_checked ( const double * weights,
size_t weights_len,
double reference_variance,
double min_relative_weight,
double * noise_var_out,
size_t noise_var_len,
int n_obs )

Noise variances from relative sample weights: noise[i] = reference_variance * max(w) / max(w[i], min_relative_weight * max(w)). The result is unchanged when every weight is scaled by the same factor, and min_relative_weight caps the largest noise at reference_variance / min_relative_weight.

This is an approximation: it treats the variance of each F estimate as inversely proportional to its weight (a histogram count, an effective sample size or a reweighting factor). It ignores correlation between samples and between neighbouring bins; use estimated variances when the estimator provides them.

Parameters
weightsn_obs positive finite weights.
reference_varianceNoise variance at the largest weight; positive.
min_relative_weightIn (0, 1].
noise_var_outn_obs variances, written only on success.
weights_lenLength of weights in elements.
noise_var_lenLength of noise_var_out in elements.
n_obsNumber of weights and noise variances.
Returns
GPR_SUCCESS, or GPR_ERR_INVALID_ARG for an invalid argument or a variance that overflows a double.

◆ gpr_fes_predict_batch_checked()

int gpr_fes_predict_batch_checked ( gpr_fes_t fes,
const double * s_query,
size_t s_query_len,
double * F_out,
size_t F_len,
double * grad_F_out,
size_t grad_F_len,
double * var_F_out,
size_t var_F_len,
int n_queries,
int dimension )

Posterior mean of F at each query point, with its gradient and the latent posterior variance of F when requested.

Parameters
s_queryn_queries x dimension points.
F_outn_queries means.
grad_F_outn_queries x dimension gradients of the mean, or NULL with length 0.
var_F_outn_queries variances of the latent F (no observation noise), or NULL with length 0.
fesFree-energy surrogate handle.
s_query_lenLength of s_query in elements.
F_lenLength of F_out in elements.
grad_F_lenLength of grad_F_out in elements.
var_F_lenLength of var_F_out in elements.
n_queriesNumber of query points.
dimensionNumber of collective variables; equals the handle dimension.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_NOT_TRAINED; GPR_ERR_INVALID_ARG for a short buffer, a dimension that differs from the handle or a non-finite query.

◆ gpr_fes_rate_config_init()

int gpr_fes_rate_config_init ( gpr_fes_rate_config_t * out,
size_t out_size )

Write the default gpr_fes_rate_config_t into the first min(out_size, sizeof) bytes of out.

Returns
GPR_SUCCESS, or GPR_ERR_INVALID_ARG for a NULL out or an out_size smaller than struct_size.

◆ gpr_fes_rate_path_checked()

int gpr_fes_rate_path_checked ( gpr_fes_t fes,
const double * path,
size_t path_len,
int n_path,
int dimension,
int reactant_index,
int product_index,
const double * diffusion,
size_t diffusion_len,
const gpr_fes_rate_config_t * config,
gpr_fes_rate_report_t * report )

Overdamped Kramers-Langer rate from path point reactant_index to product_index, with its uncertainty from joint posterior function draws.

The saddle is the stationary point of the posterior mean of F with one negative Hessian eigenvalue. The search starts at the interior path point with the highest mean and takes eigenvector-following Newton steps, uphill along the lowest Hessian mode and downhill along the others, until the gradient meets saddle_tolerance. The saddle must lie within one length scale of the path between reactant and product and not beyond either end.

Each draw samples F and its Hessian at the reactant and at the saddle jointly from the posterior. Its barrier is F(saddle) - F(reactant) and its rate is k = abs(kappa) / (2 pi) sqrt(det H_reactant / abs(det H_saddle)) exp(-beta barrier), with kappa the negative eigenvalue of beta D H_saddle and D = diag(diffusion). A draw counts only when its barrier is positive, H_reactant is positive definite and H_saddle has exactly one negative eigenvalue. Means, sample standard deviations and equal-tailed credible_mass intervals (type-7 quantiles) are over the accepted draws; the barrier interval and covariance therefore include the correlation between F at the two points.

Parameters
pathn_path x dimension points, n_path >= 3.
diffusiondimension positive diagonal entries of the diffusion tensor; entry k in the squared unit of coordinate k per time.
configRead up to config->struct_size; required.
reportWritten up to min(report->struct_size, sizeof) only on success, with struct_size set to that count.
fesFree-energy surrogate handle.
path_lenLength of path in elements.
n_pathNumber of path points; at least three.
dimensionNumber of collective variables; equals the handle dimension.
reactant_indexZero-based index of the reactant along the path.
product_indexZero-based index of the product along the path.
diffusion_lenLength of diffusion in elements.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_NOT_TRAINED; GPR_ERR_INVALID_ARG for a short path, out-of-range or adjacent indices, a diffusion whose length is not dimension or that holds an entry that is not positive and finite, or an invalid configuration; GPR_ERR_NOT_CONVERGED when the search finds no index-one saddle on the path within its step limit; GPR_ERR_UNSUPPORTED when the mean barrier at the saddle is not positive, when fewer than 90% of the draws are accepted, or for a surrogate whose posterior is not an exact squared-exponential Gaussian process.

◆ gpr_fes_train_checked()

int gpr_fes_train_checked ( gpr_fes_t fes,
const double * s,
size_t s_len,
const double * F,
size_t F_len,
const double * F_noise_var,
size_t F_noise_var_len,
const double * grad_F,
size_t grad_F_len,
const double * grad_noise_var,
size_t grad_noise_var_len,
const uint8_t * grad_present,
size_t grad_present_len,
int n_obs,
int dimension )

Replace the training data and fit the hyperparameters.

Parameters
sn_obs x dimension collective-variable points.
Fn_obs free energies.
F_noise_varn_obs non-negative noise variances of F, or NULL with length 0 for zero.
grad_Fn_obs x dimension gradients of F.
grad_noise_varn_obs x dimension non-negative gradient noise variances.
grad_presentn_obs flags, 1 where the row's gradient is observed and 0 where it is not; the gradient entries of a 0 row are not read. grad_F, grad_noise_var and grad_present are all NULL with length 0 (values only) or all given.
fesFree-energy surrogate handle.
s_lenLength of s in elements.
F_lenLength of F in elements.
F_noise_var_lenLength of F_noise_var in elements.
grad_F_lenLength of grad_F in elements.
grad_noise_var_lenLength of grad_noise_var in elements.
grad_present_lenLength of grad_present in elements.
n_obsNumber of training observations.
dimensionNumber of collective variables; equals the handle dimension.
Returns
GPR_SUCCESS; GPR_ERR_NULL_HANDLE; GPR_ERR_INVALID_ARG for a short buffer, a dimension that differs from the handle, a non-finite value, a negative variance, a flag other than 0 or 1, points with no spread, points with no spread along a coordinate when gradients are observed and gpr_fes_create took no grad_noise_var, or constant data with a fitted signal variance; GPR_ERR_CHOLESKY; GPR_ERR_OPTIMIZER. On failure the handle keeps its previous posterior.