The program

<< Click to Display Table of Contents >>

Navigation:  Hello, SMILE Wrapper! >

The program

We will show how to load this model using SMILE, how to enter observations (evidence), how to perform inference, and how to retrieve the results of SMILE’s calculations. Three complete source code versions (Java, Python, R, C#) are included below. Note that you'll need to use your SMILE license key. See the Licensing section of this manual if you want to obtain your academic or trial license key. See Platforms and Wrappers section for language-specific information on licensing.

Our network object - an instance of Network class is declared as local variable. We proceed to read the XDSL file from disk:

Java:   net.readFile("VentureBN.xdsl");

Python: net.read_file("VentureBN.xdsl")

R:             net$readFile("VentureBN.xdsl")

C#:     net.ReadFile("VentureBN.xdsl");

We want to set the evidence on the Forecast node to Moderate. The wrappers can use node and outcome identifiers directly:

Java:   net.setEvidence("Forecast", "Moderate");

Python: net.set_evidence("Forecast", "Moderate")

R:      net$setEvidence("Forecast", "Moderate")

C#:     net.SetEvidence("Forecast", "Moderate");

Now we can update the network:

Java:   net.updateBeliefs();

Python: net.update_beliefs()

R:      net$updateBeliefs()

C#:     net.UpdateBeliefs();

After network update we can retrieve the posterior probabilities of the Success node:

Java:   double[] beliefs = net.getNodeValue("Success");

Python: beliefs = net.get_node_value("Success")

R:      beliefs <- net$getNodeValue("Success")

C#:     double[] beliefs = net.GetNodeValue("Success");

To print the probabilities, we simply iterate over the elements of the returned numeric array. Each probability printed to the console is preceeded by the identifier of the node outcome. If you compile and run the program, the output should be:

Success=0.25

Failure=0.75

“Success” and “Failure” are outcome identifiers of the Success node, which in Java are returned by the Network.getOutcomeId method. At this point you should easily derive the equivalent method names for Python, R and C# from Java method name.

Note that in case of any of method calls failing, the exception would be thrown. SMILE wrappers do not use error codes on failure.

We will build upon the simple network described in this chapter in the Tutorials section of this manual.