

\newcommand{\state}{\vec{q}}
\newcommand{\statei}{\vec{q}_i}
\newcommand{\statemax}{\vec{\hat{q}}}

\newcommand{\particle}{\vec{p}}
\newcommand{\particlei}{\vec{p_i}}

\newcommand{\emp}[1]{\textcolor{red}{#1}}
\newcommand{\MISE}{\operatorname{MISE}}

 \setlength{\TPHorizModule}{\paperwidth}
% \setlength{\TPVertModule}{\textwidth}

\section{Background}
	\begin{frame}[fragile]
	  \frametitle{Indoor Localisation}
        \begin{tikzpicture}
         \node[anchor=south west,inner sep=0] at (0,0) {\includegraphics[width=\linewidth]{gfx/info_graphic}};
        \end{tikzpicture}                       
\pause
        \begin{tikzpicture}[overlay]
           \node [draw, red, ultra thick, rounded corners,  minimum height=0.75cm, minimum width=3.5cm, shift={(7cm,0.75cm)}]  at (current page.south west) { };        
        \end{tikzpicture}
	\end{frame}
    
%        \begin{frame}
%            \frametitle{Our problem}
%            Multi modalities increase the error due to weighted average \\
%            Density estimate could solve this, but to expensive to fit in 500ms window \\
%            Key was to recognise that KDE can be approximated with a Gaussian filter \\
%            
%            KDE $\approx$ binned KDE \\
%            BKDE $\approx$ Gaussian filter \\
%            Gaussian filter $\approx$ box filter \\
%            $\rightarrow$ KDE $\sim$ box filter
%        \end{frame}    
	\begin{frame}[fragile]
    \frametitle{System Properties}
    \begin{itemize}[label=\textbullet]
        \item Particle filter with importance sampling describes posterior as a set of samples        
        \item One particle: $\particlei = \langle \statei, w_i \rangle$
        
        \item Possible state: $\statei=(x,y,z,\theta,\hat{\rho}_{\text{rel}})^T$
        \begin{itemize}
            \item $\overbrace{x,y,z\in\R}^{\text{position}},  \quad \overbrace{\theta\in\R}^{\text{heading}}, \quad \overbrace{\hat{\rho}_{\text{rel}}}^{\text{rel. pressure}}$            
            %\setlength{\mathindent}{1pt}           
            %\item $\statei=(x,y,z,\theta,\hat{\rho}_{\text{rel}})^T,  \quad  \overbrace{x,y,z\in\R}^{\text{position}},  \quad \overbrace{\theta\in\R}^{\text{heading}}, \quad \overbrace{\hat{\rho}_{\text{rel}}}^{\text{rel. pressure}}$
        \end{itemize}        
        \item Constrained computational environment (Smartphone + 500ms time frames)
        \pause        
    \end{itemize}	
    \begin{tikzpicture}[overlay]
    \node [draw, red, ultra thick, rounded corners,  minimum height=1.1cm, minimum width=2.3cm, shift={(-10.4cm,-7.3cm)}]  at (current page.north east) { };
    \end{tikzpicture}        
    \end{frame}

    \begin{frame}
    \frametitle{Our problem}
    Increased error due to multi modalities 

    \resizebox{\textwidth}{!}{\input{gfx/multimodalpath.eps_tex}}
    \end{frame}

   
    \begin{frame}[fragile,t]
    \frametitle{State Estimation}    
    
    \begin{textblock*}{0.95\paperwidth}(2mm,1cm)
        \resizebox{1\textwidth}{!}{\input{gfx/max_particle.tex}}
    \end{textblock*}
    
    \begin{textblock*}{1.0\textwidth}(0.4\textwidth,7.3cm)
        Max particle: \par $\displaystyle \statemax := \max_{\statei} \{ w_i \}     \vphantom{\sum_i^N}$
    \end{textblock*}        
    \end{frame}
    
    \begin{frame}[fragile,t]
    \frametitle{State Estimation}    
        \begin{textblock*}{0.95\paperwidth}(2mm,1cm)
        \resizebox{1\textwidth}{!}{\input{gfx/weighted_avg.tex}}
    \end{textblock*}
    
    \begin{textblock*}{1.0\textwidth}(0.4\textwidth,7.3cm)
    Weighted average: \par $\displaystyle \statemax := \frac{1}{W} \sum_{i=1}^{N} w_i \statei \, \text{ with } W=\sum_{i=1}^{N}w_i$
    \end{textblock*}
    \end{frame}
    
    \begin{frame}[fragile,t]
    \frametitle{State Estimation}    
    \begin{textblock*}{0.95\paperwidth}(2mm,1cm)
    \resizebox{1\textwidth}{!}{\input{gfx/boxkde.tex}}
    \end{textblock*}
    
    \begin{textblock*}{1.0\textwidth}(0.4\textwidth,7.3cm)
    Kernel density estimation: \par $\displaystyle \statemax := \arg\max_{\statei} \hat{f}(\statei)    \vphantom{\sum_i^N}$
    \end{textblock*}
    \end{frame}    

    
%    \begin{frame}[fragile,t]
%		\frametitle{State Estimation}    
%        \textbf{Max particle} 
%        \begin{equation*}
%           \statemax := \max_{\statei} \{ w_i \}
%        \end{equation*}
%        %Select $\statemax$ with largest corresponding $w_i$
%        
%        \begin{tikzpicture}[remember picture,overlay]
%            \node[xshift=4.5cm,yshift=2.6cm] at (current page.south west) (a) {%
%            \input{gfx/max_particle.tex}};
%        \end{tikzpicture}
%        
%        \begin{columns}[t]
%          \column{0.58\linewidth}
%              %\input{gfx/max_particle.tex}
%            
%           \column{0.38\linewidth}
%             \begin{proconlist}
%              \itempro Fast
%              \itemcon Not smooth
%             \end{proconlist}                       
%        \end{columns}
%    \end{frame}
%    
%    \begin{frame}[fragile,t]
%   		\frametitle{State Estimation}    
%        \textbf{Weighted average}
%        \begin{equation*}
%            \statemax := \frac{1}{W} \sum_{i=1}^{N} w_i \statei \text{, with } W=\sum_{i=1}^{N}w_i
%        \end{equation*}
%        \begin{tikzpicture}[remember picture,overlay]
%            \node[xshift=4.5cm,yshift=2.6cm] at (current page.south west) (a) {%
%            \input{gfx/weighted_avg.tex}};
%        \end{tikzpicture}        
%        \begin{columns}[t]
%          \column{0.58\linewidth}
%            
%           \column{0.38\linewidth}
%            \begin{proconlist}
%             \itempro Fast and smooth
%             \itemcon Vulnerable to multi modalities
%            \end{proconlist}                              
%        \end{columns}
%    \end{frame}
%    
%    \begin{frame}[fragile,t]
%   		\frametitle{State Estimation}    
%        \textbf{Kernel density estimation} 
%        \begin{equation*}
%           \statemax := \arg\max_{\statei} \hat{f}(\statei) 
%        \end{equation*}              
%        \begin{tikzpicture}[remember picture,overlay]
%            \node[xshift=4.5cm,yshift=2.6cm] at (current page.south west) (a) {%
%            \input{gfx/boxkde.tex}};
%        \end{tikzpicture}        
%        \begin{columns}[t]
%          \column{0.58\linewidth}
%
%           \column{0.38\linewidth}
%             \begin{proconlist}
%              \itempro Complete density
%              \itemcon Additional max search
%              \itemcon Expensive
%             \end{proconlist}  
%        \end{columns}
%    \end{frame}
       
     % 1D: \tilde{f}(x) = \frac{1}{W} \sum_{i=1}^{N} \frac{w_i}{h} K \left(\frac{x-X_i}{h}\right) \text{, with } h\in\R^+ \text{ and }  K(u)=\frac{1}{\sqrt{2\pi}} \expp{- \frac{u^2}{2} } \\ 

% 1D     
    \begin{frame}[t]
    \frametitle{Kernel density estimation}
    \begin{flalign*}
    \hat{f}(x) &= \frac{1}{W} \sum_{i=1}^{N} \frac{w_i}{h} K \left(\frac{x-q_i}{h}\right) 
    \intertext{with Gaussian kernel} 
    K(u)   &=\frac{1}{\sqrt{2\pi}} \expp{- \frac{u^2}{2} }
    \intertext{and kernel bandwidth}
    h \in \R^+
    \end{flalign*}
    
    $\Rightarrow$ Complexity: $\landau{MN}$
    
    %        \begin{textblock*}{0.6\textwidth}(0.5\textwidth,3.7cm)
    %           \resizebox{1.0\textwidth}{!}{\includegraphics{KdeConstruction.pdf}}               
    %        \end{textblock*}        
    \end{frame}                         
 
% nD
%    \begin{frame}[t]
%   		\frametitle{Kernel density estimation}
%        \begin{flalign*}
%         \hat{f}(\vec{u}) &= \frac{1}{W} \sum_{i=1}^{n} \frac{w_i}{h_1 \dots h_d} \left[  \prod_{j=1}^{d} K\left( \frac{u_j-q_{i,j}}{h_j} \right)  \right] 
%         \intertext{with Gaussian kernel} 
%         K(u)   &=\frac{1}{\sqrt{2\pi}} \expp{- \frac{u^2}{2} }
%         \intertext{and kernel bandwidth} 
%         \vec{h} &= (h_1, \dots, h_d) 
%        \end{flalign*}
%        
%        $\Rightarrow$ Complexity: $\landau{N^2}$
%        
%%        \begin{textblock*}{0.6\textwidth}(0.5\textwidth,3.7cm)
%%           \resizebox{1.0\textwidth}{!}{\includegraphics{KdeConstruction.pdf}}               
%%        \end{textblock*}        
%    \end{frame}                
       
\section{Approximation method}  	
    \begin{frame}
        \frametitle{Binned Kernel Density Estimation}      
        Approximation of KDE assuming an equidistant grid with $G$ grid points \\
      
        \begin{equation*}
          \tilde{f}(g_x) = \frac{1}{W} \sum_{j=1}^{G} \frac{C_j}{h} K \left(\frac{g_x-g_j}{h}\right)
        \end{equation*}
        
        where the count at $g_j$ is given with
        \begin{equation*}
        \label{eq:gridCnts}
            C_j=\sum_{i=1}^{N} r_j(x_i,\delta)
        \end{equation*}
        and $r_j$ is a binning rule (simple or linear)
        
        $\Rightarrow$ Complexity: $\landau{G^2}$
    \end{frame}

    \begin{frame}
        \frametitle{Binned Kernel Density Estimation}
        
        Binned KDE has a discrete convolution structure \\

        \begin{equation*}
          \tilde{f}(g_x) = \frac{1}{W} \emp{\sum_{j=1}^{G}} \frac{\emp{C_j}}{h} \emp{K} \left(  \frac{\emp{g_x-g_j}}{h}  \right)
        \end{equation*}

        \begin{textblock*}{5cm}(0.7\textwidth,3.1cm)
          \footnotesize $\displaystyle (f*g)[n] = \sum_{m=-\infty}^{\infty} f[m]\cdot g[n-m] $\normalsize
        \end{textblock*}
        
        Using a Gaussian kernel: BKDE $\approx$ Gaussian filter \\
    
        \begin{equation*}
        \tilde{f}(g_x)=\frac{1}{W\sqrt{2\pi}} \sum_{j=1}^{G} \frac{C_j}{h} \expp{-\frac{(g_x-g_j)^2}{2h^2}}
        \end{equation*}
        
        $\Rightarrow$ fast approximation using recursive box filter
    \end{frame}
	
    \begin{frame}[fragile,t]
          \frametitle{Box Filter Approximation}
            Given by central limit theorem, iterated box filters converge to Gaussian filter
            \centering 
            \begin{minipage}[b]{0.5\linewidth}
                \centering
                \include{gfx/BoxConverge1} 
                \vspace{-2ex}
              \end{minipage}%%
              \begin{minipage}[b]{0.5\linewidth}
                \centering
                \include{gfx/BoxConverge2} 
                \vspace{-2ex}
              \end{minipage} 
              \begin{minipage}[b]{0.5\linewidth}
                \centering
                \include{gfx/BoxConverge3} 
%                \vspace{4ex}
              \end{minipage}%% 
              \begin{minipage}[b]{0.5\linewidth}
                \centering
                \include{gfx/BoxConverge4} 
%                \vspace{4ex}
              \end{minipage} 
    \end{frame}          
    
   
    \begin{frame}[t]
        \frametitle{Box Filter Approximation}       
        Naive calculation $\landau{NL}$:
        \begin{equation*}
          y[i]=\frac{1}{2l+1} \sum_{j=-l}^{l}x[i+j]
        \end{equation*}
        
        Recursive calculation $\landau{N}$:
        \begin{equation*}
          y[i] = y[i-1] + x[i+l] - x[i-l-1]
        \end{equation*}
        
        Mapping bandwidth to box filter radius:
        \begin{equation*}
            \Lideal = \sqrt{\frac{12\sigma^2}{n}+1}
        \end{equation*}

%        \begin{textblock*}{0.1}[1,0](0.6,5)        
        \begin{textblock*}{0.25\textwidth}(0.7\textwidth,2.5cm)
          \small Radius: $\displaystyle l=\frac{L-1}{2} $\normalsize
        \end{textblock*}
        
    \end{frame}

\section{Experiments}
%    \begin{frame}
%        \frametitle{Approximation error - Ground Truth}
%        
%        \begin{columns}
%        \begin{column}{0.75\textwidth}
%            \includegraphics[width=1\textwidth]{gfx/Eval1GroundTruth.png}       
%        \end{column}
%        \begin{column}{0.25\textwidth}
%            \setlength{\mathindent}{1pt}
%            \begin{align*}
%              \bm{X} \sim ~ & \G{\VecTwo{0}{0}}{0.5\bm{I}} + \\
%                          & \G{\VecTwo{3}{0}}{\bm{I}} + \\
%                          & \G{\VecTwo{0}{3}}{\bm{I}} + \\ 
%                          & \G{\VecTwo{-3}{0} }{\bm{I}}  + \\
%                          & \G{\VecTwo{0}{-3}}{\bm{I}}
%            \end{align*}
%            
%            Grid: $30\times 30$
%        \end{column}
%        \end{columns}
%        
%    \end{frame}

%    \begin{frame}[t]
%        \frametitle{Approximation error}
%        
%        \begin{columns}
%        \begin{column}{0.60\textwidth}
%          \renewcommand{\footnotesize}{\fontsize{7pt}{11pt}\selectfont}
%          \resizebox{1.0\textwidth}{!}{\input{gfx/error.tex}}
%        \end{column}
%        \begin{column}{0.40\textwidth}
%            $\displaystyle \operatorname{MISE} =~\E{\int \left( \hat{f}(x)-f(x) \right)^2 \dop{x}}$
%            
%            Average error:
%            \setlength{\mathindent}{1pt}
%            \begin{align*}
%              ~&\overline{t}_{\text{BKDE}}   &= \SI{10.10}{\second} \phantom{0} \\                  
%              ~&\overline{t}_{\text{BoxKDE}} &= \SI{0.4092}{\second} \\
%              ~&\overline{t}_{\text{WA}}     &= \SI{0.0043}{\second}
%            \end{align*}            
%        \end{column}
%        \end{columns}
%       
%    \end{frame}
    
    \begin{frame}
    \frametitle{Approximation error}
    \begin{textblock*}{0.8\textwidth}(0mm,1.5cm)
        \renewcommand{\footnotesize}{\fontsize{7pt}{11pt}\selectfont}
        \resizebox{1.0\textwidth}{!}{\input{gfx/error.tex}}                     
    \end{textblock*}
    
    %\begin{textblock*}{0.4\textwidth}(0.78\textwidth,1.5cm)
    %    \footnotesize$\displaystyle \MISE =~\E{\int \left( \hat{f}(x)-f(x) \right)^2 \dop{x}}$ \normalsize
    %\end{textblock*}
    
    \begin{textblock*}{0.3\textwidth}(0.85\textwidth,1.8cm)
        Average error {\small  $(\times 10^{-3})$}:
        \setlength{\mathindent}{1pt}
        \begin{align*}
        ~&\overline{\text{BoxKDE}} &= 5.14 \\
        ~&\overline{\text{BKDE}}   &= 4.73 \\              
        ~&\overline{\text{KDE}}    &= 4.40
        \end{align*}
    \end{textblock*}
    \end{frame}
    
    \begin{frame}
       \frametitle{Performance}
       \begin{itemize}[label=\textbullet]
         \item Hardware
         \begin{itemize}[label=-]
           \item Intel Core \mbox{i5-7600K} CPU with \SI{4.2}{\giga\hertz}
           \item \SI{16}{\giga\byte} main memory
         \end{itemize}
         \item Algorithms
         \begin{itemize}[label=-]
             \item C++ implementation of our BoxKDE approximation
             \item R language package \texttt{ks} \\ \hspace{1pt} (FFT-based BKDE; optimized in C)
             \item C++ implementation of weighted average         
         \end{itemize}
         \item Input
         \begin{itemize}[label=-]
           \item Number of grid points $G \in [10^2, 10^8]$
         \end{itemize}

       \end{itemize}
    \end{frame}    
       
    \begin{frame}
       \frametitle{Performance}
        \begin{textblock*}{0.8\textwidth}(0mm,1.5cm)
           \renewcommand{\footnotesize}{\fontsize{7pt}{11pt}\selectfont}
           \resizebox{1.0\textwidth}{!}{\input{gfx/perf2.tex}}                     
        \end{textblock*}
       \begin{textblock*}{0.3\textwidth}(0.85\textwidth,1.8cm)
        Average time:
            \setlength{\mathindent}{1pt}
            \begin{align*}
              ~&\overline{t}_{\text{BKDE}}   &= \SI{10.10}{\second} \phantom{0} \\                  
              ~&\overline{t}_{\text{BoxKDE}} &= \SI{0.4092}{\second} \\
              ~&\overline{t}_{\text{WA}}     &= \SI{0.0043}{\second}
            \end{align*}
        \end{textblock*}        
    \end{frame}    
        
\section{Summary}    
    \begin{frame}[t]
        \frametitle{Summary}
        \begin{itemize}[label=\textbullet]
          \item Novel rapid approximation scheme for KDE
          \item Key idea is to interpret KDE as filter problem
          \item Assuming a Gaussian kernel, box filter approximation can be used
          \item Sufficiently fast for our real time application
          \item Acceptable small error
        \end{itemize}
    \end{frame}

\section{Thank you}

    \begin{frame}
\frametitle{Approximation error - Ground Truth}

\begin{columns}
    \begin{column}{0.75\textwidth}
        \includegraphics[width=1\textwidth]{gfx/Eval1GroundTruth.png}       
    \end{column}
    \begin{column}{0.25\textwidth}
        \setlength{\mathindent}{1pt}
        \begin{align*}
        \bm{X} \sim ~ & \G{\VecTwo{0}{0}}{0.5\bm{I}} + \\
        & \G{\VecTwo{3}{0}}{\bm{I}} + \\
        & \G{\VecTwo{0}{3}}{\bm{I}} + \\ 
        & \G{\VecTwo{-3}{0} }{\bm{I}}  + \\
        & \G{\VecTwo{0}{-3}}{\bm{I}}
        \end{align*}
        
        $N = 5000$
        
        Grid: $30\times 30$
    \end{column}

%\begin{textblock*}{0.4\textwidth}(0.78\textwidth,1.5cm)
%    \footnotesize$\displaystyle \MISE =~\E{\int \left( \hat{f}(x)-f(x) \right)^2 \dop{x}}$ \normalsize
%\end{textblock*}
\end{columns}

\end{frame}