Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equation of Geometric Difference #6

Open
Squigspear opened this issue Mar 14, 2023 · 2 comments
Open

Equation of Geometric Difference #6

Squigspear opened this issue Mar 14, 2023 · 2 comments

Comments

@Squigspear
Copy link

Hi,

I would like to clarify the following code that was used to implement geometric difference from the paper: "The power of data in quantum machine learning".

def calculate_geometric_difference(k_1, k_2, normalization_lambda=0.001):
"""
Calculate the geometric difference g(K_1 || K_2), which is equation F9 in
"The power of data in quantum machine learning" (https://arxiv.org/abs/2011.01938)
and characterize the separation between classical and quantum kernels.
Args:
k_1: Quantum kernel Gram matrix
k_2: Classical kernel Gram matrix
normalization_lambda: normalization factor, must be close to zero
Returns:
geometric difference between the two kernel functions (float).
"""

In the paper, geometric difference between classical and quantum (gcq ) is defined with k1 = classical kernel and k2 = quantum kernel. However, in your code implementation, k1 is quantum and k2 is classical. As the equation is asymmetric to the order of the matrices k1 and k2, could there be an error in the code implementation?

Thanks for taking the time to read this!

@Fradm98
Copy link
Collaborator

Fradm98 commented May 31, 2023

Hi @Squigspear, thanks for your insight, we fixed this issue in the branch package, we are going soon to merge it to the main one.

@qifengpan
Copy link

Hi,

I would like ask a follow up question for the function calculate_geometric_difference
In your implementation, you calculate the root of matrix in following form:

        # √K1
        k_1_sqrt = np.real(sqrtm(k_1))
        # √K2
        k_2_sqrt = np.real(sqrtm(k_2))

Since the result of sqrtm(k_1) can be a matrix containing complex number, direct cast it to a real number matrix would lose the imformation of imagenary part, and lead a wrong result. For e.g:

import tensorflow as tf
import numpy as np
from scipy.linalg import sqrtm
x = tf.convert_to_tensor([[1,2],[3,3]])
x_sqrt_scipy = np.real(sqrtm(x))
print(x_sqrt_scipy @ x_sqrt_scipy )

According to the definition, the result of x_sqrt_scipy @ x_sqrt_scipy should be x itself, but the output of this block is not identical to x. The reason behind is that matrix [1,2;3,3] is not semi-definite matrix. Therefore, the result of sqrtm contains complex number.
I'm not sure if I made some mistake for this, or misunderstanding for geometric difference. Or maybe you have other intention/implementation for that. Purely from math perspective, I would code this block as

        # √K1
        k_1_sqrt = sqrtm(k_1)
        # √K2
        k_2_sqrt = sqrtm(k_2)

Thanks for your time of reading/proofing, I'm happy to have further discussion for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants