📄 bayesian filtering classes.html
字号:
<H4>Changing the state representation size</H4><P>The classes assume their state representation is a constant size.They define their matrix sizes on construction. Matrices (andvectors!) in public representation <U>should NOT be externallyresized</U>.</P><P>Since matrix resizing invariable involves reallocation, it is justas efficient to create new matrices as to resize them. Also for afilter scheme to change it size it must recomputed its internalstates. Therefore if the size of filter needs to change, the solutionis to create a new filter. The new filter can then be <I>initialized</I>from the state of the old filter plus some new states. What you dowith these new states usually influences the state representation youchoose. Generally new states either enter the system with nothingbeing know about them (zero information), or extract value being know(zero covariance).</P><H2>Numerical and Exception Guarantees</H2><P>It is important to be able to rely on the numerical results ofBayes++. Generally the Schemes are implemented using the mostnumerically stable approach available in the literature. Bayes++provides its own UdU' factorization functions to factorize PSDpositive (semi)definite matrices. The factorization is numericallystable, computing and checking the conditioning of matrices.</P><P>Exceptions are thrown in the case of numerical failure. Theyfollow a simple rule:<BR><EM><STRONG>Bayes_filter_exception</STRONG>is thrown if an algorithm cannot continue or guarantee the numericalpost-conditions of a function</EM></P><P>The only <EM>exception guarantee</EM> that Bayes++ makes whenthrowing <STRONG><EM>Bayes_filter_exception</EM> </STRONG>from anyfunction, is that no resources will be leaked. That is the <I>Weakguarantee</I> as defined by <A HREF="#Reference">Reference[9]</A>.Therefore, unless otherwise specified, the numeric value of a class'spublic state is <STRONG>undefined</STRONG> after this exception isthrown by a member of a class.</P><P>Be aware that numerical post-conditions may be met even withextreme input values. For example some inputs may result in overflowof a result. This does not invalidate the post-conditions that theresult is positive. Even some <EM>Not a Number</EM> values may bevalid. Therefore the results may be computed without exception, butinclude <EM>NaN</EM> or <EM>non-number</EM> values.</P><H3>Using exceptions in filter schemes</H3><P>What does this mean when using a filter Scheme? If the Schemethrows an exception then, unless otherwise specified, the numericvalue of its state is undefined. Therefore you <STRONG>cannot</STRONG>use any function of the filter that has any preconditions on itsnumerical state. To continue using a filter either the <EM>init</EM>()function should be used (which has no pre-conditions) or the filterdestructed.</P><P>Generally to access the public state of a Scheme you must firstcall the <EM>update</EM>() function. If no exception is thrown thenthe post-conditions of update are guaranteed. The post-conditions of<EM>update</EM>() may include such useful properties as thecovariance matrix is PSD. Many application specific tests may also berequired. Just being PSD doesn't say much about X. It could even have<EM>Infinity</EM> values on the diagonal! Conditioning, trace,determinate, and variance bounds can all be applied at his point.</P><H1>Polymorphic design</H1><P>Why are models and filter Schemes <STRONG>polymorphic</STRONG> ?OR Why are they implemented with virtual functions?</P><BLOCKQUOTE><P>One alternative would be to use <STRONG>generic</STRONG>instead of <STRONG>polymorphic</STRONG> Schemes. This would implementSchemes as templates. If the sizes of matrix operations could befixed generic models and schemes would directly manipulate matricesfor predefined size.</P></BLOCKQUOTE><P>Bayes++ relies on a <STRONG>dual abstraction</STRONG>, separatingnumerical schemes from model structure. To represent these, a<STRONG>polymorphic design </STRONG>was a very important part ofBayes++ design. After a fair bit of use I still think it was thecorrect one. Why?</P><P>A) <EM>Usage</EM> : There are many (run time) polymorphic things Ireally want to do with the library. I want to be able to buildcomposite filtering algorithms that switch models and schemes at runtime. This requires<U> both</U> polymorphic filters and models <U>and</U>runtime sizing of matrices.<BR>A generic approach, especially oneparametrized on matrix size would not allow this. The code sizeproduced would also bloat massively. Not even STL parameterizes itscontainers template with size!</P><P>B) <EM>Type safety</EM>: There is surprising little orthogonalityin filtering schemes. The numerics often dictate restrictions oradditional functionality. The type hierarchy in Bayes++ provides asuccinct and safe way to enforce much of this structure.<BR>In aGeneric approach checking that a particular Scheme models a genericconcept correct would be very difficult to enforce.</P><P>C) <EM>Compiler problems</EM>: Generic programming in C++ has anasty syntax, is very slow to compile and pushes the limits ofcompiler reliability.</P><P>D) <EM>Efficiency</EM>: The run time overhead of a polymorphicfilter is negligible compared to the matrix algebra required. In factusing common code may increase efficiency on a many computingarchitectures.</P><H1 ALIGN=LEFT>Matrix Representation</H1><P>Bayes++ requires an external library to represent matrices andvectors, and to support basic linear algebra operations. Bayes++ usesthe <A HREF="http://www.boost.org/libs/numeric/ublas/doc/index.htm"><B>uBLAS</B></A>library from <A HREF="http://www.boost.org/"><B>Boost</B></A> for allthese requirements. It an excellent basic linear algebra library. Theinterface and syntax are easy to use.</P><P>Previous versions of the filters were implemented with the <A HREF="http://www.osl.iu.edu/research/mtl/" TARGET="_top">MatrixTemplate Library</A>, <I>MPP</I> and <I>TNT</I>. Public releasesusing MTL are still available.</P><P>The Bayes++ implementation uses a set of adapter classes in thenamespace <I>Bayesian_filter_matrix</I> (FM for short) for matrixaccess. This system should make it simpler to port the library toother matrix types. For uBLAS these function generally have noruntime overhead. This efficiency is due to uBLAS's excellentexpression template implementation. For MTL most functions arereasonably efficient but some functions create matrix temporaries toreturn values.</P><H2>Matrix library efficiency - Temporary object usage</H2><P>Most of the filters avoid using Matrix and Vector temporaries.They also have optimizations for a constant (on construction) statesize, noise and observations. In particularly the UD_filter schemeavoids creating any temporary objects. All matrices maintain a fixedsize, other then when the observation state size is varied.</P><P>Why are temporary matrix objects bad? The main difficulty isconstruction and destruction of Matrices. This generally requiresdynamic memory allocation which is very slow. For small matrices thisdominates compared to the cost of simple operations such as additionand multiplication.</P><P>There are three ways out of this problem.</P><BLOCKQUOTE><P>1. Use fixed size matrices; they can (nearly) alwaysbe efficiently allocated on the stack.<BR>2. Use stack based dynamicallocators (such as C99's dynamic arrays or alloca) fortemporaries.<BR>3. Don't create temporaries. This is achievable witha combination of hard coding in the algorithms (pre-allocation) andby using a Matrix library with expression templates to avoid creatingtemporaries for return values.</P></BLOCKQUOTE><P>Bayes++ is implemented to avoid creating temporaries. At presentmy solution is somewhat of a compromise. MTL is only moderatelyefficient on most C++ compilers. On release code this results in a50% performance reduction if temporaries are avoided. uBLAS attainsclose to optimal efficiency in many situations.</P><P>The UD_filter is a good illustration. It has been hand crafted toavoid construction of any temporaries (I use it for embedding) andcan be compiled with either uBLAS, MTL or a special fast matrixlibrary. UD_filter is heavily optimized to use row operations toavoid indexing overheads. uBLAS and the special library achievecomparable results, which I believe are as fast as can be achieved.</P><P>On the flip side, the current Unscented_filter implementationshows some of the problems. Because of my wrapper classes Row/Columnof a 2D matrix are not compatible with the Vec type. This results ina lot of unnecessary copying into pre-allocated temporary vectors.</P><P>Future work includes a general method of avoiding implementationtemporaries. Filter schemes will be parameterised with helper objectsthat deal with all the temporaries required. These helper objects canthen hide all the hard work of pre-allocation or dynamic allocationof temporary objects.</P><H1>Restrictions</H1><P>For numerical precision, all filter calculations use <B>doubles</B>.Templates could be used o provide numerical type parameterization butare not. However the base class <I>Bayes_filter</I> defines <I>Float</I>,which is used throughout as the numerical type.</P><P>The <I>Bayes_filter</I> base class is constructed with constantstate size. This allows efficient use of the matrix library toimplement the algorithms. Each derived class requires additionalrepresentation and matrix temporaries and where possible they arerestricted to a constant size. In general, the only unknown is thesize of the observation state as parameterized by the observationmodel.</P><P>Where the state size varies efficient solutions are still possibleusing either spares matrix representations or by recreating newfilters with increased size.</P><H1>The future</H1><P>The Bayesian Filtering Classes are now a stable set of solutionfor the majority of linear, linearisable and non-linear filteringproblems. I am very happy with their form and function. Inparticular, the two-layer abstraction works extremely well. Theclasses show best practice in both their design and in efficiency andnumerical stability of the algorithms used. So where to go from here?</P><P>The basic tenant of Bayesian theory is that the Likelihoodfunction complete captures all that is know to update the state. TheBayesian Filtering classes now allow the modeling systems usingLikelihood functions. At present the SIR filter is the onlyLikelihood filter. Sample filters will grow into a separate branch inthe class hierarchy. A general set of adapters will be required tomove between these varied representations.</P><P>To further improve the abstraction, the method of internalvariable exposure needs to be regularized. This will require theaddition of a few classes that hold and limit access to filtersinternal variables.</P><P>The ordering of parameters used in Scheme class constructors isprone to error. It requires the parameter list to be varied for eachscheme used. An extensible method of model parameterization isrequired. A common parameterization could then be used with schemeconstructor extracting the information they require.</P><H2>STATE ABSTRACTION</H2><P>Can the state representation be abstracted away from the numericsof a filter Scheme?</P><P>At the moment Bayes++ filter Schemes are a combination of thenumerical solution (e.g. innovation update) AND the representation(e.g. Covariance matrix). Can these two functions be separated?</P><P>A highly sophisticated solution could use polymorphic (or generic)filter algorithms that depend on the type (or traits) of therepresentation. I think this in unnecessarily complex. In Bayes++ aScheme should only implement one algorithm.</P><P>The problem I would like to address is a bit more limited. A lotof representations are naturally hierarchical and dynamic.<BR>e.g.state := vehicle states & feature states, feature states :={feature1 state & feature2 state ....}</P><P>There would seem to be too possible ways to solve this</P><P>A) HARD: Use a state representation that represents this kind ofhierarchy. The filter schemes could therefore use hierarchicalnumerical solutions that exploit the properties of the hierarchicalstate.</P><P>B) EASY: Allow a sparse matrix representation of state. If thesparse representation is a Graph then the sort of augmented staterepresentation in the example can be easily built without any copyoverhead. Each scheme would then just use sparse matrix techniques inits numerical solution. Mostly what is needed is Cholesky and QRdecomposition and these have good sparse solutions. Obviously therewould be a runtime overhead for this but it would be great forSimultaneous Location and Mapping problems!</P><H1 ALIGN=LEFT></A>Copyright</H1><P ALIGN=LEFT>Copyright (c) 2003,2004,2005 Michael Stevens. This document ispart of the Bayes++ library - see Bayes++.html for copyright licensedetails.</P><H1><A NAME="References"></A>References</H1><P>[1] "A New Approach for Filtering Nonlinear Systems", SJJulier JK Uhlmann HF Durrant-Whyte, American Control Conference 1995</P><P>[2] "Factorisation Methods for Discrete SequentialEstimation", Gerald J. Bierman, ISBN 0-12-097350-2</P><P>[3] "Real time Kalman Filter Application", Mohinder S.Grewal, Angus P. Andrews, ISBN 0-13-211335-X</P><P>[4] "Extension of Square-Root Filtering to Include ProcessNoise", P. Dyer and S. McReynolds, Journal of OptimizationTheory and Applications, Vol.3 No.6 1969</P><P>[5] "Novel approach to nonlinear-non-Guassian Bayesian stateestimation", NJ Gordon, DJ Salmond, AFM Smith, IEE Proceeding-F,Vol.140 No.2 April 1993</P><P>[6] "Tracking and Data Association", Y Bar-Shalom and TFortmann, Academic Press, ISBN 0-12-079760-7</P><P>[7] "Stochastic Models, Estimation, and Control", PeterS Maybeck, Academic Press, ISBN 0-12-480701-1</P><P>[8] "A non-divergent Estimation Algorithm in th Presence ofUnknown Correlaltion", SJ Julier, JK Uhlmann, Proc. AmericanControl Conference 6/1997</P><P>[9] "Exception-Safety in Generic Components", DavidAbrahams, Proc. of a Dagstuhl Seminar 'Generic Programming', LectureNotes on Computer Science 1766,<A HREF="http://www.boost.org/more/error_handling.html" TARGET="_top">http://www.boost.org/more/error_handling.html</A></P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -