Loading...
Searching...
No Matches
Posterior-mean derivatives (ABI 1.20)

Classes

struct  gpr_derivative_options
 Options of the derivative primitives (ABI 1.20). More...
struct  gpr_derivative_report
 Report of one derivative call (ABI 1.20). More...

Typedefs

typedef struct gpr_derivative_options gpr_derivative_options_t
 Options of the derivative primitives (ABI 1.20).
typedef struct gpr_derivative_report gpr_derivative_report_t
 Report of one derivative call (ABI 1.20).
typedef void(* gpr_hvp_fn) (int n_coords, const double *positions, const double *vector, double *hv_out, void *user_data)
 Hessian-vector-product callback at a fixed point (ABI 1.20).

Enumerations

enum  gpr_energy_unit_t {
  GPR_ENERGY_UNIT_NATIVE = 0 , GPR_ENERGY_UNIT_EV = 1 , GPR_ENERGY_UNIT_HARTREE = 2 , GPR_ENERGY_UNIT_KCAL_PER_MOL = 3 ,
  GPR_ENERGY_UNIT_KJ_PER_MOL = 4
}
 Energy unit tag (ABI 1.20). Labels only; nothing is converted. More...
enum  gpr_length_unit_t { GPR_LENGTH_UNIT_NATIVE = 0 , GPR_LENGTH_UNIT_ANGSTROM = 1 , GPR_LENGTH_UNIT_BOHR = 2 , GPR_LENGTH_UNIT_NANOMETER = 3 }
 Length unit tag (ABI 1.20). Labels only; nothing is converted. More...

Functions

gpr_derivative_options_t gpr_derivative_options_defaults (void)
 Defaults of gpr_derivative_options_t with struct_size set.
int gpr_model_mean_hessian_batch (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, int n_points, int n_coords, double *H_out, double *residuals_out, gpr_derivative_report_t *report)
 Posterior-mean Hessians at n_points points.
int gpr_model_mean_hessian_batch_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, size_t R_len, int n_points, int n_coords, double *H_out, size_t H_len, double *residuals_out, size_t residuals_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_mean_hessian_batch; residuals_len is ignored when residuals_out is NULL.
int gpr_model_mean_hessian_action_batch (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, int n_points, int n_coords, const double *V, int n_vectors, double *Hv_out, gpr_derivative_report_t *report)
 Posterior-mean Hessian-vector products at n_points points.
int gpr_model_mean_hessian_action_batch_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, size_t R_len, int n_points, int n_coords, const double *V, size_t V_len, int n_vectors, double *Hv_out, size_t Hv_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_mean_hessian_action_batch.
int gpr_model_hessian_bilinear_covariance (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, int n_points, int n_coords, const double *V, int n_left, const double *W, int n_right, double *cov_out, gpr_derivative_report_t *report)
 Posterior covariance of the bilinear forms v_i^T H w_j.
int gpr_model_hessian_bilinear_covariance_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, size_t R_len, int n_points, int n_coords, const double *V, size_t V_len, int n_left, const double *W, size_t W_len, int n_right, double *cov_out, size_t cov_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_hessian_bilinear_covariance.
int gpr_model_hessian_trace_variance (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, int n_points, int n_coords, const double *A, double *var_out, gpr_derivative_report_t *report)
 Posterior variance of tr(A dH) for one symmetric A per point.
int gpr_model_hessian_trace_variance_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, size_t R_len, int n_points, int n_coords, const double *A, size_t A_len, double *var_out, size_t var_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_hessian_trace_variance.
int gpr_model_posterior_variance_batch (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, int n_points, int n_coords, double *var_E_out, double *var_G_out, gpr_derivative_report_t *report)
 Posterior variance of the energy and of each gradient component.
int gpr_model_posterior_variance_batch_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R, size_t R_len, int n_points, int n_coords, double *var_E_out, size_t var_E_len, double *var_G_out, size_t var_G_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_posterior_variance_batch.
int gpr_model_condition_fixed (gpr_model_t model, const gpr_derivative_options_t *options, const double *R_new, const double *E_new, const double *G_new, int n_new, const double *R_query, int n_query, int n_coords, double *E_out, double *G_out, double *var_E_out, double *var_G_out, gpr_derivative_report_t *report)
 Condition the posterior on new oracle rows with the hyperparameters held fixed, then predict at query points.
int gpr_model_condition_fixed_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R_new, size_t R_new_len, const double *E_new, size_t E_new_len, const double *G_new, size_t G_new_len, int n_new, const double *R_query, size_t R_query_len, int n_query, int n_coords, double *E_out, size_t E_len, double *G_out, size_t G_len, double *var_E_out, size_t var_E_len, double *var_G_out, size_t var_G_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_condition_fixed.
int gpr_model_condition_fixed_hessian (gpr_model_t model, const gpr_derivative_options_t *options, const double *R_new, const double *E_new, const double *G_new, int n_new, const double *H_new, gpr_hvp_fn hvp, void *user_data, const double *R_query, int n_query, int n_coords, double *E_out, double *G_out, double *var_E_out, double *var_G_out, gpr_derivative_report_t *report)
 Condition the posterior on a fixed point with an optional exact Hessian or Hessian-vector-product callback (ABI 1.20).
int gpr_model_condition_fixed_hessian_checked (gpr_model_t model, const gpr_derivative_options_t *options, const double *R_new, size_t R_new_len, const double *E_new, size_t E_new_len, const double *G_new, size_t G_new_len, int n_new, const double *H_new, size_t H_new_len, gpr_hvp_fn hvp, void *user_data, const double *R_query, size_t R_query_len, int n_query, int n_coords, double *E_out, size_t E_len, double *G_out, size_t G_len, double *var_E_out, size_t var_E_len, double *var_G_out, size_t var_G_len, gpr_derivative_report_t *report)
 Extent-checked gpr_model_condition_fixed_hessian; H_new_len is ignored when H_new is NULL.

Detailed Description

Batched derivatives and uncertainty of a trained GP model's posterior mean at B points of dimension d = n_coords. Every array is row-major and in the model's native training units: energies and lengths exactly as passed to gpr_model_train. No conversion and no mass weighting happens here; the energy_unit and length_unit tags of gpr_derivative_options_t are echoed into the report so a caller can carry them along.

Hessians are exact analytic second derivatives of the posterior mean; a model without an analytic mean Hessian returns GPR_ERR_UNSUPPORTED and never falls back to finite differences. Hessians are raw by default. With project_rigid set, Hessians and actions are projected with P = I - T T^T, where T spans the three translations and three centroid rotations of the point (n_coords must then be 3N).

Support: each call computes the posterior energy standard deviation at every point and reports the largest one with its index. When max_energy_std > 0 and that std exceeds it, the call fails closed with GPR_ERR_OUT_OF_SUPPORT, writes the report, and leaves every output buffer untouched. Outputs are never NaN on GPR_SUCCESS: a non-finite intermediate returns an error instead.

Covariance and variance outputs are probabilistic estimates under the GP prior and its fitted hyperparameters, never certificates. The Hessian covariances are those of a central difference of the posterior gradient process with step variance_step along each unit direction, so they converge to the Hessian posterior covariance as the step shrinks.

Calls on one model handle are serialized by a per-model lock, so any number of threads may call these functions concurrently. Points are processed in order; with one BLAS thread the results are bit-identical from run to run.

Typedef Documentation

◆ gpr_derivative_options_t

Options of the derivative primitives (ABI 1.20).

Set struct_size to sizeof(gpr_derivative_options_t); fields past struct_size take their defaults. A NULL options pointer means the defaults of gpr_derivative_options_defaults.

◆ gpr_derivative_report_t

Report of one derivative call (ABI 1.20).

Set struct_size to sizeof(gpr_derivative_report_t); the library writes only the first struct_size bytes, so an older caller's smaller struct stays valid. Written on GPR_SUCCESS and GPR_ERR_OUT_OF_SUPPORT. Residuals are -1 when gpr_model_mean_hessian_batch was not asked for them.

◆ gpr_hvp_fn

typedef void(* gpr_hvp_fn) (int n_coords, const double *positions, const double *vector, double *hv_out, void *user_data)

Hessian-vector-product callback at a fixed point (ABI 1.20).

Writes H(positions) * vector (length n_coords) into hv_out. A callback signals failure by writing a non-finite entry to hv_out.

Definition at line 2454 of file gpridge_c.h.

Enumeration Type Documentation

◆ gpr_energy_unit_t

Energy unit tag (ABI 1.20). Labels only; nothing is converted.

Enumerator
GPR_ENERGY_UNIT_NATIVE 
GPR_ENERGY_UNIT_EV 
GPR_ENERGY_UNIT_HARTREE 
GPR_ENERGY_UNIT_KCAL_PER_MOL 
GPR_ENERGY_UNIT_KJ_PER_MOL 

Definition at line 2244 of file gpridge_c.h.

2244 {
gpr_energy_unit_t
Energy unit tag (ABI 1.20). Labels only; nothing is converted.
Definition gpridge_c.h:2244
@ GPR_ENERGY_UNIT_EV
Definition gpridge_c.h:2246
@ GPR_ENERGY_UNIT_HARTREE
Definition gpridge_c.h:2247
@ GPR_ENERGY_UNIT_KJ_PER_MOL
Definition gpridge_c.h:2249
@ GPR_ENERGY_UNIT_KCAL_PER_MOL
Definition gpridge_c.h:2248
@ GPR_ENERGY_UNIT_NATIVE
Definition gpridge_c.h:2245

◆ gpr_length_unit_t

Length unit tag (ABI 1.20). Labels only; nothing is converted.

Enumerator
GPR_LENGTH_UNIT_NATIVE 
GPR_LENGTH_UNIT_ANGSTROM 
GPR_LENGTH_UNIT_BOHR 
GPR_LENGTH_UNIT_NANOMETER 

Definition at line 2253 of file gpridge_c.h.

2253 {
gpr_length_unit_t
Length unit tag (ABI 1.20). Labels only; nothing is converted.
Definition gpridge_c.h:2253
@ GPR_LENGTH_UNIT_NANOMETER
Definition gpridge_c.h:2257
@ GPR_LENGTH_UNIT_NATIVE
Definition gpridge_c.h:2254
@ GPR_LENGTH_UNIT_BOHR
Definition gpridge_c.h:2256
@ GPR_LENGTH_UNIT_ANGSTROM
Definition gpridge_c.h:2255

Function Documentation

◆ gpr_derivative_options_defaults()

gpr_derivative_options_t gpr_derivative_options_defaults ( void )

Defaults of gpr_derivative_options_t with struct_size set.

◆ gpr_model_condition_fixed()

int gpr_model_condition_fixed ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R_new,
const double * E_new,
const double * G_new,
int n_new,
const double * R_query,
int n_query,
int n_coords,
double * E_out,
double * G_out,
double * var_E_out,
double * var_G_out,
gpr_derivative_report_t * report )

Condition the posterior on new oracle rows with the hyperparameters held fixed, then predict at query points.

Appends n_new rows (R_new, E_new, G_new = dE/dR, as in gpr_model_train) without refitting hyperparameters: by a rank-k extension of the existing factor where the backend allows it, otherwise by refactoring at the same hyperparameters (report->factor_appended says which). Either way the result equals a fresh fit at those hyperparameters to roundoff. The caller chooses the rows. The posterior mean energy, gradient and their variances at the n_query points of R_query are written to E_out (n_query), G_out (n_query*n_coords), var_E_out and var_G_out. A model that cannot be refactored with the rows returns GPR_ERR_UNSUPPORTED and is unchanged. With max_energy_std > 0 a query outside the new posterior's support returns GPR_ERR_OUT_OF_SUPPORT with the rows appended and the outputs untouched. project_rigid is ignored.

◆ gpr_model_condition_fixed_checked()

int gpr_model_condition_fixed_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R_new,
size_t R_new_len,
const double * E_new,
size_t E_new_len,
const double * G_new,
size_t G_new_len,
int n_new,
const double * R_query,
size_t R_query_len,
int n_query,
int n_coords,
double * E_out,
size_t E_len,
double * G_out,
size_t G_len,
double * var_E_out,
size_t var_E_len,
double * var_G_out,
size_t var_G_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_condition_fixed.

◆ gpr_model_condition_fixed_hessian()

int gpr_model_condition_fixed_hessian ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R_new,
const double * E_new,
const double * G_new,
int n_new,
const double * H_new,
gpr_hvp_fn hvp,
void * user_data,
const double * R_query,
int n_query,
int n_coords,
double * E_out,
double * G_out,
double * var_E_out,
double * var_G_out,
gpr_derivative_report_t * report )

Condition the posterior on a fixed point with an optional exact Hessian or Hessian-vector-product callback (ABI 1.20).

When H_new (row-major n_coords x n_coords) or hvp is non-NULL, n_new must be 1 and at most one of H_new and hvp may be given. The supplied Hessian or HVP operator must be finite and symmetric; an invalid shape, non-finite entry or asymmetric operator returns GPR_ERR_INVALID_ARG before mutating the model or writing outputs (no silent fallback to GP curvature). When recorded, gpr_htst_half at R_new uses the exact Hessian in the Vineyard prefactor instead of GP curvature. When both H_new and hvp are NULL this behaves as gpr_model_condition_fixed.

◆ gpr_model_condition_fixed_hessian_checked()

int gpr_model_condition_fixed_hessian_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R_new,
size_t R_new_len,
const double * E_new,
size_t E_new_len,
const double * G_new,
size_t G_new_len,
int n_new,
const double * H_new,
size_t H_new_len,
gpr_hvp_fn hvp,
void * user_data,
const double * R_query,
size_t R_query_len,
int n_query,
int n_coords,
double * E_out,
size_t E_len,
double * G_out,
size_t G_len,
double * var_E_out,
size_t var_E_len,
double * var_G_out,
size_t var_G_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_condition_fixed_hessian; H_new_len is ignored when H_new is NULL.

◆ gpr_model_hessian_bilinear_covariance()

int gpr_model_hessian_bilinear_covariance ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
int n_points,
int n_coords,
const double * V,
int n_left,
const double * W,
int n_right,
double * cov_out,
gpr_derivative_report_t * report )

Posterior covariance of the bilinear forms v_i^T H w_j.

V holds n_points blocks of n_left vectors and W n_points blocks of n_right vectors, laid out as in gpr_model_mean_hessian_action_batch. cov_out receives one (n_left*n_right)^2 covariance matrix per point, row-major, over the pairs indexed i*n_right + j. A probabilistic estimate, not a bound. The covariance scales as the fourth power of the vector norms: GPR_ERR_UNSUPPORTED, outputs untouched, when an entry overflows, is NaN or underflows the normal double range.

◆ gpr_model_hessian_bilinear_covariance_checked()

int gpr_model_hessian_bilinear_covariance_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
size_t R_len,
int n_points,
int n_coords,
const double * V,
size_t V_len,
int n_left,
const double * W,
size_t W_len,
int n_right,
double * cov_out,
size_t cov_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_hessian_bilinear_covariance.

◆ gpr_model_hessian_trace_variance()

int gpr_model_hessian_trace_variance ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
int n_points,
int n_coords,
const double * A,
double * var_out,
gpr_derivative_report_t * report )

Posterior variance of tr(A dH) for one symmetric A per point.

A holds n_points symmetric n_coords x n_coords matrices, row-major. var_out receives n_points variances. A probabilistic estimate; GPR_ERR_UNSUPPORTED as for gpr_model_hessian_bilinear_covariance when a variance leaves the normal double range.

◆ gpr_model_hessian_trace_variance_checked()

int gpr_model_hessian_trace_variance_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
size_t R_len,
int n_points,
int n_coords,
const double * A,
size_t A_len,
double * var_out,
size_t var_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_hessian_trace_variance.

◆ gpr_model_mean_hessian_action_batch()

int gpr_model_mean_hessian_action_batch ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
int n_points,
int n_coords,
const double * V,
int n_vectors,
double * Hv_out,
gpr_derivative_report_t * report )

Posterior-mean Hessian-vector products at n_points points.

V holds n_points blocks of n_vectors row vectors of length n_coords: the vectors of point b are V[(b*n_vectors + i)*n_coords ...]. Hv_out has the same layout and receives H(x_b) v_{b,i} (P H P v with project_rigid).

◆ gpr_model_mean_hessian_action_batch_checked()

int gpr_model_mean_hessian_action_batch_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
size_t R_len,
int n_points,
int n_coords,
const double * V,
size_t V_len,
int n_vectors,
double * Hv_out,
size_t Hv_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_mean_hessian_action_batch.

◆ gpr_model_mean_hessian_batch()

int gpr_model_mean_hessian_batch ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
int n_points,
int n_coords,
double * H_out,
double * residuals_out,
gpr_derivative_report_t * report )

Posterior-mean Hessians at n_points points.

R holds n_points*n_coords coordinates. H_out receives n_points symmetric n_coords x n_coords Hessians, point-major and row-major. When residuals_out is non-NULL (n_coords = 3N) it receives n_points rows of six norms ||H g_k|| of the raw Hessian against the unit rigid generators g_k (x, y, z translations, then x, y, z rotations about the centroid); a generator that vanishes at the point gives -1.

◆ gpr_model_mean_hessian_batch_checked()

int gpr_model_mean_hessian_batch_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
size_t R_len,
int n_points,
int n_coords,
double * H_out,
size_t H_len,
double * residuals_out,
size_t residuals_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_mean_hessian_batch; residuals_len is ignored when residuals_out is NULL.

◆ gpr_model_posterior_variance_batch()

int gpr_model_posterior_variance_batch ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
int n_points,
int n_coords,
double * var_E_out,
double * var_G_out,
gpr_derivative_report_t * report )

Posterior variance of the energy and of each gradient component.

var_E_out receives n_points variances and var_G_out n_points*n_coords component variances, with the support check of this section.

◆ gpr_model_posterior_variance_batch_checked()

int gpr_model_posterior_variance_batch_checked ( gpr_model_t model,
const gpr_derivative_options_t * options,
const double * R,
size_t R_len,
int n_points,
int n_coords,
double * var_E_out,
size_t var_E_len,
double * var_G_out,
size_t var_G_len,
gpr_derivative_report_t * report )

Extent-checked gpr_model_posterior_variance_batch.