rfflearn_logo

rfflearn.cpu.RFFGPC

Gaussian Process Classification with random Fourier features. This class is essentially the same as RFFGPR, but some pre-processing and post-processing are necessary for modifying a regression task to a classification task. The required processing is:

The purpose of this RFFGPC class is only to do these pre/post-processing.

def rfflearn.cpu.RFFGPC(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)

Trains the GPC model according to the given data.

Parameters:

X: np.ndarray

Input matrix with shape (n_samples, n_features_input).

y: np.ndarray

Output vector with shape (n_samples,).

args: dict

Extra arguments. However, this arguments will be ignored. This argument exists only for keeping the same interface with scikit-learn.

Returns:

rfflearn.cpu.RFFGPC

Fitted estimator.

def predict(self, X, return_std=False, return_cov=False)

Performs classification on the given 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 class indices vector, or tuple of prediction, standard deviation, and covariance of the prediction.

def score(self, X, y, **args)

Returns the mean accuracy on the given data and labels.

Parameters:

X: np.ndarray

Input matrix with shape (n_samples, n_features_input).

y: np.ndarray

True class label vector with shape (n_samples,).

args: dict  (default={})

Extra arguments. However, this arguments will be ignored.

Returns:

float

Mean classification accuracy.

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([1, 1, 2, 2])                          # Defile label data
>>> gpc = rfflearn.RFFGPC().fit(X, y)                   # Training (on CPU)
>>> gpc.score(X, y)                                     # Inference (on CPU)
1.0
>>> gpc.predict(np.array([[-0.8, -1]]))
array([1])