# Tutorial 1 - A simple network

In this tutorial we will manually build the simple Bayesian network shown below, and calculate some queries.

##### NOTE

It is also possible to learn a model from data, using the following features.

The crude network is for the identification of UK adults. Although the network is fictitious, it demonstrates some key concepts.

The following concepts will be covered:

• Discrete variables
• Continuous variables
• Query Explorer

## Creating the model

• Click New on the File tab to create a new empty network.

• To add the Gender node, click Node on the Network tab, Editing group, to create a new node. This will launch the New node window.

• Enter Gender in the Name text box.

• In the Variable section, rename the states to the following values, by clicking on the name of each state, and typing the new name.

• Female

• Male

The New Node window should look like this:

• Click the OK button to create the new node.

• To add the Hair Length node, click Node on the Network tab, Editing group, to create a new node. This will launch the New node window.

• Enter Hair Length in the Name text box.

• Rename the states to the following values, by clicking on the name of each state, and typing the new name.

• Short

• Medium

• Long

The New Node window should look like this:

• Click the OK button to create the new node.

• To add the Height node, click Node on the Network tab, Editing group, to create a new node. This will launch the New node window.

• Enter Height in the Name text box.

• This node will contain a continuous variable, so in the Variable section, click the Continuous tab.

The New Node window should look like this:

• Click the OK button to create the new node.

##### NOTE

Note that if we have data, we could have added the nodes automatically using the Add nodes from data feature.

• To add the first link, click the Link button on the Network tab, Editing group. This will launch the New link window.
• Select Gender as the From node.
• Select Hair Length as the To node.
• Click the OK button to create the new link.
• To add the second link, click the Link button on the Network tab, Editing group. This will launch the New link window.
• Select Gender as the From node.
• Select Height as the To node.
• Click the OK button to create the new link.
##### NOTE

Note that if we have data, we could have tried adding links automatically using Structural learning.

### Create the distributions

##### NOTE

You can also launch the Distribution editor from the Node toolbar.

• Enter the following probability values for `P(Gender)`.

Gender = Female Gender = Male
0.51 0.49

The distribution should look like this:

• Click the OK button to assign the distribution.

• Select the Hair Length node in network viewer and then click the Distribution button on the Network tab, Editing group. This will launch the Distribution editor.

• Enter the following probability values for `P(Hair Length | Gender)`.

Gender Hair Length = Short Hair Length = Medium Hair Length = Long
Female 0.1 0.4 0.5
Male 0.8 0.15 0.05

The distribution should look like this:

• Click the OK button to assign the distribution.

• Select the Height node in network viewer and then click the Distribution button on the Network tab, Editing group.

This will launch the Distribution editor.

• In the table on the left, click the cell corresponding to Gender=Female, containing the value 1.

• Enter the following values for `P(Height | Gender=Female)` in the table on the right.

Mean Variance
162.56 50.58

The distribution should look like this:

• In the table on the left, click the cell corresponding to Gender=Male, containing the value 1.

• Enter the following values for `P(Height | Gender=Male)` in the table on the right.

Mean Variance
176.022 50.58

The distribution should look like this:

• Click the OK button to assign the distribution.

The Bayesian network is now complete.

##### NOTE

Note that if we have data, we could have automatically learned the distributions using Parameter learning.

## Calculate queries

• Click the All button with the green arrow at the bottom of network viewer, shown below, or use the shortcut F6.

##### NOTE

This will add a query for each node in the network (called marginals). As well as being visible in Network Viewer the queries will also be visible in Query Explorer.

• Click the Query Explorer button on the View tab, Explorers group, to ensure that Query explorer is open.

• Click the Add Custom button on the Query Explorer contextual tab, Queries group. This will launch the Custom query window, and allow us to add a joint or conditional query.

• Select the Gender and Height variables in the upper list, and then click the Add Head button.

The window should look like this:

• Click the OK button to add the new query to Query explorer.

Query explorer should now look like this:

##### NOTE

Note that you can perform an ad-hoc custom query without having to add it to query explorer, using the Custom button, Query Tab on the main ribbon toolbar.

## Enter evidence

• Click the Short check-box on the Hair Length node in Network viewer to set evidence.

Notice how the distributions in Query explorer have changed: