Skip to content

Can't easily find CPTs for car insurance Bayes net case study #1285

Closed

Description

@JacquesRobin

Page 427 of 4th ed states: The conditional distributions in the model are given in the code repository for the book; we provide a version with only discrete variables, for which exact inference can be performed. However, I can't easily find it in the code repo.

Activity

  1. dmeoli commented on Jun 27, 2026

    @dmeoli
    Member

    there is no car-insurance network in probability.py or probability4e.py (none of the names RiskAversion, Antilock, DrivingSkill, MedicalCost and so on is there), while the book says that the discrete CPTs are 'in the code repository', so the content is missing
    adding it means defining the discrete network with its CPTs as a BayesNet, as burglary and sprinkler; the CPTs are needed first (the full decision network has about 27 nodes, decision and utility nodes included)
    I'm leaving this open; with a pointer to the CPTs (e.g., in aima-java or aima-data) I can add the discrete version

  2. dmeoli commented on Jun 29, 2026

    @dmeoli
    Member

    the network is the "Insurance" Bayesian network (Binder, Koller, Russell and Kanazawa, Adaptive Probabilistic Networks with Hidden Variables, 1997), a car-insurance model of 27 nodes, and the "conditional distributions given in the code repository" of the book are its discrete version, which neither aima-python nor aima-data has

    the full CPTs of the discrete version are in the bnlearn Bayesian Network Repository (https://www.bnlearn.com/bnrepository/, the Insurance network as BIF, DSC or NET); it is also the insurance network of the R package bnlearn, and pgmpy reads it in Python (pgmpy.readwrite.BIFReader('insurance.bif').get_model())

    BayesNet and BayesNode here have boolean variables only (each CPT gives P(node=True | parents)), while the variables of Insurance have several values (e.g., Age ∈ {Adolescent, Adult, Senior}, MedCost ∈ {Thousand, TenThou, HundredThou, Million}), so enumeration_ask and elimination_ask need a discrete BayesNet with multi-valued variables first

    so this takes (1) multi-valued discrete variables in BayesNet and in inference, and (2) the Insurance network, e.g., with a small BIF reader on the file of the repository; I'm leaving this open for that

  3. dmeoli commented on Jun 29, 2026

    @dmeoli
    Member

    done on master (fe83281): aima-python has the car-insurance network and what it takes to use it

    • DiscreteBayesNode and DiscreteBayesNet (probability.py), nodes whose variables have any finite domain (BayesNet was boolean only), with the interface used by inference (node.p(value, event) and variable_values), so enumeration_ask and elimination_ask work on them as they are
    • read_bif(), which reads the BIF format of the bnlearn BN Repository
    • insurance(), which loads the Insurance network of 27 variables (Binder, Koller, Russell and Kanazawa 1997) from aima-data/insurance.bif (now in aima-data), i.e., the discrete CPTs of §16 of the 4th edition
    from aima.probability import insurance, elimination_ask
    net = insurance()                      # 27 nodes, full discrete CPTs
    elimination_ask('Age', {}, net).show_approx()
    # 'Adolescent: 0.2, Adult: 0.6, Senior: 0.2'
    elimination_ask('PropCost', {'Age': 'Adolescent', 'GoodStudent': 'False'}, net)

    exact inference runs on the whole network; the tests cover a small multi-valued network (enumeration, elimination and the values computed by hand agree), read_bif and the Insurance network
    thanks for the pointer to p. 427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions