qiskit-community / qiskit-machine-learning

Quantum Machine Learning
https://qiskit-community.github.io/qiskit-machine-learning/
Apache License 2.0
647 stars 316 forks source link

Mismatching between loss function code and documentation formula #821

Open bero1403 opened 1 month ago

bero1403 commented 1 month ago

According to this documentation the binary labels are part of the equation of SVCLoss, https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.utils.loss_functions.SVCLoss.html#:~:text=This%20class%20provides,is%20defined%20as%3A However in this line of code we don't have the label in the loss function anymore. https://github.com/qiskit-community/qiskit-machine-learning/blob/253b190eba869b4d002e490323ee4139612f01c9/qiskit_machine_learning/utils/loss_functions/kernel_loss_functions.py#L125 Can you explain why?

adekusar-drl commented 4 weeks ago

In the SVC documentation (https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html) it is stated:

Dual coefficients of the support vector in the decision function (see [Mathematical formulation](https://scikit-learn.org/stable/modules/sgd.html#sgd-mathematical-formulation)), multiplied by their targets.

That's why it is np.abs(dual_coefs) and there's no need to multiply by labels in the second term of the loss.