Index: liacs/nc/laser-pulse-shaping/latex.mk
===================================================================
--- liacs/nc/laser-pulse-shaping/latex.mk	(revision 48)
+++ liacs/nc/laser-pulse-shaping/latex.mk	(revision 49)
@@ -58,4 +58,5 @@
 
 %.m.tex: %.m
-	highlight --include-style --linenumbers --no-doc \
-	  --latex --input $< --output $@
+	highlight --linenumbers --no-doc --latex --style-outfile highlight.sty \
+	  --style vim --wrap --line-length 80 --line-number-length 3 \
+	  --input $< --output $@
Index: liacs/nc/laser-pulse-shaping/pso.m
===================================================================
--- liacs/nc/laser-pulse-shaping/pso.m	(revision 48)
+++ liacs/nc/laser-pulse-shaping/pso.m	(revision 49)
@@ -5,5 +5,5 @@
 
 % Dimention settings
-parameters = 80;
+parameters = 10;
 
 % If global optimum does not change this many steps bail out 
@@ -13,6 +13,6 @@
 
 % Flock properties 
-local_swarm_size = 10;
-local_swarms = 50;
+local_swarm_size = 50;
+local_swarms = 10;
 
 %% Particle properties
@@ -113,4 +113,6 @@
 end
 
+% Dispay hack
+g_fitness
 g_best
 
@@ -121,3 +123,3 @@
 grid on;
 legend(sprintf('Parameters %i',parameters));
-print(sprintf('pso-fitness-%f.eps', max(fitness_history)),'-depsc2');
+print(sprintf('pso-fitness-%.10f.eps', max(fitness_history)),'-depsc2');
Index: liacs/nc/laser-pulse-shaping/report.tex
===================================================================
--- liacs/nc/laser-pulse-shaping/report.tex	(revision 48)
+++ liacs/nc/laser-pulse-shaping/report.tex	(revision 49)
@@ -18,7 +18,10 @@
 \usepackage{color}
 \usepackage{subfig}
+\usepackage{marvosym}
 \floatstyle{ruled}
 \newfloat{result}{thp}{lop}
 \floatname{result}{Result}
+
+\input{highlight.sty}
 
 \title{Laser Pulse Shaping problem\\
@@ -38,5 +41,5 @@
 \section{Introduction}
 The report is focused on the so-called \emph{laser pulse shaping problem}.
-Todays lasers are also used within the range of atoms or mulecule research.
+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. 
 
@@ -45,62 +48,42 @@
 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{eg:fitness}
-SHG = \int_0^T E^4(t)dt \rightlongarrow maximization
+\label{eq:fitness}
+SHG = \int_0^T E^4(t)dt \longrightarrow maximization
 \end{equation}
 
-
-Due to the huge 'exploding' posibilities it is not possible to walk trough the
-whole list of posibities, so we need alternative approches to tackle this
-problem. First we will try the \emph{Monte Carlo Search algoritm [MCS]} and next try
-\emph{Simulated Annealing [SA]}.
-
-\emph{MCS} is all about random sequence generation and trying to find a good
-solution, do a small ajustment on the solution and compare the new solution
-again.
-
-\emph{SA} takes a more and less the same aproch, but it also accept small
-'losses' from time-to-time. But as time passes it get less likely to accept
-'bad solutions'.
-
+Note that $0 < SHG < 1$
 \section{Statistics}
-Of course many people have run numerous computer hours on finding the best
-possible fitness as shown in table~\ref{tab:best}. The algoritms used to find
-those numbers are not found.
-
-\begin{table}
-  \caption{Best known values of low-autocorrelation problem}
-  \begin{center}
-    \begin{tabular}{| l | c | r | }
-      \hline
-      $n$ & Best known $f$ \\
-      \hline \hline          
-      20  & 7.6923 \\ \hline 
-      50  & 8.1699 \\ \hline
-      100 & 8.6505 \\ \hline
-      200 & 7.4738 \\ \hline
-      222 & 7.0426 \\ \hline
-    \end{tabular}
-  \end{center}
-  \label{tab:best}
-\end{table}
 
 \section{Approach}
-The \emph{MCS} is implemented streight-forward from the wikipedia
-page\footnote{http://en.wikipedia.org/wiki/Monte\_Carlo\_method}. The mutation
-choosing is flipping one bit in the array.
-
-For the \emph{SA} implemented also comes streight from 'the book'
-\footnote{http://en.wikipedia.org/wiki/Simulated\_annealing}, the process
-choosing for the cooling-down sequence is taken from the dutch wikipedia page
-'Simulated annealing', which is nice indicator when to choose something when
-the solution is worse (logically, beter solutions will always be accepted).
-\footnote{http://nl.wikipedia.org/wiki/Simulated\_annealing}:
-\begin{math}
-p = e^{\frac{f(i)-f(j)}{c}}
-\end{math}
+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}
@@ -116,31 +99,28 @@
 \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}
-All experiments are run 5 times the best solution is choosen and will be
-resented at table~\ref{tab:result}. Iteration size is set to 1000. For $n=20$
-the best fitness history is shown at figure~\ref{fig:fitness}.
+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. 
 
-\begin{table}
-  \caption{Best known values of low-autocorrelation problem}
-  \begin{center}
-    \begin{tabular}{| r | r | r | r | }
-      \hline
-      $n$ & \multicolumn{3}{|c|}{Best fitness} \\
-          & known & MCS & SA \\
-      \hline \hline          
-      20  & 7.6923 & 4.3478 & 4.7619 \\ \hline 
-      50  & 8.1699 & 2.4752 & 2.6882 \\ \hline
-      100 & 8.6505 & 1.8342 & 1.7470 \\ \hline
-      200 & 7.4738 & 1.8678 & 1.5733 \\ \hline
-      222 & 7.0426 & 1.5657 & 1.4493 \\ \hline
-    \end{tabular}
-    \label{tab:result}
-  \end{center}
-\end{table}
+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[SA]{\label{fig:edge-a}\includegraphics[scale=0.4]{sa-fitness.eps}}
-    \subfloat[MCS]{\label{fig:edge-b}\includegraphics[scale=0.4]{mcs-fitness.eps}}
+    \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}
@@ -148,20 +128,19 @@
 \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}
-Looking at the graphs the fitness was still increasing so a larger iteration
-size would make the fitness a better result. Secondly the \emph{SA} is
-preforming much worse on large number than the \emph{MCS} one. It seems to the
-temperature function is not working as expected. 
+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.
 
-Both algoritms are preforming much worse then the best found solutions.
+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{autocorrelation.m}
-\include{initseq.m}
-\include{mcs-call.m}
-\include{mcs.m}
-\include{mutation.m}
-\include{randint.m}
-\include{sa-call.m}
-\include{sa.m}
+\include{pso.m}
+\include{SHGa.m}
+\include{SHG.m}
 \end{document}
