squlearn.kernel.loss.target_alignment.TargetAlignment

class squlearn.kernel.loss.target_alignment.TargetAlignment(rescale_class_labels=True)

Target alignment loss function. This class can be used to compute the target alignment for a given quantum kernel \(K_{\theta}\) with variational parameters \(\theta\). The definition of the function is taken from Equation (27,28) of [1]. The target alignment loss is defined as:

\[\begin{split}TA(K_{\theta}) = \frac{\\um_{i,j} K_{\theta}(x_i, x_j) y_i y_j} {\sqrt{\sum_{i,j} K_{\theta}(x_i, x_j)^2 \sum_{i,j} y_i^2 y_j^2}}\end{split}\]
Parameters:

rescale_class_labels (bool) – Whether to rescale the class labels to -1 and 1 (default=True).

References

[1]: T. Hubregtsen et al., “Training Quantum Embedding Kernels on Near-Term Quantum Computers”, arXiv:2105.02276v1 (2021).

Methods:

compute(parameter_values: ndarray, data: ndarray, labels: ndarray) float

Compute the target alignment loss.

Parameters:
  • parameter_values (np.ndarray) – The parameter values for the variational quantum kernel parameters.

  • data (np.ndarray) – The training data to be used for the kernel matrix.

  • labels (np.ndarray) – The labels of the training data.

Returns:

The negative target alignment.

Return type:

float

set_quantum_kernel(quantum_kernel: KernelMatrixBase) None

Set the quantum kernel matrix to be used in the loss.

Parameters:

quantum_kernel (KernelMatrixBase) – The quantum kernel matrix to be used in the loss.