New switch method for Bayesian networks

Issue #36 closed
Pierre Denis
repo owner created an issue

The Bayesian networks are currently implemented by the method Lea.buildCPT and Lea.if_ methods, which relies on Blea class. This works with a set of clauses, each of which contains a Lea boolean condition that guards a CPT entry.

rain = Lea.if_(cloudy,B(80,100),
                      B(20,100))
# equivalent to 
# rain = Lea.buildCPT( (  cloudy, B(80,100)),
#                      ( ~cloudy, B(20,100)))
grassWet = Lea.buildCPT( ( ~sprinkler & ~rain, False    ),
                         ( ~sprinkler &  rain, B(80,100)),
                         (  sprinkler & ~rain, B(90,100)),
                         (  sprinkler &  rain, B(99,100)))

This approach is interesting in case of contextual independence because CPT can be smaller by removing redundancies. However, in the general case, this approach is inefficient for making inference because each condition to be evaluated requires many calculations.

An alternative approach would be to provide a new Lea.switch method that model the CPT as a dictionary.

rain = cloudy.switch({True  : B(80,100),
                      False : B(20,100)})
wetGrass = X(sprinkler,rain).switch({(False, False) : False    ,
                                     (False, True)  : B(80,100),
                                     (True , False) : B(90,100),
                                     (True , True)  : B(99,100)})

This approach is actually closer to the concept of a CPT, which is basically a mapping. It could improve the efficiency of inference when a CPT involve more than one causal variable (e.g. wetGrass) because dictionary lookup is expected to be faster than a sequential evaluations of all conditions.

The new switch method requires a new Lea subclass. This construct maybe provided as an alternative approach for Bayesian networks, beside Lea.buildCPT and Lea.if_ methods.

Comments (6)

  1. Log in to comment