Loading...
Searching...
No Matches
RandomFourierFeatures.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
17
18#ifndef GPR_ML_RANDOMFOURIERFEATURES_H_
19#define GPR_ML_RANDOMFOURIERFEATURES_H_
20
21#include <Eigen/Dense>
22
24
25namespace gpr {
26
37public:
46 RandomFourierFeatures(int n_features, double lengthscale, int input_dim,
47 int seed = 42);
48
55 void setLengthscale(double l);
56
63 Eigen::VectorXd transform(const Eigen::VectorXd& x) const;
64
72
80
81 int nFeatures() const
82 {
83 return n_features_;
84 }
85 int inputDim() const
86 {
87 return input_dim_;
88 }
89 double lengthscale() const
90 {
91 return lengthscale_;
92 }
93
94private:
95 void generateWeights();
96
97 int n_features_;
98 double lengthscale_;
99 int input_dim_;
100 int seed_;
101
102 EigenMatrix W_; // (n_features x input_dim)
103 Eigen::VectorXd b_; // (n_features)
104 double scale_factor_; // sqrt(2 / n_features)
105};
106
107} // namespace gpr
108
109#endif // GPR_ML_RANDOMFOURIERFEATURES_H_
@ x
Definition Enums.h:28
void setLengthscale(double l)
Change the lengthscale and regenerate random weights.
EigenMatrix transformBatch(const EigenMatrix &X) const
Compute feature vectors for all rows of X.
RandomFourierFeatures(int n_features, double lengthscale, int input_dim, int seed=42)
Construct and initialize RFF weights from a seeded RNG.
Eigen::VectorXd transform(const Eigen::VectorXd &x) const
Compute the feature vector phi(x) for a single input.
EigenMatrix approximateKernel(const EigenMatrix &X) const
Approximate the kernel matrix K ~ Phi * Phi^T.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20