<< Click to Display Table of Contents >> Navigation: Using GeNIe > Equation-based and hybrid models > Writing equations in GeNIe > Functions > Custom functions |
User can define custom functions, which can be subsequently used in a variable definition. Custom functions are defined in the Functions tab of the Network properties dialog. The following sheet contains three definitions of functions: o2p(), p2o(), and tang(), used to convert odds to probabilities, probabilities to odds, and a redefinition of the tan() tangent function. GeNIe functions may not be recursive but they may refer to functions defined earlier (in the same Functions tab).
It is possible to test the newly defined functions by evaluating calls to them with concrete values of parameters at the bottom of the tab. Please note that arguments of the evaluated function have to evaluate to constants (even if these constants are randomly generated by reference to a random number generator, e.g., MyCustomFunc(Normal(0,1))).
User-defined functions (also called Custom functions) are defined per network and stored along with the network. GeNIe copies user-defined functions between networks when nodes using them are copied from a source network and pasted in the destination network. In this case, conflicts may occur, for example a function with the same definition may exist already in the destination network. GeNIe performs a simple check of the name of the function, its number of parameters, and determinism status (i.e., whether the function makes calls to random number generators) and will use the definition in the destination network if these three agree. Otherwise, it will copy the definition from the source to the destination network. We recommend that meaningful names are used and different definitions of the same function in different models are avoided.
Custom functions defined at the network level appear in the Node properties' Definition tab at the top of the list of functions in the upper-right pane. They can be used in node definitions alongside of the built-in functions.
While this mechanism allows for defining complex expressions that will quite likely satisfy most, if not all, modeling needs, we encourage users to let us know when the set of GeNIe's built-in function should be extended.