root/library/doc/html/ui_page.html @ 619

Revision 617, 12.7 kB (checked in by smidl, 15 years ago)

simulator + doc

Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>mixpp: User Infos and their use</title>
6<link href="tabs.css" rel="stylesheet" type="text/css"/>
7<link href="doxygen.css" rel="stylesheet" type="text/css"/>
8</head>
9<body>
10<!-- Generated by Doxygen 1.6.1 -->
11<script type="text/javascript">
12<!--
13function changeDisplayState (e){
14  var num=this.id.replace(/[^[0-9]/g,'');
15  var button=this.firstChild;
16  var sectionDiv=document.getElementById('dynsection'+num);
17  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
18    sectionDiv.style.display='block';
19    button.src='open.gif';
20  }else{
21    sectionDiv.style.display='none';
22    button.src='closed.gif';
23  }
24}
25function initDynSections(){
26  var divs=document.getElementsByTagName('div');
27  var sectionCounter=1;
28  for(var i=0;i<divs.length-1;i++){
29    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
30      var header=divs[i];
31      var section=divs[i+1];
32      var button=header.firstChild;
33      if (button!='IMG'){
34        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
35        button=document.createElement('img');
36        divs[i].insertBefore(button,divs[i].firstChild);
37      }
38      header.style.cursor='pointer';
39      header.onclick=changeDisplayState;
40      header.id='dynheader'+sectionCounter;
41      button.src='closed.gif';
42      section.id='dynsection'+sectionCounter;
43      section.style.display='none';
44      section.style.marginLeft='14px';
45      sectionCounter++;
46    }
47  }
48}
49window.onload = initDynSections;
50-->
51</script>
52<div class="navigation" id="top">
53  <div class="tabs">
54    <ul>
55      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
56      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
57      <li><a href="annotated.html"><span>Classes</span></a></li>
58      <li><a href="files.html"><span>Files</span></a></li>
59    </ul>
60  </div>
61  <div class="navpath"><a class="el" href="dev_guide.html">Howto Use BDM in C++ for your needs</a>
62  </div>
63</div>
64<div class="contents">
65
66
67<h1><a class="anchor" id="ui_page">User Infos and their use </a></h1><dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classbdm_1_1UI.html" title="UI is an abstract class which collects all the auxiliary functions useful to prepare...">bdm::UI</a></dd>
68<dd>
69<a class="el" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a></dd>
70<dd>
71<a class="el" href="classbdm_1_1UIFile.html" title="This class serves to load and/or save user-infos into/from configuration files stored...">bdm::UIFile</a></dd>
72<dd>
73<a href="http://www.hyperrealm.com/libconfig/">The web page of the libconfig library.</a></dd></dl>
74<h2><a class="anchor" id="ui_intro">
75Introduction</a></h2>
76<p>For easier interaction with users, experiments can be configured via structures called <b>User Info</b>. These structures contain information about details of the experiment that is to be performed. Since experiments involve the use of basic BDM classes and their compositions, the experiment description is also hierarchical with specific user info for each object or class.</p>
77<p>The User Infos are designed using customized version of the libconfig library (www.hyperrealm.com/libconfig). It is specialized for BDM so as to recognize basic mathematical objects, such as vectors and matrices, see details below.</p>
78<p>Technically it can be made compatible with matlab structures. </p>
79<dl class="todo"><dt><b><a class="el" href="todo.html#_todo000005">Todo:</a></b></dt><dd>it will be good to create a more detailed paragraph about the intraction with Matlab</dd></dl>
80<h2><a class="anchor" id="ui_example">
81Example</a></h2>
82<p>For example, a simple experiment can be configures in the following way: </p>
83<div class="fragment"><pre class="fragment">ndat = 100;                <span class="comment">//number of data points</span>
84prior = { <span class="keyword">class</span>=<span class="stringliteral">&quot;enorm&quot;</span>;
85        mu = [1, 2, 3];
86        R = [1, 0, 0,
87             0, 1, 0,
88             0, 0, 1];
89};
90</pre></div><p> The exact meaning of the root fields in this structure (i.e. <code>ndat</code> and <code>prior</code>) is defined by the application (or mex file) that is using this configuration file. It will look for expected fields and it will ignore any other structures. When it does not find what it is looking for, it terminates with an appropriate error message.</p>
91<p>A structure with field <code>class="identifier"</code> is special. Such a structure will be parsed by an appropriate <a class="el" href="classbdm_1_1UI.html#a1f3d45184f803e1256cfc896b43ed2f8">bdm::UI::build</a> method which will construct the desired object, in this instance of an object of the class <a class="el" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">bdm::enorm</a>.</p>
92<p>For a detailed example how this mechanism works in practice see <a class="el" href="arx_ui.html">Running experiment <code>estimator</code> with ARX data fields  this page is out of date, as the user info concept has been changed</a>. To learn about the possinility of making <b> internal or external links</b> in configuration files, see the documentation of <a class="el" href="classbdm_1_1SettingResolver.html" title="This class serves to expand links used within configuration files.">bdm::SettingResolver</a>.</p>
93<h2><a class="anchor" id="ui_implementation">
94Implementation of user info in a custom class</a></h2>
95<p>In accordance with the previous example of the configuration file, consider the class defined as follows:</p>
96<div class="fragment"><pre class="fragment"><span class="keyword">class </span>newbee : <span class="keyword">public</span> bdm::root { 
97  ...
98   
99  <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">bdm::enorm</a> prior;
100  <span class="keywordtype">int</span> ndat;
101 
102  ...   
103}
104</pre></div><p>There are few obligatory steps to implement user info mechanism in this class. At first, the class has to be <b>inherited</b> (directly or indirectly) from <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">bdm::root</a>, as you can see in our example. What is hidden behind the scene is the use of a <b>parameterless constructor.</b> Each class using User infos has to have one.</p>
105<p>Next, <b>two virtual methods</b> <a class="el" href="classbdm_1_1root.html#a0551e3121091c5199bf4413b50522176" title="This method arrange instance properties according the data stored in the Setting...">bdm::root::from_setting</a> and <a class="el" href="classbdm_1_1root.html#a67d954d255ede776eade7334d4895790" title="This method save all the instance properties into the Setting structure.">bdm::root::to_setting</a> defined in the <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">bdm::root</a> class <b>should be overriden </b> in accordance with the content of the current class. In fact, you can override just method <a class="el" href="classbdm_1_1root.html#a0551e3121091c5199bf4413b50522176" title="This method arrange instance properties according the data stored in the Setting...">bdm::root::from_setting</a> in the case you are interested only in loading from configuration files, which is quite common. It is valid also in the other way round, i.e., in the case you are interested just in saving, override only <a class="el" href="classbdm_1_1root.html#a67d954d255ede776eade7334d4895790" title="This method save all the instance properties into the Setting structure.">bdm::root::to_setting</a>.</p>
106<p>How should look the bodies of these methods? It is important not to forget to call their <b>implementation in the base class</b> (in our case, it is the <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">bdm::root</a> class). Then, they should contain loading of all the necessary class attributes in the case of <a class="el" href="classbdm_1_1root.html#a0551e3121091c5199bf4413b50522176" title="This method arrange instance properties according the data stored in the Setting...">bdm::root::from_setting</a> method and saving of them in the other case. To implement these operation, you are encouraged to use static methods of <a class="el" href="classbdm_1_1UI.html" title="UI is an abstract class which collects all the auxiliary functions useful to prepare...">bdm::UI</a> class, namely <a class="el" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">bdm::UI::get</a>, <a class="el" href="classbdm_1_1UI.html#a1f3d45184f803e1256cfc896b43ed2f8">bdm::UI::build</a> and <a class="el" href="classbdm_1_1UI.html#ac83987949e6a9e79d6e093797ab7d917" title="A root descendant instance is stored in the new child Setting appended to the passed...">bdm::UI::save</a>.</p>
107<p>It can look like this:</p>
108<div class="fragment"><pre class="fragment"><span class="keyword">class </span>newbee : <span class="keyword">public</span> bdm::root { 
109  ...
110   
111  <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">bdm::enorm</a> prior;
112  <span class="keywordtype">int</span> ndat;
113 
114  ...
115
116  <span class="keyword">virtual</span> <span class="keywordtype">void</span> from_setting(<span class="keyword">const</span> Setting &amp;<span class="keyword">set</span>) {
117    root::from_setting(<span class="keyword">set</span>);
118    <span class="keywordflow">if</span>( !UI::get( ndat, <span class="keyword">set</span>, <span class="stringliteral">&quot;ndat&quot;</span> ) )
119       ndat = 1;         
120    prior = UI::build&lt;enorm&gt;( <span class="keyword">set</span>, <span class="stringliteral">&quot;prior&quot;</span>, compulsory );
121  }
122
123  <span class="keyword">virtual</span> <span class="keywordtype">void</span> to_setting(Setting &amp;<span class="keyword">set</span>)<span class="keyword"> const </span>{
124    root::to_setting(<span class="keyword">set</span>);
125    UI::save(ndat, <span class="keyword">set</span>, <span class="stringliteral">&quot;ndat&quot;</span>);
126    UI::save(prior, <span class="keyword">set</span>, <span class="stringliteral">&quot;prior&quot;</span>);
127  }
128
129  ...
130}
131</pre></div><p>As you can see, the presence of a concrete Setting in the configuration file can be tested by the return value of these methods and the code initializing the default values can follow immediately. Imagine, for example, that the first attribute <code>ndat</code> is optional. Thereore, the default value is filled in the case that there is not any other in the configuration file (and so <a class="el" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">bdm::UI::get</a> method returs <code>false</code>). The second atribute, <code>prior</code>, is intended to be compulsory. This fact is specified by the last parameter of the templated <a class="el" href="classbdm_1_1UI.html#a1f3d45184f803e1256cfc896b43ed2f8">bdm::UI::build</a> method. In this case, the method throws an exception if there is not proper data in the configuration file.</p>
132<p>The only difference between <a class="el" href="classbdm_1_1UI.html#a1f3d45184f803e1256cfc896b43ed2f8">bdm::UI::build</a> and <a class="el" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">bdm::UI::get</a> method is in the types of variables they are prepared to. The <a class="el" href="classbdm_1_1UI.html#a1f3d45184f803e1256cfc896b43ed2f8">bdm::UI::build&lt;T&gt;</a> method is used to initialize instances of classes derived from <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">bdm::root</a>. It allocates them dynamically and return just an pointer to the new instance. This way it is possible even to load instances of inherited classes without aneven knowing about it. Oppositely, all scalar values of types int, double, string, vec, ivec or mat are loaded by the <a class="el" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">bdm::UI::get</a> method with a static memory management. It is also capable to load arrays of templated type itpp::Array&lt;T&gt;.</p>
133<p>Saving is much more easier. For all the variable types, use the <a class="el" href="classbdm_1_1UI.html#ac83987949e6a9e79d6e093797ab7d917" title="A root descendant instance is stored in the new child Setting appended to the passed...">bdm::UI::save</a> method. </p>
134</div>
135<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Sep 15 23:42:47 2009 for mixpp by&nbsp;
136<a href="http://www.doxygen.org/index.html">
137<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
138</body>
139</html>
Note: See TracBrowser for help on using the browser.