\input assets/cs-pre
\bibliography{assets/references.bib}

\begin{document}
\MYTITLE{CMPSC 383: Multi-Agent and Robotic Systems}{Final Project Progress Report}
\MYHEADERS{}

\section{Introduction}
    \textit{Flocking}, in the context of multi-agent systems, involves the collective behavior of a group of interacting, mobile agents. Flocking patterns are exhibited by such a group when the individual agents attempt to move together with their neighbors. This behavior in multi-agent systems mimics the similar flocking behaviors of groups of animals such as birds or fish. Applications of this type of behavior are diverse: multi-robot teams can use flocking to coordinate their movement towards a goal while maintaining a consistent formation or level of proximity~\cite{saska2014swarms,min2011design}, finding optimized solutions to mathematical problems~\cite{cui2009boid}, and simulating the behavior and appearance of flocks or swarms of animals.% TODO: more examples
    \par Boids particular simulation model for multi-agent flocking behaviour~\cite{hartman2006autonomous}. It was first described by Craig Reynolds in 1987~\cite{reynolds1987flocks}. Boids uses a set of three rules for the manipulation: separation, cohesion, and alignment~\cite{reynolds1987flocks,hartman2006autonomous}. More detail on this model can be found in~\Cref{boids}. This model has been used in a number of computer graphics applications, including motion pictures and video games, as well as in robotics applications~\cite{saska2014swarms,min2011design}.
    \par Our project is an implementation of this Boids simulation. To do so, we used the Haskell programming language, a purely functional language with lazy evaluation. This document describes some particulars of Haskell and how they relate to the task of agent programming, the details of the mechanism of our implementation, and the results we acquired from our implementation.

\section{Method}
\subsection{Language Choice}

We chose Haskell as the implementation language for our Boids simulation.
Haskell is a purely functional language with lazy evaluation~\cite{hudak1994haskell,jones2003haskell}. It has been observed that Haskell supports the rapid prototyping of software systems, allowing working systems to be implemented quickly and with minimal complexity~\cite{hudak1994haskell}. The functional programming paradigm in general has been noted to support modularity and allow problems to be decomposed easily~\cite{hughes1989functional}. These observations, along with our previous experience in the language, influenced our choice of Haskell as a platform for our project.

As our class experience with implementing multi-agent simulations has been solely through the object-oriented programming (OOP) paradigm, our language choice presented a challenge, but also a valuable learning experience. Our
implementation of the Boid agents involves the definition of an abstract data
type, which contains the position, velocity, and neighborhood radius of an
individual boid. In Haskell, this is defined as follows:
\begin{listing}[h!]
\begin{minted}{haskell}
data Boid = Boid { position :: Point
                 , velocity :: Vector
                 , radius   :: Float
                 }
\end{minted}
\end{listing}
\FloatBarrier
Note that Haskell, as a purely functional programming language, does not allow mutation of existing values. Therefore, once a
\mintinline{haskell}|Boid| is created, it cannot be mutated, and updating the \mintinline{haskell}|Boid|'s state
requires the creation of an entirely new \mintinline{haskell}|Boid| instance.

Also, in contrast to a corresponding OOP implementation, which might define some \mintinline{haskell}|Boid|behaviour (i.e. methods) to accompany this basic data structure, this \mintinline{haskell}|Boid| data type is kept distinct from the functions which act upon it.. Instead, we define a type called \mintinline{haskell}|Update|:

\begin{minted}{haskell}
type Update = Boid -> Boid
\end{minted}

Thus, a function of type \mintinline{haskell}|Update| is a function that takes a \mintinline{haskell}|Boid| and returns
a new \mintinline{haskell}|Boid|. We use \mintinline{haskell}|Update| to define \mintinline{haskell}|Behaviour|:

\begin{minted}{haskell}
type Perception = [Boid]
type Behaviour = Perception -> Update
\end{minted}

This defines a \mintinline{haskell}|Behaviour| as a function that maps an agent's perception of its environment (in this case, a \mintinline{haskell}|Boid|'s visible neighborhood) to
a function for updating its environment. These examples demonstrate how implementing a multi-agent
simulation in a purely-functional language requires a different conception of
what it means programmatically for an Agent to behave.

\subsection{Boids}\label{boids}

Boids models the behaviour of a flock in as being effected by three primary steering forces: \textit{cohesion}, the tendency of an individual to stay close to the centre of the flock; \textit{separation}, the tendency of an individual to avoid collision with other individuals, and \textit{alignment}, the tendency of an individual to match velocities with its neighbors~\cite{hartman2006autonomous,reynolds1987flocks}. Each of these steering forces is modeled as a vector, which are then summed to compute the position of a given boid at each time interval.

The separation steering vector $\vec{s}_i$ for a given boid $b_i$ may be calculated as the negative sum of the position vector of $b_i$ and each visible boid $b_j$, using the following formula:

\[ \vec{s}_i = - \sum\limits_{\forall b_j \in V_i} (p_i - p_j) \]

where $V_i$ is the set of boids visible by $b_i$ (i.e. the neighborhood)~\cite{hartman2006autonomous}. In our implementation, this formula corresponds to the following Haskell source code:

\begin{minted}{haskell}
separation :: Boid -> Perception -> Vector
        -- :: Boid -> [Boid] -> V3 Float
separation self neighbors =
    let p = position self
    in sumV . map (^-^ p) $ positions neighbors
\end{minted}

The cohesion steering vector $\vec{k}_i$ for a given boid $b_i$ may be calculated by finding the centre of density $c_i$ of the visible boids $V_i$ using the formula

\[ c_i = \sum\limits_{\forall b_j \in V_i} \frac{p_j}{m} \]

where $m$ is the cardinality of $V_i$. The steering vector may then be calculated by subtracting $b_i$'s position from $c_i$~\cite{hartman2006autonomous}:

\[ \vec{k}_i = c_i - p_i \]

In our implementation, these formulae corresponds to the following Haskell source code:

\begin{minted}{haskell}
centre :: Perception -> Vector
    -- :: [Boid] -> V3 Float
centre boids =
    let m = fromIntegral $ length boids :: Float
    in sumV $ map (^/ m) $ positions boids

cohesion :: Boid -> Perception -> Vector
      -- :: Boid -> [Boid] -> V3 Float
cohesion self neighbors =
    let p = position self
    in centre neighbors - p
\end{minted}

Finally, the alignment steering vector $\vec{m}_i$ for a boid $b_i$ may be calculated by averaging the velocities of the set of visible boids $V_i$ using the following formula

\[ \vec{m}_i = \sum\limits_{\forall b_j \in V_i} \frac{\vec{v}_j}{m} \]

where $\vec{v}_j$ is the velocity of $b_j$. If the cardinality of $V_i$ is zero, then $\vec{v}_i = 0$~\cite{hartman2006autonomous}. In our implementation, this formula corresponds to the following Haskell source code:

\begin{minted}{haskell}
alignment :: Boid -> Perception -> Vector
       -- :: Boid -> [Boid] -> V3 Float
alignment _ []        = V3 0 0 0
alignment _ neighbors =
    let m = fromIntegral $ length neighbors :: Float
    in (sumV $ map velocity neighbors) ^/ m
\end{minted}

Once all three steering vectors have been calculated, they are combined to find the velocity $\vec{v_i\prime}$ of a boid

\[ \vec{v_i\prime} = \vec{v_i} + S.\vec{s_i} + K.\vec{k_i} + M.\vec{m_i} \]

where $S$, $K$, and $M$ are coefficients which control the weight of each steering force and are typically global parameters to the simulation.

The position of that boid at time $t + \Delta t$ maythen  be updated using $\vec{v_i\prime}$

\[ p\prime_i = p_i + \Delta t\vec{v_i}\]

In our implementation, these formulae corresponds to the following Haskell source code:

\begin{minted}{haskell}
steer :: Weights -> Behaviour
   -- :: Weights -> [Boid] -> Boid -> Boid
steer (s, c, m) neighbors self =
    let s_i  = s *^ separation self neighbors
        c_i  = c *^ cohesion self neighbors
        m_i  = m *^ alignment self neighbors
        v'   = velocity self ^+^ s_i ^+^ c_i ^+^ m_i
        p    = position self
        p'   = p ^+^ v'
    in self { position = p', velocity = v'}
\end{minted}

\subsection{Program Usage}

Our implementation supports a number of command-line arguments to set simulation parameters and control the resulting visualization. The following options for controlling the simulation parameters are supported:

\begin{description}
    \item[Height] of the space can be set using the options \texttt{-x HEIGHT} or \texttt{--height=HEIGHT}.
    \item[Width] of the space can be set using the options \texttt{-y WIDTH} or \texttt{--width=WIDTH}.
    \item[Number of Boids] can be  set using the options \texttt{-n BOIDS} or \texttt{--num=BOIDS}.
    \item[Boid visibility radius] can be set using the options \texttt{-v RADIUS} or \texttt{--visibility=RADIUS}. The default is 50.
    \item[Simulation speed] can be set using the options \texttt{-p SPEED} or \texttt{--speed=SPEED}. This value sets a coefficient by which the movement vector of each boid is divided every simulation tick. The default is 1000 at 30 frames per second.
\end{description}

Additionally, our implementation allows the user to select one of a set of preset behavior types. These control the values of the weight constants for the three boid steering forces, as discussed in \Cref{boids}.

\begin{description}
    \item[Equal-Weight Behavior] selected with the command-line flag \texttt{-e} or \texttt{--equal}, sets all weight coefficients to 1.
    \item[Cohesive Behavior] selected with the flag \texttt{-c} or \texttt{--cohesive}, sets weights as follows: $S = 1, K = 0.5, M = 0.5$.
    \item[Swarming Behavior] selected with the flag \texttt{-s} or \texttt{--swarm}, sets the alignment coefficient ($M$) equal to zero, creating true swarming behavior.
\end{description}

Our program may also be run in `debug mode,' using the \texttt{-d} or \texttt{--debug} option. In debug mode, the program will run the visibility radius and velocity vector of each boid, so that the user can gain a greater understanding of how the simulation functions. Finally, the \texttt{-h} or \texttt{--help} flag will print out a summary of the available command-line options.

\section{Results}

    The results of this simulation are visible in the following figures:
    \begin{itemize}
        \item Figure~\ref{fig:no-debug} demonstrates our simulation without our ``debug-mode''. Of course, as a static image without any representation of boid vectors, it is difficult to tell how the swarm is behaving.
        \item Figure~\ref{fig:eqweight} demonstrates our ``debug mode'' with equal weights for cohesion, separation, and alignment. A large degree of agent clustering is visible.
        \item However, with smaller radii as in Figure~\ref{fig:eqweight-small}, we see a significantly decreased level of clustering of the agents.
        \item On the other hand, increasing the radii as in Figure~\ref{fig:eqweight-large}, gives an even greater degree of clustering than before.
        \item With our ``cohesive'' mode, as in Figure~\ref{fig:eqweight-large}, we see that the boids form a much more even distribution throughout the space. This is due the fact that the separation impulse is still present, but does not dominate the vectors of the boids, preventing them from separating a great distance apart.
    \end{itemize}

    \begin{figure}
        \centering
        \includegraphics[width=0.5\textwidth]{assets/img/nodebug}
        \caption{Simulation run in swarm mode, with debugging off.}
        \label{fig:no-debug}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=0.5\textwidth]{assets/img/eqweight}
        \caption{Simulation run in equal-weight mode, with debugging and radii of size 20.}
        \label{fig:eqweight}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=0.5\textwidth]{assets/img/eqweight-small}
        \caption{Simulation run in equal-weight mode, with debugging and radii of size 10.}
        \label{fig:eqweight-small}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=0.5\textwidth]{assets/img/eqweight-large}
        \caption{Simulation run in equal-weight mode, with debugging and radii of size 30.}
        \label{fig:eqweight-large}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=0.5\textwidth]{assets/img/cohesion}
        \caption{Simulation run in cohesion mode.}
        \label{fig:cohesion}
    \end{figure}
    % describe behavior for each mode
    \FloatBarrier
\section{Conclusion}
    \subsection{Challenges}
    One of our major challenges was the existence of a bug in the ``alignment'' behavior of our code. This bug caused all boids in the scene to speed up erratically, eventually causing overflow in the vector components of the boids' velocities, and causing the program to crash. This was fixed after we realized that the neighborhood selection code for each boid included the boid itself, and thus added on the boid's own velocity to itself in the alignment function.
    \par Another challenge we faced early on was our early ambitions of creating a 3D simulation using the Haskell OpenGL bindings. These bindings caused us a number of problems, and abandoning them in favor of the 2D \texttt{gloss} library allowed us to focus on the details of our implementation with greater detail. Neither of us is particularly experienced with computer graphics, and we found that the higher level of abstraction provided by \texttt{gloss} made our task much easier. Furthermore, using OpenGL directly requires writing code that could be considered fairly unidiomatic in Haskell.

    \subsection{Takeaways}
    Both group members enjoyed the experience of implementing a multi-agent system using a purely functional programming language. As Hawk had significantly less experience programming in Haskell than Will, he found this assignment to be a particularly good learning experience in that language, but both members of the team enjoyed the opportunity to try something different than the previous course assignments. Furthermore, we found experimenting with Haskell's libraries for vector mathematics, as necessitated by the boids algorithm, to be interesting and fun.
    \par We also enjoyed being able to implement swarming and flocking behavior in a multi-agent system. Our previous experiences with swarming in class had only involved using preexisting programs, so we were interested in how such programs were written. Although Boids is not a particularly complex algorithm, the simulations it produces provide a fairly convincing approximation of real-life bird behavior. Both team members are very interested in `artificial life' simulations in general --- for his first final project in a computer science course at Allegheny, Will wrote an implementation of Conway's Game of Life in Processing. As this project is his last final project for a computer science course here at Allegheny, artificial life provides `book ends,' in a sense, on his Allegheny career.

\printbibliography

\end{document}


\documentclass[runningheads]{llncs}

\usepackage{graphicx}
\usepackage{placeins}
\usepackage{hyperref,xcolor}
\renewcommand\UrlFont{\color{blue}\rmfamily}
\usepackage{listings}
\definecolor{very-light-gray}{gray}{0.95}

\begin{document}

\title{Solving Combinatorial Puzzles with Parallel Evolutionary Algorithms \thanks{This work was supported by a private funding of Velbazhd Software LLC.}}
\titlerunning{Solving Puzzles with PEA}

\author{Todor Balabanov\orcidID{0000-0003-3139-069X} \and
Stoyan Ivanov \and
Rumen Ketipov}
\authorrunning{T. Balabanov et al.}

\institute{Institute of Information and Communication Technologies \\
Bulgarian Academy of Sciences \\
acad. Georgi Bonchev Str., Block 2, 1113 Sofia, Bulgaria \\
\email{todorb@iinf.bas.bg} \\
\url{http://iict.bas.bg/}}

\maketitle

\begin{abstract}
Rubik's cube is the most popular combinatorial puzzle. It is well known that solutions of the combinatorial problems are generally hard to find. If 90 degree clockwise rotations of the cube's sides are taken as operations it will give a minimal cube's grammar. By building formal grammar sentences with the usage of the six operations ([L]eft, [R]ight, [T]op, [D]own, [F]ront, [B]ack) all cube's permutations can be achieved. In an evolutionary algorithms (like genetic algorithms for example) set of formal grammar sentences can be represented as population individuals. Single cut point crossover can be efficiently applied when population individuals are strings. Changing randomly selected operation with another randomly selected operation can be used as efficient mutation operator. The most important part of such global optimization is the fitness function. For better individuals fitness value evaluation a combination between Euclidean and Hausdorff distances is proposed in this research. The experiments in this research are done as parallel program written in C++ and Open MPI.

\keywords{Distributed evolutionary algorithms \and Combinatorial puzzles \and Integer optimization.}
\end{abstract}

\section{Introduction}

A parallel implementation of a genetic algorithm-based solver of the Rubik's cube was implemented by Balabanov in \cite{balabanov01} and it was presented in \cite{balabanov02}. Rubik's cube was invented and introduced by Erno Rubik in the 70s of the 20th century. After its creation the cube became the most popular combinatorial puzzle all over the world. In its original version it has 3x3x3 cubical segments. There are stickers in six different colors on each subcube square of the exposed sides. Each of the six planes (3x3x1) can be rotated in 90, 180, 270 or 360 degrees, relative to the other part of the puzzle. In the original initial state all sides of the cube are in single color. Scumbling of the puzzle is done by many random rotations of the (3x3x1) sides. The optimization task aims to restore the cube in its original state. Such combinatorial optimization problem is quite difficult because there are billions of combinations. The real number of combinations is $4.3252*10^{19}$ \cite{korf01} and all of them can be reached from any starting combination. The puzzle is successfully resolved when a sequence of moves is applied such that all subcubes are matched to each other by their color on each side of the cube. According to an estimation in \cite{korf01} resolutions sequences variate from 50 to 100 moves when the cube is well scrambled.

When there is an optimization problem with a sequence of commands it is a perfect candidate for evolutionary algorithms as optimizers. This research addresses the application of parallel genetic algorithms for Rubik's cube optimal or suboptimal solutions findings. The source code of the experiments is written in C++ with OpenMPI for parallel calculations and it can be found in a public source code repository \cite{balabanov01}. Modification of the evaluation function presented in \cite{balabanov02} is upgraded by addition of Hausdorff distance component.

The rest of this paper is organized as follows: Section 2 briefly describes theoretical details. Hence, section 3 presents the proposed modifications into a practical software example and section 4 is devoted to some experiments and results. Finally, Section 5 concludes and presents some ideas for further research.

\section{Parallel Genetic Algorithms}

Genetic algorithms are global optimization strategy inspired from the evolution process in the Biology theories. Place of the genetic algorithms and the genetic programming in the family of the metaheuristics is well presented in Fig.\ref{fig02}.

\begin{figure}
\includegraphics[width=1.0\textwidth,height=0.65\textwidth]{fig02.png}
\centering
\caption{Euler diagram of the different classifications of metaheuristics.} \label{fig02}
\end{figure}
%\FloatBarrier

Solutions of a particular problem are represented as vectors of values into the solution space. All selected solution vectors are the population of the algorithm. The most common way of initial population establishment is by generation of random vectors. Each new generation appears in the population after recombination of selected individuals. In genetic algorithms recombination is done by two consequent operators - crossover and mutation. Which individuals to participate in the recombination process is decided by application of selection operator. It is very common during selection process elitism rule to be applied. Elitism means that some percent of the best found solutions survive to the real end of the optimization process. Because genetic algorithms based optimization is an iterative optimization a stopping criteria is needed. The most used stopping criteria is initially given number of genetic algorithm generations.

Genetic algorithms are the base of the genetic programming which is used in this research. Each element of the solution vector actually is an operation applied over the state of the Rubik's cube. Ordered set of such instructions is actually an algorithmic program. Because there is no direct intermediate relation between the individuals in a particular population genetic algorithms are highly appropriate for implementation in parallel computing or distributed computing. Population of the genetic algorithm can be easily divided in many sub-population and it can be distributed on many processors/cores or even heterogeneous computers in a cluster. Separation of the global population is the preferred approach, but in cases where only the fitness value calculation is time consuming, population is kept in the central processor/computer and only fitness value calculation is sent to the other contributing processors/computers.

When sub-populations distribution calculation scheme is selected some strategy for individual migration should be applied \cite{balabanov02}. Migration between different islands is needed in order best found solutions to be available in some or in all sub-populations. When the implementation of the calculation is organized as donated distributed computing project in the inclusion of a new remote contributing computer fresh subset of the global population can be supplied. With such strategy solutions space is much better investigated.

\section{Modified Rubik's Cube Solver}

The core of the optimization code is Rubik's cube representation into the computer memory. For the needs in this research the cube is presented as six (one for each side) two-dimensional (3x3) arrays. Values in these arrays are integer numbers which correspond to cube's colors. There are better ways for digital representation \cite{korf01}, but it is much more practical in this way from algorithmic aspect.

Data structures are the first side of the modeling proccess. On the second side are the algorithmic operations done over the data structures. The cube has six sides that is why the minimum number of operations over the cube is six. Six capital letters are used for 90 degrees clockwise rotations, as proposed in \cite{randall01,balabanov02}: \\
\\
T (Top) –90 degrees clockwise rotation of the top side; \\
L (Left) –90 degrees clockwise rotation of the left side; \\
B (Back) –90 degrees clockwise rotation of the back side; \\
R (Right) –90 degrees clockwise rotation of the right side; \\
F (Front) –90 degrees clockwise rotation of the front side; \\
D (Down) –90 degrees clockwise rotation of the down side. \\

This set of six operations is the minimal fully functional grammar for the Rubik's cube. Extended grammars are also possible, for example if counter-clockwise operators are included (+T, +L, +B, +R, +F, +D, –T, –L, –B, –R, –F, –D). Next level of extension is addition as number of turns (+1T, +2T, +3T, +1L, +2L, +3L, +1B, +2B, +3B, +1R, +2R, +3R, +1F, +2F, +3F, +1D,+2D, +3D, –1T, –2T, –3T, –1L, –2L, –3L, –1B, –2B, –3B, –1R, –2R, –3R, –1F, –2F, –3F, –1D, –2D, –3D) \cite{balabanov02}.

With the presented ideas for a formal Rubik's cube grammar the neutral choice is genetic algorithm individuals to be represented as formal grammar sentences with variable length. Each of the letters can appear at any position many times repeated in the chromosome. As it was appointed in \cite{korf01} the average expected length of the chromosomes can be between 50 and 100.

\begin{figure}
\includegraphics[width=0.75\textwidth]{fig01.png}
\centering
\caption{Fitness value evaluation by combination between Euclidean and Hausdorff distance.} \label{fig01}
\end{figure}
\FloatBarrier

Single cut point is selected as crossover population, but other options \cite{poli01} are also applicable. As mutation operator random change of a single instruction is selected. Selection is done by randomly selected parents, but elitism rule is applied. For the evaluation of the newly created individuals instructions encoded in the individual are applied over the scrambled cube. After that the state of the cube is compared with the target state (cube in the solved state). The listing in Fig.\ref{fig01} shows the proposed in this paper modification of fitness evaluation function. For each pairs of cube's sides Euclidean distance is calculated. After that according to Hausdorff distance rules the maximum of the minimums is found. Evaluated fitness value is positive because the Euclidean distance is calculated with positive integers (cube's colors are mapped to integers) and the Hausdorff distance is a calculation of a maximum of the minimums. The puzzle is as better solved as the fitness value is smaller.

\section{Experiments and Results}

All experiments were done on a single processor desktop machine - Intel Core i5, 2.3 GHz, 2 Cores, 8GB RAM and Mac OS X 10.13.6, Apple LLVM version 9.1.0. For the parallel implementation Open MPI is used.

\begin{figure}
\includegraphics[width=0.75\textwidth]{fig03.png}
\centering
\caption{Algorihtm convergence with star topology.} \label{fig03}
\end{figure}
\FloatBarrier

Experiments are done in two groups with 30 independent runs for each. The source code originally is divided for test with star topology and incident nodes participation as migration strategies. That is why there are two groups of experiments. Each experiment compares pure Euclidean distance implementation and the proposed Hausdorff distance modification. Parameters of the genetic algorithm are listed in Tab. \ref{tab01}.

\begin{table}
\caption{Genetic algorithm parameters.}
\label{tab01}
\begin{tabular}{p{6.9cm}p{4.4cm}}
\hline\noalign{\smallskip}
\textbf{Parameter} & \textbf{Value} \\
\hline\noalign{\smallskip}
generation gap & 0.93 \\
crossover rate & 0.98 \\
mutation rate & 0.01 \\
maximum generations & 10000 \\
number of individuals & 37 \\
number of variables & floating \\
inserted rate & 100 \% \\
\noalign{\smallskip}\hline\noalign{\smallskip}
\end{tabular}
\end{table}
\FloatBarrier

\begin{figure}
\includegraphics[width=0.75\textwidth]{fig04.png}
\centering
\caption{Algorihtm convergence with incident nodes participation.} \label{fig04}
\end{figure}
\FloatBarrier

Fig.\ref{fig03} shows that when star topology is used the advantage of Hausdorff modification is not so great, but as it is shown in Fig.\ref{fig04} when an incident nodes participation is used the proposed modification leads to convergence seep-up. Calculation of a Euclidean distance between two cubes uses six calculations of the sides for the cube (Listing \ref{lst01}). In the case of Hausdorff distance there are six times more calls of a single Euclidean distance calculation (Listing \ref{lst02}).

\begin{lstlisting}[caption={Euclidean distance.},label={lst01},backgroundcolor=\color{very-light-gray},frame={single}]
double euclidean(const int side1[3][3],
                 const int side2[3][3]) const {
  double distance = 0.0;

  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) {
      distance += (side1[i][j]-side2[i][j]) *
                  (side1[i][j]-side2[i][j]);
    }
  }

  return sqrt(distance);
}
\end{lstlisting}
\FloatBarrier

\begin{lstlisting}[caption={Hausdorff distance.},label={lst02},backgroundcolor=\color{very-light-gray},frame={single}]
double hausdorff(const RubiksCube &cube) const {
  double min[] = {INT_MAX, INT_MAX, INT_MAX,
                  INT_MAX, INT_MAX, INT_MAX};

  for(int s1=0; s1<6; s1++) {
    for(int s2=0; s2<6; s2++) {
      double distance =
      euclidean(*sides[s1], *(cube.sides)[s2]);

      if(min[s1] > distance) {
        min[s1] = distance;
      }
    }
  }

  double result = min[0];
  for(int s1=0; s1<6; s1++) {
    if(result < min[s1]) {
      result = min[s1];
    }
  }

  return(result);
}
\end{lstlisting}
\FloatBarrier

\section{Conclusions}

The experiments show that the addition of Hausdorff distance component improves the performance of the genetic algorithm. A calculation of the Hausdorff distance is a little bit slower than the calculation of the Euclidean distance, but better solution fitness estimation generally leads to genetic algorithm convergence improvement. Further investigations in the field of the soft computing can be done for the proposed fitness value evaluation as it was done in \cite{angelova01}.

As further research it will be interesting an evaluation of the fitness value to be additionally filtered with Kalman filter \cite{alexandrov01}, for example. Another interesting direction would be an involvement of the artificial neural networks such as \cite{tashev01,atanasova01} for preliminary solutions evaluation.

\begin{thebibliography}{8}
\bibitem{balabanov01}
MPI Parallel Implementation of Genetic Algorithm Based Rubik’s Cube Solver, \url{http://github.com/TodorBalabanov/RubiksCubeGeneticAlgorithmsSolver}. Last accessed 10 Feb 2019
\bibitem{balabanov02}
Balabanov, T., Zankinski, I., Barova, M.: Strategy for Individuals Distribution by Incident Nodes Participation in Star Topology of Distributed Evolutionary Algorithms. Cybernetics and Information Technologies \textbf{16}(1), 80--88 (2016)
\bibitem{korf01}
Korf, R.: Finding Optimal Solutions to Rubik’s Cube Using Pattern Databases. In: AAAI-98 Proceedings, pp. 700--705. AAAI Press, Menlo Park, CA, USA (1998)
\bibitem{randall01}
Randall, K.: Cilk - Efficient Multithreaded Computing. Doctor of Philosophy Thesis in Computer Science and Engineering, Massachusetts Institute of Technology, USA (1998)
\bibitem{poli01}
Poli, R., Kozak J.: Genetic Programming. In: Burke, EK., Kendall, G. (eds.) Search Methodologies, pp. 143--185. Springer US (2014)
\bibitem{angelova01}
Angelova, V.: Investigations in the Area of Soft Computing Targeted State of the Art Report. Cybernetics and Information Technologies \textbf{9}(1), 18--24 (2009)
\bibitem{alexandrov01}
Alexandrov, A.: AD HOC Kalman filter based fusion algorithm for real-time Wireless Sensor Data Integration. In: FQAS-2015 Proceedings, pp. 151--160. Springer, Heidelberg (2015)
\bibitem{tashev01}
Tashev, T., Hristov, H.: Modeling of synthesis of information processes with generalized nets. Cybernetics and Information Technologies, \textbf{3}(2), 92--104 (2003)
\bibitem{atanasova01}
Atanasova T., Barova M.: Exploratory analysis of Time Series for hypothesize feature values. In: UniTech17 Proceedings,  \textbf{16}(2), 399--403 (2017)
\end{thebibliography}
\end{document}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

      \subsection{propagated.m}

\begin{par}
\textbf{Summary:} Propagate the state distribution one time step forward            with derivatives
\end{par} \vspace{1em}

\begin{verbatim}function [Mnext, Snext, dMdm, dSdm, dMds, dSds, dMdp, dSdp] = ...
  propagated(m, s, plant, dynmodel, policy)\end{verbatim}
    \begin{par}
\textbf{Input arguments:}
\end{par} \vspace{1em}
\begin{verbatim}m                 mean of the state distribution at time t           [D x 1]
s                 covariance of the state distribution at time t     [D x D]
plant             plant structure
dynmodel          dynamics model structure
policy            policy structure\end{verbatim}
\begin{par}
\textbf{Output arguments:}
\end{par} \vspace{1em}
\begin{verbatim}Mnext             predicted mean at time t+1                         [E x 1]
Snext             predicted covariance at time t+1                   [E x E]
dMdm              output mean wrt input mean                         [E x D]
dMds              output mean wrt input covariance matrix         [E  x D*D]
dSdm              output covariance matrix wrt input mean        [E*E x  D ]
dSds              output cov wrt input cov                       [E*E x D*D]
dMdp              output mean wrt policy parameters                  [E x P]
dSdp              output covariance matrix wrt policy parameters  [E*E x  P]\end{verbatim}
\begin{verbatim}where P is the number of policy parameters.\end{verbatim}
\begin{par}
Copyright (C) 2008-2013 by Marc Deisenroth, Andrew McHutchon, Joe Hall, Henrik Ohlsson, and Carl Edward Rasmussen.
\end{par} \vspace{1em}
\begin{par}
Last modified: 2013-01-23
\end{par} \vspace{1em}

\subsection*{High-Level Steps}

\begin{enumerate}
\setlength{\itemsep}{-1ex}
   \item Augment state distribution with trigonometric functions
   \item Compute distribution of the control signal
   \item Compute dynamics-GP prediction
   \item Compute distribution of the next state
\end{enumerate}

\begin{lstlisting}
function [Mnext, Snext, dMdm, dSdm, dMds, dSds, dMdp, dSdp] = ...
  propagated(m, s, plant, dynmodel, policy)
\end{lstlisting}

\subsection*{Code}

\begin{lstlisting}
if nargout <= 2                                  % just predict, no derivatives
  [Mnext, Snext] = propagate(m, s, plant, dynmodel, policy);
  return
end

angi = plant.angi; poli = plant.poli; dyni = plant.dyni; difi = plant.difi;

D0 = length(m);                                        % size of the input mean
D1 = D0 + 2*length(angi);          % length after mapping all angles to sin/cos
D2 = D1 + length(policy.maxU);          % length after computing control signal
D3 = D2 + D0;                                         % length after predicting
M = zeros(D3,1); M(1:D0) = m; S = zeros(D3); S(1:D0,1:D0) = s;   % init M and S

Mdm = [eye(D0); zeros(D3-D0,D0)]; Sdm = zeros(D3*D3,D0);
Mds = zeros(D3,D0*D0); Sds = kron(Mdm,Mdm);
X = reshape(1:D3*D3,[D3 D3]); XT = X'; Sds = (Sds + Sds(XT(:),:))/2;
X = reshape(1:D0*D0,[D0 D0]); XT = X'; Sds = (Sds + Sds(:,XT(:)))/2;

% 1) Augment state distribution with trigonometric functions ------------------
i = 1:D0; j = 1:D0; k = D0+1:D1;
[M(k) S(k,k) C mdm sdm Cdm mds sds Cds] = gTrig(M(i), S(i,i), angi);

[S Mdm Mds Sdm Sds] = ...
  fillIn(S,C,mdm,sdm,Cdm,mds,sds,Cds,Mdm,Sdm,Mds,Sds,[ ],[ ],[ ],i,j,k,D3);

mm=zeros(D1,1); mm(i)=M(i); ss(i,i)=S(i,i)+diag(exp(2*dynmodel.hyp(end,:))/2);
[mm(k), ss(k,k) C] = gTrig(mm(i), ss(i,i), angi);     % noisy state measurement
q = ss(j,i)*C; ss(j,k) = q; ss(k,j) = q';

% 2) Compute distribution of the control signal -------------------------------
i = poli; j = 1:D1; k = D1+1:D2;
[M(k) S(k,k) C mdm sdm Cdm mds sds Cds Mdp Sdp Cdp] = ...
  policy.fcn(policy, mm(i), ss(i,i));

[S Mdm Mds Sdm Sds Mdp Sdp] = ...
  fillIn(S,C,mdm,sdm,Cdm,mds,sds,Cds,Mdm,Sdm,Mds,Sds,Mdp,Sdp,Cdp,i,j,k,D3);

% 3) Compute distribution of the change in state ------------------------------
ii = [dyni D1+1:D2]; j = 1:D2;
if isfield(dynmodel,'sub'), Nf = length(dynmodel.sub); else Nf = 1; end
for n=1:Nf                               % potentially multiple dynamics models
  [dyn i k] = sliceModel(dynmodel,n,ii,D1,D2,D3); j = setdiff(j,k);

  [M(k) S(k,k) C mdm sdm Cdm mds sds Cds] = dyn.fcn(dyn, M(i), S(i,i));

  [S Mdm Mds Sdm Sds Mdp Sdp] = ...
    fillIn(S,C,mdm,sdm,Cdm,mds,sds,Cds,Mdm,Sdm,Mds,Sds,Mdp,Sdp,[ ],i,j,k,D3);

  j = [j k];                                   % update 'previous' state vector
end

% 4) Compute distribution of the next state -----------------------------------
P = [zeros(D0,D2) eye(D0)]; P(difi,difi) = eye(length(difi));  P = sparse( P);
Mnext = P*M; Snext = P*S*P'; Snext = (Snext+Snext')/2;

PP = kron(P,P);
dMdm =  P*Mdm; dMds =  P*Mds; dMdp =  P*Mdp;
dSdm = PP*Sdm; dSds = PP*Sds; dSdp = PP*Sdp;

X = reshape(1:D0*D0,[D0 D0]); XT = X';                          % symmetrize dS
dSdm = (dSdm + dSdm(XT(:),:))/2; dMds = (dMds + dMds(:,XT(:)))/2;
dSds = (dSds + dSds(XT(:),:))/2; dSds = (dSds + dSds(:,XT(:)))/2;
dSdp = (dSdp + dSdp(XT(:),:))/2;

% A1) Separate multiple dynamics models ---------------------------------------
\end{lstlisting}

\begin{lstlisting}
function [dyn i k] = sliceModel(dynmodel,n,ii,D1,D2,D3) % separate sub-dynamics
if isfield(dynmodel,'sub')
  dyn = dynmodel.sub{n}; do = dyn.dyno; D = length(ii)+D1-D2;
  if isfield(dyn,'dyni'), di=dyn.dyni; else di=[]; end
  if isfield(dyn,'dynu'), du=dyn.dynu; else du=[]; end
  if isfield(dyn,'dynj'), dj=dyn.dynj; else dj=[]; end
  i = [ii(di) D1+du D2+dj]; k = D2+do;
  dyn.inputs = [dynmodel.inputs(:,[di D+du]) dynmodel.target(:,dj)];   % inputs
  dyn.target = dynmodel.target(:,do);                                 % targets
else
  dyn = dynmodel; k = D2+1:D3; i = ii;
end

% A2) Apply chain rule and fill out cross covariance terms --------------------
function [S Mdm Mds Sdm Sds Mdp Sdp] = ...
  fillIn(S,C,mdm,sdm,Cdm,mds,sds,Cds,Mdm,Sdm,Mds,Sds,Mdp,Sdp,dCdp,i,j,k,D)

if isempty(k), return; end

X = reshape(1:D*D,[D D]); XT = X';                         % vectorized indices
I=0*X; I(i,i)=1; ii=X(I==1)'; I=0*X; I(k,k)=1; kk=X(I==1)';
I=0*X; I(j,i)=1; ji=X(I==1)'; I=0*X; I(j,k)=1; jk=X(I==1)'; kj=XT(I==1)';

Mdm(k,:)  = mdm*Mdm(i,:) + mds*Sdm(ii,:);                           % chainrule
Mds(k,:)  = mdm*Mds(i,:) + mds*Sds(ii,:);
Sdm(kk,:) = sdm*Mdm(i,:) + sds*Sdm(ii,:);
Sds(kk,:) = sdm*Mds(i,:) + sds*Sds(ii,:);
dCdm      = Cdm*Mdm(i,:) + Cds*Sdm(ii,:);
dCds      = Cdm*Mds(i,:) + Cds*Sds(ii,:);
if isempty(dCdp) && nargout > 5
  Mdp(k,:)  = mdm*Mdp(i,:) + mds*Sdp(ii,:);
  Sdp(kk,:) = sdm*Mdp(i,:) + sds*Sdp(ii,:);
  dCdp      = Cdm*Mdp(i,:) + Cds*Sdp(ii,:);
elseif nargout > 5
  aa = length(k); bb = aa^2; cc = numel(C);
  mdp = zeros(D,size(Mdp,2)); sdp = zeros(D*D,size(Mdp,2));
  mdp(k,:)  = reshape(Mdp,aa,[]); Mdp = mdp;
  sdp(kk,:) = reshape(Sdp,bb,[]); Sdp = sdp;
  Cdp       = reshape(dCdp,cc,[]); dCdp = Cdp;
end

q = S(j,i)*C; S(j,k) = q; S(k,j) = q';                           % off-diagonal
SS = kron(eye(length(k)),S(j,i)); CC = kron(C',eye(length(j)));
Sdm(jk,:) = SS*dCdm + CC*Sdm(ji,:); Sdm(kj,:) = Sdm(jk,:);
Sds(jk,:) = SS*dCds + CC*Sds(ji,:); Sds(kj,:) = Sds(jk,:);
if nargout > 5
  Sdp(jk,:) = SS*dCdp + CC*Sdp(ji,:); Sdp(kj,:) = Sdp(jk,:);
end
\end{lstlisting}


\section{Learning to Optimally Segment Point Clouds}\label{header-n863}

\emph{IEEE ROBOTICS AND AUTOMATION LETTERS, VOL. 5, NO. 2, APRIL 2020}
{[}28{]}

\subsection{Introduction}\label{header-n865}

This letter focuses on the application of autonomous vehicles.
Perception for autonomous robots presents a series of challenges. First,
the right representation of the 3D data obtained by a LiDAR sensor still
remains an open question. Secondly, contemporary approaches to object
detection and scene understanding tend to be closed-world, where the
task is predicting 1-of-N possible labels. Finally, practical autonomous
robotics makes heavy use of perceptual priors in the forms of geometric
maps and assumptions on LiDAR geometry. In this work, the authors focus
on the problem of class-agnostic instance segmentation of LiDAR point
clouds in an open-world setting.

\begin{figure}[h!]
\centering
\includegraphics[width=0.7\linewidth]{images/pointcloudseg.png}
\caption{The class-agnostic instance-level segmentation over all foreground points performed by the proposed method }
\end{figure}

They carefully mix graph-theoretic algorithms with data-driven learning.
While data-driven learning is widely used due to its performance, it is
difficult to guarantee good results when processing out-of-sample data
from an open world. The proposed method searches over an exponentially
large space of possible segmentations and returns the one most similar
to the data-driven point-based model of ``objectness". First, the search
is restricted into a subset of segmentations that are consistent with a
hierarchical grouping of a point cloud sweep. Such hierarchical groups
can be readily produced with agglomerative clustering or hierarchical
graph-based algorithms. Since that a segmentation algorithm can produce
an exponentially-large set of segmentations, the authors introduce
efficient algorithms that search over a space of tree-consistent
segmentations and return the one that maximizes a global segmentation
score.

\subsection{Proposed approach}\label{header-n869}

For 3D object point segmentation, the input is a 3D point cloud, which
contains an \emph{unknown} number of objects. The goal is to produce a
point segmentation, in which every segment contains points from one and
only one object.

\subsubsection{Definitions}\label{header-n871}

A \emph{global segmentation} $P_X$ is a partition of a set of points
$X$ into subsets of points $C_i$ (called local segment), i.e
$P_X = \{C_i\}_{i = 1}^{M}$, where $M$ denotes the number of
segments and $C_i \subset X$. Importantly, every point exists in one
and only one segment.

The concept of \emph{tree-consistent segmentation} is defined as
follows. The set of all possible global segmentations on $X$ is
defined as $S_X$. Without constraints, the size of $S_X$ is
exponential but in practice the authors reduce the number of candidates
by enforcing geometric constraints. All points are grouped
hierarchically into a tree structure $T_X$. Now, the tree-consistent
segmentation is $S_{X,T}$ and contains all possible segmentation
defined by the tree $T$. The following figure illustrates the
relationship between $S_X$ and $S_{X,T}$.

\begin{figure}[h!]
\centering
\includegraphics[width=0.7\linewidth]{images/treesegment.png}
\caption{Tree-consistent segmentation}
\end{figure}

Any tree-consistent segmentation from corresponds to a vertex cut set of
the tree $T$, i.e. a set of tree nodes, which satisfy the following
constraints:

\begin{itemize}
\item
  for each node in the vertex cut, its ancestor and itself cannot both
  be in the cut and
\item
  each leaf node must have itself or its ancestor in the cut.
\end{itemize}

The \emph{segment score} is defined as a function $f(C, \theta)$,
where $C$ is the segment and $\theta$ are the function parameters.
$f$ predicts a given segment's ``objectness" and can be implemented by
a PointNet++, where $\theta$ are the network's weights.

The \emph{segmentation score} is calculated as the aggregation of the
score of all segments in a global segmentation $P_X$. Formally, given
a global segmentation $P_X = \{Ci\}^{M}_{i=1}$, its score is
$F(P_X; \theta) : PX→ [0, 1]$ by aggregating over local objectness of
all its segments.

\subsubsection{Worst-case segmentation}\label{header-n884}

The \emph{worst-case segmentation} score of a global segmentation is the
worst objectness among its local segments:

$ F_{\min }(P_X; \theta) = \min _i{f(C_i; \theta)}, i\in {1 \ldots M}.$

Now, the optimal worst-case segmentation is

$ P_{X,\min }^* = \mathop{\operatorname{argmax}}\limits_{P_X\in S_{X,T}} {F_{\min } (P_X; \theta)} $.

It turns out the problem of finding optimal worst-case segmentation has
optimal substructure, allowing us to find the global optimum efficiently
with dynamic programming (see the following figure).

\begin{figure}[h!]
\centering
\includegraphics[width=0.8\linewidth]{images/worstcaseseg.png}
\caption{Optimal worst case segmentation}
\end{figure}

The algorithm starts from the root node $X$ and chooses between a
coarse segmentation and a fine one. The fine segmentation will be the
union of all $X$`s children's optimal worst-case segmentation, which
can be computed recursively. The algorithm would first traverse down to
the leaf nodes, representing the finest segmentation. Then it will make
its way up, during which it finalizes optimal segmentation for each
intermediate node by making local coarse vs. fine decisions. Eventually,
it returns to the root node and produces an optimal worst-case global
segmentation. This algorithm might not visit all nodes. Instead, it
skips a sub-trees whenever one sub-tree exhibits a lower score. The
algorithm's complexity is linear in $N$ despite the fact that the
search space is exponential in $N$.

\subsubsection{Average-case segmentation}\label{header-n892}

Average-case segmentation score of a global segmentation is the average
objectness among its local segments:
\newline
$ F_{\operatorname{avg}{}}(P_X; \theta) = \frac{1}{M} \sum _{i=1}^M f(C_i; \theta).$
\newline
$P_{X,\operatorname{avg}{}}^*$ can be defined as \emph{optimal
average-case segmentation} if
\newline
$ P_{X,\operatorname{avg}{}}^* = \mathop{\operatorname{argmax}}\limits_{P_X\in S_{X,T}} {F_{\operatorname{avg}{}} (P_X; \theta)}. $
\newline
It is important to specify that the problem of finding the optimal
average-case segmentation does not have optimal substructure, unlike
worst-case segmentation.

\subsubsection{Learning the Objectness Function}\label{header-n898}

Until now, the segmentation algorithms have been discussed under the
assumption that the objectness function $f(C; \theta)$ is defined (it
predicts an objectness score for a given point cloud). First of all, the
ground-truth function must be defined. Suppose to have the ground truth
segmentation $P^{gt} = \{C_1^{gt},...,C_L^{gt}\}$. To define the
target objectness of a segment, we have to consider that 3D sensors
(e.g. LiDAR) tend to produce denser points near the sensor. In
consequence, the objectness will be heavily influenced by the
partitioning of points closer to the sensor. A segment objectness
function of a segment is the largest point between itself and any ground
truth segment:
\newline
$ Objectness(C, P^{gt}) = \max _{l=1,\ldots,L} \frac{\sum _{x \in C \cap C^{gt}_l} x^T x }{\sum _{x \in C \cup C^{gt}_l} x^T x }, $
\newline
where $x^T x$ represents the squared distance of a point $x$ to
sensor origin. The authors train a PointNet++ model for learning the
objectness function. Each segment is re-sampled to 1024 points.

\subsubsection{Building tree hierarchies}\label{header-n902}

This section explains how to build a tree structure given a set of
points $X$. One natural approach is agglomerative clustering, merging
points in classes according to their spatial features. This approach
tends to create tree hierarchies with very fine granularity, e.g. one
node may differ from another with only one point of difference. In this
work, the authors propose a method which builds a coarser tree whose
leaf nodes are segments (rather than individual points) and adjacent
nodes should differ from each other much more. To build such a tree,
Euclidean Clustering algorithm is used recursively in a top-down fashion
with a list of decreasing $\epsilon$. In the beginning, the algorithm
is run with the largest $\epsilon$ value, defining the most coarse
connected components. Then, the procedure is repeated a smaller
$\epsilon$ within each connected component. This produces a
multiple-tree top-down hierarchy.

\subsection{Experiments}\label{header-n904}

For evaluation, the authors repurpose the KITTI object detection
benchmark for point cloud segmentation, following the setup in {[}30{]}.
The ground truth segmentation is composed of a series of point segments
marked with a bounding box. All the background points (those outside the
bounding box) are removed. To evaluate the performance are considered
two metrics: the \emph{under-segmentation error} $U$ and the
\emph{over-segmentation error} $O$, defined as follows:
\newline
$ U = \frac{1}{L} \sum _{l=1}^L \mathbf {1} \left(\frac{|C_{i^*} \cap C_l^{gt}|}{|C_{i^*}|} < \tau _U\right) \\ O = \frac{1}{L} \sum _{l=1}^L \mathbf {1} \left(\frac{|C_{i^*} \cap C_l^{gt}|}{|C_l^{gt}|} < \tau _O\right)$
\newline
with
\newline
$ i^* = \operatorname{argmax}_{i=1}^M{|C_i \cap C^{gt}_l|}$
\newline
and $\tau _U, \tau _O$ as constant thresholds, set to
$\frac{2}{3}, 1$.
\newline
The Euclidean clustering algorithm is applied with an
$\epsilon \in \{2 m, 1 m, 0.5 m, 0.25 m\}$. The authors include it as
a baseline to find better solutions. As baselines, other
state-of-the-art 3D detectors are included: AVOD, PointPillars,
PointRCNN, and SECOND. Since these detectors output class-specific
bounding box detection, the authors simply ignore the class label to
produce class-agnostic segmentations. In addition, the authors include
for evaluation modified versions of the proposed baselines, in order to
improve their performance. A much better approach, called
\emph{\{Detector\}++} (e.g. AVOD++ etc.), check if the leftover segments
can be included in an existing detection segment. Another approach,
SECOND++, consists of re-train and re-evaluate the best baseline, i.e.
SECOND, with background removal. These baselines are marked with ``+ BG
Removal". In addition, the authors discover that, by extending the
SECOND's detection range from 50 m to 80 m, the SECOND's performance is
significantly improved. The affected baselines are marked with ``+ Ext.
Range". Finally, they re-train and re-evaluate SECOND on all 8 classes.
The new baselines are labeled as ``SECOND++(8)", while the off-the-shelf
SECOND baselines are labeled as ``SECOND++(4)". The following figure
resumes the results obtained.

\begin{figure}[h!]
\centering
\includegraphics[width=1\linewidth]{images/segmentationerrors.png}
\caption{Segmentation errors on the proposed method (*Ours*) and the baselines}
\end{figure}

The table shows that the average-case segmentation, \emph{Ours(avg)},
consistently outperforms the optimal worst-case segmentation
\emph{Ours(min)}. \emph{Ours(min)} produces a much lower
over-segmentation error but a much higher under-segmentation error,
suggesting it makes more mistakes of grouping different objects into one
segment and fewer mistakes of splitting points from one single object
into multiple segments. The authors label Euclidean Clustering as
``EC()," where $\epsilon$ represents the distance threshold (meter) and
constructs a pool of segments that contains every node (segment) in the
hierarchy and call this ``EC(all)*". This serves as an unreachable
upper-bound. The gap between our proposed method and the upper bound is
relatively small (3--4\%), suggesting plenty of room left for
improvement in creating better hierarchies. The confront between a
\emph{Detector} algorithm and its variation \emph{Detector++}, shows
that the improved version obtains better performance (see the AVOD's
case). SECOND++ performs the best among all Detector++ baselines.
SECOND++ performs better on common classes such as cars while the
proposed method perform better on rare ones such as misc. Another
evaluation metric is measure how objectness generalizes over different
classes. The authors apply the learned objectness onto truth segments
from the validation set. The graph below shows the results.

\begin{figure}[h!]
\centering
\includegraphics[width=0.8\linewidth]{images/objectnessgen.png}
\caption{Learned objectness generalization}
\end{figure}

As the number of training data decreases dramatically, the average score
tends to drops slightly and the variance tends to rise slightly. In
conclusion, the authors prove that their algorithm is guaranteed to
achieve optimality to a specific definition. On KITTI, the proposed
approach significantly outperforms past bottom-up approaches and
top-down object-based algorithms for segmenting point clouds.


\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage[usenames, dvipsnames]{color}

\begin{document}

\begin{flushright}

\vspace{1.1cm}

{\bf\Huge Problem Set 10}

\rule{0.25\linewidth}{0.5pt}

\vspace{0.5cm}
%Put Authors
Justin Ely
\linebreak
\newline
%Put Author's affiliations
\footnotesize{605.411 Foundations of Computer Architecture \\}
\vspace{0.5cm}
% Date here below
15 November, 2016
\end{flushright}

\noindent\rule{\linewidth}{1.0pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{1a)}
\begin{itemize}
  \item A: $time = 5s + \frac{3145728 \, bytes \times s^{-1}}{5120s} = 619.4s$
  \item B: $time = 4s + \frac{3145728 \, bytes \times s^{-1}}{3072s} = 1028s$
\end{itemize}

\section*{1b)}
\begin{eqnarray}
5 + \frac{N}{5120} &=& 4 + \frac{N}{3072} \\
\frac{N}{5120} &=& -1 + \frac{N}{3072} \\
N &=& -5120 + \frac{5N}{3} \\
 \frac{-2N}{3}  &=& -5120 \\
 N  &=& 7680 \, bytes
\end{eqnarray}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{2a)}
With a device generating 150 requests per second, and each request requiring 12,000 cycles to handle, the total number of
cycles per second spent handling interrupts and processing requests will be: \\

$150 \, \frac{requests}{second} \times 12,000 \, cycles = 1,800,000 \frac{cycles}{second}$.

\section*{2b)}
For just a polling scenario, the CPU will use 500 cycles once every .5ms.  \\

$ \frac{1 \, poll}{5e^{-4} \, seconds} \times 500 \, cycles= 1,000,000 \frac{cycles}{second}$

\section*{2c)}

$ \frac{1 \, poll}{N \, seconds} \times (500 + 12000)\, cycles = 1800000 $, thus N = .0069s or 6.9ms.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{3a)}
Memory-mapping implements I/O by allowing peripheral device access through the same address bus as normal memory.  This has the benefit of not needing special I/O commands; rather the same load instruction can be used to access system memory or an external device, at the cost of decreasing the amount of addresses reserved for memory.  Consequently, CPUs are allowed to remain simpler, cheaper, smaller, and faster without the overhead of the extra logic.

\section*{3b)}
DMA is an improvement over CPU programmed I/O because it requires fewer active CPU cycles to complete memory access.  CPU Programmed I/O requires the CPU to be active during the entire read or write sequence.  With DMA, a device is allowed to directly access memory and bypass the need for the CPU to act as middleman.  In this scheme the CPU is only need at the beginning and end of an access, the rest of the time it is free to perform other functions.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


\documentclass[11pt,a4paper]{article}
% \renewcommand{\baselinestretch}{2}

\input{psfig}
\textwidth 17truecm
\textheight 24.2truecm
\hoffset -1.5truecm
\voffset -1.5truecm

\title{A New Entropy Measure Based on the Wavelet Transform and Noise Modeling}
\author{ J.-L. Starck \\
CEA/DSM/DAPNIA, CE-SACLAY, F-91191 Gif sur Yvette Cedex \\ [12pt]
F. Murtagh \\
Faculty of Informatics, University of Ulster, Magee College, \\
Londonderry BT48 7JL, Northern Ireland \\ [12pt]
R. Gastaud \\
CEA/DSM/DAPNIA, CE-SACLAY, F-91191 Gif sur Yvette Cedex}

\begin{document}
\maketitle

\abstract{
We present in this paper a new way to measure the information
in a signal, based on noise modeling. We show that the use of such
an entropy-related measure leads to good results for signal restoration.}

\section{Introduction}
The term ``entropy'' term is due to Clausius (1865), and the concept of
entropy was introduced by Boltzmann into statistical mechanics,
in order to measure the number of microscopic ways that a given macroscopic
state can be realized. Shannon \cite{shannon48}
founded the mathematical theory of
communication when he suggested that the information gained in a
measurement depends on the number of possible outcomes out of
which one is realized. Shannon also suggested that
the entropy can be used for maximization of the bits transferred under
a quality constraint. Jaynes \cite{jaynes57} proposed to use
the entropy measure
for radio interometric image deconvolution,  in
order to select in a set of possible solutions that which contains the
minimum of information, or following his entropy definition, that
which has a maximum entropy. In principle, the solution verifying such
a condition should be the most reliable. A lot of work has been carried out
in the last 30 years on the use of entropy for the general problem
of data filtering and deconvolution
\cite{ables74,bontekoe94,burg67,frieden75,gull91,narrayan86,pantin96,skilling84_1,
weir92}.

Traditionally information and entropy are determined from events and the
probability of their occurrence.  Signal and noise are basic building-blocks
of signal and data analysis in the physical sciences.  Instead of the
probability of an event, in this work
 we are led to consider the probabilities of our
data being either signal or noise.

Observed data $Y$ in the physical sciences
are generally corrupted by noise, which is often additive and which
follows in many cases a Gaussian distribution, a Poisson distribution, or
a combination of both.
 Using Bayes' theorem to evaluate the probability of the
realization of the original signal $X$,
knowing the data $Y$, we have

\begin{eqnarray}
 \mathrm{Prob}(X|Y) = \frac{\mathrm{Prob}(Y|X).\mathrm{Prob}(X)}{\mathrm{Prob}(Y)}
\label{eqn_bayes}
\end{eqnarray}
$\mathrm{Prob}(Y|X)$ is the conditional probability of getting the data
$Y$ given an original signal $X$, i.e.\ it represents the distribution
of the noise. It is given, in the case of uncorrelated Gaussian
noise with variance $\sigma^2$, by:
\begin{eqnarray}
 \mathrm{Prob}(Y|X) = \mathrm{exp}(-\sum_{pixels} \frac{ (Y-X)^2}{2{\sigma}^2} )
\label{eqn_proba}
\end{eqnarray}
The denominator in  equation \ref{eqn_bayes} is independent of $X$ and
 is considered as a constant (stationary noise).
$\mathrm{Prob(X)}$ is the a priori distribution
of the solution $X$. In the absence of any information on the solution
$X$ except its positivity, a possible course of action
is to derive the probability
of $X$ from its entropy, which is defined from information theory.

The main idea of information theory \cite{shannon48} is to establish
a relation between the received information and the probability of
the observed event \cite{bijaoui84}. If we note ${\cal I}(E)$ the information
related to the event $E$, and $p$ the probability of this
event happening, then we consider that
\begin{eqnarray}
%\cal{I}(E) =    f(p)
{\cal I}(E) = f(p)
\end{eqnarray}

Then we assume the two following principles:
\begin{itemize}
\item The information is a decreasing function of the probability. This
implies that the more information we have, the  less will be the probability
associated with one event.
\item Additivity of the information. If we have two independent events
$E_1$ and $E_2$, the information ${\cal I}(E)$ associated with the happening
of both is equal
to the addition of the information of each of them.
\begin{eqnarray}
{\cal I}(E) = {\cal I}(E_1) + {\cal I}(E_2)
\end{eqnarray}
\end{itemize}

Since $E_1$ (of probability $p_1$) and $E_2$ (of probability $p_2$) are
independent, then the probability of both happening is equal to the
product of $p_1$ and $p_2$.  Hence
\begin{eqnarray}
f(p_1 p_2) = f(p_1) + f(p_2)
\end{eqnarray}

Then we can say that the information measure is
\begin{eqnarray}
{\cal I}(E) = k \ln(p)
\end{eqnarray}
where k is a constant. Information must be positive, and $k$
is generally fixed at $-1$.

Another interesting measure is the mean information which is denoted
\begin{eqnarray}
H = - \sum_i p_i \ln(p_i)
\end{eqnarray}
This quantity is called the entropy of the system and was established by
Shannon in 1948 \cite{shannon48}.

This measure has several properties:
\begin{itemize}
\item It is maximal when all events have the same probability
$p_i = 1/ N_e$ ($N_e$ being the number of events), and is equal to
$\ln(N_e)$. It is in this
configuration that the system is the most undefined.
\item It is minimal when one event is sure. In this case, the system is
perfectly known, and no information can be added.
\item The entropy is a positive, continuous, and symmetric function.
%\item The mean information, obtained in two steps, can be added.
\end{itemize}

Then if we know the entropy $H$ of the solution (the next section
describes different ways to calculate it),
we derive its probability by
\begin{eqnarray}
\mathrm{Prob}(X) = \mathrm{exp}(- \alpha H(X))
\label{info_prop}
\end{eqnarray}

Given the data, the most probable image is obtained by maximizing
$\mathrm{Prob}(X|Y)$. Taking the logarithm of equation \ref{eqn_bayes}, we
thus need to maximize
\begin{eqnarray}
 \ln (\mathrm{Prob}(X|Y))  = - \alpha  H(X) + \ln(\mathrm{Prob}(Y|X)) -
\ln(\mathrm{Prob}(Y))
\end{eqnarray}
The last term is a constant and can be omitted.
Then, in the case of Gaussian noise, the solution is found by minimizing
\begin{eqnarray}
J(X) = \sum_{pixels} \frac{{(Y-X)}^{2}}{2 {\sigma}^{2}} + {\alpha} H(X)
= \frac{{\chi}^2}{2} + {\alpha} H(X)
\label{eqn_j1}
\end{eqnarray}
which is a linear combination of two terms: the entropy of the signal,
and a quantity corresponding to ${\chi}^2$ in statistics measuring the
discrepancy between the data and the predictions of the model.
$\alpha$ is a parameter that can be viewed alternatively as
a Lagrangian parameter or a value fixing the relative weight between
the goodness-of-fit and the entropy H.

For the deconvolution problem, the object-data relation is given by the
convolution
\begin{eqnarray}
Y = P * X
\end{eqnarray}
where $P$ is the point spread function, and the solution is found (in the case
of Gaussian noise) by minimizing
\begin{eqnarray}
J(X) = \sum_{pixels} \frac{{(Y-P*X)}^{2}}{2 {\sigma}^{2}} + {\alpha} H(X)
\end{eqnarray}

The way the entropy is defined is fundamental, because from its definition
will depend the solution. The next section discusses the different approaches
which have been proposed in the past.

\section{The concept of entropy}
\label{sect_entr}

We wish to estimate an unknown probability density $p(x)$ of the data.
A direct approach would be to build up the histogram of values $X(i)$, using
a suitable interval $\Delta x$, counting up how many times $m_k$ each interval
$(x_k, x_k + \Delta x)$ occurs among the N occurrences. Then the probability
that a data value belongs to an interval $k$ is $p_k = \frac{m_k}{N}$, and
each data value has a probability $p_k$. The entropy is defined by
\begin{eqnarray}
H_s(X) = - \sum_{k=1}^{m} p_k \ln(p_k)
\end{eqnarray}
where $m$ is the number of intervals.
The entropy is minimum and equal to zero when the signal is flat, and
increases when we have some fluctuations. Using this entropy in
equation~\ref{eqn_j1} for restoration leads to a minimum entropy restoration
 method.

The trouble with this approach is that, because the number of occurrences is
finite, the estimate $p_k$ will be in error by an amount proportional
to $m_k^{-\frac{1}{2}}$~\cite{frieden}. The error becomes significant when
$m_k$ is small. Furthermore this kind of entropy definition is not
easy to use for signal restoration, because the gradient of
equation~\ref{eqn_j1} is not easy to compute. For these reasons, other
entropy functions are generally used. The main ones are:
\begin{itemize}
\item Burg \cite{burg67}:
\begin{eqnarray}
H_b(X) = -\sum_{pixels} \ln(X)
\end{eqnarray}
\item Frieden \cite{frieden75}:
\begin{eqnarray}
H_f(X) = -\sum_{pixels}X \ln(X)
\end{eqnarray}
\item Gull and Skilling \cite{gull91}:
\begin{eqnarray}
H_g(X) = \sum_{pixels} X - M - X \ln(X|M)
\end{eqnarray}
\end{itemize}
Each of these entropies can be used, and they correspond to different
probability distributions that one can associate with
an image \cite{narrayan86}.
(See \cite{frieden75,skilling84_1,skilling89} for descriptions).
The last definition of the entropy has the advantage of having a zero
 maximum when $X$ equals the model $M$, usually taken as a flat image.
All of these entropy measures are negative, and maximum when the image is flat.
They are negative because an offset term is omitted which has no importance
for the minimization of the functional. The fact that we consider that
a signal has maximum information value when it is flat is evidently
a curious way to measure information. The probability of $X$
must be defined by $\mathrm{Prob}(X) = \mathrm{exp}(\alpha H(X))$. The sign has
been inverted
(see equation~\ref{info_prop}), which is natural if we want the best
solution to be  the smoothest. These three entropies lead to the
maximum entropy restoration method, for which the
solution is found by minimizing
(for Gaussian noise)
\begin{eqnarray}
J(X) = \sum_{pixels} \frac{{(Y-X)}^{2}}{2 {\sigma}^{2}} - {\alpha} H(X)
\label{eqn_j3}
\end{eqnarray}

In 1986, Narayan and Nityanda \cite{narrayan86}
compared several entropy functions,
 and finally
concluded by saying that all were comparable if they have good
properties, i.e.\ they enforce positivity, and they have a negative
second derivative which discourages ripple. They showed also that
results varied strongly with the background level, and
that these entropy functions produced poor results
for negative structures, i.e.\ structures under the background level
(absorption area in an image, absorption band in a spectrum, etc.), and
compact structures in the signal.
The Gull and Skilling entropy gives rise to
the difficulty of estimating a model.
Furthermore it has been shown \cite{bontekoe94}
that the solution was dependent on this choice.

Many studies \cite{weir92,bontekoe94,pantin96}
have been carried out in order to improve the functional to be minimized.
But the question which should be raised is: what is a good entropy for
signal restoration?

Trying to answer this corresponds to asking what is the information
in the signal. The entropy should verify the following criteria:
\begin{enumerate}
\item The information in a flat signal is zero.
\item The amount of information in a signal is independent of the background.
\item The amount of information is dependent on the noise. A given
signal $Y$ ($Y = X + Noise$) doesn't furnish the  same information if
the noise is high or small.
\item The entropy must work in the same way for a pixel which
has a value $B + \epsilon$ ($B$ being the background), and
for a pixel which has a value $B - \epsilon$.
\item The amount of information is dependent on the correlation in the signal.
If a signal $S$  presents large features above the noise, it contains
a lot of information. By generating a new set of  data from $S$, by
randomly taking the pixel values in $S$, the large features will
evidently disappear, and this new signal will contain less information.
But the pixel values will be the same as in $S$.
\end{enumerate}

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=lenna256.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
\psfig{figure=scrambled_lenna.ps,bbllx=1.8cm,bblly=12.9cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
}}
\caption{Lena image (left) and the same data distributed differently (right).
These
two images have the same entropy, using any of the standard entropy methods.}
\label{fig_lenna}
\end{figure}

Figure~\ref{fig_lenna} shows the Lena image (left), and an image obtained
by distributing randomly the Lena image pixel values. For someone, who is
not involved in image processing, the second image contains less information
than the first one. For someone working on image transmission, it is clear
that the second image will require more bits for a lossless transmission,
and from this point of view, he will consider that the second one contains
more information. The standard entropy methods produce exactly
the same value for both images and, for such methods, both images contain
the same amount of information. For data restoration, all fluctuations
due to noise are not of interest, and do not contain relevant
information.  From this physical point of view, that is the reason why
the standard
definition of entropy seems badly adapted to information measurement
in signal restoration.

\section{Entropy from noise modeling}

In the case of signal restoration, the noise is the main problem. This
means that we should not consider the probability of appearance of
a pixel value in an image, but rather its probability of being due to the
signal (or to the noise).
If we consider a variable $x$ which follows a probability distribution
$p(x)$, we
can define the information in $x$ by $- \ln(p(x))$, and a signal $S$ can
be considered as a set of individual variables $x_k$ (pixels), each of which
follows the same probability distribution.
Then the information contained in the data
can be measured by $- \sum_{pixel} \ln(p(x))$. If $x$ follows a Gaussian
distribution with zero mean, we have
\begin{eqnarray}
H(X) = \sum_{pixel} \frac{x^2}{2 \sigma^2}
\end{eqnarray}
The energy gives a good measurement of information. But many of the required
criteria are not fulfilled by using such an entropy (correlation between
pixels, background-independent, etc.). It seems difficult to derive
a good probability distribution from the pixel values which fulfill the
entropy requirements.

This is not so for transformed data, especially when using
the wavelet transform.
This has  already been done, in fact,
for finding threshold levels in filtering
methods by means of wavelet coefficient thresholding \cite{starck95}. Thus we
must introduce the concept of multiresolution into our entropy.
We will now consider that the information contained in some dataset
is the sum of the information at different resolution levels $j$.
Choosing the ``\`a trous'' wavelet transform (see \cite{starck95}
for a description of this wavelet transform algorithm), a signal $S$ can
be represented by:
\begin{eqnarray}
S(k) = \sum_{j=1}^{l} w_j(k) + c_l(k)
\end{eqnarray}
where $k$ is the pixel index, $w_j$ are the wavelet coefficients of $S$, $j$ the
resolution
level, and $c_l$ the smoothed version of $S$. Due to the properties of
the wavelet transform, the set $w_j(x)$ for all $x$ has a zero mean. From
noise modeling, we can derive the probability distribution in the
wavelet space of a wavelet coefficient, assuming it is due to the noise.
The entropy becomes
\begin{eqnarray}
H(X) = - \sum_{j=1}^{l}  \sum_{k=1}^{N} \ln ( p(w_j(k)))
\end{eqnarray}
For Gaussian noise, we get
\begin{eqnarray}
H(X) =  \sum_{j=1}^{l}  \sum_{k=1}^{N} \frac{w_j(k)^2}{2 \sigma_j^2}
\end{eqnarray}
where $\sigma_j$ is the noise at scale $j$. We see that
the information is proportional
to the energy of the wavelet coefficients.
The higher a wavelet coefficient, then the lower will be the  probability, and the
higher will
be the information furnished by this wavelet coefficient. We can see
easily that this entropy fulfills all the requirements of
section~\ref{sect_entr}.
If we consider two signals $S_1$, $S_2$, derived from a third one $S_0$ by
adding noise:
\begin{eqnarray}
S_1 & = & S_0 + N_1(\sigma_1) \\ \nonumber
S_2 & = & S_0 + N_2(\sigma_2)
\end{eqnarray}
then we have:
\begin{eqnarray}
\mbox{if } \sigma_1 < \sigma_2 \mbox{ then } H(S_1) > H(S_2)
\end{eqnarray}
and a flat image has zero entropy.

Our entropy definition is completely dependent on the noise modeling.
If we consider a signal $S$, and we assume that the noise is Gaussian, with
a  standard deviation equal to $\sigma$, we won't measure the same
information compared to  the case when we consider that the noise has
another standard deviation
value, or if the noise follows another distribution.

\begin{figure}[htb]
\centerline{
\hbox{
\psfig{figure=fig_multi_memscale.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=14cm,height=7cm,clip=}
}}
\caption{Multiscale entropy of the Lena image (continuous curve),
and multiscale
entropy of the scrambled image (dashed curve).}
\label{fig_multi_memscale}
\end{figure}
Figure~\ref{fig_multi_memscale} shows the information measure at each
scale for both the Lena image and its scrambled version. The global
information is the addition of the information at each scale. We see
that for the scrambled image (dashed curve), the
information-versus-scale
curve is flat, while for the unscrambled Lena image,
it increases with the scale.

\section{Signal information and noise information}
\subsection{Definition}
In the previous section, we have seen how it was possible to measure
the information related to a wavelet coefficient. Since the data
is composed of an original signal and noise, our information measure
is corrupted by noise. Trying to decompose our information measure
into two components, one ($H_S$) corresponding to the non-corrupted part, and
another  ($H_N$) to the corrupted part, we have
\begin{eqnarray}
H(X) = H_S(X) + H_N(X)
\end{eqnarray}
We will define in the following $H_S$ as the signal information, and $H_N$
as the noise information. It must be clear that noise does not
contain any information, and what we call noise information is a quantity
which is measured as information by the multiscale entropy, and which is
probably not informative to us.

As described in the previous section, the information $h$ relative to
a wavelet coefficient $w_j$ is $- \ln(p(w_j))$. If the wavelet coefficient
is small, its value can be due to the noise,
and  $h$ should be assigned to $H_N$.
If the wavelet coefficient is high, compared to the noise standard
deviation, $h$ cannot be due to the noise, and $h$ should be assigned to $H_S$.
$h$ can be distributed as $H_N$ or $H_S$ based on  the probability $p_n(w_j)$
that the wavelet coefficient is due to noise, or the probability
$p_s(w_j)$ that it is due to
signal.  We have $p_s(w_j) = 1 - p_n(w_j)$. We consider
that  $h_n(w_j) = - p_n(w_j) \ln(p(w_j))$ is
the noise information, and
$h_s(w_j) = - p_s(w_j) \ln(p(w_j))$ is the signal information.
Hence  signal information and  noise information are defined by
\begin{eqnarray}
H_s(X) & = & \sum_{j=1}^{l}  \sum_{k=1}^{N} h_s(w_j(k)) = - \sum_{j=1}^{l}
\sum_{k=1}^{N} p_s(w_j(k)) \ln ( p(w_j(k))) \\ \nonumber
H_n(X) & = & \sum_{j=1}^{l}  \sum_{k=1}^{N} h_n(w_j(k)) = - \sum_{j=1}^{l}
\sum_{k=1}^{N} p_n(w_j(k)) \ln ( p(w_j(k)))
\end{eqnarray}
For the Gaussian noise case, we estimate $p_n(w_j)$ that a wavelet
coefficient is due to the noise by
\begin{eqnarray}
p_n(w_j) = \mathrm{Prob}(W > \mid w_j \mid)  & =  & \frac{2}{\sqrt{2 \pi}
\sigma_j} \int_{\mid w_j \mid}^{+\infty} \exp(-W^2/2\sigma^2_j) dW\\ \nonumber
 & = & \mbox{erfc}(\frac{\mid w_j \mid }{\sqrt{2}\sigma_j})
\end{eqnarray}
and
\begin{eqnarray}
H_s(X) &= & \sum_{j=1}^{l}  \sum_{k=1}^{N}  \frac{w_j^2}{2\sigma_j^2}
\mbox{erf}(\frac{\mid w_j \mid }{\sqrt{2}\sigma_j}) \\ \nonumber
H_n(X) &= & \sum_{j=1}^{l}  \sum_{k=1}^{N}  \frac{w_j^2}{2\sigma_j^2}
\mbox{erfc}(\frac{\mid w_j \mid }{\sqrt{2}\sigma_j})
\label{eq_entrop_result_1}
\end{eqnarray}

Note that $H_s(X) + H_n(X)$ is always equal to $H(X)$.
For Gaussian noise, the functional to minimize becomes
\begin{eqnarray}
J(X) = \sum_{pixels} \frac{{(Y-X)}^{2}}{2 {\sigma}^{2}} + {\alpha} (H_s(X)+H_n(X))
\end{eqnarray}
If we want to preserve features with high signal-to-noise ratio from the
regularization, we just omit $H_s(X)$ and we get
\begin{eqnarray}
J(X) = \sum_{pixels} \frac{{(Y-X)}^{2}}{2 {\sigma}^{2}} + {\alpha} H_n(X)
\end{eqnarray}
We seek a solution which minimizes the amount of information which could
be due to the noise.

By this measure, information relative to high wavelet coefficients is
completely assigned to the signal. This allows us also to exclude
wavelet coefficients with high signal-to-noise ratio (SNR)
from the regularization.
It leads to perfect fit of the solution with the data at scales and
 positions with high SNR. If we want to consider the information due
to noise, even for significant wavelet coefficients, the noise information
relative to a wavelet coefficient is
\begin{eqnarray}
h_n(w_j) =  \int_{0}^{\mid w_j \mid } p_n(u|w_j) (\frac{\partial H(x)}{\partial
x})_{x=u} du
\end{eqnarray}
which gives for Gaussian noise
\begin{eqnarray}
h_n(w_j) =  \frac{1}{\sigma_j^2} \int_{0}^{\mid w_j \mid} u \mbox{
erfc}(\frac{\mid w_j \mid -u}{\sqrt{2} \sigma_j}) du
\label{eqn_hn2}
\end{eqnarray}
and the noise and signal information in a signal are
\begin{eqnarray}
H_s(X) & = & \sum_{j=1}^{l}  \sum_{k=1}^{N}  \frac{1}{\sigma_j^2} \int_{0}^{\mid
w_j \mid} u \mbox{ erf}(\frac{\mid w_j \mid -u}{\sqrt{2} \sigma_j}) du \\
\nonumber
H_n(X) & = & \sum_{j=1}^{l}  \sum_{k=1}^{N}   \frac{1}{\sigma_j^2} \int_{0}^{\mid
w_j \mid} u \mbox{ erfc}(\frac{\mid w_j \mid -u}{\sqrt{2} \sigma_j}) du
\label{eq_entrop_result_2}
\end{eqnarray}

Equations 27 and 32 lead to two
different ways to regularize a signal. The first requires that we use
all the information which is furnished in high wavelet coefficients, and
leads to an exact preservation of the flux in a structure. If the signal
presents high discontinuities, artifacts can appear in the solution
due to the fact that the wavelet coefficients located at the discontinuities
are not noisy, but have been modified like noise. The second equation
doesn't have this drawback, but a part of the flux of a structure
(compatible with noise amplitude) can be lost in the restoration process.
It is however not as effective as in the standard maximum entropy methods.

\subsection{A new approach for signal restoration}
The new  definition of the information contained
in noisy data can easily lead to a new approach for restoration of images.

The problem of filtering or restoring data $D$ can be expressed by the
following:
We search for a solution $\tilde D$ such that the difference between
$D$ and $\tilde D$ minimizes the information due to the signal, and
such that  $\tilde D$ minimizes the information due to the noise.
\begin{eqnarray}
J(\tilde D) = H_s(D-\tilde D) + H_n(\tilde D)
\label{eqn_func1}
\end{eqnarray}
Furthermore, the smoothness of the solution can be controlled by adding
a parameter:
\begin{eqnarray}
J(\tilde D) = H_s(D-\tilde D) + \alpha H_n(\tilde D)
\label{eqn_func2}
\end{eqnarray}
Here, $\alpha$ is considered as a constant value, but we can easely
imagine to have a regularization parameter per scale, or even per wavelet
coefficient, depending on the Signal to Noise Ratio of the data. This
direction will be investigated in the future.

Three points must be noted:
\begin{itemize}
\item The positivity of the solution is not enforced.
\item There is no constraint on the flux.
\item The last scale of the wavelet transform is not taken into
account in this entropy.
\end{itemize}
The first two points can be easily resolved by introducing strict a priori
 constraints on the solution \cite{thiebault95}:
\begin{eqnarray}
J(Z) = H_s(D-{\cal C}(Z)) + \alpha H_s({\cal C}(Z))
\end{eqnarray}
And the real solution is evidently $\tilde D = {\cal C}(Z)$.
Positivity and total flux conservation impose
\begin{eqnarray}
{\cal C}(Z)(x) = \frac{\sum_x I(x)}{\sum_x Z(x)^2} Z(x)^2
\end{eqnarray}
Any other constraint can evidently be introduced into the function ${\cal C}$.

There is no constraint to be introduced to cater for the third point above,
but this should not be a problem
if the number of scales we use for the entropy is high enough. Indeed, in
this case, the last scale becomes flat, and flux normalization should
correctly fix this level.

\subsection{Example}
\begin{figure}[htb]
\centerline{
\vbox{
\psfig{figure=fig_lit6_mem1.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=16cm,height=9cm}
}}
\caption{Spectrum and filtered spectrum superimposed.}
\label{fig_lit6_mem1}
\end{figure}

\begin{figure}[htb]
\centerline{
\vbox{
\psfig{figure=fig_lit6_mem2.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=16cm,height=10cm}
}}
\caption{Difference (upper part)
between the real spectrum and its smoothed version.
Part (pixels 400 to 500) of the spectrum (continuous curve),
with the filtered spectrum
overplotted (dashed).}
\label{fig_lit6_mem2}
\end{figure}
Figure~\ref{fig_lit6_mem1} presents a spectrum and the result (overplotted)
after filtering using the multiscale entropy. The difference between the
spectrum and its smoothed version is plotted in
Figure~\ref{fig_lit6_mem2} (upper part).
As we can see, the residual contains only noise.
In order to better see the quality of the smoothing, we have plotted
only a part of the spectrum (see lower part of Figure~\ref{fig_lit6_mem2}),
and the filtered spectrum superimposed. The absorption lines are not
modified using our filtering technique.

\begin{figure}[h]
\centerline{
\hbox{
\psfig{figure=fig_lenna_g10.ps,bbllx=1.8cm,bblly=12.8cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
\psfig{figure=fig_filmem_g2_lenna.ps,bbllx=1.8cm,bblly=12.8cm,bburx=14.5cm,bbury=25.5cm,width=8cm,height=8cm,clip=}
}}
\caption{Left, Lena + Gaussian noise, right, filtered image .}
\label{fig_filter_gauss_noise}
\end{figure}
Figure~\ref{fig_filter_gauss_noise} (left) shows the Lena image
(see Figure~\ref{fig_lenna}) to which Gaussian
noise of standard deviation 10 has been added.  Figure~\ref{fig_filter_gauss_noise} (right) shows
the result using equation 32 with a regularization parameter value of 2.

\section{Conclusion}

We have seen that information must be measured from the transformed
data, and not from the data itself. This approach has been used in fact
for several years in the domain of image compression. Indeed, modern
image compression methods consist firstly of  applying a transformation
(cosine transform for JPEG, wavelet transform, etc.) to the image, and
then coding the coefficients obtained. A good transform for
image compression is obviously an orthogonal transform because there
is no redundancy, and the number of pixels is the same as in the original
image. The exact number of bits necessary to code the coefficients is
given by the Shannon entropy. For signal restoration, the problem is
not to reduce the number of bits in the representation of the data, and we
prefer to use a non-orthogonal wavelet transform, which avoids
artifacts in reconstruction due to undersampling.

We could
have used the Shannon entropy to measure the information at a given scale,
and derive the bins of the histogram from the standard deviation of the noise,
but for several reasons we thought it better to directly introduce
noise probability into our information measure.
Firstly, we have seen that this leads, for Gaussian noise, to
a very physical relation between the information and the wavelet coefficients:
information is proportional to the energy of the wavelet coefficients
normalized by the standard deviation of the noise.
Secondly, it works even in the case
of images with few photons/events (the histograms in this case present a bias).
We have seen that the equations are easy to manipulate.
Finally, experiments have
confirmed that this approach gives good results.
We have seen also that our new information
measure leads naturally to a new method for signal restoration.
We are now experimenting with this method, and working on generalizations to
other classes of noise.

\newpage
\include{annexA}
\include{annexB}

\begin{thebibliography}{99}
\bibitem{ables74} J.G. Ables, {\it Astronomy and Astrophysics Supplement Series},
15, 383--393, 1974.

\bibitem{bijaoui84} A. Bijaoui, {\it Introduction au
Traitement Num\'erique des Images}, Masson, Paris, 1984.

 \bibitem{bijaoui94} A. Bijaoui, J.L. Starck and
 F. Murtagh, ``Restauration des
 images
 multi-\'echelles par l'algorithme \`a trous'', {\it Traitement du Signal},
 11, 229--243, 1994.

\bibitem{bontekoe94} Tj.R. Bontekoe, E. Koper and D.J.M. Kester,
``Pyramid maximum entropy images of IRAS survey data'', {\it Astronomy and
 Astrophysics}, 294, 1037--1053, 1994.

\bibitem{burg67} J.P. Burg, {\it
Annual Meeting International Society Exploratory Geophysics}, 1967.
Reprinted in {\it Modern Spectral Analysis}, 1978, D.G. Childers, ed.,
IEEE Press, New York, 34--41, 1978.

 \bibitem{chui92} C.H. Chui, {\it Wavelet Analysis and Its
 Applications}, Academic Press, New York, 1992.

 \bibitem{daubechies88} I. Daubechies,
 ``Orthogonal bases of compactly supported
 wavelets'', {\it Communications on Pure and Applied Mathematics},
 41, 909--996, 1988.

\bibitem {frieden75} B.R. Frieden, ``Image enhancement and restoration'',
 {\it Topics in Applied Physics}, 6,  Springer-Verlag Berlin, 177--249, 1975.

\bibitem{frieden} B.R Frieden, {\it Probability, Statistical Optics, and
Data Testing: a problem solving approach}, 2nd edition, Springer-Verlag Berlin,
1991.

\bibitem{jaynes57} E.T. Jaynes, {\it Phys. Rev.}, 106, 620--630, 1957.

 \bibitem{holschneider89} M. Holschneider, R. Kronland-Martinet, J. Morlet
 and Ph. Tchamitchian, ``A real-time algorithm for signal analysis with the
 help of the wavelet transform'', in
 {\it Wavelets: Time-Frequency Methods and Phase Space},
 Springer-Verlag,  Berlin, 286--297, 1989.

\bibitem{gull91} S.F. Gull, and J. Skilling, MEMSYS5 User's Manual, 1991.

\bibitem{narrayan86} R. Narayan, and R. Nityananda, ``Maximum
Entropy Image Restoration in Astronomy'', Ann. Rev. Astron. Astrophys.,
24, pp 127--170, 1986.

\bibitem{pantin96} E. Pantin and J.L. Starck, ``Deconvolution of
astronomical images using the multiresolution maximum entropy method'',
 {\it Astronomy and Astrophysics Supplement Series}, 118, 575--585, 1996.

 \bibitem {ruskai92} M.M. Ruskai, G. Beylkin, R. Coifman, I. Daubechies,
 S. Mallat, Y. Meyer and  L. Raphael, {\it Wavelets and Their Applications},
 Jones and Barlett, 1992.

\bibitem{shannon48} C.E. Shannon,
``A Mathematical Theory for Communication'', {\it Bell System Tech J.} 27
379--423, 1948.

\bibitem{shensa92} M.J. Shensa, ``Discrete wavelet transforms:
 wedding  the \`a trous and Mallat algorithms", {\it IEEE Transactions on
 Signal
 Processing}, 40, 2464--2482, 1992.

\bibitem{skilling84_1} J. Skilling and S.F. Gull, {\it Proceedings of
the American Mathematical Society}, SIAM, 14, 167, 1984.

\bibitem{skilling89} J. Skilling, ``Classic maximum entropy'',
in: Skilling. J, ed., {\it Maximum
Entropy and
Bayesian Methods}, Kluwer, Dordrecht, 45--52, 1989.

\bibitem{starck95}  J.L. Starck, F. Murtagh and  A. Bijaoui,
``Multiresolution support
 applied to image filtering and deconvolution'', {\it Graphical
Models and Image Processing}, 57, 420--431, 1995.

\bibitem{starck97} J.L. Starck, F. Murtagh  and A. Bijaoui,
{\it Image Processing and Data Analysis: The
Multiscale Approach},  Cambridge University Press, forthcoming, 1997.

\bibitem{weir92} N. Weir, ``A multi-channel method of maximum entropy image
restoration'', in: D.M. Worral, C. Biemesderfer and J. Barnes,
eds., {\it Astronomical Data Analysis Software and System 1}, Astronomical
Society of the Pacific, San Francisco, 186--190, 1992.

\bibitem{thiebault95} E. Thiebault and J.-M. Conan, ``Strict a priori
constraints for maximum-likelihood blind deconvolution'', {\it JOSA},
12, 485--492, 1995.

\end{thebibliography}

\end{document}
\subsection{Spectrum filtering}

\subsection{Image filtering}
\begin{figure}[h]
\centerline{
\hbox{
\psfig{figure=fig_simu4_bw.ps,bbllx=1.8cm,bblly=12.8cm,bburx=14.5cm,bbury=25.5cm,width=16cm,height=16cm,clip=}
}}
\caption{(a) Simulated image, (b) simulated image and
Gaussian noise, (c) filtered image, and (d)
residual image.}
\label{fig_filter_gauss_noise}
\end{figure}

A simulated image containing stars and galaxies is shown in Fig.\
\ref{fig_filter_gauss_noise} (top left). The simulated noisy
image, the filtered image and the residual image are respectively shown in
Fig.\ \ref{fig_filter_gauss_noise} top right, bottom left, and
bottom right. We can see that there is no structure in the residual
image. The filtering was carried out using the multiresolution support.


In this section we individually present the interpretation and rationale for our solutions.

\subsection{Question 1}
Question 1 is intended to: \textit{``Find the top 10 most frequent routes during the last 30 minutes''}.

This particular query is the same that was asked in the first delivery of this course and the execution was inspired in that same implementation with spark streaming.

At first we started by translating the coordinates to a 300x300 grid as requested in the question. After that we filter all the invalid coordinates of the new grid since all valid values should be between 0 and 300.

In order to get the top 10 most frequent areas we run a query which selects the most common coordinate combinations, of pickup and drop off, and their \textit{count()}, grouped by all the coordinates of a ride, orders them in descending order, of the \textit{count()}, and limit the top to 10 results.

\subsection{Question 2}

Question 2 is intended to: \textit{``Identify areas that are currently most profitable for taxi drivers"}.\par
For this, we start by dividing the map into a 600x600 grid. To identify the most profitable areas, we divided the profit made in that area by the number of empty taxis.
For each area we calculate the average profit in that area, where we consider the sum of fares plus the sum tips (using the aggregation function \textit{sum}) dividing by the number of trips (using the aggregation function \textit{count}), in each area in the last 15 minutes.\par
To calculate the number of empty taxis, we selected, for each taxi, its highest dropoff$_-$datetime, in the last 30 minutes, and for each area we count the taxis, using the aggregation function \textit{count}.\par
For the presentation of results, we sorted by average profit, descending, selecting only the first five results.

\subsection{Question 3}
Question 3 is intended to: \textit{``send an alert whenever the average idle time of taxis is greater than 10 minutes''}.

In our implementation we start by only selecting the medallion, to identify the taxi, and the pickup and drop off times for each event. In this selection we perform a parsing of the string value of the times to a timestamp using ``$time:timestampInMilliseconds(time_-string, format)$'', for example.

Next we use the ``arrow'' (-$>$) logical pattern in order to select the sequence of drop off and pickup times from taxis with the same medallion and use it to calculate the idle time between rides of the same taxi.

After that we perform a query over a time batch of 10 seconds so that we can see the results quickly and we select the computed average idle time, calculated with the function \textit{$avg()$} and we add a \textit{$having \ avg_-idle_-time > (10.0*60.0*1000.0)$} so that we only alert when the average idle time exceeds 10 minutes.

At last at the sink we provide an alert message which says that a 10 minute threshold was exceeded.

\subsection{Question 4}

Question 4 is intended to: \textit{``Detect congested areas"}.\par
For this query, as in query 2 we split the map into a 600x600 grid. To identify the most congested areas, we used a logical pattern, selecting the areas that had a sequence of four trips, all increasing in duration, accessing the values in \textit{trip$_-$time$_-$in$_-$secs}.\par
More details about this query in the Detailed Query Presentation section.

\subsection{Question 5}

Question 5 is intended to: \textit{``Select the most pleasant taxi drivers"}.\par
For this query, the solution was quite simple. To select the most pleasant taxi driver, we grouped by taxi driver, adding (using the aggregation function \textit{sum}) the tips received by the taxi driver on all trips that occurred in the time window. Then, sorting by the tip value in a descending way, just select the taxi driver that is at the top, using "\textit{limit 1}".