\input{../../assignment-header}

%========================================================================
\title{Assignment 6:  Scalar Solvers}
\date{Assigned:  Feb 20  ---  Due:  Feb 28 at 11:55pm}
\author{Tufts ME 149:  Optimal Control For Robotics}
%========================================================================
\begin{document}
\maketitle
%=================================================

\section*{Introduction}

In this assignment you will implement two iterative solvers in Matlab:
Ridder's method for scalar root finding and the Golden Section Search for
scalar optimization. Both methods start with a bracketed search interval.

\section*{Ridder's Method}

Ridder's method is an algorithm that searches for the root of a smooth function,
starting with an interval that brackets the root.
The method works by fitting an exponential through three data points on each
iteration and then computing the root of that exponential.
Ridder's method is described in section 9.2 of Numerical Recipes in C.

\section*{Golden Section Search}

The golden section search is method for robust optimization of a
scalar function on a bounded (bracketed) interval.
The algorithm keeps track of three points that are known to bracket the minimum.
On each iteration it samples a new point such that the relative size of the
two sub-intervals remains constant. It turns out that the relative size is
given by the golden ratio, hence the name.
See section 10.1 of Numerical Recipes in C for implementation details.

\section*{Deliverables}

Implement Ridder's method and the golden section search
using the template files that are included with the assignment,
and submit both of these files to Trunk.
You code will be run through an automated unit test,
so make sure that to test it yourself on several functions to be sure that it works.
Carefully read the inputs and output of each function.

\section*{Write-Up}

In addition to the Matlab file for you root solver and your optimization,
please also upload a short write-up for this assignment: \\
\texttt{hw\_06\_studentName\_writeup.txt}
\vspace{-0.0em} \begin{itemize}  \setlength\itemsep{0em} \setlength\itemindent{18pt}
  \item Header: full name, date, assignment name and number
  \item List any other students that you worked with.
  \item List any other references that you used.
  \item How long did this assignment take you?
  \item Briefly describe how you tested each function to verify that it was implemented correctly.
\end{itemize}

\section*{Root Solving Challenge}

You may choose to implement Brent's method for root finding instead of Ridder's method.
Use the template that is provided,
but change the name to \texttt{brentRootSolver} and update the documentation.
You will receive an extra 5 points on your assignment, although the max score will still be 50.
This method is described in section 9.3 of Numerical Recipes in C and it is what
Matlab uses to implement the \texttt{fzero} function.

\section*{Optimization Challenge}

You may choose to implement Brent's method for optimization instead of the golden section search.
Use the template that is provided,
but change the name to \texttt{brentOptimization} and update the documentation.
You will receive an extra 10 points on your assignment, although the max score will still be 50.
This method is described in section 10.2 of Numerical Recipes in C and it is what
Matlab uses to implement the \texttt{fminbnd} function.

\pagebreak
\lstinputlisting{riddersMethod.m}

\pagebreak
\lstinputlisting{goldenSection.m}

%=================================================
\end{document}


\subsection{Function convergence}\label{subsec:function_convergence}

\begin{definition}\label{def:local_convergence}
  Fix two topological spaces \( X \) and \( Y \). Let \( A \subseteq X \) be a nonempty set and let \( f: A \to Y \) be a function. We give two equivalent definitions for \( y_0 \in Y \) being a \term{limit point} of \( f \) at \( x_0 \in \cl(A) \). If \( y_0 \) is the unique limit point (e.g. in \hyperref[def:separation_axioms/T2]{Hausdorff spaces}), we write
  \begin{equation*}
    \lim_{x \to x_0} f(x) = y_0.
  \end{equation*}

  \begin{thmenum}
    \thmitem{def:local_convergence/neighborhoods}(Cauchy-style condition) For every neighborhood \( V \) of \( y_0 \) there exists a neighborhood \( U \) of \( x_0 \) such that \( f(U \cap A) \subseteq V \).

    \thmitem{def:local_convergence/nets}(Heine-style condition) For every \hyperref[def:topological_net]{net} \( \{ x_k \}_{k \in \mscrK} \subseteq A \), for which \( x_0 \) is a limit \hyperref[def:net_convergence/limit]{point}, the corresponding net \( \{ f(x_k) \}_{k \in \mscrK} \) has \( y_0 \) as a limit point.
  \end{thmenum}
\end{definition}
\begin{proof}
  \ImplicationSubProof{def:local_convergence/neighborhoods}{def:local_convergence/nets} Let \( \{ x_k \}_{k \in \mscrK} \subseteq U \) be a net  with limit point \( x_0 \). Consider the net \( \{ f(x_k) \}_{k \in \mscrK} \). Fix a neighborhood \( V \) of \( y_0 \). We need to show that \( \{ f(x_k) \}_{k \in \mscrK} \) is eventually in \( V \).

  By \fullref{def:local_convergence/neighborhoods}, there exists a neighborhood \( U \) of \( x_0 \) such that \( f(U) \subseteq V \). Since \( x_0 \) is a limit point of \( \{ x_k \}_{k \in \mscrK} \), there exists an index \( k_0 \) such that for all \( k \geq k_0 \), \( x_k \in U \) and therefore \( f(x_k) \in V \). Hence, \( \{ f(x_k) \}_{k \in \mscrK} \) is eventually in \( V \).

  We conclude that \( y_0 \) is a limit point of the net \( \{ f(x_k) \}_{k \in \mscrK} \) and that the Heine-style condition is satisfied.

  \ImplicationSubProof{def:local_convergence/nets}{def:local_convergence/neighborhoods} Suppose that \fullref{def:local_convergence/nets} holds while \fullref{def:local_convergence/neighborhoods} does not. Let \( V \) be a neighborhood of \( y_0 \). Then there exists no neighborhood \( U \) of \( x_0 \) such that \( f(U) \subseteq V \).

  For any neighborhood \( U \) of \( x_0 \) and let \( y_U \in f(U) \setminus V \) and \( x_U \in f^{-1} (U) \), so that \( f(x_U) = y_U \). Consider the families
  \begin{balign*}
    \{ x_U \}_{U \in T(x_0)},
     &  &
    \{ f(x_U) \}_{U \in T(x_0)},
  \end{balign*}
  ordered by \hyperref[ex:reverse_inclusion_net]{reverse inclusion} of the neighborhoods \( \mscrT(x_0) \) of \( x_0 \).

  Note that \( x_0 \) is a limit point of \( \{ x_U \}_{U \in T(x_0)} \). By \fullref{def:local_convergence/nets}, \( y_0 \) is a limit point of \( \{ f(x_U) \}_{U \in T(x_0)} \). But this contradicts our choice of the nets because \( f(x_U) \not\in V \) for any \( U \in T(x) \).

  The obtained contradiction demonstrates that \fullref{def:local_convergence/nets} implies \fullref{def:local_convergence/neighborhoods}.
\end{proof}

\begin{proposition}\label{thm:cauchy_function_convergence_via_subbases}
  Fix two topological spaces \( X \) and \( Y \) and two points \( x_0 \in X \) and \( y_0 \in Y \). Let \( \mscrP(x_0) \) and \( \mscrP(y_0) \) be local \hyperref[def:topological_local_subbase]{subbases} for the corresponding points. Then the function \( f: X \to Y \) \hyperref[def:local_convergence]{converges} to \( y_0 \) at \( x_0 \) if and only if every \( V_P \in P(y_0) \) there exists \( U_P \in B(x_0) \) such that \( f(U_P) \subseteq V_P \).

  Compare this result to \fullref{thm:net_convergence_via_subbases}.
\end{proposition}
\begin{proof}
  \SufficiencySubProof Obvious consequence of \fullref{def:local_convergence/neighborhoods}.
  \NecessitySubProof Fix a neighborhood \( V \) of \( x \). We will show that \fullref{def:local_convergence/neighborhoods} holds.

  Let \( \{ V_k \}_{k=1}^n \subseteq P(y_0) \) be a family such that \( \bigcap_{k=1}^n V_k \subseteq V \) (such a family exists by definition of a local subbase). By the antecedent of the implication we are proving, for every \( k = 1, \ldots, n \) there exists an \( U_k \in P(x_0) \) such that \( f(U_k) \subseteq V_k \). Then \( U \coloneqq \bigcap_{k=1}^n U_k \) is a neighborhood of \( x_0 \) and, furthermore,
  \begin{equation*}
    f(U)
    =
    f\left(\bigcap_{k=1}^n U_k \right)
    \subseteq
    \bigcap_{k=1}^n f(U_k)
    \subseteq
    \bigcap_{k=1}^n V_k
    \subseteq
    V.
  \end{equation*}

  Therefore, \fullref{def:local_convergence/neighborhoods} holds.
\end{proof}


\vsssub
\subsubsection{~$S_{bot}$: \js\ bottom friction} \label{sec:BT1}
\vsssub

\opthead{BT1}{\js\ experiment}{H. L. Tolman}

\noindent
A simple parameterization of bottom friction is the empirical, linear \js\
parameterization \citep{art:JONSWAP}, as used in the \wam\ model
\citep{art:WAM88}. Using the notation of \cite{tol:JPO91b}, this source term
can be written as

%-------------------------%
% JONSWAP bottom friction %
%-------------------------%
% eq:JONSWAP_bot

\begin{equation}
\cS_{bot}(k,\theta) = 2 \Gamma \: \frac{n-0.5}{gd} \: N(k,\theta)
\: , \label{eq:JONSWAP_bot}
\end{equation}

\noindent
where $\Gamma$ is an empirical constant, which is estimated as $\Gamma =
-0.038\:\mbox m^2 \mbox s ^{-3}$ for swell \citep{art:JONSWAP}, and as $\Gamma
= -0.067\:\mbox m^2 \mbox s^{-3}$ for wind seas \citep{art:BK83}. $n$ is the
ratio of phase velocity to group velocity given by (\ref{eq:cg}). The default
value for $\Gamma = -0.067$ can be redefined by the user by changing the {\F SBT1} namelist parameter {\code GAMMA}.


\documentclass{article}
\usepackage[a4paper,margin= 2cm]{geometry}
\usepackage{graphicx}

\title{\LARGE{\bf{Task 1 Overview}}}
\author{\Large{\bf{Kirtan Patel - AE19B038}}}
\date{}

\begin{document}

\maketitle

\section{The Amplitude Magnification Frequency Response Graph}
This Graph shows the relation between the Amplitude Magnification Function and the Frequency of the Sytem. The Frequency $\omega$ is given as a ratio over the natural frequency of the system $\omega_{n}$.
\[x(t) = \delta_{static}~|G(i\omega)|~e^{i(\omega t - \phi)}\]
where
\[|G(i \omega)|^2 = \frac{1}{(1 - r^2)^2 + (2 \zeta r)^2}\]
\begin{figure}
\centering
\includegraphics[scale = 0.56]{Amplitude Frequency_Response.png}
\caption{Frequency Response of Amplitude Magnification}
\label{fig1.}
\end{figure}

This Graph helps us analyse the nature of vibrations experienced by the system under study. Studying the graph, we can observe that:
\begin{enumerate}
	\item For an undamped system($\zeta$=0),and G$\rightarrow$ $\infty$ as r $\rightarrow$ 1
	\item Any amount of damping($\zeta$$>$0)reduces the magnification factor (G) for all values of the forcing frequency.
	\item In the degenerate case of a constant force (when r=0), the value of $|G|$
	\item The reduction in $|G|$ in the presence of damping is very significant at or near resonance.
\end{enumerate}

In System Design, we use this data to design the structure such that the frequency of vibrations handled by the structure are not near the natural frequency of the structure and hence limit the Magnification of the Transferred Vibrations.\\

The graph even helps us predict the values of Magnification Factor for intermediate Frequency Ratios by interpolation. Hence, this graph is widely used in the study and design of systems which are subjected to vibrations
\pagebreak

\section{Sinusoidal Multivariable Function Plot}
This Graph shows the sinusoidal relation expressed as
\[z(x,y) = \frac{sin(5x).cos(5y)}{5}\]

This Graph helps us analyse the nature of multivariable functions.It contains multiple Saddle Points and can be used in visualizing the concept.\\

\begin{figure} [!ht] %to keep the image where we place it.
\centering
\includegraphics[scale=0.3]{Octave_3D Plot.png}
\caption{Sinusoidal Multivariable Function Plot}
\label{fig2.}
\end{figure}

\subsection{Saddle Point}
Given the function z=f(x,y), the point $(x_{0},y_{0},f(x_{0},y_{0}))$ is a saddle point if both $f_{x}(x_{0},y_{0})=0$ and $f_{y}(x_{0},y_{0})=0$, but f does not have a local extremum at $(x_{0},y_{0})$.\\

While we have to be careful to not misinterpret the results of this fact it is very useful in helping us to identify relative extrema. Because of this fact we know that if we have all the critical points of a function then we also have every possible relative extrema for the function. The fact tells us that all relative extrema must be critical points so we know that if the function does have relative extrema then they must be in the collection of all the critical points. Remember however, that it will be completely possible that at least one of the critical points won’t be a relative extrema.\\

In machine learning for example, local/global minimums/maximums are important as the indicate the validity and accuracy of the function.
\end{document}


\documentclass{article}

\usepackage[colorlinks=true]{hyperref}
\usepackage[cmex10]{amsmath}
\usepackage{bbm}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{comment}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}

\DeclareMathOperator*{\argmin}{\mathrm{argmin}}

\begin{document}

\title{RPCAKit: MATLAB RPCA Library}
\author{Stephen Tierney}
\maketitle

%\tableofcontents

\section{RPCA}

Robust Principal Component Analysis (RPCA) \cite{candes2011robust} refers to the following problem
\begin{align}
\min_{\mathbf{A, N}} \|\mathbf A \| + \lambda\|\mathbf N\|_{q} \\
\text{s.t.} \quad \mathbf{X = A + N} \nonumber
\end{align}
where $\mathbf X$ is observed data, $\mathbf A$ is the original low-rank data $\mathbf N$ is some noise and $q$ is a placeholder for the noise type. For example if our data is corrupted by sparse noise we set $q = 1$. In other words the goal is to recover $\mathbf A$ only knowing $\mathbf X$ and the type of noise the data has been affected by. It has been shown that the solution to this objective can exactly recover $\mathbf A$ under reasonable conditions \cite{candes2011robust}. RPCAKit provides MATLAB functions to solve this problem for Gaussian, sparse and sample specific noise.

\section{Function Listing}

\begin{table}[!h]
{\small{
\centering

\begin{tabular}{c | c}
\hline
Objective & Function \\
\hline

$\begin{array}{c} \min_{\mathbf{A, N}} \|\mathbf A \| + \frac{\lambda}{2} \|\mathbf N\|_F^2 \\
\text{s.t.} \quad \mathbf{X = A + N} \end{array}$
	& rpca\_fro  \\
\hline

$\begin{array}{c} \min_{\mathbf{A, N}} \|\mathbf A \| + \lambda \|\mathbf N\|_1 \\
\text{s.t.} \quad \mathbf{X = A + N} \end{array}$
	& rpca\_l1  \\
\hline

$\begin{array}{c} \min_{\mathbf{A, N}} \|\mathbf A \| + \lambda \|\mathbf N\|_{1,2} \\
\text{s.t.} \quad \mathbf{X = A + N} \end{array}$
	& rpca\_l1l2  \\
\hline

\end{tabular}
}}
\end{table}

\section{Implementation}

We use Linearised ADMM with Adaptive Penalty \cite{lin2011linearized} to solve the RPCA problem. First form the Augmented Lagrangian
\[
\min_{\mathbf{A, N}} \|\mathbf A \| + \lambda\|\mathbf N\|_{q} + \langle \mathbf{Y, X - A - N} \rangle + \frac{\mu}{2} \| \mathbf{X - A - N}  \|_F^2
\]

\begin{enumerate}
\item Fix others and solve for $\mathbf A$
\[
\min_{\mathbf{A}} \|\mathbf A \| + \langle \mathbf{Y, X - A - N} \rangle + \frac{\mu}{2} \| \mathbf{X - A - N}  \|_F^2
\]
\[
\min_{\mathbf{A}} \|\mathbf A \| + \frac{\mu}{2} \| \mathbf{X - A - N} + \frac{1}{\mu}\mathbf Y  \|_F^2
\]
which has a closed form solution defined by the singular value shrinking operator \cite{lin2011linearized,candes2011robust}.

\item Fix others and solve for $\mathbf N$
\[
\min_{\mathbf{N}} \lambda\|\mathbf N\|_{q} + \langle \mathbf{Y, X - A - N} \rangle + \frac{\mu}{2} \| \mathbf{X - A - N}  \|_F^2
\]
\[
\min_{\mathbf{N}} \lambda\|\mathbf N\|_{q} + \frac{\mu}{2} \| \mathbf{X - A - N} + \frac{1}{\mu}\mathbf Y \|_F^2
\]
where the solutions have various closed form solutions, see \cite{candes2011robust, liu2010robust}.

\item Update $\mathbf Y$
\[
\mathbf Y = \mathbf Y + \mu( \mathbf{X - A - N} )
\]

\item Update $\mu$
\begin{align*}
 \mu = \textrm{min}( \mu_{\text{max}}, \gamma \mu)
\end{align*}
where $\rho$ is defined as
\[
\gamma =
\begin{cases}
\gamma_0 & \text{if} \;\; \mu_k \frac{\textrm{max} ( \| \mathbf A_{k+1} - \mathbf A_{k}  \|_F  , \|  \mathbf N_{k+1} - \mathbf N_{k} \|_F)}{\| \mathbf X \|_F} < \epsilon_2 \\
1 & \text{otherwise,}
\end{cases}
\]
$\mu_{\text{max}} >>  \mu_0$ and $\epsilon > 0$.

\item Check stopping criteria
\[
\|\mathbf X - \mathbf A^{k+1}  - \mathbf N^{k+1} \|_F < \epsilon_1, \;
 \mu_k \frac{\textrm{max} ( \| \mathbf A_{k+1} - \mathbf A_{k}  \|_F  , \|  \mathbf N_{k+1} - \mathbf N_{k} \|_F)}{\| \mathbf X \|_F} < \epsilon_2
\]

\end{enumerate}

\bibliographystyle{plain}
\bibliography{references}

\end{document}


\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage[pdftex]{graphicx}
%\usepackage{physymb}
%\usepackage{wrapfig}
\usepackage{braket}
\usepackage{subcaption}
\title{PH 304: Assignment 2}

\author{Manish Goregaokar (120260006)}
\date{January 26, 2015}
\begin{document}
\maketitle
\section*{Problem 1}

$$n! = \int_0^\infty e^{-x}x^n dx$$

Integrating by parts,
\begin{align*}
I_n &= \left.x^n\int e^{-x}\right|_0^\infty + \int_0^\infty nx^{n-1}\int e^{-x}\\
 &= - \left.x^n e^{-x}\right|_0^\infty + nI_{n-1}\\
 &= nI_{n-1}\\
 \therefore I_n &= nI_{n-1}
\end{align*}

Additionally, for $n=0$, $I_0 = \int_0^\infty e^{-x} = 1$. So $I_0 = 1,  I_n = nI_{n-1}$. From this we see that this is exactly the factorial function, which obeys the same recursion relation.$\hfill$ Ans. (i)

\begin{figure}[!htb]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gamma10}
\caption{Integrand for $n=10$}
\end{subfigure}
~~~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gamma20}
\caption{Integrand for $n=20$}
\end{subfigure}
\\~\\~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gamma50}
\caption{Integrand for $n=50$}
\end{subfigure}
\end{figure}

$$g(x)=A\exp\left(-\frac{(x-x_0)^2}{2\sigma^2}\right)$$

Now, $g(x) \approx e^{-x}x^n$. We take the Taylor expansion about the maxima $x=x_0$.
 \begin{align*}
e^{-x}x^n &=x_0^n e^{-x_0} + 0 +
\frac{(x-x_0)^2}{2}\left.\frac{d^2}{dx^2}e^{-x  +n\ln x}\right|_{x=x_0} + \dots\\
&=x_0^n e^{-x_0} + 0 +\frac{(x-x_0)^2}{2}\left(e^{-x_0} x_0^{n-2} \left(-2 n x_0+(n-1) n+x_0^2\right)\right)
\end{align*}

Whereas for the Gaussian, the Taylor expansion about the mean is $A(1 + 0(x-x_0) - \frac{(x-x_0)^2}{2}\frac{1}{ \sigma ^2}$

Thus, $A = x_0^ne^{-x_0}$, $-\frac{1}{ \sigma ^2} = 1 - \frac{2n}{x_0} + \frac{n(n-1)}{x_0^2}$

To find $x_0$, we set the derivative to zero: $n e^{-x} x^{n-1}-e^{-x} x^n = 0$, and we find that $x_0 = n$

Thus, $\boxed{A=n^ne^{-n}}$, $\boxed{x_0 = n}$, $\frac{1}{\sigma^2} = 1-\frac{n-1}{n}$, and $\boxed{\sigma = \sqrt{n}}$

While the higher deriviatives of these two functions diverge for large $n$, the approximation still comes closer when plotted. Thus, this approximation improves as $n$ becomes large, but the two curves are not asymptotically equal.

\begin{figure}[!htb]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gaus10}
\caption{Gaussian approximation  for $n=10$}
\end{subfigure}
~~~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gaus20}
\caption{Gaussian approximation  for $n=20$}
\end{subfigure}
\\~\\~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{gaus50}
\caption{Gaussian approximation for $n=50$}
\end{subfigure}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.5]{error}
\end{figure}
\newpage
\section*{Problem 2}

Let us take the random variable $y = \left\lbrace\begin{array}{ll}1 & \text{if} (x-\lambda)^2 > k^2\\
0 & \text{if} (x-\lambda)^2 \leq k^2\end{array}\right.$

$\therefore E(y) = P(\text{x is not in $k$ neighborhood})$

Additionally, if $x >0$, $y \leq \frac{(x-\lambda)^2}{k^2}$. Thus, $E[y] \leq E[\frac{(x-\lambda)^2}{k^2}] ~\implies~ P(\text{x is not in } k \text{ neighborhood}) \leq \frac{\sigma^2}{k^2}$

If $n\sigma = k$, we get $\boxed{P(\text{x is not in } n\sigma \text{ neighborhood}) \leq \frac1{n^2}}$

\section*{Problem 3}
\newcommand{\inint}{\int_{-\infty}^\infty}
$$S(\alpha, \beta, p(x)) = -\inint p(x)\ln p(x)dx + \alpha\left(1-\inint p(x)dx\right)+ \beta\left(f-\inint F(x)p(x)dx\right)$$

By lagrange multipliers, \begin{align*}
0 &= -\frac{\delta}{\delta p(y)}\inint p(x)\ln p(x)dx + \frac{\delta}{\delta p(y)} \alpha\left(1-\inint p(x)dx\right)+\frac{\delta}{\delta p(y)}\beta\left(f-\inint F(x)p(x)dx\right)\\
&= -\inint \ln p(x)\delta(x-y) - \inint \delta{x-y} - \alpha\inint \delta{x-y} -F(x)\beta\inint \delta{x-y} \\
&= -(1+\ln p(y)) - \alpha - F(x)\beta
\end{align*}
Thus, $p(y) = \exp(-1-\alpha - \beta F(x))$
When $\Braket{|v|} = c$, we have the equations:
\begin{align*}
p(x) &= \exp(-1-\alpha - \beta |x|)\\
\inint p(x) dx &= 1\\
\inint |x| p(x) dx &= c\\
\therefore 1 &= \inint \exp(-1-\alpha - \beta |x|) \\
 &= 2\int_0^\infty \exp(-1-\alpha - \beta x)\\
 &= \frac{2}{\beta}e^{-1-\alpha}\\
 \therefore p(y) &= \frac{\beta}{2} e^{-\beta|x|}\\
 \text {Now, } \inint |x| p(x) dx &= c\\
 \therefore c &= 2\int_0^\infty x\frac{\beta}{2} e^{-\beta x}dx \\
 c &= \frac{1}{\beta}\\
 \beta &= \frac1 c
\end{align*}

Thus, for constraining $\Braket{|v|} = c$, the distribution is $\boxed{p(v) = \frac1{2c} e^{-\frac{1} {c}v}}\hfill$ Ans.

When constraining $\Braket{v^2} = c^2$, we have
\begin{align*}
p(x) &= \exp(-1-\alpha - \beta x^2)\\
\inint p(x) dx &= 1\\
\inint |x| p(x) dx &= c\\
\therefore 1 &= \inint \exp(-1-\alpha - \beta x^2) \\
 &= 2\int_0^\infty \exp(-1-\alpha - \beta x^2)\\
 &= e^{-1-\alpha}\sqrt{\frac{\pi}{\beta}}\\
 \therefore p(y) &= \sqrt{\frac{\beta}{\pi}} e^{-\beta x^2}\\
 \text {Now, } \inint x^2 p(x) dx &= c\\
 \therefore c &= 2\int_0^\infty x^2 2 e^{-\beta x^2}dx \\
 c &=  2 \sqrt{\frac{\beta}{\pi}}\frac{\sqrt{\pi}}{4 \beta^{3/2}}\\
 \beta &=\frac{1}{2 c}
 \end{align*}

 Thus, for constraining $\Braket{v^2} = c^2$, the distribution is $\boxed{p(v) = \sqrt{\frac{\beta}{\pi}} e^{-\frac{1} {2c}v^2}}\hfill$ Ans.
\section*{Problem 4}
This is a binomial distribution.

The mean of one question will be $7$, with standard deviation $\sqrt{0.7(1-0.3)} = 0.458258$. For the exam, the mean will be $70$ with standard deviation $\sqrt{10\times 0.7(1-0.3)} = 1.44914$

\section*{Problem 5}

Here, RMS distance should be R. Thus, $\sqrt{\Braket{x_N^2}} = \sqrt{N}l = R \implies N = 5\times 10^{21}$. Thus, it takes approximately $\boxed{5\times 10^{21}}$ steps to reach the radius where convection becomes important.

The time taken will be $5\times 10^{21}\times \frac{l}{c} = \boxed{2.30504\times 10^9 ~\mathrm s}$

\section*{Problem 6}

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.5]{random1}
\end{figure}

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.5]{random2sm}
\end{figure}

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.5]{random2lg}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.5]{scatter}
\end{figure}

Such a variable has a density function as $f(x) = 1$ for all $x$ in the region $[-0.5, 0.5]$. Its RMS step size will be $\sqrt{\int_{-0.5}^{0.5}x^2=\frac1{12}}$, giving us $\boxed{\frac1{2\sqrt3}}$.

\begin{figure}[!htb]
\centering
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.4]{central1}
\end{subfigure}
~~~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.4]{central2}
\end{subfigure}
\\~\\~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.4]{central3}
\end{subfigure}
~~~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.4]{central4}
\end{subfigure}
\\~\\~
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[scale=0.5]{central5}
\end{subfigure}
\caption{As seen in the graphs above, the Gaussian approximates the random walk very quickly.}
\end{figure}

\end{document}

Course material/PH 304 - Statistical Physics/Assignment 2/assign2.tex


\documentclass{beamer}

\usepackage{beamerthemevictor,comment,verbatim,graphicx,amssymb}

\input{tutmacs}
\input{slidemacs}
\input idxmacs

\begin{document}

\title{Raster Graphics}
\author{Victor Eijkhout}
\date{Notes for CS 594 -- Fall 2004}

\frame{\titlepage}

\frame{
  \frametitle{From mathematics to pixels}
\begin{itemize}
\item Shapes and curves described mathematically (bezier)
\item Screen has pixels
\item different arithmetic
\item rounding behaviour
\item Vector graphics vs Bitmap, Raster
\end{itemize}
}

\section{Basic raster algorithms}
\subsection{Lines}

\frame{
  \frametitle{Line drawing}
\begin{itemize}
\item Symmetry: limit to slope~$\leq 1$
\pgfimage{one-per-column}
\item one pixel on per column
\end{itemize}
}

\frame{
  \frametitle{Incremental drawing}
\begin{itemize}
\item Line $y=mx+B$, slope $m=\delta y/\delta x$.
\item Pixels: $\delta x\equiv1$, so $\delta y=m$
\[y_{i+1}=y_i+\delta y.\]
\item implementation
\begin{tabbing}
let $x_0,y_0$ and $m$ be given, then\\
for \=$i=0\ldots n-1$\\
\>\n{WritePixel}$(x_i,\mathop{\textrm{Round}}(y_i))$\\
\>$x_{i+1}=x_i+1$\\
\>$y_{i+1}=y_i+m$
\end{tabbing}
\item roundoff, cost
\end{itemize}
}

\subsection{Midpoint algorithm}

\frame{
  \frametitle{Midpoint algorithm}
\begin{itemize}
\item Given `on' pixel, choices are 1~right, 2~right-and-up
\pgfimage[height=1.5in]{line-midpoint}
\item Write
\[ y={dy\over dx}x+B, \qquad F(x,y)=ax+by+c=0.\]
then $a=dy$, $b=-dx$, $c=B$
\item derive $dx,dy$ from the end points
\end{itemize}
}

\frame{
  \frametitle{Midpoint location}
\begin{itemize}
\item Does the midpoint~$M$ lie above or under the line?
\item  use~$F(\cdot,\cdot)$: evaluate the `decision value' of the midpoint:
\[ d=F(x_p+1,y_p+1/2). \]
\item The two cases to consider then are
\begin{description}
\item[$d<0$:] $M$ lies over the line, so we take $y_{p+1}=y_p$;
\item[$d\geq0$:] $M$ lies under the line, so we take $y_{p+1}=y_p+1$.
\end{description}
\end{itemize}
}

\frame{
  \frametitle{Use of $d$}
\begin{itemize}
\item Use $d$ instead of midpoint:
\[ d'=F(x_{p+1}+1,y_{p+1}+1/2). \]
\item Two cases:
\begin{footnotesize}
\[ \begin{array}{rll}
    d'=&a(x_{p+1}+1)+b(y_{p+1}+1/2)+c=\\
    d<0:&= a(x_p+2)+b(y_p+1/2)&=d+a=d+dy\\
    d\geq0:&= a(x_p+2)+b(y_p+3/2)+c&=d+a+b=d+dy-dx
\end{array} \]
\end{footnotesize}
\item Update~$d$ with $dy$ or~$dy-dx$ depending on
whether it's negative or non-negative.
\end{itemize}
}

\frame{
  \frametitle{Final refinement}
\begin{itemize}
\item Start off
\[ d_0=F(x_0+1,y_0+1/2)=F(x_0,y_0)+a+b/2=0+dy-dx/2.\]
\item Get rid of the division by~2:\\
$\tilde F(x,y)=2F(x,y)$;\\
 update~$d$ with $2dy$ and~$2(dy-dx)$ in the two cases.
\item Digital Differential Analyzers (DDA)
\end{itemize}
}

\subsectionframe{Circle drawing}
\frame{
  \frametitle{}
\pgfimage[height=1.5in]{circle-midpoint}
\begin{itemize}
\item Circle: \[ F(x,y) = x^2+y^2-R^2,\]
\item  decision value in the midpoint~$M$ is
\[ d=F(x_p+1,y_p+1/2)=x^2+2x+y^2+y+5/4. \]
\end{itemize}
}

\frame{
  \frametitle{}
\begin{itemize}
\item Cases
\begin{description}
\item[$d<0$:] $M$ lies in the circle, so we take $y_{p+1}=y_p$;
\item[$d\geq0$:] $M$ lies outside the circle, so we take $y_{p+1}=y_p+1$.
\end{description}
\item Updating:
\[ \begin{array}{rll}
    d'=&F(x_{p+1}+1,y_{p+1}+1/2)=\\
    d<0:&= x^2+4x+y^2+y+4\,1/4&=d+2x+3\\
    d\geq0:&= x^2+4x+y^2+3y+6\,1/4&=d+2(x+y)+5
\end{array} \]
\item Construct $2x$,$2y$ by shift
\end{itemize}
}

\subsectionframe{Cubics}

\frame{
  \frametitle{Stepwise computation}
\begin{itemize}
\item Cubic function $f(t)=at^3+bt^2+ct+d$
\item Strategy: compute the value $f(t+\delta)$ by updating
\[ f(t+\delta)=f(t)+\Delta f(t). \]
\item (alternatives: Horner, midpoint)
\item Difference:
\[ \begin{array}{rcl}
    \Delta f(t)&=&f(t+\delta)-f(t)\\
        &=&a(3t^2\delta+3t\delta^2+\delta^3)+b(2t\delta+\delta^2)+c\delta\\
        &=&3a\delta
    t^2+(3a\delta^2+2b\delta)t+a\delta^3+b\delta^2+c\delta
\end{array} \]
\item Quadratic term left
\end{itemize}
}

\frame{
\begin{itemize}
\item Define
\[ \begin{array}{rcl}
    \Delta^2f(t)&=&\Delta f(t+\delta)-\Delta f(t)\\
        &=&3a\delta(2t\delta+\delta^2)+(3a\delta^2+3b\delta)\delta\\
        &=&6a\delta^2t+6a\delta^3+2b\delta^2
\end{array} \]
\item Third difference:
$\Delta^3f(t)=\Delta^2f(t+\delta)-\Delta^2f(t)=6a\delta^2$
\item Together: compute $f_{n+1}\equiv f((n+1)\delta)$ by
\[ \Delta^3f_0=6a\delta^2,\quad
    \Delta^2f_0=6a\delta^3+2b\delta^2,\quad
    \Delta f_0=a\delta^3+b\delta^2+c\delta
\]
and computing by update
\[  f_{n+1}=f_n+\Delta f_n,\quad
    \Delta f_{n+1}=\Delta f_n+\Delta^2f_n,\quad
    \Delta^2f_{n+1}=\Delta^2f_n+\Delta^3f_0
\]
\end{itemize}
}

\sectionframe{Rasterizing type}

\frame{
  \frametitle{}
Type is tricky: lots of features in small objects\\
everyone immediately sees when it's wrong\\
\pgfimage[height=1.3in]{raster-problems}
\pgfimage[height=1.3in]{illegible}
}

\frame{
  \frametitle{Badly rasterized characters}
Obvious algorithm: pixel on if center in the contour\\
\pgfimage[height=1.3in]{e-bad}
\pgfimage[height=1.3in]{e-good}\\
\begin{itemize}
\item Problems with curves tangent to $n+1/2$ lines
\item Different scalings, different raster
\item Variable placement
\end{itemize}
}

\subsection{Basic algorithms}

\frame{
  \frametitle{Scaling and rasterizing}
\parbox[b]{1in}{Original character is on internal raster:}
\pgfimage[height=1in]{fig2-1-1}
\parbox[b]{1in}{Scale to target raster:}
\pgfimage[height=1in]{fig2-1-2}

\parbox[b]{1in}{Round to target raster:}
\pgfimage[height=1in]{fig2-1-3}
\parbox[b]{1in}{Set pixels:}
\pgfimage[height=1in]{fig2-1-4}
}

\frame{
  \frametitle{Scaling vs design size}
\pgfimage[height=.25in]{design-size}
\begin{itemize}
\item Scaling is a compromise
\item Different design sizes
\item Adobe Multiple Master
\end{itemize}
}

\frame{
  \frametitle{Filling in}
\begin{itemize}
\item Precisely what does `pixel lies within the contour' mean?
\item Complications: letters with `bowls'; multiple contours
\pgfimage[height=1in]{overlapping-contours}
\pgfimage[height=1in]{winding}
\item Winding rules
\end{itemize}
}

\frame{
  \frametitle{Winding rules}
\pgfimage[height=1.2in]{winding_ar4win_100}
\pgfimage[height=1.2in]{winding_ar4win_150}
}

\frame{
  \frametitle{Dropouts}
\pgfimage[height=2.5in]{dropout}
}

\subsectionframe{Hinting / instructing}

\frame{
  \frametitle{}
\pgfimage[height=1.3in]{o-horizontal}
\pgfimage[height=1.3in]{o-vertical}
\begin{itemize}
\item Small programs per font~/ character
\item Give constraints on placement, relations, distance
\end{itemize}
}

\end{document}
\sectionframe{Anti-aliasing}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}

\end{document}

\frame{
  \frametitle{}
\begin{itemize}
\item
\end{itemize}
}


\subsection{Radial Basis Function (RBF) activation function}

\(a(x)=\sum_i a_i f(||x-c_i||)\)

\(a(x)=\sum_i a_i fe^{||x-c_i||^2}\)


\subsection{Linear Approximations}\label{sec:LinApprox}
We begin by the first derivative as an application of the tangent line to approximate $f$.

Recall that the tangent line to $f(x)$ at a point $x=a$ is given by
\[ L(x) = f'(a) (x-a) + f(a).\]
The tangent line in this context is also called the \dfont{linear approximation} to $f$ at $a$.

If $f$ is differentiable at $a$ then $L$ is a good approximation of
$f$ so long as $x$ is ``not too far'' from $a$.  Put another way, if
$f$ is differentiable at $a$ then under a microscope $f$ will look
very much like a straight line, and thus will look very much like $L$;
since $L(x)$ is often much easier to compute than $f(x)$, then it makes sense to use $L$ as an approximation. Figure~\ref{fig:linear_approximation}
shows a tangent line to $\ds y=x^2$ at three different magnifications.

\figure[!ht]
\centerline{\includegraphics[width=2in]{images/linear_approx_1}\hfill
\includegraphics[width=2in]{images/linear_approx_2}\hfill
\includegraphics[width=2in]{images/linear_approx_3}\hfill}
\caption{The linear approximation to $\ds y=x^2$. \label{fig:linear_approximation}}
\endfigure

Thus in practice if we want to approximate a difficult value of $f(b)$,
then we may be able to approximate this value using a linear approximation,
provided that we can compute the tangent line at some point $a$ close to $b$.
Here is an example.

\begin{example}{Linear Approximation}{linear approximation}
Let $f(x)=\sqrt{x+4}$, what is $f(6)$?
\end{example}

\begin{solution}
We are asked to calculate $f(6)=\sqrt{6+4}=\sqrt{10}$ which is not easy
to do without a calculator. However 9 is (relatively) close to 10 and
of course $f(5)=\sqrt{9}$ is easy to compute, and we use this to approximate $\sqrt{10}$.

To do so we have $f'(x)=1/(2\sqrt{x+4})$, and thus the linear approximation to $f$ at $x=5$ is
\[L(x)=\bigg(\frac{1}{2\sqrt{5+4}}\bigg)(x-5)+\sqrt{5+4}=\frac{x-5}{6}+3.\]

Now to estimate $\sqrt{10}$, we substitute 6 into the linear approximation $L(x)$ instead of $f(x)$, to obtain
\[ \sqrt{6+4}\approx \frac{6-5}{6}+3=\frac{19}{6}=3\sfrac{1}{6}=3.1\bar{6}\approx 3.17 \]

It turns out the exact value of $\sqrt{10}$ is actually 3.16227766\ldots
but our estimate of 3.17 was very easy to obtain and is relatively accurate.
This estimate is only accurate to one decimal place.
\end{solution}

With modern calculators and computing software it may not appear
necessary to use linear approximations, but in fact they are quite
useful. For example in cases requiring an explicit numerical approximation, they
allow us to get a quick estimate which can be used as a
``reality check'' on a more complex calculation. Further in some complex
calculations involving functions, the linear approximation makes an
otherwise intractable calculation possible without serious loss of
accuracy.

\begin{example}{Linear Approximation of Sine}{linear approximation of sine}
Find the linear approximation of $\sin x$ at $x=0$, and use it to compute small values of $\sin x$.
\end{example}

\begin{solution}
If $f(x)=\sin x$, then $f'(x)=\cos x$, and thus the linear approximation of $\sin x$ at $x=0$ is:
\[ L(x)=\cos (0)(x-0)+\sin (0)=x. \]
Thus when $x$ is small this is quite a good approximation and is used
frequently by engineers and scientists to simplify some calculations.

For example you can use your calculator (in radian mode since the
derivative of $\sin x$ is $\cos x$ only in radian) to see that
\[ \sin (0.1)=0.099833416\ldots \]
and thus $L(0.1)=0.1$ is a very good and quick approximation without any calculator!
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:LinApprox}}

\begin{enumialphparenastyle}

%%%%%%%%%%
\begin{ex}
Find the linearization $L(x)$ of $f(x)=\ln (1+x)$ at $a=0$. Use
this linearization to approximate $f(0.1)$.
\begin{sol}
$L(x)=x$, $f(0.1)\approx L(0.1)=0.1$
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Use linear approximation to estimate $(1.9)^3$.
\begin{sol}
Choose $f(x)=x^3$ and $a=2$, the closest integer to 1.9. The
linearization of $f$ at $a$ is $L(x)=12(x-2)+8$, and $(1.9)^3=f(1.9)\approx L(1.9)=12(1.9-2)+8=6.8$.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Show in detail that the linear approximation of
$\sin x$ at $x=0$ is $L(x)=x$ and the linear approximation of $\cos x$
at $x=0$ is $L(x)=1$.
\end{ex}

%%%%%%%%%%
\begin{ex}
Use $f(x)=\sqrt[3]{x+1}$ to approximate $\sqrt[3]{9}$ by choosing an
appropriate point $x=a$. Are we over- or under-estimating the value of $\sqrt[3]{9}$? Explain.
\begin{sol}
Choose $a=7$ since $f(7)=\sqrt[3]{7+1}=\sqrt[3]{8}=2$ is an integer
close to $\sqrt[3]{9}$. The linearization of $f$ at $a=7$ is
$L(x)=\sfrac{1}{12}(x-7)+2$. Then $f(8)=\sqrt[3]{8+1}=\sqrt[3]{9}\approx L(8)=\sfrac{1}{12}(8-7)+2=2.08\bar{3}$. We are over-estimating $\sqrt[3]{9}$ since $L(x)>f(x)$ for all $x$ around $a=7$.
\end{sol}
\end{ex}

\end{enumialphparenastyle}


\chapter{Solution Development}\label{chapter:analysis}
In a previous work on this topic, Wörndl and Herzog  \parencite{cbrecsys2014} drew inspiration for their formal model based on the Oregon Trail knapsack problem (see Section \ref{sec:oregon}); they formulated a model that extends the value function of the problem using a penalty function.

For clarity, we adjusted the notation used in their paper to fit the notations used in previous function values. Wörndl and Herzog formally defined their value function as follows:

\begin{gather}
 \tag{1} f_j(x_j, x_{d_j}) = x_j \cdot v_j - \sum_{e \in x_{d_j}} ( t(j, e) \cdot x_j \cdot v_j \cdot [x_e > 0])\label{eq:3d}
\end{gather}

where $v_j$ is the value of region $j$ (i.e, item) for the specified user query, and $t(j, e)$ is the penalty function for the two regions $j$ and $e$. Their value function is similar to the function Type \ref{eq:2g} specified by the original Oregon Trail knapsack model. However, the previously defined value-reducing constant factor $t$, is a function of the two regions $j$ and $e$.

Wörndl and Herzog’s formal model is defined as follows:
\begin{align}
    \tag{1}maximize \qquad  &\sum_{i=1}^n  f_j(x_j, x_{d_j}) \label{eq:3a}\\
    \tag{2}subject \ to \qquad &\sum_{i=1}^n x_i d_i  \leq D \label{eq:3b}\\
    \tag{3}&\sum_{i=1}^n x_i\ b_i \leq B \label{eq:3c}\\
    \tag{4} &x_i \in \{0,1\}
\end{align}

where $f_j(x_j, x_{d_j})$ is the penalty function defined in \ref{eq:3d}; $d_i$ is item $i$'s recommended duration of stay, and $b_i$ is item $i$'s recommended daily budget. $D$ is the maximum possible duration of stay and $B$ is the maximum budget the user can spend on their trip.

Wörndl and Herzog concluded that the penalty function defined in their work could be improved to produce better results. Building penalty-based functions requires careful consideration of the function parameters and the function itself. Thus, to gain freedom from the influence of the penalty function, we reformulate and extend the problem definition to a non-penalty-based approach. If through further analysis, a penalty-based approach proves to be a better fit for our selected algorithm, we will redefine a penalty function as needed.

The framework for our \gls{rs} comprises a knapsack model for the multi-objective \gls{op}, a data model, and a meta-heuristic solution. In the following sections, we analyze these three parts in detail.

\section{Problem Reformulation} \label{sec:problem_definition}

Let us consider $n$ regions $(i = 1, ..., n)$. Each region $i$ will have $k$ profits $s_{ik}\ (p = 1, ...,k)$. Given a set $N$ of $m$ traveling preferences $N = \{N_1, N_2,...,N_m\}$, $s_{ik}$ is dependent on $i$'s score on $N$. For example, a region can have a different score for shopping and another for hiking.
The recommendation problem can be modeled as a multi-objective \gls{op}. Given a user query, some regions must be selected to maximize the $p$ total profits while not exceeding the budget limit $B$ and the total stay duration $D$. Each user preference must be fulfilled by at least one of the selected regions. Assuming the system recommends Trip $T$ comprising $n$ regions ($T = {x_1, x_2, ..., x_n}$), the physical distance between a region $x_i$ and its neighbor $x_2$ should not exceed a defined constant $\sigma$. In a case in which no location coordinates for the regions are available, the regions in the recommended trip should be within reasonable distance from one other. Additionally, the duration of stay in a particular region ${x_i}$ should ensure a minimum utility value, which is defined in the algorithm.

The mathematical model of the \gls{moop} is defined as follows:

\begin{align}
    \tag{1}maximize \qquad  &z_n(x) = \sum_{k=1}^p x_i\ s_{ik}, \hspace{1cm} i = 1,...,n \label{eq:3_1a}\\
    \tag{2}subject \ to \qquad &\sum_{i=1}^n x_i\ d_i  \leq D \label{eq:3_1b}\\
    \tag{3}&\sum_{i=1}^n x_i\ b_i \leq B \label{eq:3_1c}\\
    \tag{4}&\sum_{j \in N} x_{ij} \geq 1 \label{eq:3_1e}\\
    \tag{5}&\sum_{i=1}^n x_{i} \ g(p_i) \leq \sigma,  \hspace{1cm}  \label{eq:3_1f} \\
    \tag{7} x_i \in \{0,1\}, \qquad &\forall \ 1 \leq i \leq n \label{eq:3_1f2}
\end{align}

where $x_i = 1$ when item $i$ is chosen; otherwise $x_i = 0$.
Constraints \ref{eq:3_1b} and \ref{eq:3_1c} represent the constraints on total stay duration and budget, respectively. Equation \ref{eq:3_1e} ensures that each user preference is satisfied at least once. Constraint \ref{eq:3_1f} represents the physical distance between the regions, in which $g$ is a function of the physical location. It is assumed that all coefficients $s_{ik}, b_{i}, B, d_i,$ and $D$ are positive.

\subsection*{Pareto Optimum}
There are multiple scores to be maximized in the objective function. Therefore, choosing an objective maximizing optimal solution without trade-offs is infeasible. In multi-objective optimization, Solution $s$ is said to dominate $s'$ if $s$ is at least as good as $s'$ in every criterion, and $s$ is better in at least one criterion; $s \succ s'$ is used to denote such a case. If no solution dominates Solution $s^*$, then $s^*$ is said to be \textit{Pareto optimal} (i.e., non-dominated). The set of all non-dominated vectors is known as the \textit{Pareto front}.

\textbf{Example}:
Figure \ref{fig:moopsample} a two-objective instance of the \gls{moop} problem. For simplicity, we assume two given preferences. The gray box displays the user input. When mapped to our problem definition, there are two objectives to be maximized, where an objective represents a single item. An item can be any \gls{poi}, for example attraction sites, region, or route. $f = (\Vec{f_1}, \Vec{f_2}, ... ,\Vec{f_k})$ represents all feasible solutions. We compute a solution in the objective space $\Vec{f_i} = (z_1, z_2)$. The objective values are computed on preferences $M$ and $S$, while respecting the necessary constraints. Parameter $x$ in the illustration is a boolean array that encodes the selection of an item combination. The selected item combinations are subject to the notion of Pareto optimality defined above. For example $f_7 \succ f_2$ because it is better in at least one of its objective values as $f_2$ and it is strictly better in another value. The Pareto front consists of the selections $\{f_1,f_5,f_7,f_9,f_{10}\}$, and we achieve a total score of (24, 23).

\begin{figure}[ht!]
    \centering
    \includegraphics[width=8cm]{Moop}
    \caption{Example solution to the multi-objective orienteering problem}
    \label{fig:moopsample}
\end{figure}

Pareto optimality here implies that there is no item combination $f_k$ that will improve the achievable score of at least one item without diminishing the achievable score of another item.

We can also extend the concept of Pareto optimality from the solution space to the objective space. Given $n$ objective functions $z = (z_1,...,z_n)$, with each objective having a score $\Vec{v} = (v_1,...,v_j)$ on $j$ criteria, we define the concept of Pareto optimality in the objective space as follows. An objective $z$ dominates an objective $z'$, denoted by $z \succ z'$, if
\begin{itemize}
    \item $z_i(v) \geq z_i'(v)$ on each score of $\Vec{v_j}$; and
    \item there exists one score $v^*$ such that $z_i'(v^*) > z_i'(v)$.
\end{itemize}

Again, Pareto optimality implies that there is no feasible objective $z_i$ such that $v'$ does not make it less effective in at least one other criterion.\newline
Having gained a better understanding of what is deemed optimal, an algorithm that can efficiently compute the Pareto front from a set of given items is what we aim to develop in subsequent sections.

\section{Data Model}
The underlying data model for this thesis is a travel database curated by Wörndl and Herzog \parencite{cbrecsys2014} in their previous work. The travel database contains realistic data on a region. Information about each region includes:
\begin{enumerate}
    \item Minimum weekly budget for a region
    \item Minimum duration to achieve a 25\% and 75\% utility respectively. An algorithm can either implement a minimum 25\% threshold or a 75\% minimum utility from stay threshold;
    \item The score of a region for particular travel activity preferences on a five-point Likert scale;
    \item The security score of a region on a five-point Likert scale; and
    \item The monthly weather score of a region on a five-point Likert scale (i.e., recommended months).
\end{enumerate}
The data model is hierarchically structured such that a region is always a sub-region of another region. The world is the root region, followed by the continents at the second level. Regions are geographical areas. A region could be a country, a section of a country, or a continent. For example Figure \ref{fig:datamodel} illustrates the hierarchical structure of the data model. The US and Canada are sub-regions of North America, while Alaska and Texas are sub-regions of the US. Ontario is a sub-region of Canada. The database is composed of 196 regions. All regions (except the root region) have a recommendation for a minimum stay at 25\%. Unlike previous models that calculate the connection between regions by specifying the necessary effort (time and cost) to travel from one region to another, we model connections between regions based solely on positions in the hierarchical tree structure. We extend the underlying data model to contain all sub-regions of a region. If two regions are sub-regions of the same parent, we consider them connected.

\begin{figure}
    \centering
    \includegraphics[width=.4\textwidth, height=.4\textwidth]{Datamodel}
    \caption{Hierarchical structure of the underlying data model}
    \label{fig:datamodel}
\end{figure}

\section{Analysis of Algorithmic Methodologies}\label{sec:alg_approaches}
According to Golden et al. \parencite{Golden1987TheProblem}, \gls{op} is an NP-hard problem. Hence, no known or expected algorithm can solve the problem optimally in polynomial time (i.e., an exact solution cannot be found within a reasonable amount of time). Computing an optimal solution with multiple objectives is even more intractable. Hence, there is usually a trade-off between time and accuracy. In multi-objective optimization, one is often interested in the Pareto front. However, it is usually infeasible to generate the exact set of a Pareto front. Reasons for this can be that the number of Pareto optima is too large, or the determination of a single Pareto optimum is computationally difficult. Therefore, the goal is usually to identify a satisfactory Pareto set approximation (i.e., a set as close to the optimum as possible \parencite{Fonseca2005AOptimizers}. Approximate algorithms offer near-optimal solutions to computationally intractable problems (mostly) in a moderate amount of time and are the major alternatives for solving NP-hard optimization problems.

Approximate algorithms can be classified as heuristics and meta-heuristics. Heuristics are usually problem dependent and inflexible (i.e., defined for a specific problem). Meta-heuristics are problem independent and can be applied to a broad range of optimization problems. In Chapter \ref{chapter:literature_review}, we found that meta-heuristic solutions are commonly used to solve \glspl{op}. Meta-heuristic solutions are also commonly used in multi-objective optimization in various research areas. Certain requirements must be considered when designing or selecting an appropriate algorithm to solve the \gls{moop}. Some requirements are intuitive for our problem domain. For example, a slow computational time by the end algorithm is intolerable for a user-oriented system. Some issues are not so intuitive. Preserving uniform diversity implies that the selected solutions in the approximated Pareto front are diverse and uniformly distributed. In addition, the \gls{moop} has been defined such that a single objective represents a single user’s preference. We are unable to pre-determine the number of preferences a user might select. A user could have just one preference. They might also have two or more preferences. Therefore, an appropriate algorithm should be applicable to a dynamic number of objectives. A brief summary of the most important requirements of the desired algorithm is as follows:
\begin{itemize}
    \item Tolerable computational time,
    \item Applicability to problem domain
    \item Uniform preservation of diversity,
    \item Applicability to large-scale problems,
    \item Applicability to a dynamic number of objectives, and
    \item Moderate implementation complexity.
\end{itemize}

In developing an algorithm to solve our optimization problem, we first address the basic methodologies for designing an approximation algorithm. We then analyze possible heuristic and meta-heuristics solutions. In this chapter, we assume a maximization problem in which function $g$ means $f_k$ has to be maximized.

\subsection{Greedy Methods}
Greedy methods help find sub-optimal solutions that satisfy some performance guarantee in NP-hard problems. The idea is to generate a solution incrementally by making the best possible choice according to a simple criterion at each decision-making point. For example, a greedy approach to solving the simple knapsack problem is to iteratively select a node with the least weight. This approach is best used together with some form of heuristic rather than as a stand-alone method. When used alone, the heuristics generate only a minimal number of different solutions.

\subsection{Local Search}
Local search techniques range from simple heuristics to complex meta-heuristics. The basic idea behind a local search is to start from an initial (partial or non-partial) \gls{candidate solution}. The solution is improved by making local changes to it and moving from one \gls{candidate solution} to a neighboring \gls{candidate solution} until no further improvement is possible. A local change might involve removing elements from the ground set, adding elements, or swapping elements. Local search is a good heuristic for computing near-optimum solutions to reasonably sized problems. Usually, a neighborhood function $N: S \mapsto 2^S$ where $S $ is the set of feasible solutions specifies for each solution $s \in S$ a subset $N(s)$ of neighbors of $s$ (neighborhood relation), or solutions that are close to $s$ \parencite{Gonzalez2007HandbookMetaheuristics}.

For many problems, computing the locality gap (i.e., the difference between local and global optima) is complex, and the locality gap using a local natural search is commonly very large. Additionally, the algorithm might visit the exact location within the search space more than once. Thus, it can become trapped in a location far away from the global optimum. These situations all lead to very poor approximation. Consequently, many local search techniques use mechanisms to help escape a position or reduce the locality gap. For example, one could use a restart strategy when stuck in a local minimum in the iterative descent algorithm. Alternatively, one could relax the improvement criterion by performing a non-improving step. However, these strategies do not guaranty escaping an arbitrary local minimum \parencite{HolgerH2005StochasticSearch}.

\subsubsection{Iterative Improvement}
The iterative improvement algorithm is the most basic local search algorithm and forms the basis of most local search algorithms. Algorithm \ref{alg:iterative-improvement} (\textit{IterativeDescent)} produces a simple iterative improvement (also known as iterative descent). The solution of the iterative descent is the optimum local value, which may or may not be a global optimum. Condition $g(s') > g(s)$ is the evaluation of the candidate solution. solution. Evaluation functions serve as guidance to a solution \parencite{HolgerH2005StochasticSearch}. In optimization problems, the objective function’s properties usually determine the evaluation function. Below, the algorithm assumes a maximization objective function:

 \begin{algorithm}
  \caption{General outline of iterative improvement local search}\label{alg:iterative-improvement}
  \SetKwInOut{Input}{Input}
  \SetKwInOut{Output}{Output}
  \Input{Set of candidate solutions $S$, Neighborhood function $N$, Objective function $g$}
  \Output{A local optimum solution $s \in S$}
    determine an initial candidate solution $s$

    \While {$N(s)$ contains better solution than $s$}{
        choose a solution $s' \in N(s)$ such that\\
             \hspace{0.5cm}$g(s') > g(s)$\\
        $s := s'$\\
    }
  \end{algorithm}

The simple iterative improvement algorithm can be extended to multi-objective optimization problems. For multiple objectives, the solution of the iterative improvement and all local search-based algorithms, in general, is defined as the approximate set of Pareto optimal solutions (Pareto front) found during the search process. A move improves the current solution when a newly generated candidate solution is added to the approximate Pareto front. This means that the evaluation condition of the single-objective iterative improvement algorithm changes. The Pareto local search proposed by Paquete et al. \parencite{Paquete2004ParetoStudy} adapts the notion of Pareto optimality in a simple local search. First, the algorithm randomly selects one non-visited candidate solution s and examines all neighbors of s. Second, it adds all neighbors of s that are non-dominated by the set of candidate solutions. It stops when the neighborhood of all candidate solutions has been examined \parencite{Gonzalez2007HandbookMetaheuristics}. Similar to the Pareto local search, the two-criteria local search \parencite{Angel2004ApproximatingProblem} is another multi-objective adaptation of the single-objective iterative improvement algorithm. While the Pareto local search chooses only one candidate solution to examine its neighborhood and immediately updates the list of candidate solutions, the two-criteria local search examines the neighborhood of all candidate solutions in an iteration.

\subsection{Stochastic Local Search}
Many local search algorithms use randomized decisions, for example to determine initial solutions or when determining search steps. These are called stochastic local search (SLS) algorithms. The majority of algorithms for computing high-quality approximations to the Pareto optimal set are based on \gls{sls}. Typically, additional memory is used to store the best candidate solution from previous searches. If the solution is feasible, it is returned upon termination of the algorithm; the objective function is used to determine the quality of the candidate solutions. The performance of any \gls{sls} algorithm depends significantly on the underlying neighborhood relations and the size of the neighborhood. Determining the choice of a neighborhood relation to use for \gls{sls} is mostly problem specific. Insertion and swap are two widely used neighborhood relation-generating operators. \gls{sls} techniques are attractive because they allow solving problems using moderately generic and easily implementable algorithms that can also be extended with or adapted based on problem-specific knowledge \parencite{HolgerH2005StochasticSearch}. They range from simple constructive algorithms and iterative improvement algorithms to general algorithm frameworks adapted to a specific problem under consideration. Popular \gls{sls} algorithms include \gls{vnd}, \gls{sa}, \gls{ts}, \glspl{ea}, \gls{aoc}, and many others.

\subsubsection{Randomized Iterative Improvement}
Using large neighborhoods is particularly beneficial to escape the local minima. However, there is an associated time complexity with performing search steps in a vast neighborhood. \gls{sls} algorithms try to implement the concept of large neighborhoods, but with trade-offs. A popular idea in \gls{sls} algorithms is to use large neighborhoods but reduce their size by never examining neighbors that are unlikely to yield any improvements in evaluation function value

Algorithm \ref{alg:randomized-iterative-improvement} is a \gls{sls}-based iterative improvement to Algorithm \ref{alg:iterative-improvement}. Algorithm \ref{alg:randomized-iterative-improvement} uses randomization as a diversification mechanism to improve the algorithm’s quality. The $\rho$ is a noise parameter that corresponds to the probability of performing a random step instead of an improvement step \parencite{HolgerH2005StochasticSearch}. The search can be terminated, for example, after a certain number of steps or after no improvement has been achieved in many steps. This algorithm outperforms the pure local search version of iterative descent; when it is run long enough, an optimal solution to any given problem instance can be found \parencite{HolgerH2005StochasticSearch}.

 \begin{algorithm}
  \caption{General outline of randomized iterative improvement local search}\label{alg:randomized-iterative-improvement}
  \SetKwInOut{Input}{Input}
  \SetKwInOut{Output}{Output}
  \Input{Set of candidate solutions $S$, Neighborhood function $N$, Objective function $g$}
  \Output{A local optimum solution $s \in S$}
    \While {termination condition not satisfied}{

        \eIf{there exists a solution $s ' \in N(s)$ with probability $\rho$}{
        choose solution $s' \in N(s)$ uniformly at random\\
        }
        {
        \eIf{there exists $g(s') > g(s)$ where $s' \in N(s)$}{
        choose solution $s'$ \\
        }{
        choose a solution $s' \in N(s)$ such that $s'$ is maximal \\
        }
        }

        $s := s'$\\
    }
  \end{algorithm}

\subsubsection{Variable Neighborhood Descent}
\Gls{vnd} algorithms benefit from the advantages of large neighborhoods by reducing the time consumed in the search steps. In the descent phase, standard small neighborhoods are used until a local optimum is encountered. Then, in the perturbation phase, the search process switches to a different neighborhood, which might help exit the corresponding basin of attraction and allow further search progress. Algorithm \ref{alg:vnd} highlights the general outline of a \gls{vnd}. Unlike the previously outlined algorithms, $N$ in this algorithm is a set $\{N_1,..., N_{imax}\}$ of neighborhood relations, usually ordered according to the increasing size of respective local neighborhoods. Variations of the \gls{vnd} algorithm have been widely and successfully applied in the single-objective domain in practice and are known to show optimal results. The algorithm can adapt to refinement and solution definitions in a multi-objective setting as defined in the iterative refinement algorithm in the previous section (see \parencite{Duarte2015Multi-objectiveProblems} for an example adaptation).

\begin{algorithm}
  \caption{General outline of variable neighborhood descent}\label{alg:vnd}
  \SetKwInOut{Input}{Input}
  \SetKwInOut{Output}{Output}
  \Input{Set of candidate solutions $S$, Set of neighborhood relations $N$, Objective function $g$}
  \Output{A local optimum solution $s \in S$}
    \While {$i < imax$}{
        choose the most improving $s'$ of $s \in N_i$\\
        \eIf{$g(s') > g(s)$}{
        $s := s'$\\
        $i := 1$
        }{
        $i := i + 1$
        }
    }
  \end{algorithm}

\subsubsection{Simulated Annealing}
\Gls{sa} is related to a probabilistic iterative improvement. It is based on the idea that the probability of accepting a deteriorating step should depend on the respective deterioration in evaluation function value, such that the worse a step is, the less likely it is that it will be performed \parencite{HolgerH2005StochasticSearch}.

The algorithm has a proposal mechanism in which a neighbor $s'$ is chosen at random, and the acceptance criteria are based on statistical mechanics (metropolis condition) as follows:

\begin{align*}
    \rho_{accept}(T,s,s') := \begin{cases}
                            1, &\text{if}\quad g(s') \geq g(s);\\
                            exp(\frac{g(s)-g(s')}{T}), &\text{otherwise};
                             \end{cases}
\end{align*}
$\rho_{accept}$ is the probability of accepting $s'$ and is parameterized by the temperature $T$ used to decide whether the search accepts $s'$ or stays at $s$. The condition above depicts the case where $T$ is kept constant and can be adjusted throughout the search process according to an annealing schedule. The technique for temperature adjustment used in simulated annealing helps escape the local minima. However, the results of simulated annealing are limited since it requires a cooling process that is typically slow in practice \parencite{HolgerH2005StochasticSearch}. Additional techniques such as neighborhood pruning, greedy initialization, low-temperature starts, and look-up tables for acceptance probabilities are typically used to achieve competitive results.

SA algorithms have been used for multi-objective optimization. Such adaptations require modifying the acceptance criterion.  Serafini \parencite{Serafini1994SimulatedProblems} provides guidelines to apply in computing the probability $\rho_{accept}$ as follows:

\begin{align*}
    \rho_{accept}(T,s,s') := \begin{cases}
                            1, &\text{if}\quad \Vec{f}(s') \succ \Vec{f}(s);\\
                            [0,1), &\text{if}\quad \Vec{f}(s) \succ \Vec{f}(s');\\
                            exp(\frac{g(s)-g(s')}{T}), &\text{otherwise};
                             \end{cases}
\end{align*}

\subsubsection{Tabu Search}
\Gls{ts} is a meta-heuristic based on adaptive memory and responsive exploration \parencite{Gonzalez2007HandbookMetaheuristics}. It guides a local heuristic search routine to explore the solution space beyond the local optimum. The algorithm forbids steps to recently visited search positions by preventing the local search from immediately returning to a previously visited candidate solution \parencite{HolgerH2005StochasticSearch}. This prevention step can be implemented by explicitly memorizing previously visited candidate solutions and ruling out any step that would lead back to those. In contrast to a simple descent method, \gls{ts} permits worsening steps, but the moves are selected from a modified part of the neighborhood. Hence, the neighborhood of s is not static. \gls{ts} algorithms are highly efficient and successfully used in a wide range of fields, including \gls{op}. It is, however, crucial to carefully choose a neighborhood relation and to use efficient caching and incremental updating schemes for the evaluation of candidate solutions \parencite{HolgerH2005StochasticSearch}. In \gls{ts} for multi-objective optimization, the central idea is to examine the neighborhood of a set of solutions, extract non-dominated solutions, and accept only some non-tabu solutions for inclusion in the approximate Pareto front.

\subsection{Evolutionary Algorithms}
\Glspl{ea} are meta-heuristics whose methodologies are based on Darwin’s theory of evolution, where an individual in a population (set of candidate solutions) is referred to as a chromosome. A gene represents the individual’s properties. \glspl{ea} follow the same schema as shown in Algorithm \ref{alg:ea} \parencite{Gonzalez2007HandbookMetaheuristics} below. The basic principle behind \glspl{ea} is the survival of the fittest, where a fitness function based on the objective function, constraints, or some quality measure is used to select individuals from the population. For each generation (iteration), individuals compete to produce offspring \parencite{Engelbrecht2007ComputationalEdition}. An \gls{ea} might use a crossover operator to recombine two or more individuals to produce new individuals for the next generation. A mutation operator might also be used to alter the gene (characteristics of an individual) of a chromosome. The used reproduction operators depend on the chosen solution representation and the problem formulation. For example, one-point crossover, uniform crossover, and flip mutation are commonly used for representing binary string solutions. In contrast, binary string encoding is typically used for knapsack problems \parencite{Gonzalez2007HandbookMetaheuristics}.

\begin{algorithm}
  \caption{General outline of evolutionary algorithms}\label{alg:ea}
  $P$ = apply $\tau$ on $G$ to generate $\mu$ individuals (the initial population);\\
    \While {termination criteria not met}{
        $P'$ = apply $\theta$ on $P$\Comment*[r]{selection}
        $P''$ = apply $\omega_r$ on $P'$; $r \in \{1,..,n operators\}$ \Comment*[r]{reproduction}
        $P$ = apply $\psi$ on $P$ and $P''$\Comment*[r]{replacement}

    }
  \end{algorithm}

\Glspl{ea} are popularly used across different industries, and Pareto-based \glspl{ea} are particularly suited for multi-objective optimization. Unlike traditional techniques such as \gls{ts}, \gls{sa}, and \gls{vnd}  that originally output a single local optimum, Pareto-based \glspl{ea} typically provide the whole set of Pareto optimal solutions in a single run, making them suitable for our problem domain. Examples of Pareto-based \glspl{ea} in literature include the \gls{nsga}, \gls{spea} and \gls{pma}.The performance of these algorithms relies on specifying a robust fitness function and estimating a good fitness-sharing parameter. The fitness-sharing parameter helps adjust an individual’s fitness based on the fitness of others. Furthermore, as in most population-based meta-heuristics, determining the initial population is important. If the initial population is not diverse, premature convergence might occur \parencite{Talbi2009Metaheuristics:Implementation}.

\subsection{Ant Colony Optimization}
\Gls{aoc} is a meta-heuristic that is part of swarm intelligence and inspired by ants. Artificial ants are designed to simulate the problem-solving behavior of ants in a colony. Ants coordinate their activities \textit{stigmergy}, an indirect communication form through modification of the environment. The idea behind ant algorithms is to use a form of artificial stigmergy to coordinate societies of artificial agents \parencite{Dorigo2018TheMetaheuristic}. An effective solution is found only through cooperation among many individuals in the colony. Inspired by the pheromones deposited by real ants, virtual ants are designed to modify numeric values (virtual pheromones) associated with different problem states. The sequence of pheromone values associated with problem states (pheromone trail) enables communication. Ants can also forget the pheromone trail history and focus on new promising search directions through an evaporation mechanism \parencite{Gonzalez2007HandbookMetaheuristics}.

Solutions are created incrementally by moving through available problem states and making stochastic decisions at each step. Additionally, many improved and efficient \gls{aoc} algorithms make use of local searches to improve the probability of an ant choosing a component and consequently improve the quality of the solution constructed by the ants \parencite{Stutzle2000MAX-MINSystem}. \Gls{aoc} can be applied to any combinatorial optimization problem for which a constructive heuristic can be defined. However, the problem must be mapped to a representation that artificial ants can use to build solutions \parencite{Dorigo2018TheMetaheuristic}. Specifically, the problem must be representable as a construction graph $G_c = (C, L)$, where the set $L$ fully connects the components $C$. The ants exploit $G_c$ to search for an optimal solution. Fortunately, knapsack problems can be represented as a construction graph by representing the set of items as the set of components and fully connecting them. Therefore, \glspl{aoc} algorithms can be applied to our problem domain. Nevertheless, the pheromone trails, heuristics information, and solution construction must be carefully considered for the \gls{moop}. Strategies for using \gls{aoc} on multi-objective problems include aggregating the objective functions and using one ant colony with one pheromone structure or using a different colony for each objective function and having multiple pheromone structures \parencite{Alaya2007AntProblems}.

\subsection{Bee Colony Optimization}
\Gls{bco} is a meta-heuristic that represents a type of swarm intelligence inspired by bees. Artificial agents are created by partially simulating the real-life behavior of bees. Such behaviors include nectar exploration, mating during flight, food foraging, waggle dancing, and division of labor. Bee colony-based optimization algorithms are mainly based on food foraging, nest site search, and mating in the bee colony \parencite{Talbi2009Metaheuristics:Implementation}.

The \gls{aoc} algorithm is based on nest site search behavior and consists of alternating forward and backward passes. Every artificial bee explores the search space during the forward pass. It applies a predefined number of moves that construct and improve the solution, thus yielding a new solution. After obtaining new partial solutions, the bees return to the nest and begin the backward pass in which all the artificial bees share information about their solutions \parencite{Teodorovic2009BeeBCO}. The bee whose solution has the highest fitness score is selected to form the next bee population.

\section{Designing Algorithms for Multi-Objective Problems}
In the above sections, we define our optimization problem as a combinatorial multi-objective problem. Solving \gls{moop} implies obtaining an approximation set of Pareto optimal solutions in such a way that the set fulfills the requirements of convergence to the Pareto front and uniform diversity  \parencite{Talbi2009Metaheuristics:Implementation}. Exact methods such as branch and bound algorithms, constraint programming, and dynamic programming are used for two-criteria optimization problems. However, such methods are better suited for small-scale problems. In research, optimization problems with more than three objectives are often classified as multi-objective problems. This is due to the added difficulty of handling a higher number of objectives. Unlike many objective problems, two-objective and three-objective problems can be comprehensively visualized by graphical means, which makes it easier for decision makers to analyze and make better decisions \parencite{Deb2013AnConstraints}. Heuristics methods are needed for this problem scale, and designing heuristics for \gls{moop} requires additional concepts. The following sections summarize the concepts typically required for designing algorithms for \gls{moop}.

\subsection{Fitness Assignments}
The fitness assignment measures the quality of a solution by assigning a scalar-valued fitness to a vector objective function. This procedure can be classified into scalar approaches, criterion-based approaches, dominance-based approaches, and indicator-based approaches.

\subsubsection{Scalar Approaches}
Scalar approaches typically transform the \gls{moop} into single-objective problems. A scalar approach frequently used in designing solutions for multi-objective optimization problems consists of aggregating the objective functions into a single function using either addition, multiplication, or any combination of arithmetic operations. This approach has the advantage of simplifying the objective space such that only a single objective needs to be optimized. However, in order to avoid one function dominating another, aggregating the functions requires behavioral knowledge of each objective function \parencite{CoelloCoello1999ATechniquesc}. The most common aggregation method is the weighted sum approach, which is defined as follows:

\begin{gather*}
   \Vec{f} = \sum_{i=1}^k w_i f_i, \ \text{where}\ w_i \geq 0\ \text{and}\ \sum_{i=1}^k w_i = 1
\end{gather*}

where $w_i$ are coefficients representing the objectives’ relative importance, which is usually unknown. The algorithm designer must solve the problem for different values of $w_i$ and decide on the appropriate value for $w_i$ based on their intuition. Constant multipliers $c_i$ are often introduced to further reflect the importance of each objective. This helps normalize the vector function in approximately the exact numerical values. Other popular scalar approaches found in the survey by Carlos et al. \parencite{CoelloCoello1999ATechniquesc} use goal programming (minimize or maximize the absolute deviation from target to objectives) and $\varepsilon$-constraint methods (considering the objectives bound by some allowable levels $\epsilon_i$). However, transforming a \gls{moop} into a single-objective problem is not always feasible. Ascribing a hierarchy of importance to the objectives is a crucial step in aggregating the function. In our problem domain, the objective function already represents a user preference (i.e., each objective function is mapped to a particular user preference). Ultimately, assigning a level of importance to each objective function defeats the optimization problem’s purpose because the objectives are not comparable.

\subsubsection{Criterion-Based methods}
Criterion-based methods are commonly used in population-based meta-heuristics (e.g., \glspl{ea} and \gls{aoc}). They conduct the search process by treating the various objectives separately and assigning them fitness values. This procedure usually occurs in parallel or sequentially. For example, parallel approaches are used in \gls{aoc} (P-\gls{aoc} \parencite{Doerner2004ParetoSelection}), where one ant colony tackles an objective. Sequential approaches search sequentially in a defined preference order; the order signifies the importance of each objective function \parencite{Fishburn1974ExceptionalSurvey}.

\subsubsection{Dominance-Based approaches}
Dominance-based (or Pareto-based) approaches use dominance and Pareto optimality to guide the search process. In a single run, such approaches can generate a diverse set of Pareto optimal solutions and Pareto solutions in the concave portions of the convex hull of feasible objective space \parencite{Talbi2009Metaheuristics:Implementation}. Most Pareto approaches use \glspl{ea}. Compared to scalar methods, Pareto-based fitness assignment evaluates the quality of a solution in relation to the whole population by applying ranking methods. Ranks are scalar values obtained using dominance relation techniques. The rank assigned to a solution is considered its fitness value.

\subsection{Diversity Preservation}\label{sec:diversitypreservation}
Initial population selection and biased sampling during a search in population-based meta-heuristics are crucial for maintaining diversity. Diversity-preserving methods must be considered when designing meta-heuristics for \gls{moop}; they generally penalize solutions that have high density in their neighborhoods. According to \parencite{Emmerich2018AMethods}, diversity preservation strategies can be classified into kernel, nearest neighbor, and histogram methods.

\textit{Kernel methods} Kernel methods define the neighborhood of a solution according to a kernel function that takes the distance between solutions as an argument. The kernel function is applied to all distances. For example, fitness sharing is popularly used in \glspl{ea} as it degrades the fitness of an individual using a sharing function $sh$. The sharing function depends on a constant $\sigma$ and the sum of the distance between individuals in the population. $\sigma$ represents the non-similarity threshold. Nearest neighbor methods estimate the density of a solution while taking into account the distance between a solution and its $k^{th}$ nearest neighbor. For example, \gls{nsga}-II uses crowding distance sorting to sort solutions within a rank. A crowding distance of an individual $i$ is illustrated in Figure \ref{fig:crowdeddistance_sorting}. The crowding distance can be pictured as a cuboid on the $i$ and its two nearest neighbors (left and right). Equation \ref{eq:3.4a} shows the formula used to find the crowding distance for $i$ in an objective $f_k$ from $F$ objectives; it is defined as the circumference between a solution and its left and right neighbors.

\begin{figure}
    \centering
    \includegraphics[width=8cm]{CrowdedDistanceSorting}
    \caption{Crowding distance sorting in \gls{nsga}-II}
    \label{fig:crowdeddistance_sorting}
\end{figure}

\begin{align}
    distance(i) = distance(i) + \frac{f_k(i+1) - f_k(i-1)}{f_k^{max} - f_k^{min}} \qquad \forall \ f_k \in F \label{eq:3.4a}
\end{align}

More diversity is obtained using solutions with high crowding distances. Histogram-based diversity-preserving approaches partition the search space into several hyper-grids that define the neighborhood. The density around a solution is estimated by the number of solutions in the same box of a grid \parencite{Talbi2009Metaheuristics:Implementation}. The technique used to measure the distance between solutions is essential for diversity preservation. Diversity in the decision space may be essential to improve the search for some problems; however, some only require diversity in the objective space.

\section{Comparative Analysis of Choice Algorithms}
So far in this chapter, we have extensively discussed different algorithmic approaches that are commonly used to solve combinatorial optimization problems. We have presented algorithms that are typically suited for \glspl{moop}. Through our analysis, we can conclude that using traditional techniques such as local search, tabu search, etc., will be more difficult to implement for our \gls{moop} because such techniques yield a single local optimum. A single-objective optimizer needs to be run multiple times when using such techniques. Additionally, good distribution (uniform diversity) is not guaranteed. Thus, a considerable amount of adaptation is required to use these approaches for our problem domain. In contrast, modern algorithms such as the \glspl{ea}, \gls{aoc}, and \gls{bco} are best suited for multiple objective problems because they can return the Pareto optimal set in a single run. They can also be easily decomposed to find the optimal solution for single objectives. Hence, they do not require more effort than necessary to be implemented for our problem domain.

It is impossible to implement all algorithms considered suitable for our problem domain in this thesis. Thus, we compare \glspl{ea} and \gls{aoc}. These choices are based on their popularity for solving \glspl{op}, multi-objective knapsack problems, and multi-objective problems in general.

\begin{table}[htpb]
  \caption[Comparison of choice algorithms]{Comparison of choice algorithms.}\label{tab:comparison_alg}
  \centering
  \begin{tabular}{|c| c c |}
    \toprule
       &Evolutionary Algorithm &Ant-Colony \\
    \midrule
      Computational time & \checkmark &  \\ \hline
      Applicability to problem domain & \checkmark & \\\hline
      Approximate Pareto front & \checkmark & \checkmark \\\hline
      Diversity Preserving & \checkmark & \checkmark \\\hline
      Applicable to large-sized objectives & & \checkmark \\\hline
      Easier to Implement & \checkmark & \\
    \bottomrule
  \end{tabular}
\end{table}

In table \ref{tab:comparison_alg}, \glspl{ea} and \glspl{aoc} are compared using the desired algorithmic properties listed in Section \ref{sec:alg_approaches} of this chapter. The capabilities of widely used \gls{ea} variants like \gls{nsga}-II, \gls{nsga}-III, \gls{spea}2 were also taken into account. These scores are based on evaluation results from \parencite{Lust2012TheApproach, Florios2010SolvingAlgorithms, Alaya2007AntProblems}. as multi-objective knapsack problems were used for evaluation in these studies. A checkmark is awarded when the algorithm has an advantage over the other in that criterion. For example, in comparison to \glspl{aoc}, \glspl{ea} have demonstrated faster computational time in solving multi-objective knapsack problems. However, it is unknown which of the two algorithms for approximating to the Pareto front works best. \gls{aoc} is specifically designed to solve path-search problems. A graph representation of the knapsack model must be constructed, which increases the implementation complexity of the \gls{aoc}. Unlike \gls{aoc}, a number of \gls{ea} variants can be used directly for our optimization problem without adaptation. Moreover, there are several frameworks focusing on implementing \glspl{ea} that significantly decrease the time needed for implementation.\\
We can conclude that an \gls{ea} is the best algorithmic approach for our study.

Item Combination For DestiRec/chapters/03_solution_development.tex


\lab{Pseudorandom Number Generators}{Pseudorandom Number Generators}
\label{lab:PRNG}

\objective{Learn about the strengths and weaknesses of a few pseudorandom number generators}

\section*{Random Numbers}
Lotteries, most board games, and statistics need random numbers.
In real life, we roll dice, take balls out of a bag, or spin a wheel.
Computers are, by nature, deterministic, meaning that they do exactly what they are told.
Because of this, random number generation on a computer can be difficult.
We can have a device measure a random process and use the data to generate random numbers,
but such sampling is often too slow and too expensive for practical use.
Pseudorandom number generators (PRNGs) are a common solution to this problem.
The numbers are not truly random, but they are based on a complex formula that makes them look ``random."
For convenient use, these generators must also run quickly.
The goal is to have something that is fast and looks random.

There are many different algorithms for developing pseudorandom numbers.
Robert R. Coveyou titled an article ``The generation of random numbers is too important to be left to chance."
There has been much study about different PRNGs.
This lab will cover Linear Congruential Generators.

\section*{Linear Congruential Generators}
Linear Congruential Generators (LCGs) are one of the oldest ways of generating random numbers.
The generator is defined by the recurrence relation:
$X_{n+1}=(a*X_n + c)$ mod $m$ where

\begin{itemize}
\item $X$ is a sequence of pseudorandom values
\item $m$ is the modulus, with $m>0$
\item $a$ is the multiplier, with $0<a<m$
\item $c$ is the increment, with $0\leq c<m$
\item $X_0$ is the seed, with $0\leq X_0 <m$
\end{itemize}

The $a$, $m$, $c$, and $X_n$ are integer constants.

\begin{problem}\label{LCG1}
Write an LCG that produces an array of pseudorandom numbers between $0.0$ and $1.0$.
Define your LCG to take the size of the array as an argument, and let $a$, $c$, $m$, and $seed$ be optional arguments.
For the purpose of this example, let $a=1103515245$, $c=12345$, $m=2^{31}-1$, and $seed=4329$ be the default values.
\end{problem}

\begin{problem}
Write an LCG that produces an array of pseudorandom numbers of integers between two input arguments.
Do it by calling your algorithm from problem \ref{LCG1} and multiplying it by the values and casting the array as an integer using \li{.astype()}.
Let the arguments be the size of the array and the two integers.
Let $a$, $c$, $m$, and $seed$ continue to be optional arguments.
\end{problem}

This algorithm is used as the default random number generator in Java and C++, and is still used in a wide variety of situations.
The length over which your random number generator repeats is called the period.
The period is at most $m$, but it may be shorter based on the values of $a$ and $c$.

\begin{figure}
\includegraphics[width=.4\textwidth]{PRNG1.png}
\caption{
The bitmap with $a=3$, $c=2$, $m=2^{16}$.
There is a clear pattern in the random numbers.}
\end{figure}

One easy way to ``see" if your generator is random is to look at a bitmap of the output.
In python, you will need to import matplotlib and use \li{.imshow()} to see a bitmap of the array produced by your LCG.
Resize your output to be $512 \times 512$ (you will need $512^2$ random numbers in your array).

\begin{problem}
For what values of $a$, $c$, and $m$ does your LCG have a visible pattern?

Look at the bitmap for the output of \li{np.random.rand(512, 512)}.
Can you see any patterns?
\end{problem}

\begin{comment}
According to the Hull-Dobell Theorem (TO DO: find a source), a LCG will have a full period if and only if,
1. $c$ and $m$ are relatively prime,
2. $a-1$ is divisible by all prime factors of $m$,
3. $a-1$ is a multiple of 4 if $m$ is a multiple of 4

\begin{problem}
Test values of $a$,$c$, and $m$ that fit these requirements.
\end{problem}
\end{comment}

\begin{comment}
\section*{Mersenne Twister}
(TO DO: decide how much of  this we want to keep) All numbers can be represented in bits as a base two number.
Computers are optimized to work with numbers in that manner.
The operators XOR, OR, and AND work on the bit representation of two numbers.

AND - if both numbers have a 1 in the ith place then the ith place is 1.
Otherwise the ith place is 0.

OR - if one or both numbers have a 1 in the ith place then the ith place is 1.
Otherwise the ith place is 0.

XOR - if only one of the two numbers has a 1 in the ith place then the ith place is 1.
If both or neither of the numbers has a 1 in the ith place, the ith place is 0.

In addition you can shift the bitwise number over a number of values.
For example, shifting 10100 to the right by one yields 1010 and shifting it to the left by one yields 101000.
This is really just division and multiplication by 2.
This can be done by $\ll$ and $\gg$ in python.

The Mersenne twister PRNG does a series of bitwise operations to generate random numbers.
The Random class in python uses the Mersenne twister algorithm.

\begin{problem}
Look at the bitmap for the of output of \li{np.random.rand(512, 512)}.
Can you see any patterns?
\end{problem}

\section*{Randomness Tests}
Many statistical tests have been devised to measure the quality of a random number generator.
One of these tests is the overlapping permutations test.
This test involves taking an arbitrarily large collection of sequences of five consecutive random numbers from the generator and finding the probability that one of the 120 possible permutated orderings occurs.
In a good PRNG, the 120 orderings should occur with equal probability.

To simplify this process, instead of considering a specific sequence of five consecutive random numbers, consider the argsort of this sequence.
For example: instead of considering how often the sequence $[103, 75, 4, 57, 9]$, or any permutation thereof, shows up, consider argsort([103, 75, 4, 57, 9])=[2, 4, 3, 1, 0]$ (Remember, argsort gives index of increasing values in the array).
In this sense, we can now look at the frequency with which the permutations of 0, 1, 2, 3, and 4 show up under argsort.

It is convenient to use the $plt.bar()$ command under $matplotlib$ to generate a Histogram of the number of times each permutation shows up in the collection of sequences.

\begin{problem}
Use the overlapping permutations test to see how random python's random number generator is compared to the LCG you wrote in problem 1.
Create a bar graph with 120 bins, one for each ordering, to view graphically the difference. (Hint: Consider using a dictionary to store all possible orderings)
\end{problem}

\end{comment}

\section*{Blackjack}
\begin{figure}
\includegraphics[width=\textwidth]{Blackjack_game_1.jpg}
\caption{Initial Round of a Blackjack game.}
\end{figure}

Blackjack is a card game that involves the use of randomness.
The game is simple.
The dealer deals the player and himself each two cards.
He flips over his first card so that the player can see it.
The player has to choose to take another card ("hit") or not ("stand").
If the player hits he gets another card and again has the choice to hit or stand.

The goal is to get your hand to be at or as close to 21 without going over.
Face cards are worth 10 points.
Aces can count either as 11 or 1.
The value of all other cards are equal to the number on the card.

Once the player has decided to stand the dealer flips over his second card and deals himself cards until his hand value is 17 or greater.

If the player's value goes above 21 he automatically loses.
If his value is 21 or below and the dealer has above 21 then the player wins.
If they both have 21 or under then the player with the hand of highest value wins.
If both hands have the same value, the game is a tie.

\section*{Shuffling Algorithms}
One use of PRNGs is to shuffle cards.
The main goal of these algorithms is to make the card order be random--so that no single player has an advantage based on order.
Often, as strange as it may seem, online gambling sites will post their shuffling algorithms online; the only things they do not post are their seed values.
Often the time in milliseconds from midnight is used as the seed value.

John von Neumann said, ``Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."
As seen in the first part of this lab, weak PRNGs are periodic and are predictable once a few outputs are known.
Now we will have you break Blackjack based on a weak PRNG.

\section*{Cracking Blackjack}
For these next problems you will need three files that are provided with this lab: BlackHard.py, BlackEasy.py, and bjCommon.py.
BlackHard.py and BlackEasy.py are programs that run games of Blackjack that use an LCG to shuffle the cards.
They generate 52 random numbers and then use the natural ordering of those numbers as the ordering of the cards.
The parameters for BlackEasy.py are $a=2521$, $c=13$, $m=2^{16}$.
For BlackHard.py they are $a=25214903917$, $c=11$, $m=2^{48}$.

\begin{warn}
Both BlackEasy.py and BlackHard.py use functions that are incompatible with ipython.
To run them, use \li{python <<filename>><<numberofgames>>} in the command line.
\end{warn}

BlackEasy.py uses a seed randomly generated between 0 and 10000000.
The seed for BlackHard.py is based on the time, using \li{ (int)(time.time())}, which is the number of seconds from the start of the epoch cast as an integer.
(This can be found in the time package).
Both programs will make a list of length \li{<<numberofgames>>}, where each element in the list is a shuffling of the deck.
During each round, the program will choose the next deck in your list generated.
Cards are popped off the deck one at a time: first one to the player, second one to the dealer, third one to the player, and one last one to the dealer.

Initially three cards are visible (the last of the dealer's is face down) so our algorithms will deal with these first three cards, and the ordering (player, dealer, player) will be very important.
After the first four cards are down the next cards are popped off in the order that they appear.

bjCommon.py contains several functions to help you with the game's mechanics.
Cards have a string representation ( '6diamond' for 6 of diamonds, 'Kclub' for king of clubs, 'Aheart' for ace of hearts, and so on) and a number representation that determines their natural ordering.
bjCommon.py has functions for generating the list of cards and converting arrays to and from the string and integer representation of cards.
Particularly useful is the function \li{shuffle}, which when given the number of games, $g$, the LCG parameters, and a seed value, returns the first $g$ decks (or games) in integer representation as $g$ arrays of 52 integers.

Your goal will be to do a sweep of seed values and cross check the decks produced by \li{shuffle} against the first three cards from several games, then be able to determine the order of cards for future rounds.

\begin{problem}\label{sweeps}

Create a function, \li{getSweepsEasy(games,n)}, which has as its parameters the number of games you selected to play in BlackEasy.py and a seed value.
The function needs to return an array of size $n\times games \times 52$, representing all possible seed values 0 through $n$ in the first dimension, the different shufflings that occur based on the number of games played in the second dimension, and the ordering of the 52 cards for each shuffle in the third dimension.
(Be sure to look at \li{bjCommon.shuffle} to help get the needed results)

What seed value $n$ would you use to make sure to cover all possible shufflings?
(Look at the parameters of the LCG in BlackEasy.py]).

\end{problem}

From problem \ref{sweeps}, using the right value for $n$ will get you the list of all possible initial shuffles, as well as the appropriate number of future hands depending on the games parameter.
Once we have the possible shufflings, we want a convenient way to match the output from BlackEasy.py with the output from problem \ref{sweeps}.
The function \li{bjCommon.findSeedMatch} provides us the means of comparing these two outputs.
It takes as parameters sweeps, game, and cardNames3; sweeps is the output from problem \ref{sweeps} (an $n \times games \times 52$ array), game is the round number, and cardNames3 is a 3-tuple of the names of the first three cards dealt out (using the naming notation mentioned above).

\begin{problem}

Create a function \li{crackBlackJack(sweeps, cardTuples)} to crack the shuffling algorithm of BlackEasy.py.
The parameter sweeps represents the output from problem \ref{sweeps}.
The parameter cardTuples is a list of 3-tuples from the 1st, 2nd, etc. rounds played.
It should return a subset of shuffles from sweeps whose shuffles match in each round to each 3-tuple in cardTuples.

Be sure to make use of \li{bjCommon.findSeedMatch} and \li{bjCommon.convertToName} to see the names associated to the orderings of cards.

\end{problem}

Keep in mind the key difference between BlackEasy.py and BlackHard.py is the seed that is used and the value $m$ which the shuffling algorithm mods out by for each shuffle.
BlackEasy.py has a small selection of seeds to choose from, while BlackHard.py uses a seed based on time, which can get pretty big.
While in BlackEasy.py you could easily find all possible seed values and the corresponding shuffles, in BlackHard.py you will need to know the approximate time you initiated the game.
This can be done using the \li{time.time()} function shortly after initializing BlackHard.py in python.

\begin{problem}

Create a function, \li{getSweepsHard(games, time, approx=120)}, which returns all possible shuffles for a range of seed values.
The parameter games is how many rounds you want to play (corresponding to different shuffles of a given seed value).
The time parameter is the approximate time you started the round of BlackHard.py.
The approx parameter will give a range of seed values (120 seconds before and after the approximate time you initiated the game).
It should return a $(2*approx) \times games \times 52$ array of possible shuffles, similar to problem \ref{sweeps}.

You should be able to run \li{crackBlackJack} using this output to help determine future rounds of BlackHard.py.

\end{problem}


\subsection{Luminosity and pile-up}

\textbf{Luminosity}

In beam–beam collisions, the event rate for a process is written as~\cite{Evans_2008}:
\begin{equation}
	N = \mathcal{L} \sigma
\end{equation}
where $\sigma$ is the cross section of the process, and $\mathcal{L}$ is the luminosity.
To study rare events, $\mathcal{L}$ must be as high as possible.
The luminosity only depends on the beam parameters as:
\begin{equation} \label{eq:lumi}
	\mathcal{L} = \frac{ N_{b}^{2} n f_{r} \gamma}{4\pi \epsilon_{n} \beta^{*}}
\end{equation}
in which $N_{b}$ represents the number of particles per bunch, $n$ denotes the number of bunches per beam,
$f_{r}$ is the revolution frequency, and $\gamma$ is relativistic $\gamma$ factor,
$\epsilon_{n}$ is the normalized transverse emittance and $\beta^{*}$ denotes the $\beta$ function at the collision point.
To reduce the beam-beam interaction effects, the bunches must have a crossing angle,
which produces a geometrical luminosity reduction factor $F$:
\begin{equation}
	F = 1 / \sqrt{1 + \left( \frac{\theta_{c}\sigma_{Z}}{2\sigma^{*}} \right) }
\end{equation}
where $\theta_{c}$ denotes the crossing angle at the interaction point, $\sigma_{Z}$ is the root mean square (RMS) bunch length
and $\sigma^{*}$ is the transverse RMS beam size at crossing point.

The luminosity expressed in Eq.~\ref{eq:lumi} is normally the instantaneous luminosity.
In fact the running conditions usually vary with time, so the luminosity can change as well.
To take into account the time dependence, integrated luminosity is invited, by integraling the instantaneous luminosity over time:
\begin{equation}
	L = \int \mathcal{L}(t) dt
\end{equation}
The unit of integrated luminosity we commonly use is $b^{-1}$ that satisfying $1 b^{-1} = 10^{24} cm^{-2}$.
Figure~\ref{fig:lumi_vs_time} shows integrated luminosity as a function of time delivered to ATLAS (green),
recorded by ATLAS (yellow), and certified to be good quality data (blue) during run-2 pp collisions.
For most physics analysis, the data with good quality (require to satisfy \textit{Good Run List}) is used.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figures/Detector/intlumivstimeRun2DQall.pdf}
  \caption{Integrated luminosity vs delivered month from 2015 to 2018 in ATLAS experiment.}
  \label{fig:lumi_vs_time}
\end{figure}

\textbf{Pile-up}

In collisions, multiple interactions can happen in one single bunch crossing, which is called ``\textit{pile-up}".
The variable $\left< \mu \right>$, representing the average number of interactions per bunch crossing that used to describe pile-up effect, is defined as:
\begin{equation}
    \left< \mu \right> = \frac{\mathcal{L}_{tot}\sigma}{f_{r}n_{bunch}}
\end{equation}
where $\mathcal{L}_{tot}$ is the instantaneous luminosity, $\sigma$ denotes the inelastic cross section,
$f_{r}$ represents the LHC revolution frequency and $n_{bunch}$ is the number of colliding bunches.
Usually, with increasing luminosity, the pile-up becomes more significant.
Figure~\ref{fig:run2_mu} shows the luminosity-weighted distribution of the mean number of interactions per crossing
for pp collision data from 2015 to 2018 (full run-2), the challenge of pile-up increased in each year.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figures/Detector/mu_2015_2018.pdf}
  \caption{Number of interactions per crossing weighted bt luminosity from 2015 to 2018 in ATLAS experiment.}
  \label{fig:run2_mu}
\end{figure}