From bea3658b783564ec1cbcfdb0659dbf454975dd30 Mon Sep 17 00:00:00 2001 From: toni Date: Tue, 26 Apr 2016 16:55:12 +0200 Subject: [PATCH] started smoothing part --- code/Settings.h | 6 ++- code/eval/FixedLagEvalBase.h | 11 ++++ code/eval/SmoothingEval1.h | 2 +- code/main.cpp | 2 +- tex/bare_conf.dvi | Bin 45840 -> 58260 bytes tex/bare_conf.tex | 3 +- tex/chapters/smoothing.tex | 101 +++++++++++++++++++++++++++++++++++ 7 files changed, 120 insertions(+), 5 deletions(-) diff --git a/code/Settings.h b/code/Settings.h index a973399..8d4c0ed 100644 --- a/code/Settings.h +++ b/code/Settings.h @@ -17,9 +17,11 @@ namespace MiscSettings { const int timeSteps = 500; - const int numParticles = 7500; + const int numParticles = 500; - const int lag = 5; + const int numBSParticles = 50; + + const int lag = 15; const int fixedLagGap = 1; diff --git a/code/eval/FixedLagEvalBase.h b/code/eval/FixedLagEvalBase.h index 698edeb..bac88ea 100644 --- a/code/eval/FixedLagEvalBase.h +++ b/code/eval/FixedLagEvalBase.h @@ -486,6 +486,17 @@ public: oSError << runName << "\n\t"; statsSmoothing.appendTo(oSError); oSError << "\n\n"; oSError.close(); + // append error for each run to a file + std::ofstream oTDError("/tmp/errorsDistFiltering.txt", std::ios_base::app); + oTDError << runName << "\n\t"; statsDistFiltering.appendTo(oTDError); oTDError << "\n\n"; + oTDError.close(); + + // append error for each run to a file + std::ofstream oSDError("/tmp/errorsDistSmoothing.txt", std::ios_base::app); + oSDError << runName << "\n\t"; statsDistSmoothing.appendTo(oSDError); oSDError << "\n\n"; + oSDError.close(); + + // plot-data std::ofstream oPath("/tmp/path_" + runName + ".dat"); vis.groundTruth.addDataTo(oPath); oPath.close(); // ground truth std::ofstream oEstN("/tmp/est_norm_" + runName + ".dat"); vis.estPath.addDataTo(oEstN); oEstN.close(); // estimation via filter itself diff --git a/code/eval/SmoothingEval1.h b/code/eval/SmoothingEval1.h index 3b4adae..519fc39 100644 --- a/code/eval/SmoothingEval1.h +++ b/code/eval/SmoothingEval1.h @@ -51,7 +51,7 @@ public: //create the backward smoothing filter - bf = new K::BackwardSimulation(500); + bf = new K::BackwardSimulation(MiscSettings::numBSParticles); //bf = new K::CondensationBackwardFilter; bf->setSampler( std::unique_ptr>(new K::CumulativeSampler())); diff --git a/code/main.cpp b/code/main.cpp index 1ebf0cd..6c3215d 100644 --- a/code/main.cpp +++ b/code/main.cpp @@ -57,7 +57,7 @@ void testModelWalk() { std::vector> states; - for (int i = 0; i < 1000; ++i) { states.push_back(GridWalkState(&start, Heading::rnd())); } +// for (int i = 0; i < 1000; ++i) { states.push_back(GridWalkState(&start, Heading::rnd())); } // track the number-of-visits for each node to draw something like a particle-heat-map? diff --git a/tex/bare_conf.dvi b/tex/bare_conf.dvi index b09aec58a364b5f6e967b42077bb6dc8aab012f8..69a89f9231054cd92d286b131f209d8f32b72b7b 100644 GIT binary patch delta 11769 zcmeHNeRNdSwV%wLNeBc4fnWpzwSEu?BNIXru+#zqB9MU4svzji%uO=M%-r$bJH}{N zho>md>I}J@GLDQgL6C}8AzzjBZ<)*w?q- zKX0waTCCieId`A4_t|@&-~R2>`o8l=F9@v{52={tttczM&*5<7Fz@_}+gH@aghF98 z+Z%hqwX0CLv2)$JOLKB|vLFA`SFX$jrygcI@0=)%*!!){7w>#8XV|WSpMRdYWZYll zaeY)>6FazW9Q(og!JWs}KawMqq(ydU!#Gw`m}FHOHVY%GUh6!x;rltl@cS2a*4#T0 zQajZjs!r!e2QY4Yr#t@7Il{P?Z)2^Aaj}t!iE(|n!_l*{K}xzlofi@VVHSxh5m}X( zT*tJAfXbR%->;XICWc2%W)VeheY5S>fL~&2NR}}oT%Xt$*K-|?kfb%pel?jZ&I^Ro zx#C=(9M&X^zD23YnG%i>(*k71gE-J>N&oRJs#aPcIBcl>@S&u>*Qci#*57`chXf{ z+ANWlzNm^#fiAXr0zTbUJjE|*Vj!p*TS%HJw27kPx6D#2`kI=z@UN22{U4~I7;UAb z=+6EBMhcQl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8{YjN@NuX>JbHL|KUkh0 zg8M=h#0^NHeIyO;4j+|tha!X*hA+^xH3x)|bZmLK$fP?|9a>(GaidwuMUzS24!nV7Kek!RFtGAC_5f& z#=p~>b! diff --git a/tex/bare_conf.tex b/tex/bare_conf.tex index 295cc23..b6707d5 100644 --- a/tex/bare_conf.tex +++ b/tex/bare_conf.tex @@ -71,7 +71,6 @@ \usepackage[cmex10]{amsmath} \interdisplaylinepenalty=2500 -\usepackage{algorithmic} \usepackage{array} \usepackage{mdwmath} \usepackage{mdwtab} @@ -80,6 +79,8 @@ \usepackage{epstopdf} %\usepackage{ulem} +\usepackage{algorithm} +\usepackage{algpseudocode} diff --git a/tex/chapters/smoothing.tex b/tex/chapters/smoothing.tex index d64df5b..a4b937b 100644 --- a/tex/chapters/smoothing.tex +++ b/tex/chapters/smoothing.tex @@ -3,8 +3,109 @@ +The main purpose of this work is to provide smoothing methods in context of indoor localisation. +As mentioned before, those algorithm are able to compute probability distributions in the form of $p(\mStateVec_t \mid \mObsVec_{1:T})$ and are therefore able to make use of future observations between $t$ and $T$. +%Especially fixed-lag smoothing is very promising in context of pedestrian localisation. +In the following we discuss the algorithmic details of the forward-backward smoother and the backward simulation. +Further, two novel approaches for incorporating them into the localisation system are shown. + +\subsection{Forward-backward Smoother} + +The forward-backward smoother (FBS) of \cite{Doucet00:OSM} is a well established alternative to the simple filter-smoother. The foundation of this algorithm was again laid by Kitagawa in \cite{kitagawa1987non}. +An approximation is given by +\begin{equation} +p(\vec{q}_t \mid \vec{o}_{1:T}) \approx \sum^N_{i=1} W^i_{t \mid T} \delta_{\vec{X}^i_{t}}(\vec{q}_{t}) \enspace, +\end{equation} +where $p(\vec{q}_t \mid \vec{o}_{1:T})$ has the same support as the filtering distribution $p(\vec{q}_t \mid \vec{o}_{1:t})$, but the weights are different. +This means, that the FBS maintains the original particle locations and just reweights the particles to obtain a smoothed density. +The complete FBS can be seen in algorithm \ref{alg:forward-backwardSmoother} in pseudo-algorithmic form. +At first, the algorithm obtains the filtered distribution (particles) by deploying a forward step at each time $t$. +Then the backward step for determining the smoothing distribution is carried out. +The weights are obtained through the backward recursion in line 9. +\begin{algorithm}[t] + \caption{Forward-Backward Smoother} + \label{alg:forward-backwardSmoother} + \begin{algorithmic}[1] % The number tells where the line numbering should start + \Statex{\textbf{Input:} Prior $\mu(\vec{X}^i_1)$} + \Statex{~} + \For{$t = 1$ \textbf{to} $T$} \Comment{Filtering} + \State{Obtain the weighted trajectories $ \{ W^i_t, \vec{X}^i_t\}^N_{i=1}$} + \EndFor + \For{ $i = 1$ \textbf{to} $N$} \Comment{Initialization} + \State{Set $W^i_{T \mid T} = W^i_T$} + \EndFor + \For{$t = T-1$ \textbf{to} $1$} \Comment{Smoothing} + \For{$i = 1$ \textbf{to} $N$} +\vspace*{0.1cm} + \State{ +$ +W^i_{t \mid T} = W^i_t \left[ \sum^N_{j=1} W^j_{t+1 \mid T} \frac{p(\vec{X}^j_{t+1} \mid \vec{X}^i_t)}{\sum^N_{k=1} W^k_t ~ p(\vec{X}^j_{t+1} \mid \vec{X}^k_t)} \right] +$} + \EndFor + \EndFor + \end{algorithmic} +\end{algorithm} + + + +%Probleme? Nachteile? Komplexität etc. +By reweighting the filter particles, the FBS improves the simple filter-smoother by removing its dependence on the inheritance (smoothed) paths \cite{fearnhead2010sequential}. However, by looking at algorithm \ref{alg:forward-backwardSmoother} it can easily be seen that this approach computes in $\mathcal{O}(N^2)$, where the calculation of each particle's weight is an $\mathcal{O}(N)$ operation. To reduce this computational bottleneck, \cite{klaas2006fast} introduced a solution using algorithms from N-body simulation. By integrating dual tree recursions and fast multipole techniques with the FBS a run-time cost of $\mathcal{O}(N \log N)$ can be achieved. + +\subsection{Backward Simulation} +For smoothing applications with a high number of particles, it is often not necessary to use all particles for smoothing. This decision can for example be made due to a high sample impoverishment and/or highly certain sensors. By choosing a good sub-set for representing the posterior distribution, it is theoretically possible to further improve the estimation. + +Therefore, \cite{Godsill04:MCS} presented the \textit{backward simulation}. Where a number of independent sample realizations from the entire smoothing density are used to approximate the smoothing distribution. To derive the backward simulation algorithm we need to factorize the joint smoothing distribution as follows: +\begin{equation} +p(\vec{q}_{1:T} \mid \vec{o}_{1:T}) = p(\vec{q}_{T} \mid \vec{o}_{1:T}) \prod^{T-1}_{t=1} p(\vec{q}_{t} \mid \vec{q}_{t+1:T}, \vec{o}_{1:T}) +\end{equation} +By using the Markov property of the model, we can write +\begin{equation} +\begin{split} +p(\vec{q}_{t} \mid \vec{q}_{t+1:T}, \vec{o}_{1:T}) &= p(\vec{q}_{t} \mid \vec{q}_{t+1}, \vec{o}_{1:t})\\ +&= \frac{p(\vec{q}_{t} \mid \vec{o}_{1:t}) p(\vec{q}_{t+1} \mid \vec{q}_{t})}{p(\vec{q}_{t+1} \mid \vec{o}_{1:t})} \\ +& \propto p(\vec{q}_{t} \mid \vec{o}_{1:t}) p(\vec{q}_{t+1} \mid \vec{q}_{t}) +\enspace , +\end{split} +\label{eq:backwardSimulation-02} +\end{equation} +where $p(\vec{q}_t \mid \vec{o}_{1:t})$ is obtained using any particle filter in the forward step. Using \ref{eq:backwardSimulation-02} the particles can be approximated as follows: +\begin{equation} +p(\vec{q}_{t} \mid \vec{q}_{t+1:T}, \vec{o}_{1:T}) \approx \sum^N_{i=1} W^i_{t \mid t+1} \delta_{\vec{X}^i_{t}}(\vec{q}_{t}) \enspace, +\end{equation} +where the weights are determined with +\begin{equation} +W^i_{t \mid t+1} = \frac{ W^i_t ~ p(\vec{q}_{t+1} \mid \vec{X}^i_{t})}{\sum^N_{j=1} W^j_t p(\vec{q}_{t+1} \mid \vec{X}^j_{t})}\enspace . +\end{equation} +This can now be used to generate states successively in the reverse-time direction, conditioning upon future states. + +\begin{algorithm}[t] + \caption{Backward Simulation Smoothing} + \label{alg:backwardSimulation} + \begin{algorithmic}[1] % The number tells where the line numbering should start + \Statex{\textbf{Input:} Prior $\mu(\vec{X}^i_1)$} + \Statex{~} + \For{$t = 1$ \textbf{to} $T$} \Comment{Filtering} + \State{Obtain the weighted trajectories $ \{ W^i_t, \vec{X}^i_t\}^N_{i=1}$} + \EndFor + \For{ $k = 1$ \textbf{to} $N_{\text{sample}}$} + \State{Choose $\tilde{\vec{q}}^k_T = \vec{X}^i_T$ with probability $W^i_T$} \Comment{Initialize} + + \For{$t = T-1$ \textbf{to} $1$} \Comment{Smoothing} + \For{$j = 1$ \textbf{to} $N$} + \State{$W^j_{t \mid t+1} = W^j_t ~ p(\tilde{\vec{q}}_{t+1} \mid \vec{X}^j_{t})$} + \EndFor + \State{Choose $\tilde{\vec{q}}^k_t = \vec{X}^j_t$ with probability $W^j_{t\mid t+1}$} + \EndFor + \State{$\tilde{\vec{q}}^k_{1:T} = (\tilde{\vec{q}}^k_1, \tilde{\vec{q}}^k_2, ..., \tilde{\vec{q}}^k_T)$ is one approximate realization from $p(\vec{q}_{1:T} \mid \vec{o}_{1:T})$} + \EndFor + \end{algorithmic} +\end{algorithm} + +The backward simulation method can be seen in algorithm \ref{alg:backwardSimulation} in pseudo-algorithmic form. Again, a particle filter is performed at first and then the smoothing procedure gets applied. Here, $\tilde{\vec{q}}_t$ is a random sample drawn approximately from $p(\vec{q}_{t} \mid \tilde{\vec{q}}_{t+1}, \vec{o}_{1:T})$. Therefore $\tilde{\vec{q}}_{1:T} = (\tilde{\vec{q}}_{1}, \tilde{\vec{q}}_{2}, ...,\tilde{\vec{q}}_{T})$ is one particular sample realization from $p(\vec{q}_{1:T} \mid \vec{o}_{1:T})$. Further independent realizations are obtained by repeating the algorithm until the desired number $N_{\text{sample}}$ is reached. The computational complexity for one particular realization is $\mathcal{O}(N)$. However, the computations are then repeated for each realization drawn \cite{Godsill04:MCS}. + +\subsection{Transition for Smoothing} %komplexität eingehen