⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ublasmatrix_8hpp-source.html

📁 Bayes滤波器算法C++类说明文档,源码见Bayes滤波器算法
💻 HTML
📖 第 1 页 / 共 4 页
字号:
00300 00301 00302 00303 <span class="comment">/*</span>00304 <span class="comment"> * Vector / Matrix types</span>00305 <span class="comment"> *  Finally the definitions !</span>00306 <span class="comment"> */</span>00307 <span class="keyword">using</span> detail::FMVec;        <span class="comment">// Template class for template parameter matching</span>00308 <span class="keyword">using</span> detail::FMMatrix;00309 00310                             <span class="comment">// Default types</span><a name="l00311"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a1">00311</a> <span class="keyword">typedef</span> FMVec&lt;detail::BaseVector&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a1">Vec</a>;<a name="l00312"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a2">00312</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseRowMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a2">RowMatrix</a>;<a name="l00313"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a3">00313</a> <span class="keyword">typedef</span> <a class="code" href="namespaceBayesian__filter__matrix.html#a2">RowMatrix</a> <a class="code" href="namespaceBayesian__filter__matrix.html#a3">Matrix</a>;<a name="l00314"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a4">00314</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseColMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a4">ColMatrix</a>;<a name="l00315"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a5">00315</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::SymMatrixWrapper&lt;detail::BaseRowMatrix&gt; &gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a5">SymMatrix</a>;<a name="l00316"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a6">00316</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseUpperTriMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a6">UTriMatrix</a>;<a name="l00317"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a7">00317</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseLowerTriMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a7">LTriMatrix</a>;<a name="l00318"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a8">00318</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDiagMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a8">DiagMatrix</a>;00319 00320                             <span class="comment">// Explicitly dense types</span><a name="l00321"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a9">00321</a> <span class="keyword">typedef</span> FMVec&lt;detail::BaseDenseVector&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a9">DenseVec</a>;<a name="l00322"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a10">00322</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseRowMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a10">DenseRowMatrix</a>;<a name="l00323"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a11">00323</a> <span class="keyword">typedef</span> <a class="code" href="namespaceBayesian__filter__matrix.html#a10">DenseRowMatrix</a> <a class="code" href="namespaceBayesian__filter__matrix.html#a11">DenseMatrix</a>;<a name="l00324"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a12">00324</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseColMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a12">DenseColMatrix</a>;<a name="l00325"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a13">00325</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::SymMatrixWrapper&lt;detail::BaseDenseRowMatrix&gt; &gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a13">DenseSymMatrix</a>;<a name="l00326"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a14">00326</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseUpperTriMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a14">DenseUTriMatrix</a>;<a name="l00327"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a15">00327</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseLowerTriMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a15">DenseLTriMatrix</a>;<a name="l00328"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a16">00328</a> <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseDiagMatrix&gt; <a class="code" href="namespaceBayesian__filter__matrix.html#a16">DenseDiagMatrix</a>;00329 00330                             <span class="comment">// Explicitly sparse types (any of the gappy types)</span>00331 <span class="preprocessor">#ifdef BAYES_FILTER_GAPPY</span>00332 <span class="preprocessor"></span><span class="keyword">typedef</span> FMVec&lt;detail::BaseSparseVector&gt; SparseVec;00333 <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseDenseRowMatrix&gt; SparseRowMatrix;00334 <span class="keyword">typedef</span> SparseRowMatrix SparseMatrix;00335 <span class="keyword">typedef</span> FMMatrix&lt;detail::BaseSparseColMatrix&gt; SparseColMatrix;00336 <span class="keyword">typedef</span> FMMatrix&lt;detail::SymMatrixWrapper&lt;detail::BaseSparseRowMatrix&gt; &gt; SparseSymMatrix;00337 <span class="preprocessor">#endif</span>00338 <span class="preprocessor"></span>00339 00340 <span class="comment">/*</span>00341 <span class="comment"> * Matrix Adaptors, simply hide the uBLAS details</span>00342 <span class="comment"> */</span>00343 <span class="keyword">template</span> &lt;<span class="keyword">class</span> M&gt;00344 <span class="keyword">const</span> ublas::triangular_adaptor&lt;const M, ublas::upper&gt;<a name="l00345"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a51">00345</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a51">UpperTri</a>(<span class="keyword">const</span> M&amp; m)00346 <span class="comment">/*</span>00347 <span class="comment"> * View Upper triangle of m</span>00348 <span class="comment"> * ISSUE VC7 cannot cope with UTriMatrix::functor1_type</span>00349 <span class="comment"> */</span>00350 {00351     <span class="keywordflow">return</span> ublas::triangular_adaptor&lt;const M, ublas::upper&gt;(m);00352 }00353 00354 <span class="keyword">template</span> &lt;<span class="keyword">class</span> M&gt;00355 <span class="keyword">const</span> ublas::triangular_adaptor&lt;const M, ublas::lower&gt;<a name="l00356"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a52">00356</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a52">LowerTri</a>(<span class="keyword">const</span> M&amp; m)00357 <span class="comment">/*</span>00358 <span class="comment"> * View Lower triangle of m</span>00359 <span class="comment"> */</span>00360 {00361     <span class="keywordflow">return</span> ublas::triangular_adaptor&lt;const M, ublas::lower&gt;(m);00362 }00363 00364 00365 00366 <span class="comment">/*</span>00367 <span class="comment"> * Matrix Support Operations</span>00368 <span class="comment"> */</span>00369 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Base&gt;00370 ublas::matrix_vector_range&lt;FMMatrix&lt;Base&gt; &gt;<a name="l00371"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a53">00371</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a53">diag</a>(FMMatrix&lt;Base&gt;&amp; M, size_t n)00372 {   <span class="comment">// Return a vector proxy to the first n diagonal elements of M</span>00373     <span class="keywordflow">return</span> ublas::matrix_vector_range&lt;FMMatrix&lt;Base&gt; &gt;(M, ublas::range(0,n), ublas::range(0,n));00374 }00375 00376 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Base&gt;00377 <span class="keyword">const</span> ublas::matrix_vector_range&lt;const FMMatrix&lt;Base&gt; &gt;<a name="l00378"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a54">00378</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a53">diag</a>(<span class="keyword">const</span> FMMatrix&lt;Base&gt;&amp; M, size_t n)00379 {   <span class="comment">// Return a vector proxy to the first n diagonal elements of M</span>00380     <span class="keywordflow">return</span> ublas::matrix_vector_range&lt;const FMMatrix&lt;Base&gt; &gt;(M, ublas::range(0,n), ublas::range(0,n));00381 }00382 00383 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Base&gt;00384 ublas::matrix_vector_range&lt;FMMatrix&lt;Base&gt; &gt;<a name="l00385"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a55">00385</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a53">diag</a>(FMMatrix&lt;Base&gt;&amp; M)00386 {   <span class="comment">// Return a vector proxy to the diagonal elements of M</span>00387     <span class="keyword">const</span> size_t common_size = std::min(M.size1(),M.size2());00388     <span class="keywordflow">return</span> ublas::matrix_vector_range&lt;FMMatrix&lt;Base&gt; &gt;(M, ublas::range(0,common_size), ublas::range(0,common_size));00389 }00390 00391 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Base&gt;00392 <span class="keyword">const</span> ublas::matrix_vector_range&lt;const FMMatrix&lt;Base&gt; &gt;<a name="l00393"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a56">00393</a>  <a class="code" href="namespaceBayesian__filter__matrix.html#a53">diag</a>(<span class="keyword">const</span> FMMatrix&lt;Base&gt;&amp; M)00394 {   <span class="comment">// Return a vector proxy to the diagonal elements of M</span>00395     <span class="keyword">const</span> size_t common_size = std::min(M.size1(),M.size2());00396     <span class="keywordflow">return</span> ublas::matrix_vector_range&lt;const FMMatrix&lt;Base&gt; &gt;(M, ublas::range(0,common_size), ublas::range(0,common_size));00397 }00398 00399 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Base&gt;<a name="l00400"></a><a class="code" href="namespaceBayesian__filter__matrix.html#a57">00400</a> <span class="keywordtype">void</span> <a class="code" href="namespaceBayesian__filter__matrix.html#a57">identity</a>(FMMatrix&lt;Base&gt;&amp; I)00401 {   <span class="comment">// Set I to generalised Identity matrix. Clear I and set diag(I) to one</span>00402     I.clear();00403                             <span class="comment">// Set common diagonal elements</span>00404     size_t common_size = std::min(I.size1(),I.size2());00405     <span class="keyword">typedef</span> <span class="keyword">typename</span> Base::value_type Base_value_type;00406     <a class="code" href="namespaceBayesian__filter__matrix.html#a53">diag</a>(I) = ublas::scalar_vector&lt;Base_value_type&gt;(common_size, Base_value_type(1));00407 }00408 00409 00410 00411 <span class="comment">/*</span>00412 <span class="comment"> * Symmetric Positive (Semi) Definate multiplication: X*S*X' and X'*S*X</span>00413 <span class="comment"> *  The name is slightly misleading. The result is actually only PD if S is PD</span>00414 <span class="comment"> *  Algorithms are intended to exploit the symmerty of the result</span>00415 <span class="comment"> *  and also where possible the row by row multiplication inherent in X*X'</span>00416 <span class="comment"> */</span>00417 00418 <span class="keyword">namespace </span>detail {      <span class="comment">// mult_SPD now an implementation detail</span>00419     00420 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MatrixX&gt;<a name="l00421"></a><a class="code" href="namespaceBayesian__filter__matrix_1_1detail.html#a12">00421</a> <span class="keywordtype">void</span> <a class="code" href="namespaceBayesian__filter__matrix_1_1detail.html#a12">mult_SPD</a> (<span class="keyword">const</span> MatrixX&amp; X, <span class="keyword">const</span> Vec&amp; s, SymMatrix&amp; P)00422 <span class="comment">/*</span>00423 <span class="comment"> * Symmetric Positive (Semi) Definate multiply: P += X*diag_matrix(s)*X'</span>00424 <span class="comment"> */</span>00425 {00426     Vec::const_iterator si, send = s.end();00427     <span class="keyword">typename</span> MatrixX::const_iterator1 Xa = X.begin1();00428     <span class="keyword">const</span> <span class="keyword">typename</span> MatrixX::const_iterator1 Xend = X.end1();00429     <span class="keyword">typename</span> MatrixX::const_iterator1 Xb;00430 00431     <span class="comment">// P(a,b) = X.row(a) * X.row(b)</span>00432     <span class="keywordflow">for</span> (; Xa != Xend; ++Xa)                <span class="comment">// Iterate Rows</span>00433     {00434         <span class="keyword">typename</span> MatrixX::const_Row Xav = MatrixX::rowi(Xa);00435         Xb = Xa;                            <span class="comment">// Start at the row Xa only one triangle of symetric result required</span>00436         <span class="keywordflow">for</span> (; Xb != Xend; ++Xb)00437         {00438             SymMatrix::value_type p = 0;    <span class="comment">// Tripple vector inner product</span>00439             <span class="keyword">typename</span> MatrixX::const_Row Xbv = MatrixX::rowi(Xb);00440             <span class="keywordflow">for</span> (si = s.begin(); si != send; ++si) {00441                 Vec::size_type i = si.index();00442                 p += Xav[i] * (*si) * Xbv[i];00443             }00444             P(Xa.index1(),Xb.index1()) += p;00445         }00446     }00447 }00448 00449 <span class="keyword">template</span> &lt;<span class="keyword">class</span> MatrixX&gt;<a name="l00450"></a><a class="code" href="namespaceBayesian__filter__matrix_1_1detail.html#a13">00450</a> <span class="keywordtype">void</span> <a class="code" href="namespaceBayesian__filter__matrix_1_1detail.html#a13">mult_SPDT</a> (<span class="keyword">const</span> MatrixX&amp; X, <span class="keyword">const</span> Vec&amp; s, SymMatrix&amp; P)00451 <span class="comment">/*</span>00452 <span class="comment"> * Symmetric Positive (Semi) Definate multiply: P += X'*diag_matrix(s)*X</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -