qxmt.models.qkernels.base module#
- class qxmt.models.qkernels.base.BaseKernelModel(kernel, n_jobs=2, show_progress=True)
Bases:
BaseMLModel
Base class for kernel-based quantum machine learning models. This class is an abstract class for kernel-based quantum machine learning models. If you want to implement a new kernel-based quantum machine learning model, you should inherit this class. This class requires a kernel instance of BaseKernel class. The user can use any Feature Map or Kernel to be used, as long as it follows the interface of the BaseKernel class.
- Parameters:
kernel (BaseKernel)
n_jobs (int)
show_progress (bool)
- __init__(kernel, n_jobs=2, show_progress=True)
Initialize the kernel model.
- Parameters:
kernel (BaseKernel) – kernel instance of BaseKernel class
n_jobs (int) – number of parallel jobs. Defaults to DEFAULT_N_JOBS.
show_progress (bool) – flag for showing progress bar. Defaults to True.
- Return type:
None
- get_feature_map()
Get the feature map of the model.
- Returns:
feature map instance
- Return type:
BaseFeatureMap
- get_kernel_matrix(x_array_1, x_array_2)
Get the kernel matrix of the given data. This method is alias of kernel.compute_matrix().
- Parameters:
x_array_1 (np.ndarray) – array of samples (ex: training data)
x_array_2 (np.ndarray) – array of samples (ex: test data)
- Returns:
kernel matrix
- Return type:
np.ndarray
- plot_kernel_matrix(x_array_1, x_array_2)
Plot the kernel matrix of the given data. This method is alias of kernel.plot_matrix().
- Parameters:
x_array_1 (np.ndarray) – array of samples (ex: training data)
x_array_2 (np.ndarray) – array of samples (ex: test data)
- Return type:
None
- plot_train_test_kernel_matrix(x_train, x_test)
Plot the kernel matrix of training and testing data. This method is alias of kernel.plot_train_test_matrix().
- Parameters:
x_train (np.ndarray) – array of training samples
x_test (np.ndarray) – array of testing samples
- Return type:
None
- class qxmt.models.qkernels.base.BaseMLModel
Bases:
ABC
Base class for quantum machine learning models. This class is an abstract class for qunatum machine learning models. If you want to implement a new quantum machine learning model, you should inherit this class. For compatibility with QXMT framework, you should implement some methods such as fit, predict, save, load, get_params, and set_params.
- abstractmethod fit(X, y, **kwargs)
Fit the model with given data.
- Parameters:
X (np.ndarray) – array of features
y (np.ndarray) – array of target value
kwargs (Any)
- Return type:
None
- abstractmethod get_params()
Get the parameters of the model.
- Returns:
dictionary of parameters
- Return type:
dict
- abstractmethod load(path)
Load the model from the given path. [TODO]: standardize the save/load method using same library
- Parameters:
path (str | Path) – path to load the model
- Return type:
BaseMLModel
- abstractmethod predict(X, bar_label='')
Predict the target value with given features.
- Parameters:
X (np.ndarray) – array of features
bar_label (str) – label for progress bar. Defaults to “”.
- Returns:
array of predicted value
- Return type:
np.ndarray
- abstractmethod save(path)
Save the model to the given path. [TODO]: standardize the save/load method using same library
- Parameters:
path (str | Path) – path to save the model
- Return type:
None
- abstractmethod set_params(params)
Set the parameters of the model.
- Parameters:
params (dict) – dictionary of parameters
- Return type:
None