squlearn.kernel.matrix.kernel_matrix_base.KernelMatrixBase

class squlearn.kernel.matrix.kernel_matrix_base.KernelMatrixBase(encoding_circuit: EncodingCircuitBase, executor: Executor, initial_parameters: ndarray | None = None, parameter_seed: int | None = 0, regularization: str | None = None)

Base class for defining quantum kernels.

Parameters:
  • encoding_circuit (EncodingCircuitBase) – PQC encoding circuit

  • executor (Executor) – Executor object

  • initial_parameters (Union[np.ndarray, None], default=None) – Initial parameters of the PQC encoding circuit

  • parameter_seed (Union[int, None], default=0) – Seed for the random number generator for the parameter initialization, if initial_parameters is None.

  • regularization (Union[str, None], default=None) – Str that specifies the method with which the kernel matrix should be regularized. See method attribute from KernMatrixBase._regularize_matrix() method for valid options.

assign_parameters(parameters)

Fix the training parameters of the encoding circuit to numerical values

Parameters:

parameters (np.ndarray) – Array containing numerical values to be assigned to the trainable parameters of the encoding circuit

abstract evaluate(x: ndarray, y: ndarray = None) ndarray

Computes the quantum kernel matrix.

Parameters:
  • x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated

  • y (np.ndarray, default=None) – Vector of training or test data for which the kernel matrix is evaluated

Returns:

Returns the quantum kernel matrix as 2D numpy array.

evaluate_pairwise(x: ndarray, y: ndarray = None) float

Computes the quantum kernel matrix.

Parameters:
  • x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated

  • y (np.ndarray, default=None) – Vector of training or test data for which the kernel matrix is evaluated

evaluate_with_parameters(x: ndarray, y: ndarray, parameters: ndarray) ndarray

Computes the quantum kernel matrix with assigned parameters

Parameters:
  • x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated

  • y (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated

  • parameters (np.ndarray) – Array containing numerical values to be assigned to the trainable parameters of the encoding circuit

get_params(deep: bool = True) dict

Returns hyper-parameters and their values of the kernel method.

Parameters:

deep (bool) – If True, also the parameters for contained objects are returned (default=True).

Returns:

Dictionary with hyper-parameters and values.

abstract set_params(**params)

Sets value of the fidelity kernel hyper-parameters.

Parameters:

params – Hyper-parameters and their values, e.g. num_qubits=2