Bayesian decision theory picks, for each observation , the action with the smallest posterior expected loss . Implement:
expected_losses(posterior, loss): posterior has shape (n_obs, n_states) (each row a distribution over states), loss[h, a] has shape (n_states, n_actions). Return the (n_obs, n_actions) array of .bayes_policy(posterior, loss): the index of the minimizing action for each observation (the lowest index on ties), as an integer array.covid_table(prevalence, sens, spec, drug_cost, qaly_young=60.0, qaly_old=10.0): the book's treatment example. A test result (0 negative, 1 positive) is turned into with Bayes' rule from the prevalence, sensitivity and specificity. The actions are 0 = do nothing and 1 = give the drug. Doing nothing costs without COVID and the patient's QALY (qaly_young for age 0, qaly_old for age 1) with COVID; the drug always costs drug_cost. Return a list of 4 rows [test, age, p_covid, cost_nothing, cost_drugs, action] in the order (test, age) = (0, 0), (0, 1), (1, 0), (1, 1), with floats unrounded and test, age, action as ints.