FreedomIntelligence / qnn

112 stars 30 forks source link

measurement computation #3

Closed subhadarship closed 4 years ago

subhadarship commented 5 years ago

Hi, for computing semantic measurement using equation (2) in https://www.aclweb.org/anthology/N19-1420, the two matrix multiplications should be added instead of subtracting:

output = K.dot(input_real,K.transpose(kernel_r)) + K.dot(input_imag,K.transpose(kernel_i))

Why are they subtracted in https://github.com/wabyking/qnn/blob/master/layers/cvnn/measurement.py#L76?

wabyking commented 5 years ago

For a general multiplication of two complex numbers, (a+ib) * (c+id) = ac + bd(i^2) + (ad+bc)i . In our case, the final result should be real (refers to https://math.stackexchange.com/questions/2884094/trace-of-product-of-two-hermitian-matrices), namely ad+bc =0. We only have to consider ac+ bd(i^2) as our final output. As we knew, i^2 = -1, resulting in ac- bd .

subhadarship commented 4 years ago

thank you for the crisp answer