1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: work/git/mixpp/bdm/stat/libFN.h Source File</title> |
---|
4 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.6 --> |
---|
8 | <div class="navigation" id="top"> |
---|
9 | <div class="tabs"> |
---|
10 | <ul> |
---|
11 | <li><a href="index.html"><span>Main Page</span></a></li> |
---|
12 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
13 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
14 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
15 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
16 | </ul> |
---|
17 | </div> |
---|
18 | <h1>work/git/mixpp/bdm/stat/libFN.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span> |
---|
19 | <a name="l00002"></a>00002 <span class="comment">// C++ Interface: itpp_ext</span> |
---|
20 | <a name="l00003"></a>00003 <span class="comment">//</span> |
---|
21 | <a name="l00004"></a>00004 <span class="comment">// Description:</span> |
---|
22 | <a name="l00005"></a>00005 <span class="comment">//</span> |
---|
23 | <a name="l00006"></a>00006 <span class="comment">//</span> |
---|
24 | <a name="l00007"></a>00007 <span class="comment">// Author: smidl <smidl@utia.cas.cz>, (C) 2008</span> |
---|
25 | <a name="l00008"></a>00008 <span class="comment">//</span> |
---|
26 | <a name="l00009"></a>00009 <span class="comment">// Copyright: See COPYING file that comes with this distribution</span> |
---|
27 | <a name="l00010"></a>00010 <span class="comment">//</span> |
---|
28 | <a name="l00011"></a>00011 <span class="comment">//</span> |
---|
29 | <a name="l00012"></a>00012 <span class="preprocessor">#ifndef FN_H</span> |
---|
30 | <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define FN_H</span> |
---|
31 | <a name="l00014"></a>00014 <span class="preprocessor"></span> |
---|
32 | <a name="l00015"></a>00015 <span class="preprocessor">#include <itpp/itbase.h></span> |
---|
33 | <a name="l00016"></a>00016 <span class="preprocessor">#include "<a class="code" href="libBM_8h.html" title="Bayesian Models (bm) that use Bayes rule to learn from observations.">libBM.h</a>"</span> |
---|
34 | <a name="l00017"></a>00017 |
---|
35 | <a name="l00018"></a>00018 <span class="keyword">namespace </span>bdm{ |
---|
36 | <a name="l00019"></a>00019 |
---|
37 | <a name="l00021"></a><a class="code" href="classbdm_1_1constfn.html">00021</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1constfn.html" title="class representing function , here rv is empty">constfn</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a> |
---|
38 | <a name="l00022"></a>00022 { |
---|
39 | <a name="l00024"></a>00024 vec val; |
---|
40 | <a name="l00025"></a>00025 |
---|
41 | <a name="l00026"></a>00026 <span class="keyword">public</span>: |
---|
42 | <a name="l00027"></a>00027 <span class="comment">//vec eval() {return val;};</span> |
---|
43 | <a name="l00029"></a><a class="code" href="classbdm_1_1constfn.html#33c2631ddcad9e81ef4b743d83eed4d4">00029</a> <span class="comment"></span> vec <a class="code" href="classbdm_1_1constfn.html#33c2631ddcad9e81ef4b743d83eed4d4" title="inherited">eval</a> ( <span class="keyword">const</span> vec &cond ) {<span class="keywordflow">return</span> val;}; |
---|
44 | <a name="l00031"></a><a class="code" href="classbdm_1_1constfn.html#7df0693d3ef4f1d2a52a5a3c3fce44af">00031</a> <a class="code" href="classbdm_1_1constfn.html#7df0693d3ef4f1d2a52a5a3c3fce44af" title="Default constructor.">constfn</a> ( <span class="keyword">const</span> vec &val0 ) :<a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>(val0.length()), val ( val0 ) {}; |
---|
45 | <a name="l00032"></a>00032 }; |
---|
46 | <a name="l00033"></a>00033 |
---|
47 | <a name="l00035"></a><a class="code" href="classbdm_1_1linfn.html">00035</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1linfn.html" title="Class representing function .">linfn</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a> |
---|
48 | <a name="l00036"></a>00036 { |
---|
49 | <a name="l00038"></a>00038 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rv; |
---|
50 | <a name="l00040"></a>00040 mat A; |
---|
51 | <a name="l00042"></a>00042 vec B; |
---|
52 | <a name="l00043"></a>00043 <span class="keyword">public</span> : |
---|
53 | <a name="l00044"></a><a class="code" href="classbdm_1_1linfn.html#b8063094a2aa210dcf7ae73e2b85e09c">00044</a> vec <a class="code" href="classbdm_1_1linfn.html#b8063094a2aa210dcf7ae73e2b85e09c" title="function evaluates numerical value of at cond ">eval</a> (<span class="keyword">const</span> vec &cond ) {it_assert_debug ( cond.length() ==rv.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>(), <span class="stringliteral">"linfn::eval Wrong cond."</span> );<span class="keywordflow">return</span> A*cond+B;}; |
---|
54 | <a name="l00045"></a>00045 |
---|
55 | <a name="l00046"></a>00046 <span class="comment">// linfn evalsome ( ivec &rvind );</span> |
---|
56 | <a name="l00048"></a><a class="code" href="classbdm_1_1linfn.html#df4517947726204540735452a41206da">00048</a> <span class="comment"></span> <a class="code" href="classbdm_1_1linfn.html#df4517947726204540735452a41206da" title="default constructor">linfn</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rv0 ) : <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>(rv0.count()), rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { }; |
---|
57 | <a name="l00050"></a><a class="code" href="classbdm_1_1linfn.html#7e0e714b814532fc3e38daede24c5e68">00050</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1linfn.html#7e0e714b814532fc3e38daede24c5e68" title="Set values of A and B.">set_parameters</a> ( <span class="keyword">const</span> mat &A0 , <span class="keyword">const</span> vec &B0 ) {A=A0; B=B0;}; |
---|
58 | <a name="l00051"></a>00051 }; |
---|
59 | <a name="l00052"></a>00052 |
---|
60 | <a name="l00053"></a>00053 |
---|
61 | <a name="l00063"></a><a class="code" href="classbdm_1_1diffbifn.html">00063</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a> |
---|
62 | <a name="l00064"></a>00064 { |
---|
63 | <a name="l00065"></a>00065 <span class="keyword">protected</span>: |
---|
64 | <a name="l00067"></a><a class="code" href="classbdm_1_1diffbifn.html#5f56547d8e9378b669d3cc19d7831cbb">00067</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1diffbifn.html#5f56547d8e9378b669d3cc19d7831cbb" title="Indentifier of the first rv.">rvx</a>; |
---|
65 | <a name="l00069"></a><a class="code" href="classbdm_1_1diffbifn.html#a8e3e861d5ec2a7ae9524e6338e58320">00069</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1diffbifn.html#a8e3e861d5ec2a7ae9524e6338e58320" title="Indentifier of the second rv.">rvu</a>; |
---|
66 | <a name="l00071"></a><a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e">00071</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>; |
---|
67 | <a name="l00073"></a><a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0">00073</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a>; |
---|
68 | <a name="l00074"></a>00074 <span class="keyword">public</span>: |
---|
69 | <a name="l00076"></a><a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3">00076</a> vec <a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates (VS: Do we really need common eval? ).">eval</a> ( <span class="keyword">const</span> vec &cond ) |
---|
70 | <a name="l00077"></a>00077 { |
---|
71 | <a name="l00078"></a>00078 it_assert_debug ( cond.length() == ( <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>+<a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a> ), <span class="stringliteral">"linfn::eval Wrong cond."</span> ); |
---|
72 | <a name="l00079"></a>00079 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates (VS: Do we really need common eval? ).">eval</a> ( cond ( 0,<a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>-1 ),cond ( <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>,<a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>+<a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a> ) );<span class="comment">//-1 = end (in matlab)</span> |
---|
73 | <a name="l00080"></a>00080 }; |
---|
74 | <a name="l00081"></a>00081 |
---|
75 | <a name="l00083"></a><a class="code" href="classbdm_1_1diffbifn.html#b5462c05b58cd38367ff946836bb82d3">00083</a> <span class="keyword">virtual</span> vec <a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates (VS: Do we really need common eval? ).">eval</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0 ) {<span class="keywordflow">return</span> zeros ( <a class="code" href="classbdm_1_1fnc.html#52156cb4a52a62d51fc7455985797a62" title="Length of the output vector.">dimy</a> );}; |
---|
76 | <a name="l00085"></a><a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac">00085</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac" title="Evaluates and writes result into A .">dfdx_cond</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0, mat &A , <span class="keywordtype">bool</span> full=<span class="keyword">true</span> ) {}; |
---|
77 | <a name="l00087"></a><a class="code" href="classbdm_1_1diffbifn.html#6ea1dc7a482601b29c5ba36a52d20d07">00087</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1diffbifn.html#6ea1dc7a482601b29c5ba36a52d20d07" title="Evaluates and writes result into A .">dfdu_cond</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0, mat &A, <span class="keywordtype">bool</span> full=<span class="keyword">true</span> ) {}; |
---|
78 | <a name="l00089"></a><a class="code" href="classbdm_1_1diffbifn.html#6ecfa9bf42b2421bd56c260a8b2c51e1">00089</a> <a class="code" href="classbdm_1_1diffbifn.html#6ecfa9bf42b2421bd56c260a8b2c51e1" title="Default constructor (dimy is not set!).">diffbifn</a> (<span class="keywordtype">int</span> <a class="code" href="classbdm_1_1fnc.html#52156cb4a52a62d51fc7455985797a62" title="Length of the output vector.">dimy</a>, <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvx0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvu0 ) : <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>(dimy), <a class="code" href="classbdm_1_1diffbifn.html#5f56547d8e9378b669d3cc19d7831cbb" title="Indentifier of the first rv.">rvx</a> ( rvx0 ),<a class="code" href="classbdm_1_1diffbifn.html#a8e3e861d5ec2a7ae9524e6338e58320" title="Indentifier of the second rv.">rvu</a> ( rvu0 ) {<a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>=<a class="code" href="classbdm_1_1diffbifn.html#5f56547d8e9378b669d3cc19d7831cbb" title="Indentifier of the first rv.">rvx</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>();<a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a>=<a class="code" href="classbdm_1_1diffbifn.html#a8e3e861d5ec2a7ae9524e6338e58320" title="Indentifier of the second rv.">rvu</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>();}; |
---|
79 | <a name="l00091"></a><a class="code" href="classbdm_1_1diffbifn.html#1b3c8f5949f13d86d2661e191d4b369b">00091</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1diffbifn.html#1b3c8f5949f13d86d2661e191d4b369b" title="access function">_dimx</a>()<span class="keyword"> const</span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>;} |
---|
80 | <a name="l00093"></a><a class="code" href="classbdm_1_1diffbifn.html#031458f38c97cdb3aecde16f6a06dced">00093</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1diffbifn.html#031458f38c97cdb3aecde16f6a06dced" title="access function">_dimu</a>()<span class="keyword"> const</span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a>;} |
---|
81 | <a name="l00094"></a>00094 }; |
---|
82 | <a name="l00095"></a>00095 |
---|
83 | <a name="l00097"></a>00097 <span class="comment">//TODO can be generalized into multilinear form!</span> |
---|
84 | <a name="l00098"></a><a class="code" href="classbdm_1_1bilinfn.html">00098</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1bilinfn.html" title="Class representing function .">bilinfn</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a> |
---|
85 | <a name="l00099"></a>00099 { |
---|
86 | <a name="l00100"></a>00100 mat A; |
---|
87 | <a name="l00101"></a>00101 mat B; |
---|
88 | <a name="l00102"></a>00102 <span class="keyword">public</span> : |
---|
89 | <a name="l00103"></a>00103 vec <a class="code" href="classbdm_1_1bilinfn.html#e36a16e72e7f9fedf3cb18d2d5505a24" title="Evaluates .">eval</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0 ); |
---|
90 | <a name="l00104"></a>00104 |
---|
91 | <a name="l00106"></a><a class="code" href="classbdm_1_1bilinfn.html#1e86e5081f13964ee64342f8e988032c">00106</a> <a class="code" href="classbdm_1_1bilinfn.html#1e86e5081f13964ee64342f8e988032c" title="Default constructor.">bilinfn</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvx0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvu0 ) : <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a> (<a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>, rvx0,rvu0 ) ,A ( eye ( <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a> ) ),B ( zeros ( <a class="code" href="classbdm_1_1diffbifn.html#a193aa2c4a500139c0c4b669691e588e" title="cache for rvx.count()">dimx</a>,<a class="code" href="classbdm_1_1diffbifn.html#30c45617eec89adeb4ebaa763d093fb0" title="cache for rvu.count()">dimu</a> ) ) {}; |
---|
92 | <a name="l00108"></a>00108 <a class="code" href="classbdm_1_1bilinfn.html#1e86e5081f13964ee64342f8e988032c" title="Default constructor.">bilinfn</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvx0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvu0, <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0 ); |
---|
93 | <a name="l00110"></a><a class="code" href="classbdm_1_1bilinfn.html#33066f1054dd259df2ec5fafae4b46e6">00110</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1bilinfn.html#33066f1054dd259df2ec5fafae4b46e6" title="Evaluates and writes result into A .">dfdx_cond</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0, mat &F, <span class="keywordtype">bool</span> full ) |
---|
94 | <a name="l00111"></a>00111 { |
---|
95 | <a name="l00112"></a>00112 it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),<span class="stringliteral">"Allocated F is not compatible."</span> ); |
---|
96 | <a name="l00113"></a>00113 <span class="keywordflow">if</span> ( full ) F=A; <span class="comment">//else : nothing has changed no need to regenerate</span> |
---|
97 | <a name="l00114"></a>00114 } |
---|
98 | <a name="l00116"></a><a class="code" href="classbdm_1_1bilinfn.html#9cfe2f1c115ba7c3c75849a10a4f2c08">00116</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1bilinfn.html#9cfe2f1c115ba7c3c75849a10a4f2c08" title="Evaluates and writes result into A .">dfdu_cond</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0, mat &F, <span class="keywordtype">bool</span> full=<span class="keyword">true</span> ) |
---|
99 | <a name="l00117"></a>00117 { |
---|
100 | <a name="l00118"></a>00118 it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),<span class="stringliteral">"Allocated F is not compatible."</span> ); |
---|
101 | <a name="l00119"></a>00119 <span class="keywordflow">if</span> ( full ) F=B; <span class="comment">//else : nothing has changed no need to regenerate</span> |
---|
102 | <a name="l00120"></a>00120 } |
---|
103 | <a name="l00121"></a>00121 }; |
---|
104 | <a name="l00122"></a>00122 |
---|
105 | <a name="l00123"></a>00123 } <span class="comment">//namespace</span> |
---|
106 | <a name="l00124"></a>00124 <span class="preprocessor">#endif // FN_H</span> |
---|
107 | </pre></div></div> |
---|
108 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jan 27 16:29:53 2009 for mixpp by |
---|
109 | <a href="http://www.doxygen.org/index.html"> |
---|
110 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> |
---|
111 | </body> |
---|
112 | </html> |
---|