First steps with Elvira

Version 0.11

  1. Introduction
  2. Bayesian networks
  3. 2.1. Presentation
    2.2. Editing BNs
    2.3. Inference
    2.4. Canonical models
  4. Influence diagrams
  5. 3.1. Edition
    3.2. Evaluation
  6. Final remarks

1. Introduction

The software package Elvira is the fruit of a research project supported by the CICYT (a national research agency) and the Spanish Ministry of Science and Technology as a join effort of several Spanish universities, in collaboration with two Mexican researchers.

Elvira is a tool for building and evaluating graphical probabilistic models, more specifically Bayesian networks and influence diagrams. Elvira has its own format for the coding of models, a parser, a graphical interface for the construction of networks, with options for canonical models (OR-, AND-, and MAX-gates), exact and approximate algorithms for both discrete and continuous variables, explanation methods, decision-making algorithms, learning from databases, fusion of networks, etc.

Elvira is written and compiled in Java, which allows it to run on different architectures and operating systems (MS-DOS/Windows, linux, Solaris, etc.).

Warning.  Version 0.11 of this manual accompanies the January 2003 release of Elvira. You may obtain a more recent version of Elvira through the installation page

2. Bayesian networks

2.1. Presentation

Elvira's main screen has the following elements:

  1. The menu bar offers seven options: File, Edit, View, Tasks, Options, Window and Help, although, unfortunately, the current version of Elvira offers no on-line help.
  2. The first toolbar contains icons for creating, opening and saving networks, zooming, obtaining information about Elvira, and selecting the working mode: namely Edit, Inference or Learning.
  3. The second toolbar varies in accordance with the selected working mode. The Edit toolbar, shown in the above figure, has icons for several operations: cut, copy, paste, undo, and redo, as well as five icons for choosing the edit tool, which may be one the following:
  4. The message window and the network windows are displayed below the second toolbar. The above figure shows the network Example1.

2.2. Editing BNs

Let's assume we wish to solve the following problem by using Elvira:

Example 1.   For a disease whose prevalence is 8% there exists a test having a 75% sensitivity and a 96% specificity. What are the predictive of the test w.r.t. the disease?

In this problem there are two variables involved: Disease and Test. The disease can have to values, present and absent, and the test can give two results: positive and negative. Since the first variable causally influences the second, we will draw a link Disease->Test.

2.2.1. Creation of the network

In order to create a network in Elvira, we clic on the Icon Create a new network (), which is in the first toolbar. This opens the Network properties window. The default network type is Bayesian network, so we do not have to modify this value. In the Network name field we write Example1. Then we clic on the Accept button.

2.2.2. Structure of the network (graph)

In order to add the nodes, we clic on the Add random node () in the second toolbar.

Then we clic on the point were we wish to place the node Disease. By double-clicking on this node, we open the Node properties window. In the Title field in this window we write Disease. By clicking on the Values tab in the same window we can check that the values that Elvira has assigned by default are "present" and " absent", which are just what we wished. The we clic on the Accept button.

In the same way, we create the second node, we double-clic on it to open the Node properties window and write Test in the Title field. In the Values tab we open the pull-down menu Type of values and select Positive-negative. Then we clic on the Accept button to close the window.

We complete the graph by adding a link from the first node to the second. First we have to change the Add random node tool () by the Add directed link tool (), which is also on the second toolbar. Then we drag the mouse from the origin node, Disease, to the destiny node, Test. The result must be similar to the above figure.

If you with to move a node, change to the Selection too by clicking on the corresponding icon () on the second toolbar and drag the node with the mouse.

2.2.3. Conditional probabilities

Once we have the nodes and links, we have to introduce the numerical probabilities, namely, a conditional probability table (CPT) for each node.

The CPT for the variable Disease is given by its prevalence, which, according with the statement of the example, is P(Disease=present) = 0.08. We introduce this parameter by double-clicking on the Disease node, selecting the Relation tab, writing 0.08 in the corresponding cell and clicking on pressing Enter. Please note that the bottom cell changes to 0.92, because the sum of the probabilities must be one.

In this figure we can see both probabilities because the All parameters radio button is selected. If we select the Independent parameters radio button we only see the value 0.08--the 0.92 value does not appear, because it is not necessary to display it.

The CPT for the variable Test is built by remembering that the sensitivity (75%) is the probability of a positive test result when the Disease is present, and the specificity (96%) is the probability of a negative test result when the Disease is absent. The CPT introduced into Elvira will look like this:

In principle, the graph of the network does not offer information about the conditional probabilities. However, when clicking on the Show link influences button (), Elvira offers qualitative information about the numerical parameters by drawing links with different colors and widths. A red-colored link represents a positive influence, which, roughly speaking, means that an increase in the value of the parent node implies an increase in the value of the child node. A blue link represents a negative influence. A purple link represents an ambiguous influence, i.e., an influence that is positive for some values and negative for others. The higher the influence, the thicker the link. A black link means that the link does not transmit any influence. Before introducing the CPTs all links are black, because Elvira initially assigns a uniform distribution for each configuration of the parent nodes.

2.2.4. Saving the network

It is recommended to save the network on disk before changing to inference mode. The easiest way to do it is by clicking on the Save network icon (). It is also possible to save a network by means of the File option in the bar menu, by selecting Save network, Save network as... or Save all networks. Finally, if we decide to exit Elvira when there are non-saved changes, a window will ask us if we wish to save the network.

2.3. Propagation of evidence in Elvira

2.3.1. From edit mode to inference mode

After creating and saving the network, let us see how to use it to solve the problem posed in the above section, i.e., how to compute the predictive values of the test w.r.t. the disease. Therefore, we open the pull-down menu on the first toolbar, which displayed the value Edit, and change it to Inference. Elvira will look like this:

:

We can see that the second toolbar has changed: the edit buttons, such as cut, copy and paste, has disappeared, and there are new buttons and fields: expansion threshold, purpose, save case in file, store case in memory, expand/contract node, inference options, etc.

A second change, unnoticed to the user, is that Elvira creates an internal data structure, which will be use to compute the probability of each variable. This process, known as compilation of the network, makes that, in the case of large networks, it may take a few seconds to change from edit mode to inference mode. 

We can also observe that some nodes have been expanded. In fact, in the example we are showing, Elvira shows the probability of each value in two ways: by means of a horizontal bar whose probability is proportional to the probability, and by means of a number. Since we have not introduced any finding yet, these are the prior probabilities. For instance, the probability for Disease=present is 0.08, one of the parameters we introduced after the statement of the problem, while the prior probability for the values of Test has been computed by Elvira. In fact, we can check that
 

P(Test=positive) = P(Test=positive| Disease=present)×P(Disease=present)  
  + P(Test=positive| Disease=absent)×P(Disease=absent)  
= 0.75×0.08 + 0.04×0.92 = 0.0968  
P(Test=negative) = P(Test=negative| Disease=present)×P(Disease=present)  
  + P(Test=negative| Disease=absent)×P(Disease=absent)  
= 0.25×0.08 + 0.96×0.92 = 0.9032  

In principle, Elvira displays the numerical value with two decimal digits. The number of decimals can be increased by selecting the View option in the bar menu and selecting the desired Precision.

2.3.2. Introduction of evidence. Posterior probabilities

The question posed in the above problem was to compute the predictive values. The positive predictive value (PPV) es the certainty with which we can diagnose the Disease then the test gives a positive result: P(Disease=present|Test=positive). The way to compute it with Elvira is to introduce the finding Test=positive and to observe the posterior probability for the value Disease=present.

When double-clicking on the value "positive" of node Test, we observe that its probability is now 1, which means that we know this value with certainty, and the probability of the other value, "Test=negative", is 0, because the values of a variable are mutually exclusive. We also observe that the probability of  Disease=present has increase from 0.08 to 0.62, which is just the value we were looking for:

PPV  = P(Disease=present| Test=positive) = 0.62 = 62%

As expected, this posterior probability is much higher than the prior probability, because a positive result in the test tends to confirm the presence of the Disease.

Analogously, the negative predictive value (NPV) es the certainty with which we can discard the Disease when the Test gives a negative result: NPV = P(Disease=absent|Test=negative). The way to compute it with Elvira is to introduce the finding "Test=negative" and to observe the posterior probability of the value "Disease=absent".

If we are interested also in seeing how the probability of the Disease varies as a function of the result of the Test, we have to store the current evidence case (an evidence case consists of a set of findings. In this example, the only finding we have is the result of the Test), which can be accomplished by means of the button Store case in memory () in the second toolbar. We see that the text field in this toolbar changes from Case number 1 on a red background to Case number 2 on a blue background.

Now that the second evidence case is the current one, we double-clic on the value "negative" of node Test. The probability of "Test=negative" becomes one and the probability of "Test=positive" becomes 0. We also observe that P(Disease=present|Test=negative) = 0.02 and P(Disease=absent|Test=negative) = 0.98. Therefore,

NPV  = P(Disease=absent| Test=negative) = 0.98 = 98%

which solves our problem.

2.3.3. Working with several evidence cases

As said above, in Elvira, an evidence case consists of a set of findings. In our examples, we have considered three cases: This way we can graphically observe the impact of each finding on the rest of the variables, which helps us to understand the behavior of the Bayesian network and, in case we wish to improve the accuracy, we can modify the structure or the probabilities when the results are not what we wish (this process is known as debugging the network).

In the inference bar there is a button for deleting all the findings of the current evidence case, and another button for deleting all the evidence cases (except the initial case, corresponding to the prior probability).

2.4. Canonical models

Elvira is able to represent several canonical models and use its properties to propagate the evidence more efficiently. The next figure corresponds to a node D having three parents, A, B y C. When editing the relation by the first time, Elvira asks whether the variables interact by means of a general model (no restrictions on the CPT) of by an OR/MAX/MIN gate. We assume the interaction is given by a noisy OR such that the probability that each cause produces the effect D is 0.9, 0.75, and 0.7, respectively. When all the explicit causes are absent, the probability of D (due to other causes implicit in the model) is 0.01.

Please note that in this figure we have selected Independent parameters instead of All parameters. We have also selected Canonical parameters. If we select CPT Elvira will show the conditional probability table, computed from the canonical parameters.

3. Influence diagrams

3.1. Edition of influence diagrams

The edition of influence diagrams is similar to the edition of networks. As an example, we can follow the next steps to create the graph of an influence diagram:
  1. Clic on the icon Create new network ( ), select Influence diagram, and write "Therapeutic decision" in the Title field. Introduce the variables Disease and Test, as explained above.
  2. Select the icon Insert decision nodes () and add a node Therapy. After double-clicking on it, select the Values tab and assign the values "yes" and "no". Draw a link Test->Therapy. This is an information link, which means that at the moment of making the decision on Therapy (whether to apply it or not) the result of the Test is already known.
  3. Select the icon Insert utility nodes () and add the node Utility. Draw links Disease->Utility and Therapy->Utility. These two links mean that the state of the patient depends on whether he/she has the Disease or not and on whether he/she receives the Therapy or not.

After editing the graph, we can introduce the conditional probability tables for nodes Disease and Test, as explained in Section 2.2.3. The node Therapy does not have a probability table because it does not represent a random variable, but a decision, which will be made depending on the available information, as will see in the next section. Now, we only have to introduce the utility table for the node Utility.

Therefore, we double-clic on the node Utility and type in the values shown in the following table:

We can save this network on disk.

3.2. Evaluation of an influence diagram

Given the above influence diagram, open the pull-down menu in the first toolbar and change its content from Edit to Inference. This makes Elvira evaluate the influence diagram. To see it, we double-clic on the node Therapy in order to observe the utility corresponding to each decision, which depends on the information available when making the decision (in this example, the information is the result of the test), as shown in the next figure.

From this table we can deduce that when the test gives a positive result the best decision is to apply the Therapy, because it entails a higher expected utility: 83.80 vs. 56.61. On the contrary, when the test gives a negative result, it is better not to apply the Therapy, because the utility of this decision is 98.45,  vs. a utility of 89.78 in case of applying the Therapy..

4. Final remarks

In this introductory manual we have only described the most elementary steps for creating and evaluating Bayesian networks and influence diagrams. In future editions of this manual we will explain more advanced options. Therefore, we recommend you to visit the installation page from time to time to check if there is a more recent version of Elvira and of this manual.

You can also download a user manual of Elvira (360 KB in PDF), by Carmen Lacave.

The source code of Elvira is available from Elvira's home page.

In the future we will try to offer an e-mail list and a FAQ where the users of Elvira can look for answers to their questions. Unfortunately, the author of this page cannot offer support to the users of Elvira.


Javier Díez.  Last update: April 15, 2003.