gpridge.fes

Gaussian-process free-energy surrogate on collective variables.

FreeEnergySurrogate learns a free energy \(F(s)\) from values and, optionally, gradients \(\nabla F\) at points of a collective-variable space, and estimates an overdamped Kramers-Langer rate along a path with its posterior uncertainty. The library converts no units: \(F\), its noise variances, beta and diffusion share whatever units the caller uses. The surrogate does not see a bias potential; convert a metadynamics bias, an umbrella-sampling window or a histogram to \(F\) first. A mean force, as thermodynamic integration or adaptive biasing reports it, is \(-\nabla F\); negate it into grad_F.

Example:

fes = FreeEnergySurrogate(2)
fes.train(s, F, F_noise_var=var_F, grad_F=-mean_force,
          grad_noise_var=var_mean_force)
F_mean, _, F_var = fes.predict(grid, with_variance=True)
report = fes.rate_path(path, 0, len(path) - 1, beta=1.0,
                       diffusion=[1.0, 1.0])

Classes

RateReport

Posterior summary of a Kramers-Langer rate along a path.

FreeEnergySurrogate

GP surrogate of a free energy over dimension collective variables.

Functions

noise_from_weights(→ numpy.typing.NDArray[numpy.float64])

Noise variances that scale as the inverse relative sample weight.

Module Contents

class gpridge.fes.RateReport

Posterior summary of a Kramers-Langer rate along a path.

Means and sample standard deviations are over the accepted draws, and the bounds are the equal-tailed interval of the requested mass.

barrier_mean: float
barrier_std: float
barrier_lower: float
barrier_upper: float
prefactor_mean: float
prefactor_std: float
rate_mean: float
rate_std: float
rate_lower: float
rate_upper: float
samples_requested: int
samples_accepted: int
saddle_gradient_norm: float
gpridge.fes.noise_from_weights(weights: numpy.typing.ArrayLike, reference_variance: float, min_relative_weight: float) → numpy.typing.NDArray[numpy.float64]

Noise variances that scale as the inverse relative sample weight.

The largest weight gets reference_variance; a weight below min_relative_weight times the largest is treated as that floor. The approximation ignores correlation between samples.

class gpridge.fes.FreeEnergySurrogate(dimension: int, *, ard: bool = False, noise_variance: float | None = None, jitter_variance: float | None = None, gradient_noise_variance: numpy.typing.ArrayLike | None = None, signal_variance: float | None = None, max_iter: int | None = None, tol_func: float | None = None, tol_sol: float | None = None)

GP surrogate of a free energy over dimension collective variables.

The prior is a squared-exponential kernel with one length scale, or one per coordinate when ard is true, around the mean of the observed \(F\). noise_variance and jitter_variance add to every \(F\) noise variance. gradient_noise_variance holds one variance per coordinate added to each observed gradient component, in the unit of \(F\) squared per unit of that coordinate squared; None divides noise_variance + jitter_variance by the squared spread of the training points along each coordinate. signal_variance fixes the signal variance, which is otherwise fitted with the length scales.

property dimension: int

Number of collective variables.

property n_observations: int

Training points of the last successful train().

train(s: numpy.typing.ArrayLike, F: numpy.typing.ArrayLike, *, F_noise_var: numpy.typing.ArrayLike | None = None, grad_F: numpy.typing.ArrayLike | None = None, grad_noise_var: numpy.typing.ArrayLike | None = None, grad_present: numpy.typing.ArrayLike | None = None) → None

Replace the training data and fit the hyperparameters.

grad_F is the gradient \(\nabla F\), the negative of the mean force. s and grad_F have shape (n, dimension). grad_noise_var is required with grad_F and has the same shape, and grad_present marks the rows whose gradient is observed; without it every row is. A failed train keeps the previous posterior.

predict(s: numpy.typing.ArrayLike, *, with_gradient: bool = False, with_variance: bool = False) → tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64] | None, numpy.typing.NDArray[numpy.float64] | None]

Posterior mean of \(F\), its gradient and its latent variance.

The gradient and variance are None unless requested. The variance excludes observation noise.

rate_path(path: numpy.typing.ArrayLike, reactant_index: int, product_index: int, *, beta: float, diffusion: numpy.typing.ArrayLike, posterior_samples: int = 2048, seed: int = 0, credible_mass: float = 0.95, saddle_tolerance: float = 1e-06) → RateReport

Kramers-Langer rate from reactant_index to product_index.

The saddle is the stationary point of the posterior mean with one negative Hessian eigenvalue, searched from the highest interior path point until the gradient in length-scale units is at most saddle_tolerance times the prior standard deviation. No such point on the path raises NotConvergedError. Each posterior draw samples \(F\) and its Hessian at the reactant and the saddle jointly and counts only when its barrier is positive, the reactant Hessian is positive definite and the saddle has one negative eigenvalue. A mean barrier that is not positive, or fewer than 90% counted draws, raise UnsupportedError.

diffusion is the diagonal of the diffusion tensor, one entry per collective variable in its squared unit per time; the unstable rate is the negative eigenvalue of beta * diag(diffusion) @ H.