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/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.3 --> |
---|
8 | <div class="tabs"> |
---|
9 | <ul> |
---|
10 | <li><a href="index.html"><span>Main Page</span></a></li> |
---|
11 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
12 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
13 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
14 | </ul> |
---|
15 | </div> |
---|
16 | <h1>work/mixpp/bdm/stat/libFN.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span> |
---|
17 | <a name="l00002"></a>00002 <span class="comment">// C++ Interface: itpp_ext</span> |
---|
18 | <a name="l00003"></a>00003 <span class="comment">//</span> |
---|
19 | <a name="l00004"></a>00004 <span class="comment">// Description:</span> |
---|
20 | <a name="l00005"></a>00005 <span class="comment">//</span> |
---|
21 | <a name="l00006"></a>00006 <span class="comment">//</span> |
---|
22 | <a name="l00007"></a>00007 <span class="comment">// Author: smidl <smidl@utia.cas.cz>, (C) 2008</span> |
---|
23 | <a name="l00008"></a>00008 <span class="comment">//</span> |
---|
24 | <a name="l00009"></a>00009 <span class="comment">// Copyright: See COPYING file that comes with this distribution</span> |
---|
25 | <a name="l00010"></a>00010 <span class="comment">//</span> |
---|
26 | <a name="l00011"></a>00011 <span class="comment">//</span> |
---|
27 | <a name="l00012"></a>00012 <span class="preprocessor">#ifndef FN_H</span> |
---|
28 | <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define FN_H</span> |
---|
29 | <a name="l00014"></a>00014 <span class="preprocessor"></span> |
---|
30 | <a name="l00015"></a>00015 <span class="preprocessor">#include <itpp/itbase.h></span> |
---|
31 | <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> |
---|
32 | <a name="l00017"></a>00017 |
---|
33 | <a name="l00018"></a>00018 <span class="keyword">using namespace </span>itpp; |
---|
34 | <a name="l00019"></a>00019 |
---|
35 | <a name="l00021"></a><a class="code" href="classconstfn.html">00021</a> <span class="keyword">class </span><a class="code" href="classconstfn.html" title="class representing function $f(x) = a$, here rv is empty">constfn</a> : <span class="keyword">public</span> <a class="code" href="classfnc.html" title="Class representing function $f(x)$ of variable $x$ represented by rv.">fnc</a> |
---|
36 | <a name="l00022"></a>00022 { |
---|
37 | <a name="l00024"></a>00024 vec val; |
---|
38 | <a name="l00025"></a>00025 |
---|
39 | <a name="l00026"></a>00026 <span class="keyword">public</span>: |
---|
40 | <a name="l00027"></a>00027 <span class="comment">//vec eval() {return val;};</span> |
---|
41 | <a name="l00029"></a><a class="code" href="classconstfn.html#0411f603cbf675f2bc04a8f85e4e3b52">00029</a> <span class="comment"></span> vec <a class="code" href="classconstfn.html#0411f603cbf675f2bc04a8f85e4e3b52" title="inherited">eval</a> ( <span class="keyword">const</span> vec &cond ) {<span class="keywordflow">return</span> val;}; |
---|
42 | <a name="l00031"></a><a class="code" href="classconstfn.html#d08acd7fac0ef3edfa59bbe48403f2bc">00031</a> <a class="code" href="classconstfn.html#d08acd7fac0ef3edfa59bbe48403f2bc" title="Default constructor.">constfn</a> ( <span class="keyword">const</span> vec &val0 ) :val ( val0 ) {}; |
---|
43 | <a name="l00032"></a>00032 }; |
---|
44 | <a name="l00033"></a>00033 |
---|
45 | <a name="l00035"></a><a class="code" href="classlinfn.html">00035</a> <span class="keyword">class </span><a class="code" href="classlinfn.html" title="Class representing function $f(x) = Ax+B$.">linfn</a>: <span class="keyword">public</span> <a class="code" href="classfnc.html" title="Class representing function $f(x)$ of variable $x$ represented by rv.">fnc</a> |
---|
46 | <a name="l00036"></a>00036 { |
---|
47 | <a name="l00038"></a>00038 <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> rv; |
---|
48 | <a name="l00040"></a>00040 mat A; |
---|
49 | <a name="l00042"></a>00042 vec B; |
---|
50 | <a name="l00043"></a>00043 <span class="keyword">public</span> : |
---|
51 | <a name="l00044"></a><a class="code" href="classlinfn.html#fac0e56701f4c7beaf1c91f9b2a55f0b">00044</a> vec <a class="code" href="classlinfn.html#fac0e56701f4c7beaf1c91f9b2a55f0b" title="function evaluates numerical value of $f(x)$ at $x=cond$">eval</a> (<span class="keyword">const</span> vec &cond ) {it_assert_debug ( cond.length() ==rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>(), <span class="stringliteral">"linfn::eval Wrong cond."</span> );<span class="keywordflow">return</span> A*cond+B;}; |
---|
52 | <a name="l00045"></a>00045 |
---|
53 | <a name="l00046"></a>00046 <span class="comment">// linfn evalsome ( ivec &rvind );</span> |
---|
54 | <a name="l00048"></a><a class="code" href="classlinfn.html#01c70122a7783ddb0d87e6a82685adcb">00048</a> <span class="comment"></span> <a class="code" href="classlinfn.html#01c70122a7783ddb0d87e6a82685adcb" title="default constructor">linfn</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0 ) :rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { }; |
---|
55 | <a name="l00050"></a><a class="code" href="classlinfn.html#15eb81f2141984a61706b7ad5b411505">00050</a> <span class="keywordtype">void</span> <a class="code" href="classlinfn.html#15eb81f2141984a61706b7ad5b411505" 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;}; |
---|
56 | <a name="l00051"></a>00051 }; |
---|
57 | <a name="l00052"></a>00052 |
---|
58 | <a name="l00053"></a>00053 |
---|
59 | <a name="l00063"></a><a class="code" href="classdiffbifn.html">00063</a> <span class="keyword">class </span><a class="code" href="classdiffbifn.html" title="Class representing a differentiable function of two variables $f(x,u)$.">diffbifn</a>: <span class="keyword">public</span> <a class="code" href="classfnc.html" title="Class representing function $f(x)$ of variable $x$ represented by rv.">fnc</a> |
---|
60 | <a name="l00064"></a>00064 { |
---|
61 | <a name="l00065"></a>00065 <span class="keyword">protected</span>: |
---|
62 | <a name="l00067"></a><a class="code" href="classdiffbifn.html#bcf96b86250c3cbd465ba5ee62474b75">00067</a> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classdiffbifn.html#bcf96b86250c3cbd465ba5ee62474b75" title="Indentifier of the first rv.">rvx</a>; |
---|
63 | <a name="l00069"></a><a class="code" href="classdiffbifn.html#c41c74c7942dba51ef0b0bfed963447d">00069</a> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classdiffbifn.html#c41c74c7942dba51ef0b0bfed963447d" title="Indentifier of the second rv.">rvu</a>; |
---|
64 | <a name="l00071"></a><a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78">00071</a> <span class="keywordtype">int</span> <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>; |
---|
65 | <a name="l00073"></a><a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79">00073</a> <span class="keywordtype">int</span> <a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a>; |
---|
66 | <a name="l00074"></a>00074 <span class="keyword">public</span>: |
---|
67 | <a name="l00076"></a><a class="code" href="classdiffbifn.html#ad7673e16aa1a046b131b24c731c4632">00076</a> vec <a class="code" href="classdiffbifn.html#ad7673e16aa1a046b131b24c731c4632" title="Evaluates $f(x0,u0)$ (VS: Do we really need common eval? ).">eval</a> ( <span class="keyword">const</span> vec &cond ) |
---|
68 | <a name="l00077"></a>00077 { |
---|
69 | <a name="l00078"></a>00078 it_assert_debug ( cond.length() == ( <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>+<a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a> ), <span class="stringliteral">"linfn::eval Wrong cond."</span> ); |
---|
70 | <a name="l00079"></a>00079 <span class="keywordflow">return</span> <a class="code" href="classdiffbifn.html#ad7673e16aa1a046b131b24c731c4632" title="Evaluates $f(x0,u0)$ (VS: Do we really need common eval? ).">eval</a> ( cond ( 0,<a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>-1 ),cond ( <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>,<a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>+<a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a> ) );<span class="comment">//-1 = end (in matlab)</span> |
---|
71 | <a name="l00080"></a>00080 }; |
---|
72 | <a name="l00081"></a>00081 |
---|
73 | <a name="l00083"></a><a class="code" href="classdiffbifn.html#40d8a7eee45acc55cda33d43282faa03">00083</a> <span class="keyword">virtual</span> vec <a class="code" href="classdiffbifn.html#ad7673e16aa1a046b131b24c731c4632" title="Evaluates $f(x0,u0)$ (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="classfnc.html#22d51d10a7901331167f64f80d1af8e9" title="Length of the output vector.">dimy</a> );}; |
---|
74 | <a name="l00085"></a><a class="code" href="classdiffbifn.html#6d217a02d4fa13931258d4bebdd0feb4">00085</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdiffbifn.html#6d217a02d4fa13931258d4bebdd0feb4" 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> ) {}; |
---|
75 | <a name="l00087"></a><a class="code" href="classdiffbifn.html#1978bafd7909d15c139a08c495c24aa0">00087</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classdiffbifn.html#1978bafd7909d15c139a08c495c24aa0" 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> ) {}; |
---|
76 | <a name="l00089"></a><a class="code" href="classdiffbifn.html#0b33e1bfa23be5ed234d172eb4c0e4b5">00089</a> <a class="code" href="classdiffbifn.html#0b33e1bfa23be5ed234d172eb4c0e4b5" title="Default constructor (dimy is not set!).">diffbifn</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> rvx0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> rvu0 ) : <a class="code" href="classdiffbifn.html#bcf96b86250c3cbd465ba5ee62474b75" title="Indentifier of the first rv.">rvx</a> ( rvx0 ),<a class="code" href="classdiffbifn.html#c41c74c7942dba51ef0b0bfed963447d" title="Indentifier of the second rv.">rvu</a> ( rvu0 ) {<a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>=<a class="code" href="classdiffbifn.html#bcf96b86250c3cbd465ba5ee62474b75" title="Indentifier of the first rv.">rvx</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>();<a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a>=<a class="code" href="classdiffbifn.html#c41c74c7942dba51ef0b0bfed963447d" title="Indentifier of the second rv.">rvu</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>();}; |
---|
77 | <a name="l00091"></a><a class="code" href="classdiffbifn.html#436de7a7301ea9eac7d6081b893bbf57">00091</a> <span class="keywordtype">int</span> <a class="code" href="classdiffbifn.html#436de7a7301ea9eac7d6081b893bbf57" title="access function">_dimx</a>()<span class="keyword"> const</span>{<span class="keywordflow">return</span> <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>;} |
---|
78 | <a name="l00093"></a><a class="code" href="classdiffbifn.html#fc8779acbff170611aff0ee70cee3879">00093</a> <span class="keywordtype">int</span> <a class="code" href="classdiffbifn.html#fc8779acbff170611aff0ee70cee3879" title="access function">_dimu</a>()<span class="keyword"> const</span>{<span class="keywordflow">return</span> <a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a>;} |
---|
79 | <a name="l00094"></a>00094 }; |
---|
80 | <a name="l00095"></a>00095 |
---|
81 | <a name="l00097"></a>00097 <span class="comment">//TODO can be generalized into multilinear form!</span> |
---|
82 | <a name="l00098"></a><a class="code" href="classbilinfn.html">00098</a> <span class="keyword">class </span><a class="code" href="classbilinfn.html" title="Class representing function $f(x,u) = Ax+Bu$.">bilinfn</a>: <span class="keyword">public</span> <a class="code" href="classdiffbifn.html" title="Class representing a differentiable function of two variables $f(x,u)$.">diffbifn</a> |
---|
83 | <a name="l00099"></a>00099 { |
---|
84 | <a name="l00100"></a>00100 mat A; |
---|
85 | <a name="l00101"></a>00101 mat B; |
---|
86 | <a name="l00102"></a>00102 <span class="keyword">public</span> : |
---|
87 | <a name="l00103"></a>00103 vec <a class="code" href="classbilinfn.html#e36a16e72e7f9fedf3cb18d2d5505a24" title="Evaluates $f(x0,u0)$.">eval</a> ( <span class="keyword">const</span> vec &x0, <span class="keyword">const</span> vec &u0 ); |
---|
88 | <a name="l00104"></a>00104 |
---|
89 | <a name="l00106"></a><a class="code" href="classbilinfn.html#af9f36282730d910a41b95f4d1fb8221">00106</a> <a class="code" href="classbilinfn.html#af9f36282730d910a41b95f4d1fb8221" title="Default constructor.">bilinfn</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvx0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvu0 ) : <a class="code" href="classdiffbifn.html" title="Class representing a differentiable function of two variables $f(x,u)$.">diffbifn</a> ( rvx0,rvu0 ) ,A ( eye ( <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a> ) ),B ( zeros ( <a class="code" href="classdiffbifn.html#f6918bc0a9dad656b4cddc028137eb78" title="cache for rvx.count()">dimx</a>,<a class="code" href="classdiffbifn.html#2e07ce491e973f03d763e37624d0fe79" title="cache for rvu.count()">dimu</a> ) ) {}; |
---|
90 | <a name="l00108"></a>00108 <a class="code" href="classbilinfn.html#af9f36282730d910a41b95f4d1fb8221" title="Default constructor.">bilinfn</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvx0, <span class="keyword">const</span> <a class="code" href="classRV.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 ); |
---|
91 | <a name="l00110"></a><a class="code" href="classbilinfn.html#79c022de8dbe2b054bb9cc49345f3ef5">00110</a> <span class="keywordtype">void</span> <a class="code" href="classbilinfn.html#79c022de8dbe2b054bb9cc49345f3ef5" 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 ) |
---|
92 | <a name="l00111"></a>00111 { |
---|
93 | <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> ); |
---|
94 | <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> |
---|
95 | <a name="l00114"></a>00114 } |
---|
96 | <a name="l00116"></a><a class="code" href="classbilinfn.html#90f2b15612b14883d6ed2b0e295cb82b">00116</a> <span class="keywordtype">void</span> <a class="code" href="classbilinfn.html#90f2b15612b14883d6ed2b0e295cb82b" 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> ) |
---|
97 | <a name="l00117"></a>00117 { |
---|
98 | <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> ); |
---|
99 | <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> |
---|
100 | <a name="l00120"></a>00120 } |
---|
101 | <a name="l00121"></a>00121 }; |
---|
102 | <a name="l00122"></a>00122 |
---|
103 | <a name="l00123"></a>00123 <span class="preprocessor">#endif // FN_H</span> |
---|
104 | </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed Mar 12 16:15:45 2008 for mixpp by |
---|
105 | <a href="http://www.doxygen.org/index.html"> |
---|
106 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address> |
---|
107 | </body> |
---|
108 | </html> |
---|