Equation-based nodes

<< Click to Display Table of Contents >>

Navigation:  Using SMILE Wrappers > Continuous models >

Equation-based nodes

To create an equation node, use Network.NodeType.EQUATION node type when creating a node with Network.addNode. The node equation will be initialized to id=0, where id is the node identifier passed to addNode. 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).

Java:

int hx = net.addNode(Network.NodeType.EQUATION, "x");
net.setNodeEquation(hx, "x=Normal(0,1)");

Python:

hx = net.add_node(pysmile.NodeType.EQUATION, "x")

net.set_node_equation(hx, "x=Normal(0,1)")

R:

hx <- net$addNode(net$NodeType$EQUATION, "x")
net$setNodeEquation(hx, "x=Normal(0,1)")

C#:

int hx = net.AddNode(Network.NodeType.Equation, "x");

net.SetNodeEquation(hx, "x=Normal(0,1)");

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

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

Java:

int hy = net.addNode(Network.NodeType.EQUATION, "y");
net.setNodeEquation(hx, "y=2*x");

Python:

hy = net.add_node(pysmile.NodeType.EQUATION, "y")

net.set_node_equation(hy, "y=2*x")

R:

hy <- net$addNode(net$NodeType$EQUATION, "y");
net$setNodeEquation(hx, "y=2*x");

C#:

int hy = net.AddNode(Network.NodeType.Equation, "y");

net.SetNodeEquation(hx, "y=2*x");

Second node is added and its equation is set to y=2*x, where x is a reference to previously defined node. SMILE adds an arc between x and y automatically and it is not necessary to call 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 Network.deleteArc or 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 deleteArc, d's equation would become d=a+c.

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