Tutorial 8: Hybrid model

<< Click to Display Table of Contents >>

Navigation:  Tutorials >

Tutorial 8: Hybrid model

We extend the model described in Tutorial 7 by adding two discrete nodes: Climate Zone and Perceived Temperature. Climate Zone refines the probability distribution of the outside air temperature and Perceived Temperature is an additional input originating from a subjective perception of the temperature, useful in case of a failure in the outside temperature sensor.

hybrid

After loading the network created in the previous tutorial, the program adds two discrete nodes using the CreateCptNode helper function first seen in Tutorial 1. The arc from Climate Zone (node identifier is zone) to Outside Air Temperature (node identifier is toa) is created by changing the equation of the latter:

Java:

net.setNodeEquation(toaHandle, "toa=If(zone=\"Desert\",Normal(22,5),Normal(11,10))");

Python:

net.set_node_equation("toa", 'toa=If(zone="Desert",Normal(22,5),Normal(11,10))')

C#:

net.SetNodeEquation(toaHandle, "toa=If(zone=\"Desert\",Normal(22,5),Normal(11,10))");

In the Java and C# code, we need to escape the double quote characters in order to use the text literal representing the Desert outcome of the parent. Python allows for single quotes to be used as string literal delimiter.

The new equation switches between two normal distribution based on the outcome of the parent. The equation could be also written in the following ways, all being functionally identical (assuming that Climate Zone has two outcomes, Temperate and Desert):

toa=zone="Desert" ? Normal(22,5) : Normal(11,10)

toa=zone="Temperate" ? Normal(11,10) : Normal(22,5)

toa=Switch(zone, "Desert",Normal(22,5),"Temperate",Normal(11,10))

toa=Choose(zone,Normal(11,10),Normal(22,5))

To create the arc from Outside Air Temperature to Perceived Temperature the program calls Network.addArc. The model loaded from disk had 5 discretization intervals already defined for Outside Air Temperature. With 5 possible discretized outcomes of its single parent and its own 3 outcomes, the CPT for Perceived Temperature has 3*5=15 entries. It is initialized by a call to Network.setNodeDefinition with an appropriately sized array as input. Note that for simplicity we do not change the default uniform distribution for the binary Climate Zone node.

The program performs inference for each of the Climate Zone outcomes set as evidence. The output displayed for the Outside Air Temperature node (toa) shows changing mean and standard deviation. Finally, the network is saved to disk. This concludes the tutorial.