Search⌘ K

Calculating the Posterior

Explore the process of calculating posterior probabilities for priors greater than 0.5 using multiple qubits and controlled quantum gates. Understand how to apply controlled RY gates, manage probability modifiers, and perform measurements to reconstruct conditional probabilities. This lesson covers challenges in handling priors and modifiers, precision trade-offs, and practical quantum circuit implementation for probability calculations.

Calculating the posterior for prior > 0.5

Javascript (babel-node)
# Calculating the posterior for prior > 0.5
# Specify the prior probability and the modifier
prior = 0.6
modifier = 1.2
qc = QuantumCircuit(4)
# Apply prior to qubit 0
qc.ry(prob_to_angle(prior), 0)
# Apply 0.3*prior to qubit 1
qc.x(0)
qc.cry(prob_to_angle(0.3*prior/(1-prior)), 0, 1)
# Apply the modifier to qubit 2
qc.cry(prob_to_angle((modifier-1)/0.3), 1,2)
# Make qubit 3 represent the posterior
qc.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.

Python
qc.cry(prob_to_angle((modifier-1)/0.3), 1,2)

We apply a controlled RYR_Y-gate. Thus, we only change states where qubit 1 is 1. This is the case for the state 00100010, which represents 0.30.3 ...