Hi, SMILE creators,
Thank you so much for your time! I tried to create a DBN structure file using JSMILE's methods rather than "manual" coding (after successfully running em.learn of the DBN with the given structure file from the tutorial). I tried to create it in a "roll" way in which I don't have to write down all the unrolled variables and arcs. However, I don't find a way to specify number of slices, or specify temporal arcs. Here is the code I constructed:
--------------------------------------------
...
import smile.Network;
import smile.SMILEException;
import smile.learning.DataMatch;
import smile.learning.DataSet;
import smile.learning.EM;
public class CallSmile {
public static void createDBN1(String outfile) {
Network net = new Network();
String[] nodes = { "A", "B", "C" };
for (String n : nodes) {
net.addNode(Network.NodeType.Cpt, n);
net.setOutcomeId(n, 0, "f");
net.setOutcomeId(n, 1, "t");
}
// Adding an arc from "A" to "C", from "B" to "C"
net.addArc("A", "C");
net.addArc("B", "C");
net.addTemporalArc("A", "A", 1); //<-- an error here
// Filling in the conditional distribution for node "A", "B". The probabilities are:
double[] aDef = { 0.5, 0.5 };
net.setNodeDefinition("A", aDef);
net.setNodeDefinition("B", aDef);
// Filling in the conditional distribution for node "C". The probabilities are:
double[] aDef2 = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
net.setNodeDefinition("C", aDef2);
double[] aDef3 = { 0.5, 0.5, 0.5, 0.5 };
net.setNodeTemporalDefinition("A", 1, aDef3);
// Writting the network to a file:
net.writeFile(outfile);
System.out.println("Saved network!");
}
public static void main(String[] args) throws IOException {
createDBN1("net_tut_6_bycode.xdsl");
}
}
---------------------------------------------------
However, it gives me an error as follows with respect to the line "net.addTemporalArc("A", "A", 1)" ("addTemporalArc" is the only method I could find related to adding temporal arcs; its arguments are parentId, childID, and order):
Exception in thread "main" smile.SMILEException: SMILE error -2 in function AddTemporalArc
at smile.Network.addTemporalArc(Native Method)
at CallSmile.createDBN1(CallSmile.java:489)
at CallSmile.main(CallSmile.java:911)
I wonder whether I should explicitly write down the unrolled variables and arcs as follows:
net.addNode(Network.NodeType.Cpt, "A");
net.addNode(Network.NodeType.Cpt, "A_1");
net.addNode(Network.NodeType.Cpt, "A_2");
net.addTemporalArc("A", "A_1", 1);
net.addTemporalArc("A_1", "A_2", 1);
I wonder whether you could give me some hints on resolving this? I really appreciate it!
Yun
PhD, University of Pittsburgh
Create the DBN structure by JSMILE methods
-
- Site Admin
- Posts: 1417
- Joined: Mon Nov 26, 2007 5:51 pm
Re: Create the DBN structure by JSMILE methods
Only nodes residing on a temporal plate can be linked with temporal arcs (this includes self-arcs). You'll need to ensure node A is a plate node:
Other temporal node types are: Contemporal, Anchor and Terminal. By default, a node is Contemporal.
Code: Select all
net.setNodeTemporalType("A", Network.NodeTemporalType.Plate);
Re: Create the DBN structure by JSMILE methods
Thank you so much!!! Now I can use JSMILE methods to create a network same as the the one from the tutorial :)
In case it is useful to others, I am posting the code after fixing the problem:
Network net = new Network();
String[] nodes = { "A", "B", "C" };
int nbSlices = 3;
for (String n : nodes) {
net.addNode(Network.NodeType.Cpt, n);
net.setOutcomeId(n, 0, "f");
net.setOutcomeId(n, 1, "t");
net.setNodeTemporalType(n, Network.NodeTemporalType.Plate);
}
net.setSliceCount(nbSlices);
net.addArc("A", "C");
net.addArc("B", "C");
net.addTemporalArc("A", "A", 1);
double[] aDef = { 0.5, 0.5 };
net.setNodeDefinition("A", aDef);
net.setNodeDefinition("B", aDef);
double[] aDef2 = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
net.setNodeDefinition("C", aDef2);
double[] aDef3 = { 0.5, 0.5, 0.5, 0.5 };
net.setNodeTemporalDefinition("A", 1, aDef3);
net.writeFile("net_tut_6_bycode.xdsl");
In case it is useful to others, I am posting the code after fixing the problem:
Network net = new Network();
String[] nodes = { "A", "B", "C" };
int nbSlices = 3;
for (String n : nodes) {
net.addNode(Network.NodeType.Cpt, n);
net.setOutcomeId(n, 0, "f");
net.setOutcomeId(n, 1, "t");
net.setNodeTemporalType(n, Network.NodeTemporalType.Plate);
}
net.setSliceCount(nbSlices);
net.addArc("A", "C");
net.addArc("B", "C");
net.addTemporalArc("A", "A", 1);
double[] aDef = { 0.5, 0.5 };
net.setNodeDefinition("A", aDef);
net.setNodeDefinition("B", aDef);
double[] aDef2 = { 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
net.setNodeDefinition("C", aDef2);
double[] aDef3 = { 0.5, 0.5, 0.5, 0.5 };
net.setNodeTemporalDefinition("A", 1, aDef3);
net.writeFile("net_tut_6_bycode.xdsl");