Calculating the Posterior
Learn how we can calculate the posterior.
We'll cover the following...
Calculating the posterior for prior > 0.5
Press + to interact
# Calculating the posterior for prior > 0.5# Specify the prior probability and the modifierprior = 0.6modifier = 1.2qc = QuantumCircuit(4)# Apply prior to qubit 0qc.ry(prob_to_angle(prior), 0)# Apply 0.3*prior to qubit 1qc.x(0)qc.cry(prob_to_angle(0.3*prior/(1-prior)), 0, 1)# Apply the modifier to qubit 2qc.cry(prob_to_angle((modifier-1)/0.3), 1,2)# Make qubit 3 represent the posteriorqc.x(0)qc.cx(0,3)qc.cx(2,3)run_circuit(qc)
Up until line 12, there’s nothing new. The important part is line 16.
Press + to interact
qc.cry(prob_to_angle((modifier-1)/0.3), 1,2)
We apply a controlled -gate. Thus, we only change states where qubit 1 is 1
. This is the case for the state ...