QuantumKernel¶
- class QuantumKernel(feature_map=None, enforce_psd=True, batch_size=900, quantum_instance=None, training_parameters=None, evaluate_duplicates='off_diagonal')[source]¶
Bases:
TrainableKernel
,BaseKernel
Pending deprecation: A dedicated trainable quantum kernel implementation that constructs and executes quantum circuits directly.
The general task of machine learning is to find and study patterns in data. For many algorithms, the datapoints are better understood in a higher dimensional feature space, through the use of a kernel function:
\[K(x, y) = \langle f(x), f(y)\rangle.\]Here K is the kernel function, x, y are n dimensional inputs. f is a map from n-dimension to m-dimension space. \(\langle x, y \rangle\) denotes the dot product. Usually m is much larger than n.
The quantum kernel algorithm calculates a kernel matrix, given datapoints x and y and feature map f, all of n dimension. This kernel matrix can then be used in classical machine learning algorithms such as support vector classification, spectral clustering or ridge regression.
Deprecated since version unknown: The QuantumKernel class has been superseded by the qiskit_machine_learning.kernels.FidelityQuantumKernel and qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel classes. This class will be deprecated in a future release and subsequently removed after that.
- Parameters:
feature_map (QuantumCircuit | None) – Parameterized circuit to be used as the feature map. If None is given, the ZZFeatureMap is used with two qubits.
enforce_psd (bool) – Project to closest positive semidefinite matrix if x = y. Only enforced when not using the state vector simulator. Default True.
batch_size (int) – Number of circuits to batch together for computation. Default 900.
quantum_instance (QuantumInstance | Backend | None) – Quantum Instance or Backend
training_parameters (ParameterVector | Sequence[Parameter] | None) – Iterable containing
Parameter
objects which correspond to quantum gates on the feature map circuit which may be tuned. If users intend to tune feature map parameters to find optimal values, this field should be set.evaluate_duplicates (str) –
Defines a strategy how kernel matrix elements are evaluated if duplicate samples are found. Possible values are:
all
means that all kernel matrix elements are evaluated, even the diagonal ones when training. This may introduce additional noise in the matrix.off_diagonal
when training the matrix diagonal is set to 1, the rest elements are fully evaluated, e.g., for two identical samples in the dataset. When inferring, all elements are evaluated. This is the default value.none
when training the diagonal is set to 1 and if two identical samples are found in the dataset the corresponding matrix element is set to 1. When inferring, matrix elements for identical samples are set to 1.
- Raises:
ValueError – When unsupported value is passed to evaluate_duplicates.
Attributes
Returns
True
if the kernel matrix is required to project to the closest positive semidefinite matrix.Return feature map
Returns the number of features in this kernel.
Returns the number of training parameters.
Returns numerical values assigned to the training parameters as a numpy array.
Return quantum instance
Return a copy of the current training parameter mappings for the feature map circuit.
Return the vector of training parameters.
Return unbound feature map
[Deprecated property]Return a copy of the current training parameter mappings for the feature map circuit.
[Deprecated property]Return the vector of training parameters.
Methods
assign_training_parameters
(parameter_values)Assign training parameters in the quantum kernel's feature map.
assign_user_parameters
(values)[Deprecated method]Assign training parameters in the
QuantumKernel
feature map.bind_training_parameters
(values)Alternate function signature for
assign_training_parameters
bind_user_parameters
(values)[Deprecated method]Alternate function signature for
assign_training_parameters
construct_circuit
(x[, y, measurement, ...])Construct inner product circuit for given datapoints and feature map.
evaluate
(x_vec[, y_vec])Construct kernel matrix for given data and feature map
Return a list of any unbound training parameters in the feature map circuit.
[Deprecated method]Return a list of any unbound training parameters in the feature map circuit.