Author Topic: LabelledDCNode and States  (Read 15981 times)

Offline jeff_porter

  • Newbie
  • *
  • Posts: 5
    • View Profile
LabelledDCNode and States
« on: June 26, 2007, 10:05:13 »

I'd like to create a LabelledDCNode via my java code that has two states, false and true.
I seem to be able to do this via the Researcher tool, but not via the java api.

I just get an exception thrown...
(The exception comes from the second set state label line 'node.setStateLabel(1, "true");' )

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:122)
   at COM.hugin.HAPI.DiscreteChanceNode.setStateLabel(DiscreteChanceNode.java:170)




Code...

LabelledDCNode node = new LabelledDCNode(networkModel);
node.setStateLabel(0, "false");
node.setStateLabel(1, "true");
node.selectState(1);

Am I missing something or is this a bug?   ???

Version: 6.6

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: LabelledDCNode and States
« Reply #1 on: June 26, 2007, 12:29:14 »
The LabelledDCNode has by default a single state. This fact implies that the line:
node.setStateLabel(1, "true");
will fail with a "usage" exception. If you set the number of states of the node prior to defining its state labels, the code will work properly. For instance,
LabelledDCNode node = new LabelledDCNode(networkModel);
node.setNumberOfStates (2);

node.setStateLabel(0, "false");
node.setStateLabel(1, "true");

Since the node has states "false" and "true", you may want to consider using the BooleanDCNode class as it implements Boolean nodes. This could be useful in the specification of expressions.
HUGIN EXPERT A/S

Offline jeff_porter

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: LabelledDCNode and States
« Reply #2 on: June 26, 2007, 15:24:54 »
Thanks Anders.

I was looking at the TB model (Chest clinic), which has nodes that imply yes/no states. e.g.

'visit to asia'

This node is of type 'labelled', hence I thought I'd copy what is does, and make it a labelled node.

Thanks again
Jeff