Nodes

<< Click to Display Table of Contents >>

Navigation:  Using SMILE Wrappers > Networks, nodes and arcs >

Nodes

Use the following methods to add and delete nodes:

Java:

Network.addNode

Network.deleteNode

Python:

Network.add_node

Network.delete_node

R:

Network$addNode

Network$deleteNode

C#:

Network.AddNode

Network.DeleteNode

When creating the node you need to specify its type.

Within the network, the nodes are uniquely identified by their handle. The node handle is a non-negative integer, which is preserved when network is copied. In addition to handles, each node has an unique (in the context of its containing network), persistent, textual identifier. This identifier is specified as an argument to Network.addNode method at node creation (it may be changed later). The identifiers in SMILE start are case-sensitive, start with a letter and contain letters, digits and underscores. Node’s identifier can be converted to node handle with a call to Network.getNode method.

All methods of the Network class dealing with nodes can use either integer node handles or string identifiers to specify the nodes. However, the versions using identifiers will be internally performing O(N) string lookup (where N is the number of nodes in the network), while the versions using handlers are only using O(1) validity check.

The values of the handles are not guaranteed to be consecutive or start from any particular value. To iterate over nodes in the network, use Network.getFirstNode and getNextNode:

Java:

for (int h = net.getFirstNode(); h >= 0; h = net.getNextNode(h)) {

    // do something with net and node identified by h

}

Python:

h = net.get_first_node()

while (h >= 0):

    # do something with net and node identified by h

    h = net.get_next_node(h)

R:

for (h in net$getAllNodes()) {

    # do something with net and node identified by h

}

C#:

for (int h = net.GetFirstNode(); h >= 0; h = net.GetNextNode(h))

{

 // do something with net and node identified by h

}

Note the loop exit condition - we proceed only if the returned handle is greater than or equal to zero.

Here are the methods to obtain an array of all node handles, an array of all node identifiers or a number of nodes in the network:

Java:

Network.getAllNodes

Network.getAllNodeIds

Network.getNodeCount

Python:

Network.get_all_nodes

Network.get_all_node_ids

Network.get_node_count

R:

Network$getAllNodes

Network$getAllNodeIds

Network$getNodeCount

C#:

Network.GetAllNodes

Network.GetAllNodeIds

Network.NodeCount (read-only property)

Nodes may be marked as targets with Network.setTarget method. Target nodes are always guaranteed to be updated by the inference algorithm. Other nodes, i.e., nodes that are not designated as targets, may be updated or not, depending on the internals of the algorithm used, but are not guaranteed to be updated. Focusing inference on the target nodes can reduce time and memory required to complete the calculation. When no targets are specified, SMILE assumes that all nodes are of interest to the user.