.. index:: pair: class; gpr::RandomFourierFeatures .. _doxid-classgpr_1_1_random_fourier_features: class gpr::RandomFourierFeatures ================================ .. toctree:: :hidden: Overview ~~~~~~~~ Random Fourier Features for SE kernel approximation. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class RandomFourierFeatures { public: // construction :ref:`RandomFourierFeatures`(int n_features, double lengthscale, int input_dim, int seed = 42); // methods void :ref:`setLengthscale`(double l); Eigen::VectorXd :ref:`transform`(const Eigen::VectorXd& x) const; :ref:`EigenMatrix` :ref:`transformBatch`(const :ref:`EigenMatrix`& X) const; :ref:`EigenMatrix` :ref:`approximateKernel`(const :ref:`EigenMatrix`& X) const; int :target:`nFeatures`() const; int :target:`inputDim`() const; double :target:`lengthscale`() const; }; .. _details-classgpr_1_1_random_fourier_features: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Random Fourier Features for SE kernel approximation. The random weights W (n_features x input_dim) and biases b (n_features) are generated once from a seeded PRNG. The feature map is: phi(x)_i = sqrt(2/D) \* cos(w_i^T x + b_i) The approximate kernel is Phi \* Phi^T where Phi has rows phi(x_j)^T. Construction ------------ .. index:: pair: function; RandomFourierFeatures .. _doxid-classgpr_1_1_random_fourier_features_1aaded3b85a094da26ae6076169e523b04: .. ref-code-block:: cpp :class: doxyrest-title-code-block RandomFourierFeatures(int n_features, double lengthscale, int input_dim, int seed = 42) Construct and initialize RFF weights from a seeded RNG. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - n_features - Number of random features D * - lengthscale - Kernel lengthscale l (w_i ~ N(0, 1/l^2)) * - input_dim - Dimensionality of input vectors * - seed - RNG seed for reproducibility Methods ------- .. index:: pair: function; setLengthscale .. _doxid-classgpr_1_1_random_fourier_features_1a1f4b21e1981f74da0615c4bc5a8ded21: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setLengthscale(double l) Change the lengthscale and regenerate random weights. The same seed is reused so the random structure is preserved (only the scale changes). .. index:: pair: function; transform .. _doxid-classgpr_1_1_random_fourier_features_1ac62241c4cb0d3a4d4c3e50be750a55f2: .. ref-code-block:: cpp :class: doxyrest-title-code-block Eigen::VectorXd transform(const Eigen::VectorXd& x) const Compute the feature vector phi(x) for a single input. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - x - Input vector of dimension input_dim .. rubric:: Returns: Feature vector of dimension n_features .. index:: pair: function; transformBatch .. _doxid-classgpr_1_1_random_fourier_features_1aa208dc6186e752f4b3d9f47872dde601: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`EigenMatrix` transformBatch(const :ref:`EigenMatrix`& X) const Compute feature vectors for all rows of X. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - X - Input matrix (n_samples x input_dim) .. rubric:: Returns: Feature matrix Phi (n_samples x n_features) .. index:: pair: function; approximateKernel .. _doxid-classgpr_1_1_random_fourier_features_1acdf21deb68667f5319ae11192259c383: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`EigenMatrix` approximateKernel(const :ref:`EigenMatrix`& X) const Approximate the kernel matrix K ~ Phi \* Phi^T. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - X - Input matrix (n_samples x input_dim) .. rubric:: Returns: Approximate kernel matrix (n_samples x n_samples)