Author Topic: Questions on parseCase and parseCases  (Read 14693 times)

Offline yenpei

  • Newbie
  • *
  • Posts: 2
    • View Profile
Questions on parseCase and parseCases
« on: March 13, 2010, 04:58:44 »
Hi,

We have just purchase Hugin OEM 7.2 in January and have some questions as below:

-There is Domain.parseCase() and Domain.parseCases() function in Hugin OEM API 7.2 for Java. What is the difference between these 2 functions? If we have a case file with a lot of entries in it, which one should we use?

-Does the DiscreteNode.setCaseState(0,1) function set the first state in the discrete node to true and will cause the belief for the related node to change automatically in the Domain? If yes, DiscreteNode.setCaseState(1,0) function will set the second state to false? This is setting the belief state? What we are trying to do here is to programmatically do something similar to like having the knowledge model in Running Mode in Hugin Explorer and setting either the tested state or the normal state to TRUE/FALSE.


We also have a question previously directed to Hugin Support Email but did not get any reply so far.
Please help!

Thanks,
Yen Pei.

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2278
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #1 on: March 13, 2010, 14:55:06 »
Quote
There is Domain.parseCase() and Domain.parseCases() function in Hugin OEM API 7.2 for Java. What is the difference between these 2 functions? If we have a case file with a lot of entries in it, which one should we use?

The method Domain.parseCase() parses a single case or scenario. This method is used to load an evidence set from file when computing updated belief.

The method Domain.parseCases() parses a dataset, i.e., a file of cases. This method is used to load a dataset from file for parameter learning.

The case and data file tutorial of the HUGIN GUI documentation briefly describes the difference:
http://download.hugin.com/webdocs/manuals/7.2/Htmlhelp/

Quote
Does the DiscreteNode.setCaseState(0,1) function set the first state in the discrete node to true and will cause the belief for the related node to change automatically in the Domain?
No, this function sets the node to the state with index 1 in the case with index 1.

You are probably looking for the method DiscreteNode.selelectState(index)
« Last Edit: March 13, 2010, 14:56:39 by Anders L Madsen »
HUGIN EXPERT A/S

Offline shawn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #2 on: March 14, 2010, 04:13:35 »
Thanks a lot for the clarification.

I'm Shawn. Yen Pei's team member.

Can I also check if calling Domain.propagate() after calling Domain.parseCases(caseFilename, parseListener) propagate the evidences read in from parseCases to all the nodes in the Domain object to create an adapted Domain object. So calling the saveAsKB() function save the adapted model to a new HKB file?

What we are trying to do is to generate a XML file (for our application's X Query) from the Knowledge Model created using Hugin GUI and updated using Hugin OEM API. Is the below pseudo codes correct or is there a better way to achieve this?

Create a Domain object and pass in the filename of HKB or NET file. (The Domain object will then be loaded with all the Discrete Nodes defined in the HKB or NET file passed in)
Retrieve the evidences stored in database and generates the data file (cases.dat)
Call Domain.parseCases(“cases.dat”, parseListener) and this will load the case file to the Domain object.
Call Domain.propagate(Domain.H_EQUILIBRIUM_SUM, Domain.H_EVIDENCE_MODE_NORMAL) to propagate the evidences to all the DiscreteNode in the Domain object.
Call Domain.getNodes() and store the return object to a NodeList object.
    For each level in the Domain
        Call DiscreteNode.selectState(0) to simulate the different state of the node
        Store next level's DiscreteNode(s) call into the XML according to the Domain.getBelief(0) returned value in ascending level
    End (For each level in Domain)
Call Domain.saveAsKB() function to store the adapted knowledge base file.


Thanks.
Shawn.

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2278
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #3 on: March 14, 2010, 22:07:54 »
Quote
Can I also check if calling Domain.propagate() after calling Domain.parseCases(caseFilename, parseListener) propagate the evidences read in from parseCases to all the nodes in the Domain object to create an adapted Domain object. So calling the saveAsKB() function save the adapted model to a new HKB file?
No. Domain.propagate () only propagates a single set (or case) of evidence. This evidence should be read from a case file using Domain.parseCase or set using DiscreteNode.selectState on the discrete nodes with evidence.

The method Domain.parseCases reads a dataset of cases to be used for parameter estimation or/and learning structure.

Quote
What we are trying to do is to generate a XML file (for our application's X Query) from the Knowledge Model created using Hugin GUI and updated using Hugin OEM API. Is the below pseudo codes correct or is there a better way to achieve this?

To learn the parameters of a model, I suggest you use either Domain.learnTables to learn tables in batch or use Domain.adapt to update the paramters one case at a time. Please consider reading the EM and Adaptation tutorials of the HUGIN GUI help pages.

I apologize, if I have misunderstood what you are trying to achieve.
HUGIN EXPERT A/S

Offline shawn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #4 on: March 15, 2010, 08:05:58 »
So does it mean that if I use Domain.parseCases instead of Domain.parseCase, I can do a single call of Domain.learnTables() and the evidences read from the data file (case.dat) will be updated to the nodes in the Domain and the belief of the table will change accordingly?


Thanks.

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2278
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #5 on: March 15, 2010, 11:31:18 »
The Domain.learnTables method will estimate the conditional probability tables (CPTs) from the dataset read with Domain.parseCases.

The parameter estimation is performed using the Expectation-Maximization (EM) algorithm. You can read about the EM learning algorithm in the EM Learning tutorial of the HUGIN GUI help.

Notice that to estimate a CPT for a node, the node should have an experience table.

This thread describes a complete example of EM learning using the API:
http://forum.hugin.com/index.php?topic=97.0
HUGIN EXPERT A/S

Offline shawn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #6 on: March 16, 2010, 05:25:14 »
Thanks a lot.  :)

Offline yenpei

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #7 on: May 06, 2010, 08:08:02 »
Hi Anders,

We managed to propagate the experience and noticed that there's an experience entry added to the original CPT.

We also notice that some values in the original CPT has been reflected to a very insignificant value 3.32503E-10 from the original value of 0.9. Is this normal?

Original CPT : http://www.flickr.com/photos/yenpei/4582923211/
New CPT: http://www.flickr.com/photos/yenpei/4582922991/


How does the experience populated affects the CPT?


Regards,
Yen Pei
« Last Edit: May 06, 2010, 08:17:16 by yenpei »

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2278
    • View Profile
Re: Questions on parseCase and parseCases
« Reply #8 on: May 06, 2010, 08:44:34 »
Hi Yen Pei,

Quote
We also notice that some values in the original CPT has been reflected to a very insignificant value 3.32503E-10 from the original value of 0.9. Is this normal?

The experience count associated with each parent configuration reflect how many times the parent configuration is present in the data. The value also depends on the number of missing values and the experience count specified prior to learning. A very small value reflects that only few if any cases has this configuration.

To give a more specific answer. I would like to know more about your data and the settings you are using (prior experience count, and parameter values for the EM algorithm.


Quote
How does the experience populated affects the CPT?

Once the EM learning has completed the experience counts are no longer used. The experience counts does not have any impact on the computation of posterior beliefs. The HUGIN GUI help pages have a detailed tutorial and explanation on the parameter estimation process using the EM algorithm. Also, you may find it useful to read about Adaptation.

Hope this helps
HUGIN EXPERT A/S