Author Topic: NULL pointer in learnClassTables  (Read 10980 times)

Offline btessem

  • Newbie
  • *
  • Posts: 2
    • View Profile
NULL pointer in learnClassTables
« on: February 13, 2014, 20:42:22 »
Hi,

I'm trying to use learnClassTables on a dynamic network (in a Java program). The network has three timeslices and three nodes (of which one is output and one is input). Have tried to follow the instructions in the API manual, but get this message

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).
Exception caught: 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:119)
   at COM.hugin.HAPI.Domain.learnClassTables(Domain.java:1322)
   at ConfidenceHugin.main(ConfidenceHugin.java:79)

which is hard for me to interpret.

The network runs nicely as long as long as I don't try the learnClassTables. the node that  I want to learn the CPT for is set up with an experience table in the program, but I use two cases only.

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: NULL pointer in learnClassTables
« Reply #1 on: February 15, 2014, 23:20:55 »
It's hard to guess what is wrong (all the usage conditions should be mentioned in the Hugin API Reference Manual).  The most obvious things to check are that the domain is an unmodified runtime domain constructed from some class, and that the equilibrium is sum-normal with all evidence incorporated (by calling "propagate" if necessary).

I hope this helps.

Frank

Offline btessem

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: NULL pointer in learnClassTables
« Reply #2 on: February 19, 2014, 10:17:58 »
I tried to run a propagate before running the learning algorithm. Still there is an error. The essential part of the Java code is found below. In addition I attach the oobn file that contains the time slice model. The run stops at domain.learnClassTables(). Hope you can help! :)

Bjørnar

         ClassCollection cc = new ClassCollection();
         TestParseListener parseListener = new TestParseListener();
         cc.parseClasses(className + ".oobn", parseListener);
         // Unfold the Class to a Domain that can be compiled and
         // used for inference, etc.
         COM.hugin.HAPI.Class timeSlice = cc.getClassByName(className);
         Node hitNode = timeSlice.getNodeByName("hit");
         DiscreteChanceNode confiNode = (DiscreteChanceNode)timeSlice.getNodeByName("confidence");
         confiNode.getExperienceTable();
         Node initConfiNode = timeSlice.getNodeByName("initial_confidence");
         COM.hugin.HAPI.Class confiClass = new COM.hugin.HAPI.Class(cc,"ConfiMany");
         InstanceNode inst1 = new InstanceNode(confiClass,timeSlice);
         InstanceNode inst2 = new InstanceNode(confiClass,timeSlice);
         InstanceNode inst3 = new InstanceNode(confiClass,timeSlice);
         Node out1 = inst1.getOutput(confiNode);
         inst2.setInput(initConfiNode,out1);
         Node out2 = inst2.getOutput(confiNode);
         inst3.setInput(initConfiNode,out2);

         Domain domain = confiClass.createDomain();           
         domain.openLogFile (className + ".log");
               domain.triangulate (Domain.H_TM_BEST_GREEDY);
               DiscreteChanceNode initConf1 = (DiscreteChanceNode)domain.getNodeByName(inst1.getName()+"."+ "initial_confidence");
               DiscreteChanceNode hit1 = (DiscreteChanceNode)domain.getNodeByName(inst1.getName()+"."+ "hit");
               DiscreteChanceNode conf1 = (DiscreteChanceNode)domain.getNodeByName(inst1.getName()+"."+ "confidence");
               DiscreteChanceNode hit2 = (DiscreteChanceNode)domain.getNodeByName(inst2.getName()+"."+ "hit");
               DiscreteChanceNode conf2 = (DiscreteChanceNode)domain.getNodeByName(inst2.getName()+"."+ "confidence");
               DiscreteChanceNode hit3 = (DiscreteChanceNode)domain.getNodeByName(inst3.getName()+"."+ "hit");
               DiscreteChanceNode conf3 = (DiscreteChanceNode)domain.getNodeByName(inst3.getName()+"."+ "confidence");

               domain.setNumberOfCases(2);
            
               initConf1.setCaseState(0, 0);
               hit1.setCaseState(0, 0);
               conf1.setCaseState(0, 2);
               hit2.setCaseState(0, 1);
               conf2.setCaseState(0, 1);
               hit3.setCaseState(0, 1);
               conf3.setCaseState(0, 0);
              
               initConf1.setCaseState(1, 2);
               hit1.setCaseState(1, 1);
               conf1.setCaseState(1, 2);
               hit2.setCaseState(1, 0);
               conf2.setCaseState(1, 2);
               hit3.setCaseState(1, 1);
               conf3.setCaseState(1, 1);
              
               domain.compile();
              
          domain.propagate(Domain.H_EQUILIBRIUM_SUM, Domain.H_EVIDENCE_MODE_NORMAL);
               domain.learnClassTables();
          printBeliefs(domain);

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: NULL pointer in learnClassTables
« Reply #3 on: March 02, 2014, 01:03:47 »
Your code is correct.  However, the learnClassTables method incorrectly diagnosed that the domain was not a proper runtime domain for the class.  The problem will be fixed in the next release of the Hugin software.

Sorry for the inconvenience.