rfflearn.cpu.RFFGPR
Gaussian Process Regression with random Fourier features.
def rfflearn.cpu.RFFGPR(self, dim_kernel=128, std_kernel=0.1, std_error=0.1, W=None, b=None, a=None, S=None)
Parameters:
dim_kernel: int (default=128)
Dimension of the random matrix.
std_kernel: float (default=0.1)
Standard deviation of the random matrix.
std_error: float (default=0.1)
Standard deviation of the measurement error.
W: np.ndarray (default=None)
Random matrix for the input X. If None then generated automatically.
b: np.ndarray (default=None)
Random bias for the input X. If None then generated automatically.
a: np.ndarray (default=None)
Cache of the matrix a. If None then generated automatically.
S: np.ndarray (default=None)
Cache of the matrix S. If None then generated automatically.
Attributes:
dim: int
Dimension of the random matrix.
s_k: float
Standard deviation of the random matrix.
mat: Callable
A function to generate the random matrix W.
W: np.ndarray
Random matrix for the input X.
b: np.ndarray
Random bias for the input X.
s_e: np.ndarray
Standard deviation of the measurement error.
a: np.ndarray
Cache of the matrix a. If None then generated automatically.
S: np.ndarray
Cache of the matrix S. If None then generated automatically.
Member functions
def fit(self, X, y, **args)
Trains the GPR model according to the given data.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
y: np.ndarray
Output matrix with shape (n_samples, n_features_output).
args: dict (default={})
Extra arguments. However, this arguments will be ignored. This argument exists only for keeping the same interface with scikit-learn.
Returns:
rfflearn.cpu.RFFGPR
Fitted estimator.
def predict(self, X, return_std=False, return_cov=False)
Performs regression on the input data.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
return_std: bool (default=False)
Returns standard deviation of the prediction if True.
return_cov: bool (default=False)
Returns covariance of the prediction if True.
Returns:
np.ndarray, or tuple
Predicted vector, or tuple of prediction, standard deviation, and covariance of the prediction.
def std(self, F)
Returns standard deviation of the prediction.
Parameters:
F: np.ndarray
Matrix F (= self.conv(X).T).
Returns:
np.ndarray
Standard deviation of the prediction.
def cov(self, F)
Returns covariance of the prediction.
Parameters:
F: np.ndarray
Matrix F (= self.conv(X).T).
Returns:
np.ndarray
Covariance of the prediction.
def score(self, X, y, **args)
Returns the R2 score (coefficient of determination) of the prediction.
Parameters:
X: np.ndarray
Input matrix with shape (n_samples, n_features_input).
y: np.ndarray
True output matrix with shape (n_samples, n_features_output).
args: dict (default={})
Extra arguments. However, this arguments will be ignored.
Returns:
float
R2 score of the prediction.
Minimal Example
>>> import numpy as np # Import Numpy
>>> import rfflearn.cpu as rfflearn # Import module
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) # Define input data
>>> y = np.array([0.5, 1, 1.5, 2]) # Defile label data
>>> gpr = rfflearn.RFFGPR().fit(X, y) # Training (on CPU)
>>> gpr.score(X, y) # Inference (on CPU)
0.982939182798136
>>> gpr.predict(np.array([[-0.8, -1]]))
array([0.52784025])