📄 sirflt_8hpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Bayes++ Bayesian Filtering Classes: SIRFlt.hpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>SIRFlt.hpp</h1><a href="SIRFlt_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef _BAYES_FILTER_SIR</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define _BAYES_FILTER_SIR</span>00003 <span class="preprocessor"></span>00004 <span class="comment">/*</span>00005 <span class="comment"> * Bayes++ the Bayesian Filtering Library</span>00006 <span class="comment"> * Copyright (c) 2002 Michael Stevens</span>00007 <span class="comment"> * See accompanying Bayes++.htm for terms and conditions of use.</span>00008 <span class="comment"> *</span>00009 <span class="comment"> * $Header: /cvsroot/bayesclasses/Bayes++/BayesFilter/SIRFlt.hpp,v 1.14.2.1 2004/02/11 21:06:42 mistevens Exp $</span>00010 <span class="comment"> * $NoKeywords: $</span>00011 <span class="comment"> */</span>00012 00013 <span class="comment">/*</span>00014 <span class="comment"> * Sampling Importance Resampleing Filter Scheme.</span>00015 <span class="comment"> * Also know as a weighted Booststrap</span>00016 <span class="comment"> *</span>00017 <span class="comment"> * References</span>00018 <span class="comment"> * [1] "Novel approach to nonlinear-non-Guassian Bayesian state estimation"</span>00019 <span class="comment"> * NJ Gordon, DJ Salmond, AFM Smith IEE Proceeding-F Vol.140 No.2 April 1993</span>00020 <span class="comment"> * [2] Building Robust Simulation-based Filter for Evolving Data Sets"</span>00021 <span class="comment"> * J Carpenter, P Clifford, P Fearnhead Technical Report Unversity of Oxford</span>00022 <span class="comment"> *</span>00023 <span class="comment"> * A variety of reampling algorithms can be used for the SIR filter.</span>00024 <span class="comment"> * There are implementations for two algorihtms:</span>00025 <span class="comment"> * standard_resample: Standard resample algorithm from [1]</span>00026 <span class="comment"> * systematic_resample: A Simple stratified resampler from [2]</span>00027 <span class="comment"> * A virtual 'weighted_resample' provides an standard interface to these and defaults</span>00028 <span class="comment"> * to the standard_resample.</span>00029 <span class="comment"> *</span>00030 <span class="comment"> * NOTES:</span>00031 <span class="comment"> * SIR algorithm is sensative to random generator</span>00032 <span class="comment"> * In particular random uniform must be [0..1) NOT [0..1]</span>00033 <span class="comment"> * Quantisation in the random number generator must not approach the sample size.</span>00034 <span class="comment"> * This will result in quantisation of the resampling.</span>00035 <span class="comment"> * For example if random identically equal to 0 becomes highly probable due to quantisation</span>00036 <span class="comment"> * this will result in the first sample being selectively draw whatever its likelihood.</span>00037 <span class="comment"> *</span>00038 <span class="comment"> * Numerics</span>00039 <span class="comment"> * Resampling requires comparisons of normalised weights. These may</span>00040 <span class="comment"> * become insignificant if Likelihoods have a large range. Resampling becomes ill conditioned</span>00041 <span class="comment"> * for these samples.</span>00042 <span class="comment"> */</span>00043 <span class="preprocessor">#include "<a class="code" href="bayesFlt_8hpp.html">bayesFlt.hpp</a>"</span>00044 00045 <span class="comment">/* Filter namespace */</span>00046 <span class="keyword">namespace </span>Bayesian_filter00047 {00048 <a name="l00049"></a><a class="code" href="structBayesian__filter_1_1SIR__random.html">00049</a> <span class="keyword">struct </span><a class="code" href="structBayesian__filter_1_1SIR__random.html">SIR_random</a>00050 <span class="comment">/*</span>00051 <span class="comment"> * Random number generators interface</span>00052 <span class="comment"> * Helper to allow polymorthic use of random number generators</span>00053 <span class="comment"> */</span>00054 {00055 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="structBayesian__filter_1_1SIR__random.html#a0">normal</a>(FM::DenseVec& v) = 0;00056 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="structBayesian__filter_1_1SIR__random.html#a1">uniform_01</a>(FM::DenseVec& v) = 0;00057 };00058 00059 <a name="l00060"></a><a class="code" href="classBayesian__filter_1_1Importance__resampler.html">00060</a> <span class="keyword">class </span><a class="code" href="classBayesian__filter_1_1Importance__resampler.html">Importance_resampler</a> : <span class="keyword">public</span> <a class="code" href="classBayesian__filter_1_1Bayes__base.html">Bayes_base</a>00061 <span class="comment">/*</span>00062 <span class="comment"> * Importance resampler</span>00063 <span class="comment"> * Represents a function that computes the posterior resampling from importance weights</span>00064 <span class="comment"> * Polymorphic function object used to parameterise the resampling operation</span>00065 <span class="comment"> */</span>00066 {00067 <span class="keyword">public</span>:<a name="l00068"></a><a class="code" href="classBayesian__filter_1_1Importance__resampler.html#w0">00068</a> <span class="keyword">typedef</span> std::vector<size_t> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html#w0">Resamples_t</a>; <span class="comment">// resampling counts</span>00069 00070 <span class="keyword">virtual</span> <a class="code" href="classBayesian__filter_1_1Bayes__base.html#w0">Float</a> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html#a0">resample</a> (Resamples_t& presamples, size_t& uresamples, FM::DenseVec& w, <a class="code" href="structBayesian__filter_1_1SIR__random.html">SIR_random</a>& r) <span class="keyword">const</span> = 0;00071 <span class="comment">/*</span>00072 <span class="comment"> * The resampling function</span>00073 <span class="comment"> * Weights w are proportional to the posterior Likelihood of a state</span>00074 <span class="comment"> * Sideeffect</span>00075 <span class="comment"> * w becomes a normalised cumulative sum</span>00076 <span class="comment"> * Random draws can be made from 'r'</span>00077 <span class="comment"> *</span>00078 <span class="comment"> * Exceptions:</span>00079 <span class="comment"> * bayes_filter_exception for numerical problems with weights including</span>00080 <span class="comment"> * any w < 0, all w == 0</span>00081 <span class="comment"> * Return</span>00082 <span class="comment"> * lcond, smallest normalised weight, represents conditioning of resampling solution</span>00083 <span class="comment"> * presamples: posterior resample, the number of times each sample should appear posterior baes on it weight</span>00084 <span class="comment"> * uresample: the number of unique resamples in the posterior == number of non zero elements in presamples</span>00085 <span class="comment"> * Preconditions</span>00086 <span class="comment"> * wresample,w must have same size</span>00087 <span class="comment"> */</span>00088 };00089 <a name="l00090"></a><a class="code" href="classBayesian__filter_1_1Standard__resampler.html">00090</a> <span class="keyword">class </span><a class="code" href="classBayesian__filter_1_1Standard__resampler.html">Standard_resampler</a> : <span class="keyword">public</span> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html">Importance_resampler</a>00091 <span class="comment">// Standard resample algorithm from [1]</span>00092 {00093 <a class="code" href="classBayesian__filter_1_1Bayes__base.html#w0">Float</a> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html#a0">resample</a> (<a class="code" href="classBayesian__filter_1_1Importance__resampler.html#w0">Resamples_t</a>& presamples, size_t& uresamples, FM::DenseVec& w, <a class="code" href="structBayesian__filter_1_1SIR__random.html">SIR_random</a>& r) <span class="keyword">const</span>;00094 };00095 <a name="l00096"></a><a class="code" href="classBayesian__filter_1_1Systematic__resampler.html">00096</a> <span class="keyword">class </span><a class="code" href="classBayesian__filter_1_1Systematic__resampler.html">Systematic_resampler</a> : <span class="keyword">public</span> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html">Importance_resampler</a>00097 <span class="comment">// Systematic resample algorithm from [2]</span>00098 {00099 <a class="code" href="classBayesian__filter_1_1Bayes__base.html#w0">Float</a> <a class="code" href="classBayesian__filter_1_1Importance__resampler.html#a0">resample</a> (<a class="code" href="classBayesian__filter_1_1Importance__resampler.html#w0">Resamples_t</a>& presamples, size_t& uresamples, FM::DenseVec& w, <a class="code" href="structBayesian__filter_1_1SIR__random.html">SIR_random</a>& r) <span class="keyword">const</span>;00100 };00101 00102 00103 <span class="keyword">template</span> <<span class="keyword">class</span> Predict_model><a name="l00104"></a><a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html">00104</a> <span class="keyword">class </span><a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html">Sampled_general_predict_model</a>: <span class="keyword">public</span> Predict_model, <span class="keyword">public</span> <a class="code" href="classBayesian__filter_1_1Sampled__predict__model.html">Sampled_predict_model</a>00105 <span class="comment">/*</span>00106 <span class="comment"> * Generalise a predict model to sampled predict model using and SIR random</span>00107 <span class="comment"> * To instantiate template std::sqrt is required</span>00108 <span class="comment"> */</span>00109 {00110 <span class="keyword">public</span>:<a name="l00111"></a><a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html#a0">00111</a> <a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html#a0">Sampled_general_predict_model</a> (size_t x_size, size_t q_size, <a class="code" href="structBayesian__filter_1_1SIR__random.html">SIR_random</a>& random_helper) :00112 Predict_model(x_size, q_size),00113 <a class="code" href="classBayesian__filter_1_1Sampled__predict__model.html">Sampled_predict_model</a>(),00114 genn(random_helper),00115 xp(x_size),00116 n(q_size), rootq(q_size)00117 {00118 first_init = <span class="keyword">true</span>;00119 }00120 <a name="l00121"></a><a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html#a1">00121</a> <span class="keyword">virtual</span> <span class="keyword">const</span> FM::Vec& <a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html#a1">fw</a>(<span class="keyword">const</span> FM::Vec& x) <span class="keyword">const</span>00122 <span class="comment">/*</span>00123 <span class="comment"> * Definition of sampler for addative noise model given state x</span>00124 <span class="comment"> * Generate Gaussian correlated samples</span>00125 <span class="comment"> * Precond: init_GqG, automatic on first use</span>00126 <span class="comment"> */</span>00127 {00128 <span class="keywordflow">if</span> (first_init)00129 <a class="code" href="classBayesian__filter_1_1Sampled__general__predict__model.html#a2">init_GqG</a>();00130 <span class="comment">// Predict state using supplied functional predict model</span>00131 xp = Predict_model::f(x);00132 <span class="comment">// Additive random noise</span>00133 genn.<a class="code" href="structBayesian__filter_1_1SIR__random.html#a0">normal</a>(n); <span class="comment">// independant zero mean normal</span>00134 <span class="comment">// multiply elements by std dev</span>00135 <span class="keywordflow">for</span> (FM::DenseVec::iterator ni = n.begin(); ni != n.end(); ++ni) {00136 *ni *= rootq[ni.index()];00137 }00138 FM::noalias(xp) += FM::prod(this->G,n); <span class="comment">// add correlated noise</span>00139 <span class="keywordflow">return</span> xp;00140 }00141
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -