Random Fourier Features for SE kernel approximation. More...
#include <gpr/ml/RandomFourierFeatures.h>
Public Member Functions | |
| RandomFourierFeatures (int n_features, double lengthscale, int input_dim, int seed=42) | |
| Construct and initialize RFF weights from a seeded RNG. | |
| void | setLengthscale (double l) |
| Change the lengthscale and regenerate random weights. | |
| Eigen::VectorXd | transform (const Eigen::VectorXd &x) const |
| Compute the feature vector phi(x) for a single input. | |
| EigenMatrix | transformBatch (const EigenMatrix &X) const |
| Compute feature vectors for all rows of X. | |
| EigenMatrix | approximateKernel (const EigenMatrix &X) const |
| Approximate the kernel matrix K ~ Phi * Phi^T. | |
| int | nFeatures () const |
| int | inputDim () const |
| double | lengthscale () const |
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.
Definition at line 36 of file RandomFourierFeatures.h.
| gpr::RandomFourierFeatures::RandomFourierFeatures | ( | int | n_features, |
| double | lengthscale, | ||
| int | input_dim, | ||
| int | seed = 42 ) |
Construct and initialize RFF weights from a seeded RNG.
| 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 |
Definition at line 12 of file RandomFourierFeatures.cpp.
| EigenMatrix gpr::RandomFourierFeatures::approximateKernel | ( | const EigenMatrix & | X | ) | const |
Approximate the kernel matrix K ~ Phi * Phi^T.
| X | Input matrix (n_samples x input_dim) |
Definition at line 66 of file RandomFourierFeatures.cpp.
|
inline |
Definition at line 85 of file RandomFourierFeatures.h.
|
inline |
Definition at line 89 of file RandomFourierFeatures.h.
|
inline |
Definition at line 81 of file RandomFourierFeatures.h.
| void gpr::RandomFourierFeatures::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).
Definition at line 25 of file RandomFourierFeatures.cpp.
| Eigen::VectorXd gpr::RandomFourierFeatures::transform | ( | const Eigen::VectorXd & | x | ) | const |
Compute the feature vector phi(x) for a single input.
| x | Input vector of dimension input_dim |
Definition at line 50 of file RandomFourierFeatures.cpp.
| EigenMatrix gpr::RandomFourierFeatures::transformBatch | ( | const EigenMatrix & | X | ) | const |
Compute feature vectors for all rows of X.
| X | Input matrix (n_samples x input_dim) |
Definition at line 57 of file RandomFourierFeatures.cpp.