.. index:: pair: class; gpr::laplace::SteinVariational .. _doxid-classgpr_1_1laplace_1_1_stein_variational: class gpr::laplace::SteinVariational ==================================== .. toctree:: :hidden: Overview ~~~~~~~~ .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class SteinVariational { public: // typedefs typedef std::function :ref:`GradOracle`; // construction :target:`SteinVariational`(); // methods void :ref:`initFromCCD`(const Eigen::VectorXd& theta_star, const Eigen::MatrixXd& L, double f0 = 0.0); int :ref:`fit`(:ref:`GradOracle` grad_oracle, int T = 30, double eps = 0.05, double conv_tol = 1e-3); int :target:`fit`(:ref:`GradOracle` grad_oracle, int T, double eps, double conv_tol, const :ref:`linalg::MpiContext`& process_group); int :ref:`fit`(:ref:`GradOracle` grad_oracle, const :ref:`SteinVariationalConfig`& cfg); int :target:`fit`(:ref:`GradOracle` grad_oracle, const :ref:`SteinVariationalConfig`& cfg, const :ref:`linalg::MpiContext`& process_group); const std::vector& :ref:`particles`() const; std::size_t :target:`numParticles`() const; Eigen::VectorXd :ref:`uniformWeights`() const; bool :target:`fitted`() const; void :target:`invalidate`(); }; .. _details-classgpr_1_1laplace_1_1_stein_variational: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Typedefs -------- .. index:: pair: typedef; GradOracle .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1ac1f33ce27e21d3acbaaab56b7dc525e9: .. ref-code-block:: cpp :class: doxyrest-title-code-block typedef std::function GradOracle Type of the negative-log-marginal-likelihood gradient oracle. Caller provides a callable that returns grad_log_p(theta) = -grad_NLML(theta) + grad_log_prior(theta) at a given theta. Methods ------- .. index:: pair: function; initFromCCD .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1a5a044918c9ef1f631a1d250ea6cb96b9: .. ref-code-block:: cpp :class: doxyrest-title-code-block void initFromCCD(const Eigen::VectorXd& theta_star, const Eigen::MatrixXd& L, double f0 = 0.0) Initialise K particles from a CCD-style grid centred at theta_star with stretch L (theta_k = theta_star + L \* z_k). theta_star: p-dim MAP point. L: p x q z-to-theta stretch matrix (typically U \* Lambda^{-1/2} from the :ref:`LaplaceINLA ` decomposition; provides a sensible initial spread that the SVGD updates will refine). Updates remain in the affine span of L when q < p. f0: CCD radius (default Rue 2009: sqrt(q + 2)). .. index:: pair: function; fit .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1a5337af16b85ef2226f806e79befaf583: .. ref-code-block:: cpp :class: doxyrest-title-code-block int fit(:ref:`GradOracle` grad_oracle, int T = 30, double eps = 0.05, double conv_tol = 1e-3) Run T SVGD iterations using the given gradient oracle. step_size eps: 0.01-0.1 typical (Liu & Wang 2016 use 0.1 with AdaGrad scaling; we use a fixed step for simplicity since our gradient magnitudes are already O(1) post-RBF). Returns the iteration count actually performed (<=T if converged early). .. index:: pair: function; fit .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1a7f734d970ee51981bfe75095240fc76b: .. ref-code-block:: cpp :class: doxyrest-title-code-block int fit(:ref:`GradOracle` grad_oracle, const :ref:`SteinVariationalConfig`& cfg) Config-struct overload of fit. Forwards to the primitive fit(oracle, T, eps, tol) above; new code should prefer this form so the hardcoded literals don't proliferate at call sites and so future knobs can be added without breaking the caller API. .. index:: pair: function; particles .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1a6a89c5b3ebb493d9025a3d2f5592bb1a: .. ref-code-block:: cpp :class: doxyrest-title-code-block const std::vector& particles() const Particle access (post-fit). .. index:: pair: function; uniformWeights .. _doxid-classgpr_1_1laplace_1_1_stein_variational_1a6f58f95bbe4d93a133f746e96b55ddcc: .. ref-code-block:: cpp :class: doxyrest-title-code-block Eigen::VectorXd uniformWeights() const Uniform mixture weights (1/K each); included for API parity with :ref:`LaplaceINLA ` 's gridWeights() which returns Rue-weighted CCD points.