Node value & evidence

<< Click to Display Table of Contents >>

Navigation:  Using SMILE > Anatomy of a node >

Node value & evidence

The value of the node contains the values (typically, the marginal probability distribution or the expected utilities) calculated for the node by the inference algorithm. Unlike the definition, the value is not written as part of the network by DSL_network::WriteFile and WriteString. Like the definition, the value object is managed by the network. The actual value object, which you can access through DSL_node::Value method, is an instance of the class derived from DSL_nodeValue. SMILE chooses the class appropriate for the node type during node creation.

In addition to the numeric output of the inference algorithm, the node value object may contain the evidence for the node, which is (along with node definition) part of the input to the inference algorithm. To set and remove the evidence, use DSL_nodeValue::SetEvidence and ClearEvidence methods. As with the definition part of node, most of the time there is no need to cast the pointer returned by DSL_node::Value to specific class, because the base class provides the set of general purpose virtual functions overriden by derived value classes.

int evidenceNodeHandle = …

DSL_nodeValue *evVal = net.GetNode(evidenceNodeHandle)->Value();

evVal.SetEvidence(1); 1 is the 0-based outcome index


int beliefNodeHandle = …;

DSL_nodeValue *beVal = net.GetNode(beliefNodeHandle)->Value();

if (beVal->IsValueValid())


 const DSL_Dmatrix *m = beVal->GetMatrix();

 // read the matrix contents


Note that before accessing the actual numeric value of the node with GetMatrix we need to check if the value is valid by calling IsValueValid. The value will not be valid if inference algorithm was not called yet, or some definition or evidence has changed after the last inference call.

It is also possible to specify the virtual evidence using DSL_nodeValue::SetVirtualEvidence method. Virtual evidence allows for entering uncertain observation (in form of probability distribution over the possible states of the observation) directly into the normally unobservable variable. SetVirtualEvidence requires a std::vector<double> with a size equal to the number of node outcomes. The following snippet show how to set virtual evidence for a node with tree outcomes:

int evidenceNodeHandle = …

DSL_nodeValue *evVal = net.GetNode(evidenceNodeHandle)->Value();

std::vector<double> virtEv(3);
virtEv[0] = 0.2; virtEv[1] = 0.7; virtEv[2] = 0.1;