.. index:: pair: class; gpr::RFFModel .. _doxid-classgpr_1_1_r_f_f_model: class gpr::RFFModel =================== .. toctree:: :hidden: enum_gpr_RFFModel_NormalEquationBackend.rst Overview ~~~~~~~~ Random Fourier Features (RFF) approximation to the SE kernel. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class RFFModel { public: // enums enum :ref:`NormalEquationBackend`; // construction :target:`RFFModel`(); :target:`RFFModel`(std::shared_ptr`> communication); // methods void :ref:`build`(:ref:`SexpatCF`& kernel, const :ref:`AtomsConfiguration`& conf_info, const :ref:`Observation`& training_data, int D_rff, double noise_var = 1e-6, double grad_noise_var = 1e-4); void :ref:`calculatePotential`(:ref:`Observation`& image) const; void :ref:`calculateVariance`(:ref:`Observation`& image) const; bool :ref:`meanHessianVector`(const Eigen::VectorXd& x, const Eigen::VectorXd& v, Eigen::VectorXd& action) const; bool :target:`isBuilt`() const; :ref:`NormalEquationBackend` :target:`normalEquationBackend`() const; const char* :target:`normalEquationBackendName`() const; }; .. _details-classgpr_1_1_r_f_f_model: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Random Fourier Features (RFF) approximation to the SE kernel. Approximates the :ref:`SexpatCF ` kernel with D_rff random cosine features, then solves Bayesian linear regression in the feature space. Training cost is O(N \* D \* D_rff + D_rff^3), prediction is O(D_rff \* D) per test point compared to O((N\*(D+1))^3) for exact GP. The spectral density of the SE kernel with effective variance 1/(2\*l^2) per feature is N(0, 2/l^2). Per-pairtype ARD lengthscales are applied: each feature f has pairtype p(f), and W[:,f] ~ N(0, 2/l_p^2). Workflow: #. Train exact GP on subset to optimize hyperparameters #. Call :ref:`build() ` with trained kernel and all training data #. Call :ref:`calculatePotential() ` / :ref:`calculateVariance() ` for prediction .. note:: The factor-of-2 convention: dist_at computes d = sqrt(sum 2\*s2\*delta^2), and the kernel is k = sigma^2 \* exp(-0.5\*d^2). Expanding: k = sigma^2 \* exp(-sum s2\*delta^2) where s2 = 1/l^2. This is an SE kernel with effective variance 1/(2\*l^2) per feature, so the spectral density is N(0, 2\*s2\*I) = N(0, 2/l^2 \* I). .. rubric:: See also: :ref:`InverseDistanceDescriptor ` for the feature map from Cartesian coordinates to inverse distances. :ref:`SexpatCF ` for the exact kernel this approximates. Methods ------- .. index:: pair: function; build .. _doxid-classgpr_1_1_r_f_f_model_1a0a646b79e5b41c67e299daaad72fb2a6: .. ref-code-block:: cpp :class: doxyrest-title-code-block void build(:ref:`SexpatCF`& kernel, const :ref:`AtomsConfiguration`& conf_info, const :ref:`Observation`& training_data, int D_rff, double noise_var = 1e-6, double grad_noise_var = 1e-4) Build the RFF model from trained hyperparameters and data. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - kernel - Trained :ref:`SexpatCF ` with optimized magnSigma2 and lengthScale values. * - conf_info - Configuration argument retained for callers. The kernel configuration defines the descriptor and its reference chart. * - training_data - All training observations (R, E, G). * - D_rff - Number of random features. * - noise_var - Energy-channel noise variance for each joint observation. * - grad_noise_var - Gradient-channel noise variance for each joint observation. .. index:: pair: function; calculatePotential .. _doxid-classgpr_1_1_r_f_f_model_1a74f6fe19bf21f1f1abd989ead6455db0: .. ref-code-block:: cpp :class: doxyrest-title-code-block void calculatePotential(:ref:`Observation`& image) const Predict energy and gradient at test configurations. Fills image.E and image.G from the RFF model. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - image - :ref:`Observation ` with R set; E and G are filled. .. index:: pair: function; calculateVariance .. _doxid-classgpr_1_1_r_f_f_model_1a3734cfc279f581a18d73df50c337d224: .. ref-code-block:: cpp :class: doxyrest-title-code-block void calculateVariance(:ref:`Observation`& image) const Predict energy/gradient variance at test configurations. Fills image.E and image.G with predictive variances. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - image - :ref:`Observation ` with R set; E and G filled with variances. .. index:: pair: function; meanHessianVector .. _doxid-classgpr_1_1_r_f_f_model_1adc0a1b5171b5e93c99f9ee6cf4decb0b: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool meanHessianVector(const Eigen::VectorXd& x, const Eigen::VectorXd& v, Eigen::VectorXd& action) const Exact Hessian of the predicted energy at x applied to v. Differentiates calculatePotential's mean twice: the cosine features through the descriptor Jacobian, plus the descriptor curvature along v weighted by the feature gradient. False before :ref:`build() ` or for a shape mismatch.