%
% $Id: report.tex 571 2008-04-20 17:31:04Z rick $
%

\documentclass[12pt,a4paper]{article}

\usepackage{listings}

\frenchspacing
\usepackage[english,dutch]{babel}
\selectlanguage{dutch}
\usepackage{graphicx}
\usepackage{url}
\usepackage{multicol}
\usepackage{fancybox}
\usepackage{amssymb,amsmath}
\usepackage{float}
\usepackage{color}
\usepackage{subfig}
\usepackage{marvosym}
\floatstyle{ruled}
\newfloat{result}{thp}{lop}
\floatname{result}{Result}

\input{highlight.sty}

\title{Laser Pulse Shaping problem\\
\large{Practical Assignments Natural Computing, 2009}}
\author{Rick van der Zwet\\
  \texttt{<hvdzwet@liacs.nl>}}
\date{\today}


\begin{document}
\newcommand{\wekacmd}[1]{\begin{quote}\small{\texttt{#1}}\end{quote}}
\newcommand{\unixcmd}[1]{\begin{quote}\small{\texttt{#1}}\end{quote}}


\maketitle

\section{Introduction}
The report is focused on the so-called \emph{laser pulse shaping problem}.
Today's lasers are also used within the range of atoms or molecule research.
Using small pulses it is able to align and alter the movement of the atoms. 

The problem lies in the fact the atoms cannot be controlled by any type of
laser pulse. There are many parameters which could all be set to 'shape' the
laser pulse the way it can move the atoms.

To turn and tweak all the 'knobs' at the same time there will be \emph{Particle
Swarm Optimizer (PSO)} used to explore the search space. The \emph{PSO} is
basically a whole bunch of individual agents which all try to find an optimum
into the search space. During this search they get input about other potential
bests from the whole swarm (broadcast style) and the neighborhood
(observation) and using this values they determine their new location.

\section{Problem description}
A laser pulse going through a crystal produces light at the octave of its
frequency spectrum. The total energy of the radiated light is proportional to
the integrated squared intensity of the primary pulse. Explicitly, the
time-dependent profile of the laser field in our simulations is given by:
\begin{equation}
\label{eq:simulation}
E(t) = \int_{-\infty}^\infty A(\omega)exp(i\phi(\omega))exp(i{\omega}t) d\omega,
\end{equation}

where $A(\omega)$ is a Gaussian window function describing the contribution of
different frequencies to the pulse and $\phi(\omega)$, the phase function,
equips these frequencies with different complex phases.

To determine the best solution a fitness function is needed, which could be
found in the shape of equation~\ref{eq:fitness}
\begin{equation}
\label{eq:fitness}
SHG = \int_0^T E^4(t)dt \longrightarrow maximization
\end{equation}

Note that $0 < SHG < 1$
\section{Statistics}

\section{Approach}
The Wikipedia page 'Particle swarm
optimization'~\footnote{http://en.wikipedia.org/wiki/Particle\_swarm\_optimization}
contained a reference implementation used to implement the algorithm. The nice
part about the algorithm is its flexibility in tuning. As within the \emph{PSO}
there are many 'knobs' which could be tweaked as well, like likeliness of
heading for the global optimum, neighborhood optimum and local optimum.

\section{Implementation}
The code is written in
\emph{Octave}\footnote{http://www.gnu.org/software/octave/} which is the
open-source 'variant' of \emph{MATLAB}\copyright 
\footnote{http://www.mathworks.com/products/matlab/}. There are small minor
differences between them, but all code is made compatible to to run on both
systems. The code is to be found in Appendix~\ref{app:code}.

As work is done remotely, the following commands are used:
\unixcmd{matlab-bin -nojvm -nodesktop -nosplash -nodisplay < \%\%PROGRAM\%\%}
\unixcmd{octave -q \%\%PROGRAM\%\%}

The flock is represented into a 3d block. A slice of that block contains a
local swarm, a column in slice is a individual particle.

\section{Results}
The program is run against a parameter set of 80. The algorithm is allowed to run
for 10 minutes with a maximum of 1000 iterations. If there are no improvements
after 5 iterations then it will bail out as well. 

The algorithm is kind of 'social' e.g. it will favor the neighborhood and the
global optimum more than it's own local optimum. Also its active, meaning it
changes direction fast the moment the optimum is found somewhere else.

Size of the local swarms is 50, each with 10 agents.

After running 5 times, the best fitness found was $0.0000045481$. Improvement is
almost only shown in the first 100 iterations see figure~\ref{fig:pso-fitness},
afterwards it quickly stalls.
Trying with a smaller number more and less show the same result as seen in
figure~\ref{fig:pso-small}

\begin{figure}[htp]
  \begin{center}
    \subfloat[80]{\label{fig:pso-fitness}\includegraphics[scale=0.4]{pso-fitness.eps}}
    \subfloat[10]{\label{fig:pso-small}\includegraphics[scale=0.4]{pso-fitness-10.eps}}
  \end{center}
  \caption{Fitness throughout the iterations}
  \label{fig:fitness}
\end{figure}

Changing various flags like walkspeed $wander$ or changing the socialness of
the agents does not prove to change much in the algoritm result.

\section{Conclusions}
Giving the lack of external results of other algorithms in large scale setups
(80 parameters) its hard to say whether this is a good or worse preforming
algorithm.

For furher research within the algorithm there are many knobs to tweak as well.
One could think of implementing a algorithm around this setup as well.

\section{Appendix 1}
\label{app:code}
\include{pso.m}
\include{SHGa.m}
\include{SHG.m}
\end{document}
