Bayesian Rejection Sampling
Learn the concept of Bayesian rejection sampling.
Our QBN is well trained. However, when we look back to all the CPT it consists of (see the lesson titled Estimating a Variable), we haven’t completed it. We still miss the CPT of being favored by a Norm
given the passenger’s Sex
and Age
, and we miss the CPT of Surviva
l given the Norm
and the Pclass
. Let’s catch up on this.
Press + to interact
def get_trained_qbn_norm(passengers, params):prepared_passengers = prepare_data(passengers, params)norm_params = calculate_norm_params(prepared_passengers)surv_params = calculate_surv_params(prepared_passengers)def qbn_titanic():def circuit(qc, qr=None, cr=None):apply_ischild_sex(qc)apply_norm(qc, norm_params)apply_class(qc)apply_survival(qc, surv_params)qc.measure(QPOS_ISCHILD, cr[0])qc.measure(QPOS_SEX, cr[1])qc.measure(QPOS_NORM, cr[2])return as_pqc(QUBITS, circuit, hist=False, cnt_classical=3, measure=True, shots=10000)return qbn_titanic()
Again, estimating the numbers in the CPT of a Bayesian network builds upon counting how many times that event occurred in our training data.
First, we need to change the variables we measure.
Instead of the qubit at ...