Equation-based nodes

<< Click to Display Table of Contents >>

Navigation:  Using SMILE > Continuous models >

Equation-based nodes

To create an equation node, use DSL_EQUATION node type when creating a node with DSL_network::AddNode. The node equation will be initialized to id=0, where id is the node identifier passed to AddNode. The definition of the equation node is represented by an object of the DSL_equation class. The code snippet below changes the default equation of the freshly created node (x=0) to an equation representing the standard Gaussian distribution: x=Normal(0, 1).

DSL_network net;

int hx = net.AddNode(DSL_EQUATION, "x");

auto eqDefX = net.GetNode(hx)->Def<DSL_equation>();

eqDefX->SetEquation("x=Normal(0,1)");

SMILE defines many functions for use in node equations. The complete list of functions is available in the Equations section in the reference chapter of this manual. Among these functions, there are random generators, each of which generates a single sample based on the passed parameters. In the example above, the Normal is the name of SMILE's random generator function which draws samples from normal distribution.

Node equations can reference other nodes by using their identifiers. Continuing with our code snippet:

int hy = net.AddNode(DSL_EQUATION, "y");

auto eqDefY = net.GetNode(hy)->Def<DSL_equation>();

eqDefY->SetEquation("y=2*x");

Second node is added and its equation is set to y=2*x, where x is a reference to the previously defined node. SMILE adds an arc between x and y automatically and it is not necessary to call DSL_network::AddArc before setting the equation referencing other nodes. Calling AddArc will change the child node equation by adding a term representing the parent node as a last term on the right hand side of the child equation. Assuming network with equation nodes a, b, c and d and d's equation set to d=Normal(a, 1)+Normal(b, 2), calling AddArc to with node handles of c and d would rewrite d's equation to d=Normal(a, 1)+Normal(b, 2)+c.

If an arc is removed, either by calling DSL_network::RemoveArc or DSL_network::DeleteNode on one of the parents, the node equation will be rewritten as sum of the remaining parents. This ensures that equations and arcs are always in sync. If node b would be removed with DeleteNode, or an arc from b to d would be removed by RemoveArc, d's equation would become d=a+c.

Node identifier changes are propagated to all equations referring that node. If the identifier of the first node from the code snippet above were changed from x to x_prime, the equation of node y would change to y=2*x_prime.

The equation nodes can be unbounded, semi-bounded or bounded. The bounds are defined with DSL_equation::SetBounds.

See the DSL_equation reference for details.