Postulate is the best way to take and share notes for classes, research, and other learning.
When building a QGAN following the Pennylane tutorial, I came across something strange:
the expectation value that the circuit returns with the function qml.expval()
is not equal to the probability of the discriminator classifying the data as real. This sounded like saying, the expectation value of, for example, a qubit that can collapse into either |0⟩ or |1⟩ upon measurement in the computational basis is not equal to the probability that the qubit collapses into either |0⟩ or |1⟩.
If the expectation value does not represent probability, what does the expectation value even mean?
More specifically, when building my QGAN, here's the troubling segment of code:
def prob_real_true(disc_weights): true_disc_output = real_disc_circuit(phi, theta, omega, disc_weights) prob_real_true = (true_disc_output + 1) / 2 return prob_real_true
true_disc_output
represents the expectation value, and prob_real_true
stores the probability of the discriminator classifying as real.
To convert the expectation value into the probabilty, we add 1 to the expectation value and divide the sum by 2. I didn't know why this function outputs the probability as I don't understand what exactly the expectation value represents well enough.
But this is easy to calculate.
probability = (expval + 1) / 2
We know that probability ranges from 0 to 1. Following the above equation, we can compute that when probability is 1, expval is 1. When probability is 0, expval is -1. so expval ranges from -1 to 1, and this above function is simply fitting the range of -1 to 1 onto the range of 0 to 1 linearly.
Why does the expectation value range from -1 to 1? How can a wire have a negative expectation value? What does a negative expectation value represent? That the wave function of the qubit has a negative amplitude? And then I guess complex amplitudes would mean complex expectation values? But the function never outputs a complex expctation value...
According to Wikipedia,
In quantum mechanics, the expectation value is the probabilistic expected value of the result (measurement) of an experiment.
Expectation value = the probability of getting a certain measurement
Wiki is saying that expectation value = probability. If expectation value = probability, how can expval be negative?
I don't know the answer to this question. But for now, I am satisfied with knowing that at least for this QGAN, the expectation value ranges from -1 to 1.
Working notes from learning QC