Table of Contents
- Introduction
- Role of Cost Functions in QML
- Characteristics of a Good Cost Function
- Cost Functions for Classification
- Binary Cross-Entropy Loss
- Mean Squared Error (MSE)
- Hinge Loss for Margin-Based Models
- Fidelity-Based Loss
- KL Divergence in Quantum Models
- Quantum Relative Entropy
- Loss Functions for Variational Circuits
- Cost in Quantum Generative Models (QGANs)
- Quantum Adversarial Losses
- Cost Functions in Reinforcement Learning
- Regularization in Quantum Cost Functions
- Gradient Estimation and Differentiability
- Challenges in Quantum Cost Evaluation
- Tools and Frameworks with Built-in Losses
- Custom Cost Design Strategies
- Conclusion
1. Introduction
Cost functions are fundamental components in quantum machine learning (QML), serving as quantitative measures of model performance and guiding the optimization of quantum parameters.
2. Role of Cost Functions in QML
- Quantify the difference between predicted and actual outcomes
- Provide gradient signals for parameter updates in variational circuits
- Help models generalize and avoid overfitting
3. Characteristics of a Good Cost Function
- Differentiable with respect to parameters
- Sensitive to model changes
- Robust to noise (especially on real quantum devices)
4. Cost Functions for Classification
- Compare predicted class probabilities or expectation values with true labels
- Often based on classical formulations
5. Binary Cross-Entropy Loss
Used in binary classification:
\[
\mathcal{L}(y, \hat{y}) = -[y \log(\hat{y}) + (1 – y) \log(1 – \hat{y})]
\]
Where \( \hat{y} \) is derived from quantum measurement (e.g., Pauli-Z expectation).
6. Mean Squared Error (MSE)
\[
ext{MSE} = rac{1}{n} \sum_{i=1}^{n} (y_i – \hat{y}_i)^2
\]
Simple and widely used for regression or expectation-based output.
7. Hinge Loss for Margin-Based Models
Useful for SVM-inspired quantum classifiers:
\[
\mathcal{L}(y, \hat{y}) = \max(0, 1 – y \cdot \hat{y})
\]
8. Fidelity-Based Loss
Measures overlap between quantum states:
\[
\mathcal{L} = 1 – |\langle \psi_{ ext{target}} | \psi_{ ext{output}}
angle|^2
\]
Used in quantum state synthesis and autoencoders.
9. KL Divergence in Quantum Models
\[
D_{ ext{KL}}(P || Q) = \sum_i P(i) \log \left( rac{P(i)}{Q(i)}
ight)
\]
Used to compare two probability distributions output by quantum circuits.
10. Quantum Relative Entropy
\[
S(
ho || \sigma) = ext{Tr}[
ho (\log
ho – \log \sigma)]
\]
Quantum analog of KL divergence for density matrices.
11. Loss Functions for Variational Circuits
- Expectation of observable:
\[
\mathcal{L}( heta) = \langle \psi( heta) | H | \psi( heta)
angle
\]
Used in VQE, QAOA, and hybrid models
12. Cost in Quantum Generative Models (QGANs)
- Adversarial losses:
\[
\mathcal{L}_G = -\mathbb{E}[\log D(G(z))]
\quad
\mathcal{L}_D = -\mathbb{E}[\log D(x)] – \mathbb{E}[\log(1 – D(G(z)))]
\]
13. Quantum Adversarial Losses
- Use Wasserstein distance or maximum mean discrepancy
- May involve dual optimization steps with gradient penalties
14. Cost Functions in Reinforcement Learning
- Temporal difference loss
- Policy gradient loss using quantum expectation values
- Hybrid RL cost based on Q-value approximations
15. Regularization in Quantum Cost Functions
- Add L2 penalty on weights
- Penalize circuit depth or entanglement
- Dropout-like randomness in gate selection
16. Gradient Estimation and Differentiability
- Use parameter-shift rule for analytic gradients
- Finite difference when exact shift not available
- Ensure cost is differentiable wrt circuit parameters
17. Challenges in Quantum Cost Evaluation
- Measurement shot noise
- Non-convexity and barren plateaus
- High variance in gradient estimates
18. Tools and Frameworks with Built-in Losses
- PennyLane:
qml.losses
- TensorFlow Quantum: integrated Keras loss support
- Qiskit Machine Learning: supports classical and quantum loss tracking
19. Custom Cost Design Strategies
- Combine quantum + classical loss terms
- Define domain-specific observables
- Use hybrid multi-objective formulations
20. Conclusion
Cost functions are the bridge between model predictions and optimization in quantum machine learning. Carefully chosen or custom-designed loss functions enable effective training, stability, and practical performance of quantum models across diverse learning tasks.