Expressions

It is possible to specify expressions as a more compact representation of the tables of discrete chance nodes and utility nodes.

From manual table editing mode you can switch to expression editing mode by selecting the Expressions item of the Table menu. You can also select the Specify Expressions button in the Table tab of the Node Properties dialog.

If you have chosen to edit the table of a discrete chance node or utility node in expression mode, you will see the label "Expression" in the left most column, below the parent labels (if any). Figure 1 shows the expression table of a discrete chance node in the node edit pane.

Figure 1: The node edit pane showing the expression table of a discrete chance node.

In expression mode, you can type in expressions in the table fields. If you are not that familiar with the expression language, you can use the node types are introduced.

The functions specified by expressions also differ in that some are deterministic functions specifying the exact state of a node, eg: nPeople = "nMen + nWomen" whereas others are distribution functions specifying the probability distribution of the states, eg: P(nSix) = "Binomial(nDice, 1/6)". There are a limited number of distribution functions available so Hugin will know how to interpret the expression you write.

The building blocks available for expressions are listed below.

Constant Values

The following kinds of constants can be used in expressions: state labels, numeric values, and Boolean values.

State labels must be encapsulated in quotation characters (").

Numeric values are typed in as you would probably expect to do - without any encapsulating characters or other formatting stuff: Eg. "X + 3.4" (here, the quotation characters are used only to separate the expression from the rest of the text - it has nothing to do with state labels as discussed above).

There are two Boolean constant values: "false" and "true". Notice that the Boolean constants must be lower case.

Discrete Distribution Functions

These distribution functions are available for numbered nodes only. You type a distribution function as the function name followed by a comma separated list of arguments in brackets. Eg. "Binomial(4, 0.2)".

Function Node requirements Comments Arguments Arg. range
Binomial Numbered: 0, 1, 2, ... , n   n 0, 1, 2, ...
p [0,1]
Negative Binomial Numbered: 0, 1, 2, ... , n n will get prob. mass of n, n+1, ... n 0, 1, 2, ...
p [0,1]
Poisson Numbered: 0, 1, 2, ... , n n will get prob. mass of n, n+1, ... Mean ]0, inf[
Geometric Numbered: 0, 1, 2, ... , n n will get prob. mass of n, n+1, ... p [0, 1]

Continuous Distribution Functions

These distribution functions are available for interval nodes.

Function Node requirements Comments Arguments Arg. range
Normal Interval. First state must start in -inf. Last interval must end in inf.   Mean ]-inf, inf[
Variance ]0, inf[
Beta Interval. First state must start below Lower. Last interval must end after Upper (see arguments). If not specified, arguments Lower and Upper will be 0 and 1, respectively Alpha ]0, inf[
Beta ]0, inf[
Lower (optional) ]-inf, Upper[
Upper (optional) ]Lower, inf[
Gamma Interval: First state must start below 0. Last interval must end in inf.   Shape ]0, inf[
Scale ]0, inf[
Exponential Interval: First state must start below 0. Last interval must end in inf.   Lambda ]0, inf[
Weibull Interval: First state must start below 0. Last interval must end in inf.   Shape ]0, inf[
Scale ]0, inf[
Uniform Interval: The state intervals must cover Lower and Upper - at least in end points (see arguments).   Lower ]-inf, Upper[
Upper ]Lower, inf[

Arithmetic Functions

The arithmetic functions can be used in deterministic expressions for numbered nodes, interval nodes, and utility nodes. They can also be used in all kinds of functions taking numeric arguments. Below are listed the arithmetic functions:

+ (sum)
- (subtract, negate)
* (multiply)
/ (divide)
^ (power)
min
max
log
log2
log10
exp
sqrt
sin
cos
tan
sinh
cosh
tanh

The first four arithmetic functions (operators) use infix notation: "A + B". The rest have prefix notation: "max(A, B, 0.7)".

Boolean Functions

The Boolean functions can be used in deterministic expressions for Boolean nodes. They can also be used in all kinds of functions taking Boolean arguments. The Boolean functions are:

and
or
not

Boolean functions have infix notation: "and(or(X, Y), A, B)".

Comparison Operators

The comparison operators can be used in deterministic expressions for Boolean nodes. They can also be used in all kinds of functions taking Boolean arguments. Below are listed the comparison operators:

= (equals)
!= (equals not)
< (less than)
> (greater than)
<= (less than or equals)
>= (greater than or equals)

All comparison operators can be used to compare numeric values. The equality comparison operators (= and !=) can also be used to compare Boolean values and labels. All comparison operators use infix notation: "A = 14".

The if-then-else Function

The if-then-else function takes three arguments: The first argument is the Boolean condition determining if the function should return the second or third argument as the result. Eg. "if(false, "yes", "no")" would return "no".

The if-then-else function can be used to combine both deterministic functions and distribution functions. Eg. if you are building a system for predicting how many times you will roll six with a number of dice, you could be in a situation where you were uncertain about whether the dice were fair or not, having probability 1/6 and 1/2 for rolling six respectively. If you have a Boolean node "DiceFake" representing this uncertainty, you could specify one of these two expressions:

"Binomial(nDice, if(DiceFake, 1/2, 1/6))"

or

"if(DiceFake, Binomial(nDice, 1/2), Binomial(nDice, 1/6)"


Back