Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jack

Pages: [1] 2
1
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: October 09, 2011, 14:02:26  »
ok now everything works well.
But I have yet another question.
I do not know a priori the number of states of the node, but if I don't set first setNumberOfStates I cannot call setStateLabel.
How can I solve this problem?
thaanks,thanks,thanks very very much

2
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: October 03, 2011, 17:48:58  »
OK..................
Thanks, thanks thanks..........................
Now I have a problem to the print of tables.
I use to the print tables the metod "printTable (Table CPT)" of post "How to pass .dat file using JAVA HUgin API for EM learning.":

//print tables for all discrete chance nodes
    public static void printTable (Table CPT) throws ExceptionHugin {
   NodeList nodes = CPT.getNodes();
   int[] configuration = new int[nodes.size()];
   int tableSize = CPT.getSize();
   for (int i = 0; i < tableSize; i++) {
       CPT.getConfiguration(configuration, i);
       for (int j = 0; j < nodes.size(); j++) {
      Node n = (Node)nodes.get(j);
      System.out.print(n.getName() + "=" + configuration[j] + " ");
       }
       System.out.println(":= " + CPT.getDataItem(i));
       }
    }

Now in output I have the print of table but the values ​​are not equal to those obtained by Hugin GUI:

table of node "one" with hugin GUI:
car          := 0.166667
pen         :=0.5
house     :=0.166667
computer:=0.166667

table of node "one" with hugin java output:
one=0      := 0.16666666666666669
one=1      := 0.16666666666666669
one=2      := 0.16666666666666669
one=3      := 0.16666666666666669
one=4      := 0.16666666666666669
one=5      := 0.16666666666666669

but the value of one=1,one=2,one=3 is "pen" and then I should have a single value with probability value 0.5 as well in hugin gui


3
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 30, 2011, 13:07:05  »
This is my new file "cases.dat":

#   one   two

1   "car"   "yellow"
1   "pen"   "red"
1   "train"   "white"
1   "bag"     "black"   
1   "house"   "blue"
1   "computer"   "green"

If I use "pen","bag","yellow" and "black" two or three times instead of "train","bag","yellow"and "white", I have values #0,#1,.........

This is my old file "cases.dat":
#  one  two

1  "car"  #0
1  #1  "red"
1  #2  #2
1  #3  #3
1  "house"  #4
1  "computer"  "green"


4
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 29, 2011, 16:48:01  »
thanks....
I have always the same error:
"COM.hugin.HAPI.ExceptionUsage: An API function was called with an invalid argument (e.g., a NULL object was passed to a function that expects a non-NULL argument).
   at COM.hugin.HAPI.ExceptionHugin.throwException(ExceptionHugin.java:115)
   at COM.hugin.HAPI.Domain.learnStructure(Domain.java:1451)
   at Prova.main(Test.java:80)"
In my code:
1 - in the while loop I pass the value of record of my database to the states of nodes
2 - I use Domain.saveCases(java.lang.String fileName, NodeList nodes, int[] cases, boolean caseCounts, java.lang.String separator, java.lang.String missingData) to save the cases in a file "cases.dat"
3 - I use Domain.parseCases(java.lang.String fileName, ParseListener parseListener) to pass the cases stored in "cases.dat" and enters the cases into this Domain.
4 - I use Domain.leanStructure for PC-algorithm
5 - I use Domain.compile()
6 - I use Domain.learnTables()

This is a part of my new code:
...........................
int cases[]=new int[30];
int p=0;
int z=0;
boolean caseCount=true;
int statenode = 0;
NodeList nodes = new NodeList();
nodes.add(one);
nodes.add(two);
Resulset rset = stmt.executeQuery("SELECT one FROM table;");
Resulset rset2 = stmt2.executeQuery("SELECT two FROM table;");

while(rset.next()&&rset2.next()){
p=myDomain.newCase();
cases[z]=p;
one.setCaseState(p,statenode);
two.setCaseState(p,statenode);
a = rset.getString("one");
b = rset2.getString("two");
one.setStateLabel(statenode,a);
two.setStateLabel(statenode,b);
statenode++;
z++
}

two.addParent(one);
myDomain.saveCases("cases.dat",nodes,cases,caseCount," "," ");
myDomain.parseCases("cases.dat",new DefaultClassParseListener());
myDomain.learnStructure();
myDomain.compile();
myDomain.learnTables();
........................

5
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 21, 2011, 17:36:22  »
thanks..........
I used
Domain.saveCases();
and I could see the .dat file:

# - one - two

1 - "car" - #0
1 - #1 - "red"
1 - #2 - #2
1 - #3 - #3
1 - "house" - #4
1 - "computer" - "green"

the. dat file generated doesn't contain all the values but it has in some position #0,#1,#2..............
Why???
If I print with System.out.println() those values I have the right values

6
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 20, 2011, 18:39:24  »
I think, my error is this, but I cannot understand how I pass cases to the domain.
For the my code, I haven't data file but I have the data of my database.
In the while loops after
p=myDomain.newCase();
I save the cases with Domain.saveCase(String) in a txt file but I have a file empty.
How I save the cases???



7
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 19, 2011, 17:49:28  »
thank you.
I added try-catch with a printStackTrace call and the output is:
"COM.hugin.HAPI.ExceptionUsage: An API function was called with an invalid argument (e.g., a NULL object was passed to a function that expects a non-NULL argument).
   at COM.hugin.HAPI.ExceptionHugin.throwException(ExceptionHugin.java:115)
   at COM.hugin.HAPI.Domain.learnStructure(Domain.java:1451)
   at Prova.main(Test.java:80)"

to the line 80 of Test.java there is :
myDomain.learnStructure();

8
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 18, 2011, 21:50:51  »
Thank you.
If I call Domain.compile after Domain.learnStructure I have always the same output:
"Error: An API function was called with an invalid argument (e.g., a NULL object was passed to a function that expects a non-NULL argument)."
.......I can't understand wher's this error.


9
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 16, 2011, 17:05:58  »
import java.sql.*;
import java.util.*;
import COM.hugin.HAPI.*;

public class Test{
public static void main (String []args throws ExceptionHugin{
try{
java.lang.Class.forName("com.mysql.jdbc.Driver");
}
catch (Exception exc){
System.out.println("Error - Driver jdbc not present: "+exc.getMessage());
}
try{
String a,b;
Domain myDomain=new Domain();
int p=0;
int q=0;

LabelledDCNode one = new LabelledDCNode(myDomain);
one.setLabel("one");
one.setName("one");
one.setNumberOfStates(40);

LabelledDCNode two = new LabelledDCNode(myDomain);

two.setLabel("two");
two.setName("two");
two.setNumberOfStates(40);

Connection conn = DriverManager.getConnection("url","user","password");
Statement stmt = conn.createStatement();

Resulset rset = stmt.executeQuery("SELECT one FROM table;");
int statenode1 = 0;
while(rset.next()){
p=myDomain.newCase();
one.setCaseState(p,statenode1);
a = rset.getString("one");
//System.out.println(a);
one.setStateLabel(statenode1,a);
statenode1++
}

Resulset rset2 = stmt.executeQuery("SELECT two FROM table;");
int statenode2 = 0;
while(rset2.next()){
q=myDomain.newCase();
two.setCaseState(q,statenode2);
b=rset2.getString("two");
//System.out.println(b);
two.setStateLabel(statenode2,b);
statenode2++
}

two.addParent(one);
one.getExperienceTable();
two.getExperienceTable();
myDomain.compile();
myDomain.learnStructure();

Table t = two.getTable();
printTable(t);

Table t1 = one.getTable();
printTable(t1);

rset.close();
rset2.close();
stmt.close();
conn.close();
}
catch(Exception exc){
System.out.println("Error:"+exc.getMessage());
}
}

public static void printTable(Table CPT) throws ExceptionHugin{
NodeList nodes = CPT.getNodes();
int[] configuration = new int [nodes.size()];
int tableSize = CPT.getSize();
for(int i=0;i<tableSize;i++){
CPT.getConfiguration(configuration,i);
for (int j=0;j<nodes.size();j++){
DiscreteNode n = (DiscreteNode)nodes.get(j);
int h=configuration[j];
System.out.print(n.getStateLabel(h)+" ");
}
System.out.println(":= "+CPT.getDataItem(i));
}
}
}


P.S.On your code EnterDataExample i have two error:
Sex.setCaseState(j,s);   
Height.setCaseState(j,s);

Error:The metod setCaseState(int,int) in the type DiscreteNode is not applicable for the arguments(long,long)

10
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 15, 2011, 15:14:28  »
thanks a lot.............
I added
one.getExperienceTable();
two.getExperienceTable();
before of myDomain.compile() and now my code is running with learnTable().
If I use learnStructure() (algorithm PC) get the same output:
"Error: An Api function was called with an invalid argument(e.g., a NULL object was passed to a function that expects a non-NULL argument)".


11
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 13, 2011, 15:15:51  »
thank you for the quick answer but the error isn't that......
i have the same error
My code complete is:

import java.sql.*;
import java.util.*;
import COM.hugin.HAPI.*;

public class Test{
public static void main (String []args throws ExceptionHugin{
try{
java.lang.Class.forName("com.mysql.jdbc.Driver");
}
catch (Exception exc){
System.out.println("Error - Driver jdbc not present: "+exc.getMessage());
}
try{
String a,b;
Domain myDomain=new Domain();
int p=0;
int q=0;

LabelledDCNode one = new LabelledDCNode(myDomain);
one.setLabel("one");
one.setName("one");
one.setNumberOfStates(40);

LabelledDCNode two = new LabelledDCNode(myDomain);
two.addParent(one);
two.setLabel("two");
two.setName("two");
two.setNumberOfStates(40);

Connection conn = DriverManager.getConnection("url","user","password");
Statement stmt = conn.createStatement();

Resulset rset = stmt.executeQuery("SELECT one FROM table;");
int statenode1 = 0;
while(rset.next()){
p=myDomain.newCase();
one.setCaseState(p,statenode1);
a = rset.getString("one");
//System.out.println(a);
one.setStateLabel(statenode1,a);
statenode1++
}

Resulset rset2 = stmt.executeQuery("SELECT two FROM table;");
int statenode2 = 0;
while(rset2.next()){
q=myDomain.newCase();
two.setCaseState(q,statenode2);
b=rset2.getString("two");
//System.out.println(b);
two.setStateLabel(statenode2,b);
statenode2++
}

myDomain.compile();
myDomain.learnTable();  // or myDomain.learnStructure();

Table t = two.getTable();
printTable(t);

Table t1 = one.getTable();
printTable(t1);

rset.close();
rset2.close();
stmt.close();
conn.close();
}
catch(Exception exc){
System.out.println("Error:"+exc.getMessage());
}
}

public static void printTable(Table CPT) throws ExceptionHugin{
NodeList nodes = CPT.getNodes();
int[] configuration = new int [nodes.size()];
int tableSize = CPT.getSize();
for(int i=0;i<tableSize;i++){
CPT.getConfiguration(configuration,i);
for (int j=0;j<nodes.size();j++){
Node n = (Node)nodes.get(j);
System.out.print(n.getName()+"="+configuration[j]+" ");
}
System.out.println(":= "+CPT.getDataItem(i));
}
}
}




...........If I print a and b, I can see which they are the values ​​of my databases.
I think which the error is generated by learntable() or learnStructure()

12
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 09, 2011, 18:40:12  »
Thanks for the quick answer....
My codes generates error :
"Errore: An Api function was called with an invalid argument(e.g., a NULL object was passed to a function that expects a non-NULL argument).
I have written some code that creates the cases in the Domain from your mysql data:

...................
String a;
int p=0;
LabelledDCNode node1 = new LabelledDCNode(myDomain);
node1.setName.........
node1.setLabel...........
......................
Resulset rset = stmt.executeQuery("SELECT ....... FROM .......;")
int statenode1=0;
while(rset.next()){
p.myDomain.newCase();
node1.setCaseState(p,statenode1);
a = rset.getString("node1");
node1.setStateLabel(statenode1,a);
statenode1++;
 }
Resulset rset2............
.........................
.................
myDomain.compile();
myDomain.learnTables();
.............


and I have written some code that print tables for all discrete node
public static void printTable(Table CPT)..........
..................
...................

You could help me solve this problem?
Thanks a lot
P.S. ...and to use the algorythm PC?
I use void Domain.learnStructure() instead learnTable?

13
Java / Re: How to pass database using JAVA HUgin API for EM learning.
« on: September 05, 2011, 17:24:43  »
I must to add a new case for each state of node with:
"int Domain.newCase() "??
Another, instead of using:
void DiscreteNode.setCaseState(int c, int state)
I used
void LabelledDCNode.setStateLabel(int state, java.lang.String newLabel)
because the state of my node are words and they aren't number

14
Java / Re: 64 bit platform
« on: September 05, 2011, 17:03:31  »
At the moment I'm using hugin lite waiting which the universities to provide me the software with license

15
Java / Re: 64 bit platform
« on: August 29, 2011, 18:38:29  »
In the HUGIN email with my license data there is only one link....

Pages: [1] 2