...

/

Calculating the Posterior

Calculating the Posterior

Learn how we can calculate the posterior.

Calculating the posterior for prior > 0.5

Press + to interact
# 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.

Press + to interact
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 0010 ...