Sunday 31 May 2015

GSoC Week1

The first week of coding period is now almost over.

This week I worked on improving the XMLBIF module.The reader class of XMLBIF module was working fine but the writer class was not implemented.
Also the reader class din't have any method which would return the model instance (for ex Bayesian or Markov model instance). Since i was not familiar with the Bayesian and Markov models very much, so my mentors helped me in understanding the Bayesian and Markov models so that i can easily implement them for the next set of modules in the later stage.

Also this week i worked on writing the writer class of the module.Now it has been completed. I have send a PR and hopefully it would be mergeg until next week.


Details about the Writer class

Writer class takes a model_data as input.

An example of sample model_data is

 self.model_data = 
{'variables': ['light-on', 'bowel-problem', 'dog-out', 'hear-bark', 'family-out'],
  'states': {'bowel-problem': ['true', 'false'],
                'dog-out': ['true', 'false'],
                'family-out': ['true', 'false'],
                'hear-bark': ['true', 'false'],
                'light-on': ['true', 'false']},
  'property': {'bowel-problem': ['position = (190, 69)'],
                      'dog-out': ['position = (155, 165)'],
                      'family-out': ['position = (112, 69)'],
                      'hear-bark': ['position = (154, 241)'],
                      'light-on': ['position = (73, 165)']},
'parents': {'bowel-problem': [],
                   'dog-out': ['family-out', 'bowel-problem'],
                   'family-out': [],
                   'hear-bark': ['dog-out'],
                   'light-on': ['family-out']},
'cpds': {'bowel-problem': np.array([[0.01],[0.99]]),
              'dog-out': np.array([[0.99, 0.01, 0.97, 0.03],[0.9, 0.1, 0.3, 0.7]]),
              'family-out': np.array([[0.15],[0.85]]),
              'hear-bark': np.array([[0.7, 0.3],[0.01, 0.99]]),
              'light-on': np.array([[0.6, 0.4],[0.05, 0.95]])}}
 
 
The writer class has following methods:
  1.  add_variables
    1. This method basically adds variables tags to the file.
  2.  add_definition
    1. This method add definition tags to the file.
  3.  add_cpd
    1. This method adds table tags to the file.
And, finally the file returned by the Writer class is as follows:
<BIF version="0.3">
  <NETWORK>
    <VARIABLE TYPE="nature">
      <OUTCOME>true</OUTCOME>
      <OUTCOME>false</OUTCOME>
      <PROPERTY>position = (190, 69)</PROPERTY>
    </VARIABLE>
    <VARIABLE TYPE="nature">
      <OUTCOME>true</OUTCOME>
      <OUTCOME>false</OUTCOME>
      <PROPERTY>position = (155, 165)</PROPERTY>
    </VARIABLE>
    <VARIABLE TYPE="nature">
      <OUTCOME>true</OUTCOME>
      <OUTCOME>false</OUTCOME>
      <PROPERTY>position = (112, 69)</PROPERTY>
    </VARIABLE>
    <VARIABLE TYPE="nature">
      <OUTCOME>true</OUTCOME>
      <OUTCOME>false</OUTCOME>
      <PROPERTY>position = (154, 241)</PROPERTY>
    </VARIABLE>
    <VARIABLE TYPE="nature">
      <OUTCOME>true</OUTCOME>
      <OUTCOME>false</OUTCOME>
      <PROPERTY>position = (73, 165)</PROPERTY>
    </VARIABLE>
    <DEFINITION>
      <FOR>bowel-problem</FOR>
      <TABLE>0.01 0.99 </TABLE>
    </DEFINITION>
    <DEFINITION>
      <FOR>dog-out</FOR>
      <GIVEN>bowel-problem</GIVEN>
      <GIVEN>family-out</GIVEN>
      <TABLE>0.99 0.01 0.97 0.03 0.9 0.1 0.3 0.7 </TABLE>
    </DEFINITION>
    <DEFINITION>
      <FOR>family-out</FOR>
      <TABLE>0.15 0.85 </TABLE>
    </DEFINITION>
    <DEFINITION>
      <FOR>hear-bark</FOR>
      <GIVEN>dog-out</GIVEN>
      <TABLE>0.7 0.3 0.01 0.99 </TABLE>
    </DEFINITION>
    <DEFINITION>
      <FOR>light-on</FOR>
      <GIVEN>family-out</GIVEN>
      <TABLE>0.6 0.4 0.05 0.95 </TABLE>
    </DEFINITION>
  </NETWORK>
</BIF>

No comments:

Post a Comment