Tutorial 7: Continuous model

<< Click to Display Table of Contents >>

Navigation:  Tutorials >

Tutorial 7: Continuous model

The continuous Bayesian network used in this tutorial focuses on a fragment of a forced air heating and cooling system. In order to improve the system's efficiency, return air is mixed with the air that is drawn from outside. Temperature of the outside air depends on the weather and is specified by means of a Normal distribution. Return air temperature is constant and depends on the thermostat setting. Damper control signal determines the composition of the mixture.

continuous

Temperature of the mixture is calculated according to the following equation: tma=toa*u_d+(tra-tra*u_d), where tma is mixed air temperature, toa is outside air temperature, u_d is the damper signal, and tra is return air temperature.

The nodes in this model are created by the helper function createEquationNode. It is a modified version of the createCptNode function used in the previous tutorials. The bold text marks the difference between two functions.

static int createEquationNode(

        Network net, String id, String name,

                String equation, double loBound, double hiBound,

                int xPos, int yPos) {

    int handle = net.addNode(Network.NodeType.EQUATION, id);

            net.setNodeName(handle, name);

            net.setNodeEquation(handle, equation);

            net.setNodeEquationBounds(handle, loBound, hiBound);

            

            net.setNodePosition(handle, xPos, yPos, 85, 55);

         

 return handle;

}

Instead of discrete outcomes, we specify the node equation and the bounds for the node value. Another helper function, setUniformIntervals, is used to define the discretization intervals. They will be used by the inference algorithm when the evidence is set for Mixed Air Temperature node (which has parents). The uniform intervals are chosen for simplicity here; in general case the choice of interval edges should be done based on the actual expected distribution of the node value (for example, in case of the Normal distribution, we might create narrow discretization intervals close to the mean.)

Note that while the model has three arcs, there are no calls to Network.addArc in this tutorial. The arcs are created implicitly by Network.setNodeEquation method (called by createEquationNode function).

The network is complete now and we can proceed to inference. Three inference calls are made, one without evidence and two with continuous evidence specified by calling Network.setContEvidence. Setting the Outside Air Temperature to 28.5 degrees (toa is the name of int variable holding the handle of the Outside Air Temperature node):

Java:

net.setContEvidence(toa, 28.5);

Python:

net.set_cont_evidence(toa, 28.5)

C#:

net.SetContEvidence(toa, 28.5);

The program uses updateAndShowStats helper function for inference. The helper calls Network.updateBeliefs and iterates over the nodes in the network and calls another helper, showStats, for each node. showStats first checks if the node has evidence set. If it does, the evidence value is printed, and the function returns. If node has no evidence, we need to check if its value comes from the sampling or discretized inference.

If discretization was used, Network.isValueDiscretized returns true. In such case, the array returned from Network.getNodeValue contains the probability distribution over node discretization intervals. To display human-readable information about the intervals and probabilities, showStats calls Network.getNodeEquationDiscretization and getNodeEquationBounds. Note that the program setup these node attributes in createEquationNode.

If node value was sampled, Network.isValueDiscretized returns false. Network.getNodeValue returns the array of sampled node values. After sampling, it's also possible to obtain sample statistics (mean, standard deviation, min and max values) with a call to Network.getNodeSampleStats.

At the end of the tutorial, the model is saved to disk. Tutorial 8 will expand it into a hybrid network by adding CPT nodes.