squlearn.kernel.matrix
.FidelityKernel
- class squlearn.kernel.matrix.FidelityKernel(encoding_circuit: EncodingCircuitBase, executor: Executor, evaluate_duplicates: str = 'off_diagonal', mit_depol_noise: str | None = None, initial_parameters: ndarray | None = None, parameter_seed: int | None = 0, regularization: str | None = None)
Fidelity Quantum Kernel.
The Fidelity Quantum Kernel is a based on the overlap of the quantum states. These quantum states can be defined by a parameterized quantum circuit. The Fidelity Quantum Kernel is defined as:
\[K(x,y) = |\langle \phi(x) | \phi(y) \rangle|^2\]This class wraps to the respective Quantum Kernel implementations from Qiskit Machine Learning. Depending on the choice of the backend and the choice of trainable parameters, the appropriate Quantum Kernel implementation is chosen.
- Parameters:
encoding_circuit (EncodingCircuitBase) – PQC encoding circuit.
executor (Executor) – Executor object.
evaluate_duplicates (str) – Option for evaluating duplicates (‘all’, ‘off_diagonal’, ‘none’).
mit_depol_noise (Union[str, None]) – Option for mitigating depolarizing noise (
"msplit"
or"mmean"
) after Ref. [4]. Only meaningful for FQKs computed on a real backend.initial_parameters (Union[np.ndarray, None], default=None) – Initial parameters for the 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) – Option for choosing different regularization techniques (
"thresholding"
or"tikhonov"
) after Ref. [4] for the training kernel matrix, prior to solving the linear system in thefit()
-procedure.
References
- 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
- evaluate(x: ndarray, y: ndarray | None = None) ndarray
Evaluates the fidelity 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 fidelity kernel.
- Parameters:
deep (bool) – If True, also the parameters for contained objects are returned (default=True).
- Returns:
Dictionary with hyper-parameters and values.
- set_params(**params)
Sets value of the fidelity kernel hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2