Author Topic: structure learning  (Read 10881 times)

Offline Olivia Mahaux

  • Newbie
  • *
  • Posts: 3
    • View Profile
structure learning
« on: August 26, 2016, 10:36:05 »
Dear,

I am trying to code in C a way load cases and perform structure and EM learning to build a domain from scratch. While I could code the EM learning part for an existing domain, the structure learning part from a dataset is more tricky.
From my reading of the API manual this si the sequence I could understand and I wanted to use:
h_new_domain
h_domain_new_node (for all nodes of the domain)
h_node_set_name
h_domain_parse_case /*here it is bugging, is there anything else that is required before we are able to parse cases and store in the domain?*/
h_domain_learn_structure  (h_domain_set_log_file known how the PC algorithm worked + facultative h_constraint_...)
h_node_get_experience_table (for all nodes of the domain)     
h_domain_compile
h_domain_learn_tables
h_domain_save_as_net

Could you please confirm if this would be the right sequence of codes to use?
I am not very advanced yet and still need to improve my error handler however with a very simple one I get the following error message when trying to parse the cases to the domain "An error occurred during parsing.  If a parse error handling function was specified, it will have been called with a description of the error and its location in the source." so I known it didn't work and didn't parse the cases, any idea why? is there anything else required I forgot (code below)?
The easier would be if you could share an example of building a domain from scratch with parsing cases and structure learning (there were some examples received from installation of the software but none on this topic). Could you please share this example or something close to it?  Thanks a lot in advance

(defparameter null-pointer (cffi:null-pointer))
(defparameter pointer (cffi:inc-pointer null-pointer 1))

(defparameter domain (h_new_domain))
(defparameter newnode (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode "E")
(h_node_get_name newnode)

(defparameter newnode1 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode1 "T")
(defparameter newnode2 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode2 "L")
(defparameter newnode3 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode3 "S")
(defparameter newnode4 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode4 "A")
(defparameter newnode5 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode5 "D")
(defparameter newnode6 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode6 "B")
(defparameter newnode7 (h_domain_new_node domain :h_category_chance :h_kind_discrete))
(h_node_set_name newnode7 "X")

(h_domain_parse_cases domain "U:\\Data\\Bayesian network\\Course Examples and Exercises\\datasets\\asia_005.dat"
(cffi:null-pointer) (cffi:null-pointer))

(h_error_description (h_error_code))

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: structure learning
« Reply #1 on: August 29, 2016, 16:26:02 »
The only thing missing from your code is the specification of the states of the nodes.  You need to specify the number of states and the labels (names) of the states, assuming labeled states.  If the states represent numbers or (numeric) intervals, then state values must be specified.

For example, in the "asia" example, the nodes are binary (2 states) with labels "yes" and "no".  The labels must match exactly the labels used in the data file (that is, "yes", "Yes", and "YES" are all diffent).

I hope this helps.

Frank

Offline Olivia Mahaux

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: structure learning
« Reply #2 on: September 13, 2016, 15:37:11 »
Thanks this is exactly what I was missing. I am able to do it now  :D