...

/

Calculating New Parameters

Calculating New Parameters

Learn how to calculate the new parameter and train the QBN.

Obtaining new parameter values from the results

Press + to interact
def to_params(results):
states = results.items()
def calc_norm(ischild_val, sex_val, surv_val):
pop = filter_states(filter_states(filter_states(states, QPOS_SEX, sex_val), QPOS_ISCHILD, ischild_val), QPOS_SURV, surv_val)
p_norm = sum(map(lambda item: item[1], filter_states(pop, QPOS_NORM, '1')))
p_total = sum(map(lambda item: item[1], pop))
return p_norm / p_total
return {
'p_norm_cms': calc_norm('1', '0', '1'),
'p_norm_cmd': calc_norm('1', '0', '0'),
'p_norm_cfs': calc_norm('1', '1', '1'),
'p_norm_cfd': calc_norm('1', '1', '0'),
'p_norm_ams': calc_norm('0', '0', '1'),
'p_norm_amd': calc_norm('0', '0', '0'),
'p_norm_afs': calc_norm('0', '1', '1'),
'p_norm_afd': calc_norm('0', '1', '0'),
}

The to_params function takes the results as a parameter in line 1. It returns a dictionary with the probabilities of being favored by a norm, given the set of values for the variables IsChild, Sex, and Survival in lines 12 to 21. These are conditional probabilities. We first filter all the states that have the specified values for the variables in line 5. From this set, we filter those states where the Norm has value ...