gpridge.fes =========== .. py:module:: gpridge.fes .. autoapi-nested-parse:: Gaussian-process free-energy surrogate on collective variables. :class:`FreeEnergySurrogate` learns a free energy :math:`F(s)` from values and, optionally, gradients :math:`\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: :math:`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 :math:`F` first. A mean force, as thermodynamic integration or adaptive biasing reports it, is :math:`-\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 ------- .. autoapisummary:: gpridge.fes.RateReport gpridge.fes.FreeEnergySurrogate Functions --------- .. autoapisummary:: gpridge.fes.noise_from_weights Module Contents --------------- .. py:class:: 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. .. py:attribute:: barrier_mean :type: float .. py:attribute:: barrier_std :type: float .. py:attribute:: barrier_lower :type: float .. py:attribute:: barrier_upper :type: float .. py:attribute:: prefactor_mean :type: float .. py:attribute:: prefactor_std :type: float .. py:attribute:: rate_mean :type: float .. py:attribute:: rate_std :type: float .. py:attribute:: rate_lower :type: float .. py:attribute:: rate_upper :type: float .. py:attribute:: samples_requested :type: int .. py:attribute:: samples_accepted :type: int .. py:attribute:: saddle_gradient_norm :type: float .. py:function:: 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. .. py:class:: 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 :math:`F`. ``noise_variance`` and ``jitter_variance`` add to every :math:`F` noise variance. ``gradient_noise_variance`` holds one variance per coordinate added to each observed gradient component, in the unit of :math:`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. .. py:property:: dimension :type: int Number of collective variables. .. py:property:: n_observations :type: int Training points of the last successful :meth:`train`. .. py:method:: 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 :math:`\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. .. py:method:: 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 :math:`F`, its gradient and its latent variance. The gradient and variance are ``None`` unless requested. The variance excludes observation noise. .. py:method:: 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 :class:`~gpridge.errors.NotConvergedError`. Each posterior draw samples :math:`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 :class:`~gpridge.errors.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``.