\section{Particle Filtering}

As described earlier, we use a CONDENSATION particle filter to implement the recursive state estimator described in section \ref{sec:rse}.
A set of $N$ particles is defined by $\{\vec{X}^i_{t}, w^i_{t} \}_{i=1}^N$, where $\mParticleVec^{i}_{t}$ is sampled based on the state transition $p(\mStateVec_{t} \mid \mStateVec_{t-1}, \mObsVec_{t-1})$.
The weight $w_t^i$ is obtained by the probability density of the state evaluation $p(\mObsVec_{t} \mid \mStateVec_{t})$.
A particle set approximates the posterior as follows:

\begin{equation}
p(\mStateVec_{t} \mid \mObsVec_{1:t}) \approx \sum^N_{i=1} w^i_t \delta_{\vec{X}^i_{t}}(\vec{q}_{t}) \enspace,
\label{eg:monteEstimation}
\end{equation}

\noindent where $\delta_{x_0}(x)$ denotes the Dirac delta mass located at $x_0$.
As one can imagine, after a few iterations with continuously reweighting particles, the weight will concentrate on a few particles only.
To handle this phenomenon of weight degeneracy, a resampling procedure is performed after every filter step \cite{robotics}. 

\input{chapters/estimation}

\subsection{Sample Impoverishment}
\label{sec:impo}
As we have extensively discussed in \cite{Fetzer-17}, besides sample degeneracy, particle filters (and nearly all of its modifications) continue to suffer from another notorious problem: sample impoverishment. 
It refers to a situation, in which the filter is unable to sample enough particles into proper regions of the building, caused by a high concentration of misplaced particles.
%Such situations are strongly influenced by the resampling step and most of all by restrictive transition models.
As described in section \ref{sec:relatedWork}, sample impoverishment is often a problem of environmental restrictions and system dynamics. 
An example using the so far presented approach can be seen in fig. \ref{fig:multimodalPath}.
Due to uncertain measurements, the posterior distribution of the particle filter is captured within a room.
Between time $t-1$ and $t$, the resampling step abandons all particles on the corridor and drawing new particles outside the room is not possible due to the restricted transition.
At this point, standard filtering methods are not able to recover. 
%
\begin{figure}[t]
	\centering
	\def\svgwidth{0.75\columnwidth}
  \input{gfx/multimodalPath.eps_tex}
	\caption[An example of the occurrence of sample impoverishment.]{
	An example of the occurrence of sample impoverishment enhanced by a restrictive transition model that prevents sampling through walls. At time $t-1$ the approximated position (green line) drifts apart from the ground truth (black line) due to uncertain measurements. The posterior distribution is then captured within the room and not able to recover by itself \cite{Fetzer-17}. }
	\label{fig:multimodalPath}
\end{figure}
%

%todo: umschreiben weng
The simplest solution to handle sample impoverishment is by drawing a handful new particles randomly in the building. 
For this, we add a slight chance of \SI{0.01}{\percent} to the resampling step, so that every particle can be chosen for repositioning instead of the standard procedure.
A new position for those particles is then drawn uniformely from the underlying mesh. 
It is obvious that this leads to a higher uncertainty and possibly a multimodal posterior distribution.
Additionally, very uncertain absolute measurements, like attenuated Wi-Fi signals, can cause unpredictable jumps to such a newly drawn position, which would otherwise not be possible.
Especially, methods using relative measurements like pedestrian dead reckoning are losing their importance. 
Nevertheless, this method is very easy to implement and we expect that the system should be able to recover from nearly every situation regardless of the cause. 

A second method we suggest within this paper is a simplified version of our approach presented in \cite{Fetzer-17}. 
Here, we used an additional, very simple particle filter to monitor if our primary (localization) filter suffers from sample impoverishment.
If that is true, both filters are combined by exchanging particles among each other. 
This allows the primary filter to recover, while retaining prior knowledge.
However, we believe that such a combination of two independent filters is not necessary for most scenarios and thus the resulting overhead can be avoided.

%neue methode:
For the simplified version we distribute \SI{10000}{} samples uniformly within the complete building to approximate $p(\vec{o}_t \mid \vec{q}_t)_\text{wifi}$ as presented in section \ref{sec:wifi}.
From the resulting probability grid $\probGrid_{t, \text{wifi}}$ we are able to identify the areas where the \docWIFI{} model assumes the pedestrian is most likely located. 
Of course, this often results in a multimodal representation of the probability density and thus multiple possible whereabouts.  
However, compared to the used particle filter, this representation enables us to monitor the complete building without any environmental restrictions and can thus be deployed as an indicator to detect sample impoverishment. 
If $\probGrid_{t, \text{wifi}}$ and the current posterior $p(\mStateVec_{t} \mid \mObsVec_{1:t})$ show a significant difference, we can assume that either the posterior got stuck and suffers from impoverishment or the \docWIFI{} quality is low due to factors like attenuation or bad coverage. 
A good measure of how one probability distribution differs from a second is the well-established Kullback-Leibler divergence $D_\text{KL}$ \cite{Fetzer-17}.
To calculate $D_\text{KL}$, we need to sample densities from both probability density functions likewise. 
For the posterior we use the results provided by our rapid kernel density estimation performed in the state estimation procedure, while $\probGrid_{t, \text{wifi}}$ is already in the desired form.
%To handle $D_\text{KL}$ as probability, we use a positive exponential distribution 

%	\begin{equation}
%		f(D_{\text{KL}}, \lambda) = e^{-\lambda D_{\text{KL}}}
%		\enspace .
%	\label{equ:KLD}
%	\end{equation}
	%

Using $D_\text{KL}$, we are now able to take countermeasures against sample impoverishment, depending on its size. 
However, those countermeasures will only work reliable if the \docWIFI{} measurement noise is within reasonable limits. 
Attenuated or bad \docWIFI{} readings are leading $D_\text{KL}$ to grow, even if the posterior provides good results. 
For this, we introduce a \docWIFI{} quality factor, enabling us to identify such situations. 
The quality factor is defined by

		\begin{equation}
            \newcommand{\leMin}{l_\text{min}}
            \newcommand{\leMax}{l_\text{max}}
            q(\mObsVec_t^{\mRssiVec_\text{wifi}}) = 
                \max \left(0,
                    \min \left(
                        \frac{
                            \bar\mRssi_\text{wifi} - \leMin
                        }{
                            \leMax - \leMin
                        },
                        1
                    \right)
                \right)
                %,\enskip
				%\bar\mRssi_\text{wifi} = \frac{1}{n} \sum_{i = 1}^{n} \mRssi_i
            \label{eq:wifiQuality}
        \end{equation}

\noindent where $\bar\mRssi_\text{wifi}$ is the average of all signal strength measurements received from the observation $\mObsVec_t^{\mRssiVec_\text{wifi}}$. An upper and lower bound is given by $l_\text{max}$ and $l_\text{min}$. 
The quality factor is extensively discussed within \cite{Ebner-17} and \cite{Fetzer-17}.

%\commentByMarkus{Nochmal eine second method, meintest du third? wenn nicht versteh ich den Satz hier oder oben nicht}
Finally, we have all necessary tools to implement the second method to prevent impoverishment into the particle filter. 
For this, the state transition model is extended. 
Compared to the resampling step, as used by the first method, the transition $p(\mStateVec_{t} \mid \mStateVec_{t-1}, \mObsVec_{t-1})$ enables us to use prior measurements, which is obviously necessary for all \docWIFI{} related calculations.
As described in chapter \ref{sec:transition}, our transition method only allows to sample particles at positions, that are actual feasible for a humans within a building e.g. no walking trough walls. 
If a particle targets a position which is not walk-able e.g. behind a wall, we deploy a strategy how to handle this. 
For example, drawing a new position within a very small, but reachable area around the particle's current position. 
%
%Instead of such a small area or even the complete building, as suggested in method one, we now define a sphere.
To prevent sample impoverishment we extend this transition strategy by making the reachable area depended upon $D_\text{KL}$ and the \docWIFI{} quality factor.
Particles are thus drawn uniformly on a sub-region of the mesh, given by a radius $ r_\text{sub} = D_\text{KL} \cdot q(\mObsVec_t^{\mRssiVec_\text{wifi}})$.
The sub-region consists of all walk-able and connected triangles within $r_\text{sub}$, including stairs and elevators.
%\todo{radius ist falsch! all connected triangles... warte aber noch aufs franks transition teil.}
%The radius is given by $D_\text{KL} \cdot q(\mObsVec_t^{\mRssiVec_\text{wifi}})$ and particles are drawn uniformly on the mesh enclosed by the sphere.
This allows to increase the diversity of particles by the means of \docWIFI{}, allowing to ignore any restrictions made by the system, as long as the difference between $\probGrid_{t, \text{wifi}}$ and the posterior is high. 
The subsequent evaluation step of the particle filter then reweights the particles, so that only those in proper regions will survive the resampling. 
 
To further improve the method we give particles a chance of \SI{0.01}{\percent} to walk trough a nearby wall, if the destination is not outside. 
This enables to handle sample impoverishment more quickly in situations caused by environmental restrictions, even when the \docWIFI{} quality is low.
Especially in areas full of nooks an crannies, the vulnerability to errors should be decreased.
%In most cases $\lambda$ tends to be somewhere between \SI{0.01}{} and \SI{0.10}{}.


