\chapter{Experiment preparation}

\epigraph{\textit{On est trop souvent imprécis lorsqu'on fait une citation.}}{Quelqu'un, un jour.}

Generative part of all experiments

\section{Base Z cercle}

\begin{lstlisting}
def complex_cal(qc, statevector_sim):
    statevector_job = execute(qc, statevector_sim)
    statevector_result = statevector_job.result()
    psi = statevector_result.get_statevector()
    z0 = psi[0]
    z1 = psi[1]
    if z1.real != 0 or z1.imag != 0:
        z = z0/z1
        z = round(z.real, 2) + round(z.imag, 2) * 1j
    else:
        z = 0
    return z

init_q = QuantumRegister(1, 'q')
qc_cercle = QuantumCircuit(init_q)

tab_cercle = [[], []]
x_cercle = []
y_cercle = []
tab_temp = []
z0 = 0+0j
z1 = 0+0j
z = 0+0j

shots = 100
max_shots = 1
qc_cercle.h(init_q)
for w in range(max_shots):
    for i in range(shots):
        qc_cercle.rz(pi/(shots/8), init_q)
        z = complex_cal(qc_cercle, statevector_sim)
        if z != 0:
            tab_temp.append(z)
    qc_cercle.barrier()

    if (w + 1) % 5 == 0:
        print("Full circuit bloch :", w+1, "/", max_shots)

print("Fini!")

for i in tab_temp:
    iteration = tab_temp.count(i)
    if tab_cercle[0].count(i) < 1:
        tab_cercle[0].append(i)
        tab_cercle[1].append(iteration)

for i in range(len(tab_cercle[0])):
    x_cercle.append(tab_cercle[0][i].real)
    y_cercle.append(tab_cercle[0][i].imag)

print("Total of SV :", len(tab_temp))
\end{lstlisting}

\section{Generical functions}

\subsection{Qubit and variable preparation}
\begin{lstlisting}
init_q = QuantumRegister(1, 'q')
qc = QuantumCircuit(init_q)

tab = [[], []]
x = []
y = []
x_north = []
y_north = []
x_south = []
y_south = []
tab_temp = [[], [], []]
z0 = 0+0j
z1 = 0+0j
z = 0+0j
z_north = 0*0j
z_south = 0*0j

shots = 100   # Never change -> Concidere it as 1 full circuit
max_shots = 100   # Change in fonction of how many full block we want
\end{lstlisting}

\subsection{Transform spherical plan to 2d plan}

\begin{lstlisting}
def complex_cal(qc, statevector_sim):
    statevector_job = execute(qc, statevector_sim)
    statevector_result = statevector_job.result()
    psi = statevector_result.get_statevector()
    z0 = psi[0]
    z1 = psi[1]
    if z1.real != 0 or z1.imag != 0:
        z = z0/z1
        z = round(z.real, 2) + round(z.imag, 2) * 1j
        if np.abs(z0.real) >= 1.0 / np.sqrt(2):
            z_north = z0/z1
            z_north = round(z_north.real, 2) + round(z_north.imag, 2) * 1j
            z_south = 0
            return z, z_north, z_south
        if np.abs(z0.real) <= 1.0 / np.sqrt(2):
            z_south = z0/z1
            z_south = round(z_south.real, 2) + round(z_south.imag, 2) * 1j
            z_north = 0
            return z, z_north, z_south
    else:
        z = 0
        z_north = 0
        z_south = 0
    return z, z_north, z_south
\end{lstlisting}

\subsection{Data analyse for plan}

\begin{lstlisting}
for i in tab_temp[0]:
    iteration = tab_temp[0].count(i)
    if tab[0].count(i) < 1:
        tab[0].append(i)
        tab[1].append(iteration)

# the whole world
for i in range(len(tab[0])):
    x.append(tab[0][i].real)
    y.append(tab[0][i].imag)
# northern hemisphere
for i in range(len(tab_temp[1])):
    x_north.append(tab_temp[1][i].real)
    y_north.append(tab_temp[1][i].imag)
# southern hemisphere
for i in range(len(tab_temp[2])):
    x_south.append(tab_temp[2][i].real)
    y_south.append(tab_temp[2][i].imag)

print("Total of SV :", len(tab_temp[0]))
\end{lstlisting}

\section{Graph}

\begin{lstlisting}
plt.scatter(x_cercle, y_cercle, c=tab_cercle[1], s=1, cmap="coolwarm")
plt.scatter(x, y, c=tab[1], s=1, cmap="coolwarm")
plt.colorbar()
print("Number of different value : ", len(x))
\end{lstlisting}

\begin{lstlisting}
print("The whole world !")
gen_tab = [[], [], []]
zoom_in = 4

for i in range(len(x)):
    if (x[i] > -1.05 and x[i] < 2) and (y[i] > -1.05 and y[i] < 1.05):
        gen_tab[0].append(x[i])
        gen_tab[1].append(y[i])
        gen_tab[2].append(tab[1][i])

#plt.scatter(x_cercle, y_cercle, c=tab_cercle[1], s=2, cmap="coolwarm")
plt.scatter(gen_tab[0], gen_tab[1], c=gen_tab[2], s=2, cmap="coolwarm")
#plt.colorbar()
print("Number of different values in zoom : ", len(gen_tab[0]), "/", len(x))
\end{lstlisting}


\documentclass[12pt]{article}
\usepackage{theorem}
\usepackage{amsmath,amssymb,latexsym,xspace,float,multirow,fancyvrb,xr-hyper,xr}
\usepackage{subfigure,epsfig,url}
\usepackage[breaklinks=true]{hyperref}
\usepackage{amsmath,latexsym,epsfig}
\floatstyle{ruled}
\newfloat{Algorithm}{tb}{lox}
\floatname{Algorithm}{Algorithm}
\usepackage{paralist}
\usepackage{afterpage}
\usepackage{natbib}
\usepackage{color}

\newfloat{Algorithm}{tb}{lox}
\floatname{Algorithm}{Algorithm}

\def\bw{{\boldsymbol w}}
\def\balpha{{\boldsymbol \alpha}}
\def\bd{{\boldsymbol d}}
\def\be{{\boldsymbol e}}
\def\bzero{{\boldsymbol 0}}
\def\bx{{\boldsymbol x}}
\def\by{{\boldsymbol y}}
\def\bxi{{\boldsymbol \xi}}
\def\liblinear{{\sf LIBLINEAR}\xspace}

\begin{document}
\title{LIBLINEAR MKL Document}
\author{Ming-Hen Tsai
  \\ Ph.D student, Columbia University
  \\ mt2767@columbia.edu}
\maketitle
\section{Introduction to Multiple Kernel Learning SVM}
The original multiple kernel learning SVM has a dual form,
\begin{equation}
\label{eq:mkl_svm_dual}
\min_{\bd} \min_{\balpha} \frac{1}{2} \balpha^T Q \balpha + \gamma \balpha^T \balpha - \be^T \balpha
\end{equation}
, where
\begin{equation}
\label{eq:mkl_svm_dual_sum_kernel}
Q = \sum_{m=1}^M d_m Q_m
\end{equation}
, subject to
\begin{align}
\label{eq:mkl_svm_dual_eq_constraint}
\balpha^T \by = 0 \\
\sum_m \|d_m\| = 1
\end{align}
and
\begin{align}
\label{eq:mkl_svm_dual_ineq_constraint}
d_m \ge 0 \quad \forall m\\
0 \le \alpha_i \le U \quad \forall i \mbox{.}
\end{align}

L2-regularized L1-loss SVM has $U = C$ and $\gamma = 0$. While
L2-regularized L2-loss SVM has $U = \infty$ and $\gamma = \frac{1}{2C}$.

It has a corresponding primal form (without considering $\bd$),
\begin{equation}
\label{eq:mkl_svm_primal}
\min_{\bd} \min_{\bw,b} \frac{1}{2} \sum_m \frac{1}{d_m} \bw_m^T \bw_m + \sum_i \xi^p
\end{equation}
, subject to
\begin{align}
\label{eq:mkl_svm_primal_ineq_constraint}
\sum_m \|d_m\| = 1\\
d_m \ge 0 \quad \forall m\\
\xi_i \ge 0 \\
\xi_i \ge 1-y_i \sum_m \bw_m^T \phi_m(\bx_i) + b \quad \forall i \mbox{.}
\end{align}

The primal-dual correspondence is
\begin{equation}
\label{eq:primal_dual_correspondence_w}
\bw_m = d_m \sum_i y_i \alpha_i \phi_m(x_i)
\end{equation}
, and
\begin{equation}
\label{eq:primal_dual_correspondence_Q}
Q_m =
[y_1\phi_m(\bx_1)  y_2\phi_m(\bx_2) \ldots y_l\phi_m(\bx_l)]^T
[y_1\phi_m(\bx_1)  y_2\phi_m(\bx_2) \ldots y_l\phi_m(\bx_l)]
\end{equation}

For L2-regularized L1-loss SVM, $p=1$.
For L2-regularized L2-loss SVM, $p=2$.

\section{Dual Coordinate Descent for Multiple Kernel Learning SVM}

In practice, we can use a formulation without $b$, and obtaining similar performance.
If we want this $b$, we can add a dimension of all ones to all training instances $\bx_i$ to get a similar formula.
Details can be found in \liblinear document.

By not using $b$, we get a new primal formula that has
$b=0$ in \eqref{eq:mkl_svm_primal_ineq_constraint}
and will not have \eqref{eq:mkl_svm_dual_eq_constraint} in the dual form.

By letting $\bd$ as constants, we let the dual objective function as
$$ f(\balpha) = \frac{1}{2} \balpha^T Q \balpha + \frac{1}{2} \gamma \balpha^T \balpha - \be^T \balpha  $$
It has gradient
$$ \nabla f(\balpha) = Q \balpha + \gamma \balpha - \be \mbox{.} $$
In dimension $i$, it is
\begin{align}
\label{eq:gradient_one_dim}
\nabla_i f(\balpha) & = \sum_j \alpha_j Q_{ij} \balpha + \gamma \alpha_i  - 1 \\
                    &  \mbox{By \eqref{eq:primal_dual_correspondence_Q}} \\
                    & = \sum_j \alpha_j \sum_m d_m y_i y_j \phi_m(x_i) \phi_m(x_j) \balpha + \gamma \alpha_i  - 1 \\
                     & \mbox{By \eqref{eq:primal_dual_correspondence_w}} \\
                     & = y_i \sum_m w_m^T \phi_m(\bx_i) + \gamma \alpha_i -1 \mbox{.}
\end{align}

Let $\be_i$ be the vector with $i$-th dimension as one and all others zero.
Let $g(d) = f(\balpha + d\be_i)$.
\begin{equation}
\label{eq:second_order_opt}
\arg \inf_d g(d) =  \nabla_i f(\balpha) /(Q_{ii} + \gamma)
\end{equation}
  is the lowest point of the quadratic figure.

For notation convenience, we let $$\bw = [\bw_1^T \bw_2^T \ldots \bw_M^T]^T$$
and $$\bar{\bx_i} = [\phi_1(\bx_i)^T \phi_2(\bx_i)^T \ldots \phi_M(\bx_i)^T]^T \mbox{.}$$
So \eqref{eq:gradient_one_dim} becomes
\begin{equation}
\label{eq:gradient_one_dim_simplified}
\nabla_i f(\balpha)  = y_i \bw^T \bar{\bx_i} + \gamma \alpha_i  - 1 \mbox{.}
\end{equation}

Here comes a dual coordinate descent method for multiple kernel learning SVM in primal in Algorithm \ref{alg:dual-cd-mkl}.

Now, we can take $\bd$ into consideration. By fixing other parameters, $\bd$ can be solved by linear programming methods. Then, we can alternatively solve linear SVM and a linear programming problem. It is the core idea in \liblinear MKL.

\begin{Algorithm}
	\caption{A dual coordinate descent method for MKL SVM}
	\label{alg:dual-cd-mkl}
\begin{compactitem}
		\item Given $\balpha = \bzero$ and the corresponding $\bw= \sum_i y_i \alpha_i \bx_i$.
		\item While $\balpha$ is not optimal
			\begin{description}
				\item  Random choose instance $i$
            \begin{enumerate}[(a)]
          \item $G = y_i \bw^T \bar{\bx_i} -1 + \gamma\alpha_i$ by \eqref{eq:gradient_one_dim_simplified}
          \item \begin{equation*}
				  \hspace{-25pt}
				  PG = \begin{cases}
              \min(G,0) & \text{if $\alpha_i = 0$},\\
              \max(G,0) & \text{if $\alpha_i = U$},\\
              G & \text{if $0<\alpha_i < U$}
            \end{cases}
          \end{equation*}
        \item If $|PG| \neq 0$, \label{step:last}
          \begin{itemize}

           \item[] $\bar{\alpha}_i \leftarrow \alpha_i$
   		  \item[] $\alpha_i \leftarrow \min (\max (\alpha_i - G/(Q_{ii} + \gamma), 0),U )$ by \eqref{eq:second_order_opt}
					\item[]  $\bw_m \leftarrow \bw_m + d_m (\alpha_i - \bar{\alpha}_i) y_i \bx_i \quad \forall m$
          \end{itemize}

			\end{enumerate}
		\end{description}
	\end{compactitem}
\end{Algorithm}

\end{document}


\documentclass[journal,12pt,twocolumn]{IEEEtran}

\usepackage{setspace}
\usepackage{gensymb}

\singlespacing

\usepackage[cmex10]{amsmath}
%\usepackage{amsthm}
%\interdisplaylinepenalty=2500
%\savesymbol{iint}
%\usepackage{txfonts}
%\restoresymbol{TXF}{iint}
%\usepackage{wasysym}
\usepackage{amsthm}

\usepackage{mathrsfs}
\usepackage{txfonts}
\usepackage{stfloats}
\usepackage{bm}
\usepackage{cite}
\usepackage{cases}
\usepackage{subfig}

\usepackage{longtable}
\usepackage{multirow}

\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{steinmetz}
\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{verbatim}
\usepackage{tfrupee}
\usepackage[breaklinks=true]{hyperref}

\usepackage{tkz-euclide} %loads TikZ and tkz-base

\usetikzlibrary{calc,math}
\usepackage{listings}
    \usepackage{color}
    \usepackage{array}
    \usepackage{longtable}
    \usepackage{calc}
    \usepackage{multirow}
    \usepackage{hhline}
    \usepackage{ifthen}
    \usepackage{lscape}
\usepackage{multicol}
\usepackage{chngcntr}

\DeclareMathOperator*{\Res}{Res}

\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\renewcommand\thesubsubsection{\thesubsection.\arabic{subsubsection}}

\renewcommand\thesectiondis{\arabic{section}}
\renewcommand\thesubsectiondis{\thesectiondis.\arabic{subsection}}
\renewcommand\thesubsubsectiondis{\thesubsectiondis.\arabic{subsubsection}}

\hyphenation{op-tical net-works semi-conduc-tor}
\def\inputGnumericTable{}                                 %%

\lstset{
%language=C,
frame=single,
breaklines=true,
columns=fullflexible
}

\begin{document}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{problem}{Problem}
\newtheorem{proposition}{Proposition}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{example}{Example}[section]
\newtheorem{definition}[problem]{Definition}

\newcommand{\BEQA}{\begin{eqnarray}}
\newcommand{\EEQA}{\end{eqnarray}}
\newcommand{\define}{\stackrel{\triangle}{=}}
\bibliographystyle{IEEEtran}
\providecommand{\mbf}{\mathbf}
\providecommand{\pr}[1]{\ensuremath{\Pr\left(#1\right)}}
\providecommand{\qfunc}[1]{\ensuremath{Q\left(#1\right)}}
\providecommand{\sbrak}[1]{\ensuremath{{}\left[#1\right]}}
\providecommand{\lsbrak}[1]{\ensuremath{{}\left[#1\right.}}
\providecommand{\rsbrak}[1]{\ensuremath{{}\left.#1\right]}}
\providecommand{\brak}[1]{\ensuremath{\left(#1\right)}}
\providecommand{\lbrak}[1]{\ensuremath{\left(#1\right.}}
\providecommand{\rbrak}[1]{\ensuremath{\left.#1\right)}}
\providecommand{\cbrak}[1]{\ensuremath{\left\{#1\right\}}}
\providecommand{\lcbrak}[1]{\ensuremath{\left\{#1\right.}}
\providecommand{\rcbrak}[1]{\ensuremath{\left.#1\right\}}}
\theoremstyle{remark}
\newtheorem{rem}{Remark}
\newcommand{\sgn}{\mathop{\mathrm{sgn}}}
\providecommand{\abs}[1]{\left\vert#1\right\vert}
\providecommand{\res}[1]{\Res\displaylimits_{#1}}
\providecommand{\norm}[1]{\left\lVert#1\right\rVert}
%\providecommand{\norm}[1]{\lVert#1\rVert}
\providecommand{\mtx}[1]{\mathbf{#1}}
\providecommand{\mean}[1]{E\left[ #1 \right]}
\providecommand{\fourier}{\overset{\mathcal{F}}{ \rightleftharpoons}}
%\providecommand{\hilbert}{\overset{\mathcal{H}}{ \rightleftharpoons}}
\providecommand{\system}{\overset{\mathcal{H}}{ \longleftrightarrow}}
	%\newcommand{\solution}[2]{\textbf{Solution:}{#1}}
\newcommand{\solution}{\noindent \textbf{Solution: }}
\newcommand{\cosec}{\,\text{cosec}\,}
\providecommand{\dec}[2]{\ensuremath{\overset{#1}{\underset{#2}{\gtrless}}}}
\newcommand{\myvec}[1]{\ensuremath{\begin{pmatrix}#1\end{pmatrix}}}
\newcommand{\mydet}[1]{\ensuremath{\begin{vmatrix}#1\end{vmatrix}}}
\numberwithin{equation}{subsection}
\makeatletter
\@addtoreset{figure}{problem}
\makeatother
\let\StandardTheFigure\thefigure
\let\vec\mathbf
\renewcommand{\thefigure}{\theproblem}
\def\putbox#1#2#3{\makebox[0in][l]{\makebox[#1][l]{}\raisebox{\baselineskip}[0in][0in]{\raisebox{#2}[0in][0in]{#3}}}}
     \def\rightbox#1{\makebox[0in][r]{#1}}
     \def\centbox#1{\makebox[0in]{#1}}
     \def\topbox#1{\raisebox{-\baselineskip}[0in][0in]{#1}}
     \def\midbox#1{\raisebox{-0.5\baselineskip}[0in][0in]{#1}}
\vspace{3cm}
\title{Matrix Theory (EE5609) Challenging Problem}
\author{Arkadipta De\\MTech Artificial Intelligence\\AI20MTECH14002}
\maketitle
\newpage
%\tableofcontents
\bigskip
\renewcommand{\thefigure}{\theenumi}
\renewcommand{\thetable}{\theenumi}
\begin{abstract}
This document proves that $\vec{A^TA}$ has positive eigen values.
\end{abstract}
Download latex codes from
%
\begin{lstlisting}
https://github.com/Arko98/EE5609/tree/master/Challenge_5
\end{lstlisting}
%
\section{Problem}
Show that the eigen values of $\vec{A^TA}$ are positive.
\section{Proof}
Let, $\vec{A}$ is an arbitrary $m\times n$ matrix. Now consider the symmetric matrix $\vec{A^TA}$,
\begin{comment}

\begin{align}
\intertext{for any n dimensional vector $\vec{z}$,}
\vec{z^T}(\vec{A^TA})\vec{z} &= \vec{z^TA^T}\vec{Az}\\
\implies\vec{z^T}(\vec{A^TA})\vec{z} &= \vec{({Az})^T}(\vec{Az})\\
\implies\vec{z^T}(\vec{A^TA})\vec{z} &= \norm{\vec{Az}}^2 \geq0\label{eq1}
\intertext{From \eqref{eq1}, if $\vec{z} \not=0$, $\vec{A^TA}$ is positive definite, i.e}
\norm{\vec{Az}}^2 > 0
\intertext{Again, $\vec{A^TA}$ is positive semi-definite, if $\vec{z} = 0$,}
\norm{\vec{Az}}^2 = 0
\end{align}
Hence, $\vec{A^TA}$ is positive semi-definite if the columns of $\vec{A}$ are linearly dependent and $\vec{A^TA}$ is positive definite if columns of $\vec{A}$ are linearly dependent.\\
Again,
\begin{align}
\vec{({A^TA})^T} = \vec{(A^T)(A^T)^T} = \vec{A^TA}\label{eqSym}
\end{align}
Hence, $\vec{A^TA}$ is symmetric. As every eigen value of a Hermitian matrix is real and every symmetric matrix is Hermitian then $\vec{A^TA}$ (being a symmetric and hence Hermitian) has real eigen values.\\

\end{comment}
Let $\lambda$ be a (real) eigenvalue of $\vec{B}=\vec{A^TA}$ and let $\vec{x}$ be a corresponding real eigen-vector hence,
\begin{align}
\vec{Bx} = \lambda \vec{x}\label{eq2}
\intertext{Multiplying $\vec{x^T}$ in \eqref{eq2},}
\vec{x^TBx} &= \lambda \vec{x^T}\vec{x}\\
\implies\vec{x^TBx} &= \lambda \norm{\vec{x}}^2\\
\implies\vec{x^T(A^TA)x} &= \lambda \norm{\vec{x}}^2 \qqaud{\text{[$\because\vec{B}=\vec{A^TA}$]}}\\
\implies\vec{(x^TA^T)Ax} &= \lambda\norm{\vec{x}}^2\\
\implies\vec{(Ax)^T(Ax)} &= \lambda\norm{\vec{x}}^2\\
\implies\norm{\vec{Ax}}^2 &= \lambda\norm{\vec{x}}^2\label{eqFinal}
\intertext{In \eqref{eqFinal} as $\norm{\vec{Ax}}^2 > 0$ then,}
\lambda > 0
\end{align}
\begin{comment}

When $\vec{A^TA}$ is positive definite (i.e columns of $\vec{A}$ are linearly independent) then, the left hand side of \eqref{eqFinal} is positive as $\vec{A^TA}$ is positive-definite and $\vec{x}$ is a nonzero vector as it is an eigen-vector.\\
Also if $\vec{A}$ has linearly independent columns then $\vec{A^TA}$ will be invertible and hence a non-singular matrix, so $\norm{\vec{x}}$ cannot be zero in \eqref{eqFinal}. Since $\norm{\vec{Ax}}^2$ is positive, hence all eigen-values must be positive.\\

\end{comment}
Hence proved that all eigen values of $\vec{A^TA}$ are positive.
\end{document}


\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{natbib}
\usepackage{url}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\graphicspath{{img/}}
\usepackage{listings}
\usepackage{url}
\usepackage{parskip}
\usepackage{fancyhdr}
\usepackage{vmargin}
\setmarginsrb{3 cm}{2.5 cm}{3 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

\title{Lab Report on \\Image Enhancement Techniques.}								% Title
\author{Rabi Raj Khadka}								% Author
\date{June 27, 2017}											% Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\lhead{\thetitle}
\cfoot{\thepage}

\begin{document}
\begin{titlepage}
	\centering
   % \vspace*{0.5 cm}
    \includegraphics[scale = 0.3]{kheclogo.jpg}\\[1.0 cm]	% University Logo
    \textsc{\LARGE Khwopa Engineering College}\\[1.5 cm]	% University Name
	\textsc{\Large Course Code :BEG 475 IP}\\[0.5 cm]				% Course Code
	\textsc{\large Image Processing and Pattern recogntiion}\\[0.5 cm]				% Course Name
	\rule{\linewidth}{0.2 mm} \\[0.4 cm]
	{ \huge \bfseries \thetitle}\\
	\rule{\linewidth}{0.2 mm} \\[1.0 cm]

	% \texttt{Lab Report \#1}

	\rule{\linewidth}{0 mm} \\[1.0 cm]

	\begin{minipage}{0.4\textwidth}
		\begin{flushleft} \large
			\emph{Author:}\\
			\theauthor
			\end{flushleft}
			\end{minipage}~
			\begin{minipage}{0.4\textwidth}
			\begin{flushright} \large
			\emph{Roll  Number:} \\
			700324									% Your Student Number
		\end{flushright}
	\end{minipage}\\[2cm]

	{\large \thedate}\\[2 cm]

	\vfill

\end{titlepage}
\tableofcontents
\pagebreak
\section{Theory}
\subsection{Histogram Equalization}
Histogram equalization is the technique to change the histogram through the use of certain function into a histogram that is constant for a bright value. The probability of occurrence of gray level in an image is approximated by \\
$$P(r_k) = \frac{n_k}{N}$$  for k=0,1,2...L-1 \\
The discrete version of transformation is\\
$$ S_k = T(r_k) = \sum_{j=0}^k P_r(r_j) =  \sum_{j=1}^k\frac{n_j}{N}$$ for k=0,1,2,....L-1\\

Histogram equalization has  a disadvantage that it can generate only one type of output image. But with histogram specification, it can specify the shape of histogram that we wish the output image to have.It does not have to be uniform histogram.
\subsection{Histogram Specification}
\texttt{ Process for Histogram specification}
\begin{enumerate}
\item Obtain the transformation function T(r) by calculating the histogram equalized on the input image
$$ S = T(r) = \sum_{j=0}^r P_r(r_j) $$
\item Obtain the transformation function G(z) by calculating the histogram equalization of desired image
$$ Z = G(z) = \sum_{i=0}^z P_z(r_i) $$
\item Obtain the inverse transformation function $G^{-1}$\\
$$Z= G^{-1}(S) = G^{-1}[t(r)]$$
\item Obtain output image by applying the processed gray level from the inverse transformation function to all the pixels in the image.
\end{enumerate}
\subsection{Algorithm for Histogram Specification}
1. Start \\
2. Read source image and reference image\\
3. Break down the picture elements R, G, B of both color image and reference image\\
4. Make a histogram of each of the picture elements of the reference image\\
5. Assign the equalized histogram of the individual picture elements of the source image with reference to the histogram of the reference image\\
6. Merge the individual resultant individual picture elements to another variable ' histsp'  as $$ histsp(:,:,1) = outr; $$ $$ histsp(:,:,2) = outg; $$ $$ histsp(:,:,3) = outb; $$
7. show the specialized image 'histsp'\\
8. Stop
\pagebreak
\section{Code Description}
myimage = imread('\path{C\:\Users\rabiraj\Desktop\seventhsemester\ImageProcessingLab\img\one.jpg}');\\
reference = imread('\path{C\:\Users\rabiraj\Desktop\seventhsemester\ImageProcessingLab\img\two.jpg}');\\
myimage\_R=myimage(:,:,1);myimage\_G=myimage(:,:,2);myimage\_B=myimage(:,:,3);\\
reference\_R=reference(:,:,1);reference\_G=reference(:,:,2);reference\_B=reference(:,:,3);\\
hist\_myimage\_R=imhist(myimage\_R);\\
hist\_myimage\_G=imhist(myimage\_G);hist\_myimage\_B=imhist(myimage\_B);\\
hist\_reference\_R=imhist(reference\_R);\\
hist\_reference\_G=imhist(reference\_G);hist\_reference\_B=imhist(reference\_B);\\
outr =histeq(myimage\_R,hist\_reference\_R);\\
outg=histeq(myimage\_G,hist\_reference\_G);outb=histeq(myimage\_B,hist\_reference\_B);\\
histsp(:,:,1)=outr;histsp(:,:,2)=outg;histsp(:,:,3)=outb;\\
img\_lowcontrast=imadjust(rgb2gray(myimage),[0.0,1.0],[0.3,0.6]);  \\
img\_equalization = histeq(rgb2gray(myimage));\\
figure;\\
subplot(2,3,1);imshow(myimage);title('Original');\\
subplot(2,3,4);imhist(rgb2gray(myimage));title('original histogram');\\
subplot(2,3,2);imshow(img\_lowcontrast);title('lowcontrast image');\\
subplot(2,3,5);imhist(img\_lowcontrast);title('lowcontrast histogram');\\
subplot(2,3,3);imshow(img\_equalization);title('Equalized Image');\\
subplot(2,3,6);imhist(img\_equalization);title('Equalized histogram');\\
figure;\\
subplot(1,3,1);imshow(myimage);title('Original Image');\\
subplot(1,3,2);imshow(reference);title('Reference image');\\
subplot(1,3,3);imshow(histsp);title('Output Image');\\
figure;\\
subplot(3,3,1);plot(hist\_myimage\_R);title('Red Input');\\
subplot(3,3,2);plot(hist\_myimage\_G);title('Green Input');\\
subplot(3,3,3);plot(hist\_myimage\_B);title('Blue Input');\\
subplot(3,3,4);plot(hist\_reference\_R);title('Red Reference');\\
subplot(3,3,5);plot(hist\_reference\_G);title('Green Reference');\\
subplot(3,3,6);plot(hist\_reference\_B);title('Blue Reference');\\
subplot(3,3,7);plot(imhist(outr));title('output R');\\
subplot(3,3,8);plot(imhist(outg));title('output G');\\
subplot(3,3,9);plot(imhist(outb));title('output B');
%\lstinputlisting[language=Matlab]{labfive.m}
\pagebreak
\section{Result and Discussion}
The histogram of an image can be adjusted as per the user requirement. IN the image we have used, the point to be stretched is calculated by dividing the current positions of the begin and end point of the histogram by 255. By this we can adjust/stretch the image histogram. The histogram of the image can also equalized using the histeq() function\\

The histogram of one image is specified / merged with another image to form a specific image. The merged image of the first image and second image can be seen in the third one as in the output Figure 2.\\

\emph{Outputs}

\includegraphics[scale = 0.6]{output_labfive_1.png}\\
{\centering
\texttt{Figure 1:  Equalized Specification and its Histogram}\par}
\includegraphics[scale = 0.6]{output_labfive_2.png}\\
{\centering
\texttt{Figure 2:  Histogram Specification of two image}\par}
\includegraphics[scale = 0.6]{output_labfive_3.png}\\
{\centering
\texttt{Figure 3:  Histogram of  input images and output images used in Histogram Specification}\par}
\pagebreak
\section{Conclusion}
Hence, \\
We are familiarized with how the Histogram Stretching, Equalization and Specification of an image using the MATLAB application.
\end{document}


\section*{A1\hspace{1em}Example predictions by minutely network (section~\ref{sec:aao-comparison})}

\includegraphics[width=0.95\linewidth]{minutely-prediction-samples}

\section*{A2\hspace{1em}Spread prices by leg}

\includegraphics[width=0.99\linewidth]{spreads-legwise}

\section*{A3\hspace{1em}Spread prices by month}

\includegraphics[width=0.99\linewidth]{spreads-monthwise}

\section*{A4\hspace{1em}Classification network's configuration}

Hyperparameters:

\begin{itemize}
	\item Number of classes $C=3$
	\item Activation functions: Mostly ReLU (same as above). At the last layer the softmax function is used: $f(z)_j = \frac{e^{z_j}}{\sum_{i=1}^C e^{z_i}}$ where $j \in \{1,\dots,C\}$
	\item Loss function: Categorical cross entropy
	\item Optimization method: Adam (same as above)
	\item Weight initializations: Using \eqref{eq:glorot-initialization} (same as above)
	\item Network depth $L = 1$
	\item Network width $K = 30$
\end{itemize}

Furthermore, during training there is scaling applied to the loss function to reflect the imbalanced ratio of samples per category. Otherwise the network would likely learn to always predict the first category as it is overrepresented in the dataset as seen below.

\vspace{1em}

\includegraphics[width=0.9\linewidth]{classification-samples-per-category}