<< Click to Display Table of Contents >> Navigation: Introduction > Embedding decision-theoretic methodology into custom software |
GeNIe allows for interactive model building and examination. Every action performed in GeNIe is translated to a call to SMILE, GeNIe's API. It is possible to automate these actions and embed decision-theoretic methodology into user software by accessing SMILE directly. We offer a collection of wrappers that allow for accessing SMILE from a variety of programming languages. This makes it possible to embed decision-theoretic methods into existing enterprise software. It is just a matter of linking SMILE with the existing software and communicating with it through SMILE API calls. Calls to SMILE are simple and intuitive and can be used by any programmer.
Here is a Python code sample that illustrates loading a previously saved model (VentureBN.xdsl), entering evidence, and obtaining results:
import pysmile
def hello_smile():
net = pysmile.Network()
net.read_file("VentureBN.xdsl");
net.set_evidence("Forecast", "Moderate")
net.update_beliefs()
beliefs = net.get_node_value("Success")
for i in range(0, len(beliefs)):
print(net.get_outcome_id("Success", i) + "=" + str(beliefs[i]))
hello_smile()
Java code for the same problem:
import smile.*;
public class Hello {
public static void main(String[] args) {
Network net = new Network();
net.readFile("VentureBN.xdsl");
net.setEvidence("Forecast", "Moderate");
net.updateBeliefs();
double[] beliefs = net.getNodeValue("Success");
for (int i = 0; i < beliefs.length; i ++) {
System.out.println(
net.getOutcomeId("Success", i) + " = " + beliefs[i]);
}
}
}
R code for the same problem:
library(rSMILE)
net <- Network()
net$readFile("VentureBN.xdsl")
net$setEvidence("Forecast", "Moderate")
net$updateBeliefs()
beliefs <- net$getNodeValue("Success")
for (i in 1:length(beliefs)) {
cat(sprintf(
"%s = %f\n", net$getOutcomeId("Success", i-1L), beliefs[i]))
}
C# code for the same problem:
using System;
using Smile;
namespace SmileNetTutorial
{
class Hello
{
static void Main(string[] args)
{
Network net = new Network();
net.ReadFile("VentureBN.xdsl");
net.SetEvidence("Forecast", "Moderate");
net.UpdateBeliefs();
double[] beliefs = net.GetNodeValue("Success");
for (int i = 0; i < beliefs.Length; i++)
{
Console.WriteLine("{0} = {1}",
net.GetOutcomeId("Success", i),
beliefs[i]);
}
}
}
}
Finally, here is C++ (native to SMILE) code sample for the same problem:
#include <cstdio>
#include <smile.h>
int main()
{
DSL_errorH().RedirectToFile(stdout);
DSL_network net;
int res = net.ReadFile("VentureBN.xdsl");
if (DSL_OKAY != res)
{
return res;
}
net.GetNode("Forecast")->Val()->SetEvidence("Moderate");
net.UpdateBeliefs();
DSL_node* sn = net.GetNode("Success");
const DSL_Dmatrix& beliefs = *sn->Val()->GetMatrix();
const DSL_idArray& outcomes = *sn->Def()->GetOutcomeIds();
for (int i = 0; i < outcomes.GetSize(); i++)
{
printf("%s=%g\n", outcomes[i], beliefs[i]);
}
return DSL_OKAY;
}