Introduction

<< Click to Display Table of Contents >>

Navigation:  Using GeNIe > Equation-based and hybrid models > Writing equations in GeNIe >

Introduction

Equations in GeNIe may involve variables (nodes), their states, numerical and text constants, tied with each other by means of operators and functions. The following Definition dialog shows an explicit equation defining the variable a as a function of two variables, f and m, and a constant representing normal noise in the interaction.

newton_a

The lower-right pane of the dialog shows the list of variables/nodes involved in the interaction (this list includes the current node and all its parents). Adding another node existing in the model is possible, even if the node is currently not a parent of the current node. The upper-right pane shows a list of functions and probability distributions available in GeNIe. Selecting them (by a mouse click) places them in the dialog and allows for editing their formal parameters.

Auto-completion

Pressing Ctrl+Space when editing an equation prompts for allowable elements. Normally, Ctrl+Space will pop-up an alphabetically ordered list of GeNIe functions.

newton_a_editing

Pressing a letter will show functions starting with that letter. Pressing n, for example, yields

newton_a_editing1

Typing several letters in a sequence will position the selection at the element starting with the prefix typed.

Ctrl+Space helps also with selecting states of discrete nodes. Let a parent of a be a variable planet with four outcomes: Earth, Mars, Jupiter, and Venus. Pressing Ctrl+Space after typing the double quote in the equation box opens an auto-complete list of relevant state names.

newton_a_editing2

This feature does not perform parsing of the entire expression, only tokenization, so the resulting expression may not always be valid. Pressing OK at the end of editing will perform full validation and check whether the equation is syntactically valid.

Numerical equivalent of state IDs

While all expressions evaluate ultimately to numbers, there is one translation to numbers that deserves special attention. It is the translation of state IDs of discrete nodes to their indexes. When used in expressions, discrete state IDs translate naturally to integers between 0 and n-1, where n is equal to the number of states. The integer number corresponding to a state ID is determined by the order of states. The first state in the definition is assigned 0, the second, 1, etc. Thus,

If(Planet="Earth",9.81,10)

is equivalent to

If(Planet=0,9.81,10)

The Switch() function allows for its first argument to be a node ID. In that case, the current node's state evaluates to an integer. For example:

Switch(Planet,0,9.81,1,5.2,2,10,3,12.4,0,100)

will yield 9.81, 5.2, 10, and 12.4 if the current state of the variable Planet is Earth, Mars, Jupiter and Venus respectively and 100 (the default value) in case variable Planet has more than four states.

Translation of the state ID to an integer happens with all comparison operators (=, <, >, <=, >=, and <>). In case of the < and > operators, it is not the alphabetical order of IDs that is compared but their order in the node definition! This allows, for example, for Water>="Medium" to evaluate to 1 for "Medium" and "High", assuming that state High comes after Medium, regardless of the alphabetical ordering of Medium and High.

Wherever an equation expects a logical expression, equality operator can be abbreviated by omitting the variable name and the operator. For example, Water="Medium" can be abbreviated to "Medium". While it is perfectly legal to rely on the defaults, we do advise to be explicit in the expressions for the sake of modeling clarity. Additionally, being explicit makes models more robust to future model modifications.

At this point, GeNIe does not rename literals in the equations of the child nodes when parent definition changes, so when this happens, the user has to carefully check the literals in the child node definitions.

Equations evaluating to a constant

An equation node is considered to be a constant if it has no references to variables or distributions on the right-hand side of the equation. The following equation, for example, will evaluate to a constant:

x=Sin(Pi()/3)

There is no runtime penalty for writing an equation this way rather than x=0.866025, which is what Sin(Pi()/3) evaluates to. GeNIe evaluates constants once, before entering sampling loops, so sampling code will refer to the value 0.866025 and not Sin(Pi()/3).