started smoothing part

This commit is contained in:
toni
2016-04-26 16:55:12 +02:00
parent 0e7c45eb02
commit bea3658b78
7 changed files with 120 additions and 5 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -51,7 +51,7 @@ public:
//create the backward smoothing filter
bf = new K::BackwardSimulation<MyState>(500);
bf = new K::BackwardSimulation<MyState>(MiscSettings::numBSParticles);
//bf = new K::CondensationBackwardFilter<MyState>;
bf->setSampler( std::unique_ptr<K::CumulativeSampler<MyState>>(new K::CumulativeSampler<MyState>()));

View File

@@ -57,7 +57,7 @@ void testModelWalk() {
std::vector<GridWalkState<MyGridNode>> states;
for (int i = 0; i < 1000; ++i) { states.push_back(GridWalkState<MyGridNode>(&start, Heading::rnd())); }
// for (int i = 0; i < 1000; ++i) { states.push_back(GridWalkState<MyGridNode>(&start, Heading::rnd())); }
// track the number-of-visits for each node to draw something like a particle-heat-map?

Binary file not shown.

View File

@@ -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}

View File

@@ -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