Arcs

<< Click to Display Table of Contents >>

Navigation:  Using SMILE > Networks, nodes and arcs >

Arcs

SMILE does not define a class representing an arc between nodes. When you call DSL_network::AddArc method, the internal data structures are updated to keep the relationship between the parent and child node. To remove an arc, call DSL_network::RemoveArc. Arcs are automatically removed when either the parent or the child node represented by the arc is deleted.

The graph defined by nodes and arcs in DSL_network is an acyclic directed graph (DAG) at all times. If your call to AddArc would result in a cycle in the graph, the method fails and returns DSL_CYCLE_DETECTED.

To inspect the graph structure, use DSL_network::GetParents and GetChildren methods, which return a const reference to the DSL_intArray object containing the handles of theparents/children:

int nodeHandle = …;

const DSL_intArray& parents = net.GetParents(nodeHandle);

for (int i = 0;i < parents.GetSize(); i ++)

{

    printf("Parent %d: %d %s\n", i, parents[i], net.GetNode(parents[i]->GetId());

}

const DSL_intArray& children = net.GetChildren(nodeHandle);

for (int i = 0; i < children.GetSize(); i ++)

{

    printf("Child %d: %d %s\n", i, children[i], net.GetNode(children[i]->GetId());

}

To check if an arc exists, use DSL_intArray::Contains with either parents or children array. For example, if an arc exists betwen h1 and h2 both net.GetParents(h2).Contains(h1) and net.GetChildren(h1).Contains(h2) will return true.

To check if two nodes are connected by an arc irrespective of its direction, use DSL_network::Related function. DSL_network::GetAncestors and GetDescendants return all ancestors and descendants of the node.

Arcs can be reversed with DSL_network::ReverseArc. This operation preserves the joint probability distribution represented by the network.

After adding an arc with AddArc, the child node's probability distribution is expanded to accommodate the parent, but the actual probabilities in the distribution are copied. Call DSL_network::IsArcNecessary to verify if the child node's conditional dependencies expressed by different probabilities in its probability table.