% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí
\setcounter{chapter}{4}
\chapter{DC Circuits}
%
In this experiment you will learn about circuits with DC sources, capacitors, and inductors.
%
\section{Preliminary}
%
In a previous experiment you constructed circuits with resistors and a battery. The resistors were connected either in series or in parallel. The battery served as a source producing a steady current. Such a source is called a \textbf{DC source}. Here DC stands for direct current, meaning that the current is always in the same direction along a circuit.

A circuit consisting exclusively of resistors and a DC source is not very interesting. Quantities like current and voltage in this circuit have fixed values over time. That is, when you flip a switch to complete the circuit, the current along the circuit jumps instantly to a non-zero value, and then does not change much. Similarly for the voltage across each resistor.

Besides resistors, you can have other components in a circuit with more complex physical properties like capacitance and inductance.
%
\subsection{Resistance and Resistors}
%
By now, electrical \textbf{resistance} should be familiar. The \textbf{SI unit} for electrical resistance is the \textbf{ohm}:
\begin{equation}
	1 \text{ ohm} = 1\;\Omega = 1 \text{ V/A}
\end{equation}
Here, V is volt (voltage) and A is ampere (current). A component in a circuit with a fixed amount of resistance is called a \textbf{resistor}. The mathematical symbol for resistance is $R$.
%
\subsection{Capacitance and Capacitors}
%
Another important property is \textbf{capacitance}. The \textbf{SI unit} for capacitance is the \textbf{farad}:
\begin{equation}
	1 \text{ farad} = 1 \text{ F} = 1 \text{ C/V}
\end{equation}
Here, C is coulomb (electric charge) and V is volt (voltage). In some ways, capacitance measures the amount of electric charge needed to sustain an electric potential difference (i.e. a voltage). The mathematical symbol for capacitance is $C$.

A component in a circuit with a fixed amount of capacitance is called a \textbf{capacitor}. You can think of a capacitor as two parallel plates of conducting material where equal-but-opposite amounts of electric charge can accumulate.
%
\subsection{Inductance and Inductors}
%
The last property is \textbf{inductance}, which is like a magnetic cousin of capacitance. The \textbf{SI unit} for inductance is the \textbf{henry}:
\begin{equation}
	1 \text{ henry} = 1 \text{ H} = 1 \text{ T}\cdot\text{m}^{2}\text{/A}
\end{equation}
Here, T is tesla (magnetic field), m$^{2}$ is square meter (area), and A is ampere (current). Recall that the tesla unit is equivalent to
\begin{equation}
    1 \text{ T} = 1 \text{ V} \cdot \text{s/m}^{2}
\end{equation}
Thus, the henry unit is equivalent to:
\begin{equation}
    1 \text{ H} = 1 \text{ V}\cdot\text{s/A}
\end{equation}
In some ways, inductance measures the amount of voltage that arises per unit rate of change of electric current with time. The mathematical symbol for inductance is $L$.

A component in a circuit with a fixed amount of inductance is called an \textbf{inductor}. You can think of an inductor as a solenoid coil with a given amount of loops, with each loop enclosing some amount of area.
%
\subsubsection{Non-Ideal Inductors}
%
An \textbf{ideal inductor} is a component in a circuit with \textbf{zero} electrical resistance and a desired amount of inductance. In practice, ideal inductors are usually not available and you usually use non-ideal inductors are used.

A \textbf{non-ideal inductor} is a component in a circuit with \textbf{non-zero} electrical resistance and non-zero amount of inductance. You can think of a non-ideal inductor as a resistor and an ideal inductor connected in series.
%
\subsection{Exponential Decay Function}
%
In a circuit with resistors and capacitors, or in a circuit with resistors and inductors, quantities like current and voltage do not always take steady values. That is because both capacitors and inductors can be thought of as storage containers for electric charge (or changing magnetic flux). These containers do not fill up instantly. Indeed, it can take a few seconds to fill-up a capacitor. The result is a behavior over time similar to an exponential decay curve.

Before discussing the behavior of quantities like current and voltage in circuits with capacitors and inductors in more detail, it will be good to review the \textbf{exponential decay} function:
\begin{equation}
    \exp(-t) = e^{-t}
\end{equation}
Here, $e$ is the \textbf{natural base}:
\begin{equation}
    e = 2.71828...
\end{equation}
When $t = 0$, the exponential decay function gives 1:
\begin{equation}
    \exp(0) = 1
\end{equation}
For large values of $t$, the exponential decay function approaches 0:
\begin{equation}
    \exp(-\infty) = 0
\end{equation}
In between $t = 0$ and $t \rightarrow \infty$ you have smaller and smaller values approaching zero.

The exponential decay function is an example of a function that is always positive, and always \textbf{decreasing} towards zero:
\begin{align}
    f(t) = \exp(-t) && 0 < f(t) \leq 1 && 0 \leq t < \infty
\end{align}
Multiplying the exponential decay function by a negative sign produces a function that is always negative, and always \textbf{increasing} towards zero:
\begin{align}
    g(t) = -\exp(-t) && -1 \leq g(t) < 0 && 0 \leq t < \infty
\end{align}
Another important combination is shifting vertically by 1, which gives a function that is always positive, and always \textbf{increasing} towards one:
\begin{align}
    h(t) = 1 - \exp(-t) && 0 \leq h(t) < 1 && 0 \leq t < \infty
\end{align}
Figures \ref{figure.05.f}, \ref{figure.05.g}, and \ref{figure.05.h} provide charts for these three functions.
%
\subsection{Resistor and Capacitor in Series}
%
A circuit with a resistor, a capacitor, and a DC source is called an \textbf{RC circuit}. In the simplest RC circuit, the resistor and capacitor are connected in series to the DC source via a particular switch.
%
\subsubsection{Charging the Capacitor}
%
When the switch is on, and the circuit is complete, the DC source pushes charges out into the circuit in the form of a current. This current causes positive electric charges to accumulate on one of the terminals of the capacitor, and negative electric charges on the other terminal of the capacitor. But the amount of electric charge $Q$ on the capacitor does not increase indefinitely: It settles on a maximum value $Q_{\infty}$. The particular manner in which the amount of \textbf{electric charge} on the capacitor increases with time is an example of an \textbf{exponential} increase:
\begin{equation}
    Q(t) = Q_{\infty} \left[ 1 - \exp\left(-\frac{t}{\tau_{C}}\right) \right]
    \label{eq.05.RC.q.charging}
\end{equation}
Here $Q_{\infty}$ is the amount of charge accumulated on the capacitor after an infinite amount of time, and $t$ correspond to the amount of time after the switch has been opened (the switch is opened at $t = 0$). The amount of \textbf{current} corresponds to the rate of change of the electric charge with respect to time:
\begin{equation}
    I(t) = I_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.i.charging}
\end{equation}
For a capacitor with capacitance $C$, the amount of \textbf{voltage} $V_{C}$ across the \textbf{capacitor} is directly proportional to the amount of electric charge accumulated on the capacitor:
\begin{equation}
    V_{C}(t) = \frac{Q(t)}{C} = V_{\infty} \left[ 1 - \exp\left(-\frac{t}{\tau_{C}}\right) \right]
    \label{eq.05.RC.vC.charging}
\end{equation}
The constant of proportionality is the inverse of the capacitance.

The \textbf{voltage} $V_{R}$ across the \textbf{resistor} is directly proportional the the amount of current, via Ohm's law:
\begin{equation}
    V_{R}(t) = R I(t) = V_{\infty} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.vR.charging}
\end{equation}
Here, $V_{\infty}$ is related to $Q_{\infty}$ and/or $I_{0}$ via
\begin{eqnarray}
    V_{\infty} = \frac{Q_{\infty}}{C} = I_{0} R
\end{eqnarray}
The value of $V_{\infty}$ should correspond to the steady voltage across the DC source.

As you can see from (\ref{eq.05.RC.q.charging}), (\ref{eq.05.RC.i.charging}), and (\ref{eq.05.RC.vC.charging}), the amount of charge, current and voltage related to a capacitor all involve exponential functions. The constant $\tau_{C}$ is known as the \textbf{capacitive time constant}. It has units of time (seconds). The value of $\tau_{C}$ acts as a \textbf{time scale} for the change in values that occur. The same time scale appears in all three quantities.

In an RC circuit, the value of $\tau_{C}$ depends on how much resistance $R$ and capacitance $C$ you have:
\begin{equation}
    \tau_{C} = R C
    \label{eq.05.tauC}
\end{equation}
You can check that, in fact, by multiplying something with ohm units by something with farad units you get something with second units:
\begin{equation}
    1 \text{ ohm} \cdot 1 \text{ F} = \left(1 \text{ V}\cdot\text{ s/C}\right) \cdot \left(1 \text{ C/V}\right) = 1 \text{ s}
\end{equation}
Since the exponential function is a mathematical function that changes very fast, the current will take noise-level values after a time corresponding to about 5 capacitive time constants.
%
\subsubsection{Discharging the Capacitor}
%
After some time with the switch on, the amount of charge on the capacitor becomes almost constant (close to $Q_{\infty}$), the amount of voltage across the capacitor also becomes almost constant (close to $V_{\infty}$), and the current through the circuit becomes almost zero.

Upon opening the circuit by setting the switch off, the DC source stops supporting the charge accumulated on the capacitor, and that amount of charge begins to leave the capacitor. That is, the capacitor now is producing the current! The amount of charge on the capacitor follows a particular manner:
\begin{equation}
    Q(t) = Q_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.q.discharging}
\end{equation}
Here $Q_{0}$ is the amount of charge at the moment that the switch is turned off. The electric current is given by
\begin{equation}
    I(t) = - I_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.i.discharging}
\end{equation}
This behavior is very similar to the behavior of the current (\ref{eq.05.RC.i.charging}) while the capacitor is charging, except that the negative sign indicates the current is in the opposite direction, since the charge is leaving the capacitor. The voltage $V_{C}$ across the \textbf{capacitor} can, again, be found from the amount of electric charge:
\begin{equation}
    V_{C}(t) = \frac{Q(t)}{C} = V_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
    \label{eq.05.RC.vC.discharging}
\end{equation}
The capacitive time constant appears again, and also dictates the time scale for the decrease of the charge, current and voltage across the capacitor during the discharging event. The voltage $V_{R}$ across the \textbf{resistor} can, again, be found from the amount of electric current:
\begin{equation}
    V_{R}(t) = R I(t) = - V_{0} \exp\left(-\frac{t}{\tau_{C}}\right)
\end{equation}
Just as before, there is a relation between $Q_{0}$, $I_{0}$, and $V_{0}$:
\begin{equation}
    V_{0} = \frac{Q_{0}}{C} = I_{0} R
\end{equation}
The value of $V_{0}$ should correspond to the voltage across the capacitor just before the switch is opened.
%
\subsection{Resistor and Inductor in Series}
%
A circuit with a resistor, an inductor, and a DC source is called an \textbf{RL circuit}. In the simplest RL circuit, the resistor and inductor are connected in series to the DC source via a particular switch.

An \textbf{ideal inductor} is an inductor that has \textbf{zero electrical resistance}. In practice, the inductors that you will use in these experiments have an amount of resistance that cannot be ignored and has to be taken into account. One way to do this is to think of a \textbf{non-ideal inductor} as consisting of a resistor and an ideal inductor connected in series:
\begin{equation}
    \text{non-ideal inductor} = \text{resistor} + \text{ideal inductor in series}
\end{equation}
Thus, an RL circuit with one resistor with resistance $R$ and one non-ideal inductor with resistance $r$ and inductance $L$ in series is equivalent to an RL circuit with \textbf{two} resistors and one ideal inductor in series. Let $V_{0}$ correspond to the steady voltage produced by the DC source in the RL circuit. Then, since the circuit is in series, the amount of steady voltage from the DC source must be equivalent to the sum of voltages across the two resistors and the ideal inductor:
\begin{equation}
    V_{0} = V_{R}(t) + V_{r}(t) + V_{L}(t)
\end{equation}
Here, $V_{R}$ is the voltage across the main resistor, $V_{r}$ is the voltage across the resistor within the non-ideal inductor, and $V_{L}$ is the voltage across the ideal inductor. The problem is that you can directly measure $V_{R}$, but not $V_{L}$. Instead, measuring the voltage across the inductor gives the non-ideal total $V_{N} = V_{r} + V_{L}$. The other problem is that $V_{L}$ is what you really want, so $V_{r}$ has to be subtracted from $V_{N}$:
\begin{equation}
    V_{L}(t) = V_{N}(t) - V_{r}(t)
\end{equation}
Although an inductor does not accumulate electric charge like a capacitor, the behavior of electric current and voltage across an inductor in an RL circuit also involves \textbf{exponential} functions. Whereas in an RC circuit the current becomes zero for large time values after closing the switch, in an RL circuit the current rises to a steady value:
\begin{equation}
    I(t) = I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.i.rise}
\end{equation}
The \textbf{voltage} $V_{R}$ across the main \textbf{resistor} is given by Ohm's law:
\begin{equation}
    V_{R}(t) = R I(t) = R I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.vR}
\end{equation}
The \textbf{voltage} $V_{r}$ across the resistor within the non-ideal inductor is also given by Ohm's law:
\begin{equation}
    V_{r}(t) = r I(t) = r I_{\infty} \left[ 1 - \exp\left(- \frac{t}{\tau_{L}}\right) \right]
    \label{eq.05.RL.vr}
\end{equation}
The \textbf{voltage} $V_{L}$ across the \textbf{ideal inductor} is given by
\begin{equation}
    V_{L}(t) = V_{0} - V_{R}(t) - V_{r}(t) = V_{0} \exp\left(- \frac{t}{\tau_{L}}\right)
    \label{eq.05.RL.vL}
\end{equation}
Here $I_{\infty}$ and $V_{0}$ are related via
\begin{equation}
    V_{0} = I_{\infty} \left(R + r\right)
\end{equation}
Instead of $\tau_{C}$, you now have $\tau_{L}$ which corresponds to the \textbf{inductive time constant}. Just like $\tau_{C}$, the value of $\tau_{L}$ depends on the total amount of resistance and also on the inductance you have in the circuit:
\begin{equation}
    \tau_{L} = \frac{L}{R + r}
    \label{eq.05.tauL}
\end{equation}
You can check that, in fact, by dividing something with henry units by something with ohm units you get something with second units.
%
\section{Experiment}
%
You did experiments with both RC and RL circuits.
%
\subsection{RC Circuits}
%
For RC circuits there are two kinds of experiments: the \textbf{charging} event and the \textbf{discharging} event. In each experiment you measured three quantities:
\begin{itemize}
    \item the \textbf{voltage} across the \textbf{resistor}, $V_{R}(t)$;
    \item the \textbf{current} flowing between the resistor and the capacitor, $I(t)$; and
    \item the \textbf{voltage} across the \textbf{capacitor}, $V_{C}(t)$.
\end{itemize}
For the \textbf{charging event}, the data collection was started with the switch off (i.e. incomplete circuit) and shortly after the switch was turned on. You should analyze the \textbf{current} and the \textbf{voltage across the resistor} for such events.

For the \textbf{discharging event}, the data collection was started with the switch on (i.e. complete circuit) and shortly after the switch was turned off. You should analyze the \textbf{voltage across the capacitor} for such events.

There are many resistors and capacitors available. Each time the resistance or the capacitance changes, the time constant $\tau_{C}$ will also change.
%
\subsection{Non-Ideal Inductors}
%
You need to take into account the electrical resistance of the inductor used because it is non-ideal. In order to obtain the resistance of the inductor, you use a circuit with the inductor and the DC source (an L DC circuit) and measure the current through the circuit and the voltage across the inductor.

The solenoid inductors that are available come with a metallic core that can be inserted inside the solenoid. It is good to check that the resistance of the non-ideal inductor is not affected by using the metallic core.

When two resistors are connected in series, the equivalent resistance is the sum of the individual resistances. In a similar way, you can check that connecting two non-ideal inductors in series yields an equivalent non-ideal inductor with a resistance corresponding to the sum of the resistances of each non-ideal inductor.
%
\subsection{RL Circuits}
%
For RL circuits, all the experiments involved closing the switch after the data collection was started. You measured
\begin{itemize}
    \item the \textbf{voltage} across the resistor, $V_{R}(t)$;
    \item the \textbf{current} flowing between the resistor and the non-ideal inductor, $I(t)$; and
    \item the \textbf{voltage} across the non-ideal inductor, $V_{N}(t)$.
\end{itemize}
Because the inductive time constants are so small, the data acquisition needs to be activated with the trigger feature.

The inductors come with a \textbf{metallic core}. Each experiment is done twice: Once without the core, and once with the core. The effect of the core is to change the inductance of the inductor.

There are many resistors, and many ways to connect inductors of the same type. Each time the resistance or the inductance changes, the time constant $\tau_{L}$ will also change.
%
\section{Analysis}
%
The common feature of $f(t)$, $g(t)$, and $h(t)$ above is that they all settle on steady values for infinite time after $t = 0$. In an experiment, you do not have an infinite amount of time, so a relevant question is: how long corresponds to infinite time? Since you are using imperfect sensors to measure current and voltage, after some time of decreasing values towards zero, there will be a point where measurements are not distinguishable from noise.

Consider the following function:
\begin{equation}
    A(t) = A_{0} \exp\left(- \frac{t}{\tau}\right)
\end{equation}
At $t = 0$, you have
\begin{equation}
    A(0) = A_{0}
\end{equation}
Thus, $A_{0}$ correspond to the amount of $A$ present at $t = 0$. The value of $A$ after one unit of $\tau$ is:
\begin{equation}
    A(\tau) = A_{0} \exp\left(-1\right) = 0.3679 \cdot A_{0}
\end{equation}
That is, about 37\% of the starting value. After two units of $\tau$ you have:
\begin{equation}
    A(2\tau) = A_{0} \exp\left(-2\right) = 0.1353 \cdot A_{0}
\end{equation}
That is, about 14\% of the starting value. After three units of $\tau$ you have:
\begin{equation}
    A(3\tau) = A_{0} \exp\left(-3\right) = 0.0498 \cdot A_{0}
\end{equation}
That is, about 5\% of the starting value. After four units of $\tau$ you have:
\begin{equation}
    A(4\tau) = A_{0} \exp\left(-4\right) = 0.0183 \cdot A_{0}
\end{equation}
That is, about 2\% of the starting value. After five units of $\tau$ you have:
\begin{equation}
    A(5\tau) = A_{0} \exp\left(-5\right) = 0.0067 \cdot A_{0}
\end{equation}
That is, about 0.67\% of the starting value. Five units of $\tau$ is a good rule of thumb. In principle, the quantity that is being measured will continue decreasing in value, but in practice those small values cannot be reliably measured. If you have an estimate of the amount of $\tau$, then from the time the decay begins you should keep data until after $5 \tau$ of time has passed.
%
%
\subsection{RC Circuits: Charging Events}
%
In a charging even both the voltage across the resistor and the current decay exponentially. Here are some steps to follow:
%
\subsubsection{Visualize $V_{R}$ and $I$}
%
Make two scatter charts:
\begin{itemize}
    \item Voltage across the resistor in the vertical axis, and time in the horizontal axis.
    \item Current in the vertical axis, and time in the horizontal axis.
\end{itemize}
You might want to add exponential fits, although at this stage they would most likely not be appropriate. See Figure \ref{figure.05.run.1.vR.full} for an example.
%
\subsubsection{Truncate the part before closing circuit}
%
Before the exponential fit can be made meaningful, you need to truncate the part of the data before the switch is closed. Looking at the columns, it should be obvious when the values for $V_{R}$ and $I$ suddenly take large values. See Figure \ref{figure.05.run.1.vR.truncated} for an example after truncation.
%
\subsubsection{Truncate the long tail}
%
It is very likely that after removing the part of the data before closing the circuit, the exponential fit might still not be appropriate. If the decay is relatively quick, and the voltage or current has a long segment where it is just zero, that long tail section will skew the fit process and render incorrect results. For this reason, it is good to only keep a time segment that is about $5\tau_{C}$ long. For example, after truncation in Figure \ref{figure.05.run.1.vR.truncated}, the decay begins around $t = 1.85$ seconds. For this particular run, the expected value of the time constant is $\tau_{C} = 0.250$ seconds. Thus,
\begin{equation}
    1.85 \text{ s} + 5 \tau_{C} = 3.10 \text{ s}
\end{equation}
All the data after $t = 3.10$ seconds should be truncated also. For good measure, I am keeping everything up to $t = 3.20$ seconds. See Figure \ref{figure.05.run.1.vR.no.tail} for an example.
%
\subsubsection{Extract the experimental value of $\tau_{C}$}
%
After truncating the initial and long tail parts, the exponential fit should be appropriate for the data. The exponential fit is given in the form
\begin{equation}
    a \exp(-bx)
\end{equation}
The value of $b$ corresponds to the inverse of the time constant:
\begin{equation}
    b = \frac{1}{\tau_{C}}
\end{equation}
Thus, the observed value of the time constant follows from the inverse of $b$:
\begin{equation}
    \text{Observed } \tau_{C} = \frac{1}{b}
\end{equation}
You should get a value from the $V_{R}$ chart, and another value from the $I$ chart. Both values should be consistent with each other.
%
\subsection{RC Circuits: Discharging Events}
%
In the discharging event, only the voltage across the capacitor follows an exponential decay. The steps are similar:
\begin{enumerate}
    \item Visualize the data with a scatter chart with the voltage across the capacitor in the vertical axis, and time in the horizontal axis.
    \item Truncate the part before opening the circuit.
    \item Truncate the long tail and keep close to $5\tau_{C}$ after the time the decay begins.
    \item Extract the experimental value of $\tau_{C}$ from the fit equation.
\end{enumerate}
The value of $\tau_{C}$ for the discharging even should be consistent with the values for the charging event.
%
\subsection{RL Circuits: Resistance of Inductors}
%
Before dealing with the inductive time constant experiments, you have to determine how much electrical resistance does the non-ideal inductors that are available have. Just like for resistors, in order to obtain resistance you measure current and voltage data over time. Using
\begin{equation}
    r = \frac{V_{r}(t)}{I(t)}
\end{equation}
should provide the observed value of the resistance of the non-ideal inductor over time. This value should be steady and almost constant, so take a time average to get the best estimate.

For two non-ideal inductors in series, you should find that the resistance is close to double the resistance for a single non-ideal inductor in series. This is consistent with the rule
\begin{equation}
    R_{\text{eq}} = R_{1} + R_{2}
\end{equation}
For a single non-ideal inductor, you should find a resistance close to 4.2 ohms. For two non-ideal inductors, you should find a resistance close to 8.5 ohms.
%
\section{My Data}
%
...
%
\section{Your Data}
%
...
%
\newpage
\section{Your Report}
%
...
%
\newpage
\section{Tables}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|r|r|r|r|}
            \hline
            Run & $R$ (ohm) & $C$ (F) & Expected $\tau_{C}$ (s) & Observed $\tau_{C}$ (s) & P.D. (\%) \\
            \hline
            1.1 & 10 & 0.025 & 0.2500 & 0.2950 & 17.9941 \\
            1.2 & 10 & 0.025 & 0.2500 & 0.3033 & 20.1201 \\
            3.1 & 51 & 0.025 & 1.2750 & 1.4327 & 12.3659 \\
            3.2 & 68 & 0.025 & 1.7000 & 1.8904 & 11.1976 \\
            5.1 & $2.2 \times 10^{4}$ & $10^{-5}$ & 0.2200 & 0.2674 & 21.5362 \\
            5.2 & $4.7 \times 10^{4}$ & $10^{-5}$ & 0.4700 & 0.5495 & 16.9044 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for $\tau_{C}$ from $V_{R}$ (charging)}
\end{table}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|r|r|r|r|}
            \hline
            Run & $R$ (ohm) & $C$ (F) & Expected $\tau_{C}$ (s) & Observed $\tau_{C}$ (s) & P.D. (\%) \\
            \hline
            1.1 & 10 & 0.025 & 0.2500 & 0.2950 & 17.9941 \\
            1.2 & 10 & 0.025 & 0.2500 & 0.2994 & 19.7605 \\
            3.1 & 51 & 0.025 & 1.2750 & 1.4265 & 11.8850 \\
            3.2 & 68 & 0.025 & 1.7000 & 1.8939 & 11.4082 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for $\tau_{C}$ from $I$ (charging)}
\end{table}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|r|r|r|r|}
            \hline
            Run & $R$ (ohm) & $C$ (F) & Expected $\tau_{C}$ (s) & Observed $\tau_{C}$ (s) & P.D. (\%) \\
            \hline
            2.1 & 10 & 0.025 & 0.2500 & 0.2618 & 4.7120 \\
            2.2 & 10 & 0.025 & 0.2500 & 0.2625 & 4.9869 \\
            4.1 & 51 & 0.025 & 1.2750 & 1.3680 & 7.2933 \\
            4.2 & 68 & 0.025 & 1.7000 & 1.8149 & 6.7578 \\
            6.1 & $2.2 \times 10^{4}$ & $10^{-5}$ & 0.2200 & 0.2674 & 16.5501 \\
            6.2 & $4.7 \times 10^{4}$ & $10^{-5}$ & 0.4700 & 0.5495 & 15.6337 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for $\tau_{C}$ from $V_{C}$ (discharging)}
\end{table}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|}
            \hline
            Component & Resistance (ohm) \\
            \hline
            Single inductor without metallic core & 4.244 \\
            Single inductor with metallic core & 4.247 \\
            Two inductors in series without metallic core & 8.522 \\
            Two inductors in series with metallic core & 8.526 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for resistance of non-ideal inductors}
\end{table}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|r|r|r|r|}
            \hline
            Run & $R+r$ (ohm) & $L$ (H) & Expected $\tau_{L}$ (s) & Observed $\tau_{L}$ (s) & P.D. (\%) \\
            \hline
            1 & 14.24 & $5 \times 10^{-3}$ & $3.5112 \times 10^{-4}$ & $3.1990 \times 10^{-4}$ & $-8.8932$ \\
            3 & 18.52 & $10^{-2}$ & $5.3996 \times 10^{-4}$ & $5.5432 \times 10^{-4}$ & $2.6608$ \\
            5 & 9.24 & $5 \times 10^{-3}$ & $5.4113 \times 10^{-4}$ & $4.7664 \times 10^{-4}$ & $-11.9161$ \\
            7 & 13.52 & $10^{-2}$ & $7.3964 \times 10^{-4}$ & $6.9252 \times 10^{-4}$ & $-6.3712$ \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for $\tau_{L}$ from $V_{L}$ (without metallic core)}
\end{table}
%
\begin{table}[ht!]
    \begin{center}
        \begin{tabular}{|l|r|r|r|}
            \hline
            Run & $R+r$ (ohm) & Observed $\tau_{L}$ (s) & Ratio with result not using metallic core \\
            \hline
            2 & 14.24 & $1.5244 \times 10^{-3}$ & 4.7652 \\
            4 & 18.52 & $2.3148 \times 10^{-3}$ & 4.1759 \\
            6 & 9.24 & $2.1692 \times 10^{-3}$ & 4.5510 \\
            8 & 13.52 & $3.0488 \times 10^{-3}$ & 4.4024 \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results for $\tau_{L}$ from $V_{L}$ (with metallic core)}
\end{table}
%
\newpage
\section{Figures}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/f.pdf}
    \caption{Function $f(t)$}
    \label{figure.05.f}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/g.pdf}
    \caption{Function $g(t)$}
    \label{figure.05.g}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/h.pdf}
    \caption{Function $h(t)$}
    \label{figure.05.h}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-full.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.full}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-truncated.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.truncated}
\end{figure}
%
\begin{figure}[ht]
    \centering
    \includegraphics[scale=0.74]{image/05-RC-RL/run-1-vR-no-tail.pdf}
    \caption{Run 1: $V_{R}(t)$}
    \label{figure.05.run.1.vR.no.tail}
\end{figure}


\section{Filtering Approach}

\begin{frame}<handout:0>{Filtering Approach}{Workflow}
    \begin{center}
        \resizebox {\textwidth} {!} {
            {\tiny
                \begin{tikzpicture}[node distance = 1.5cm, auto]
                    \node [block] (sod) {sensors or devices};
                    \node [block, right of=sod, node distance=6cm, text width=2cm] (extract) {Extract last subsequence from Q of size $w$, $Q[t-w,t]$};
                    \node [block, draw=blue, right of=extract, node distance=4cm, text width=2cm, color=white] (filter) {Time series filter};
                    \node [decision, draw=blue, below of=filter, node distance=1.5cm, color=white] (filterdecide) {$Q[t-w,t]$ can pass?};
                    \node [block, below of=filterdecide, node distance=1.5cm, text width=2cm, color=white] (nnc) {Time series classificator};
                    \node [decision, below of=nnc, node distance=1.5cm, color=white] (decide) {$Q[t-w,t]$ classifiable?};
                    \node [block, left of=decide, node distance=3cm, color=white] (sleeps) {Sleep for $s$ time};
                    \node [block, below of=decide, node distance=1.5cm, text width=2cm, color=white] (action) {Trigger event that $Q[t-w,t]$ has been classified and sleep for $w$ time};

                    \path [line,dashed] (sod) -- node (ctss) {Continuous time series stream $Q$} (extract);
                    \path [line] (extract) -- node {$Q[t-w,t]$} (filter);
                \end{tikzpicture}
            }
        }
    \end{center}
\end{frame}

\begin{frame}<handout:0>{Filtering Approach}{Workflow}
    \begin{center}
        \resizebox {\textwidth} {!} {
            {\tiny
                \begin{tikzpicture}[node distance = 1.5cm, auto]
                    \node [block] (sod) {sensors or devices};
                    \node [block, right of=sod, node distance=6cm, text width=2cm] (extract) {Extract last subsequence from Q of size $w$, $Q[t-w,t]$};
                    \node [block, draw=blue, right of=extract, node distance=4cm, text width=2cm] (filter) {Time series filter};
                    \node [decision, draw=blue, below of=filter, node distance=1.5cm] (filterdecide) {$Q[t-w,t]$ can pass?};
                    \node [block, below of=filterdecide, node distance=1.5cm, text width=2cm, color=white] (nnc) {Time series classificator};
                    \node [decision, below of=nnc, node distance=1.5cm, color=white] (decide) {$Q[t-w,t]$ classifiable?};
                    \node [block, left of=decide, node distance=3cm, color=white] (sleeps) {Sleep for $s$ time};
                    \node [block, below of=decide, node distance=1.5cm, text width=2cm, color=white] (action) {Trigger event that $Q[t-w,t]$ has been classified and sleep for $w$ time};

                    \path [line,dashed] (sod) -- node (ctss) {Continuous time series stream $Q$} (extract);
                    \path [line] (extract) -- node {$Q[t-w,t]$} (filter);
                    \path [line] (filter) -- (filterdecide);
                \end{tikzpicture}
            }
        }
    \end{center}
\end{frame}

\begin{frame}<handout:0>{Filtering Approach}{Workflow}
    \begin{center}
        \resizebox {\textwidth} {!} {
            {\tiny
                \begin{tikzpicture}[node distance = 1.5cm, auto]
                    \node [block] (sod) {sensors or devices};
                    \node [block, right of=sod, node distance=6cm, text width=2cm] (extract) {Extract last subsequence from Q of size $w$, $Q[t-w,t]$};
                    \node [block, draw=blue, right of=extract, node distance=4cm, text width=2cm] (filter) {Time series filter};
                    \node [decision, draw=blue, below of=filter, node distance=1.5cm] (filterdecide) {$Q[t-w,t]$ can pass?};
                    \node [block, below of=filterdecide, node distance=1.5cm, text width=2cm, color=white] (nnc) {Time series classificator};
                    \node [decision, below of=nnc, node distance=1.5cm, color=white] (decide) {$Q[t-w,t]$ classifiable?};
                    \node [block, left of=decide, node distance=3cm] (sleeps) {Sleep for $s$ time};
                    \node [block, below of=decide, node distance=1.5cm, text width=2cm, color=white] (action) {Trigger event that $Q[t-w,t]$ has been classified and sleep for $w$ time};

                    \path [line,dashed] (sod) -- node (ctss) {Continuous time series stream $Q$} (extract);
                    \path [line] (extract) -- node {$Q[t-w,t]$} (filter);
                    \path [line] (filter) -- (filterdecide);
                    \path [line] (filterdecide) -| node [near start] {no} (sleeps);
                    \path [line,dashed] (sleeps) -| (ctss);
                \end{tikzpicture}
            }
        }
    \end{center}
\end{frame}

\begin{frame}{Filtering Approach}{Workflow}
    \begin{center}
        \resizebox {\textwidth} {!} {
            {\tiny
                \begin{tikzpicture}[node distance = 1.5cm, auto]
                    \node [block] (sod) {sensors or devices};
                    \node [block, right of=sod, node distance=6cm, text width=2cm] (extract) {Extract last subsequence from Q of size $w$, $Q[t-w,t]$};
                    \node [block, draw=blue, right of=extract, node distance=4cm, text width=2cm] (filter) {Time series filter};
                    \node [decision, draw=blue, below of=filter, node distance=1.5cm] (filterdecide) {$Q[t-w,t]$ can pass?};
                    \node [block, below of=filterdecide, node distance=1.5cm, text width=2cm] (nnc) {Time series classificator};
                    \node [decision, below of=nnc, node distance=1.5cm] (decide) {$Q[t-w,t]$ classifiable?};
                    \node [block, left of=decide, node distance=3cm] (sleeps) {Sleep for $s$ time};
                    \node [block, below of=decide, node distance=1.5cm, text width=2cm] (action) {Trigger event that $Q[t-w,t]$ has been classified and sleep for $w$ time};

                    \path [line,dashed] (sod) -- node (ctss) {Continuous time series stream $Q$} (extract);
                    \path [line] (extract) -- node {$Q[t-w,t]$} (filter);
                    \path [line] (filter) -- (filterdecide);
                    \path [line] (filterdecide) -- node {yes} (nnc);
                    \path [line] (filterdecide) -| node [near start] {no} (sleeps);
                    \path [line] (nnc) -- (decide);
                    \path [line] (decide) -- node {no} (sleeps);
                    \path [line,dashed] (sleeps) -| (ctss);
                    \path [line] (decide) -- node {yes} (action);
                    \path [line,dashed] (action) -| (ctss);
                \end{tikzpicture}
            }
        }
    \end{center}
\end{frame}

\begin{frame}{Statistical measures}
    \begin{block}{Sample variance \cite{chan1983algorithms}}
        $VAR(Q) = \frac{1}{n}\sum \limits_{i=1}^{n} (q_i - \mu)^2$
    \end{block}
    \begin{block}{Length normalized complexity estimate \cite{batista2011complexity}}
        $LNCE(Q) = \frac{1}{n-1}\sqrt[2]{\sum \limits_{i=1}^{n-1} (q_i - q_{i + 1})^2}$
    \end{block}
\end{frame}


\documentclass[hyperpdf,bindnopdf,twocolumn]{hepthesis}

\usepackage{url, relsize, booktabs, ccaption, braket}
\usepackage{maybemath,xspace,setspace,fancyvrb,fancybox}
\usepackage{a4wide,url,relsize,underscore}
\usepackage[colorlinks=true,bookmarks=true]{hyperref}

%=============================================
\usepackage{slashed} % Feynman slash notation
\usepackage{cancel} % alternative for slash
\usepackage{hep} % hepunits and hepnames by insectnation dude! 2007. hepnames comes from hepparticles
\usepackage{genmisc} % macro for slashed, braket, and normal ordered
%=============================================

\newcommand{\hepunits}{\texttt{hepunits}\xspace}
\newcommand{\texcmd}[1]{\texttt{\char`\\#1}}

\begin{document}
    \paragraph{Slash Notation}
    \[ \left( i\slashed{\partial} - m\right) \psi(x) = 0\]
    \[ \left( i\cancel{\partial} - m\right) \psi(x) = 0\] % used in 8.323S11

    \paragraph{hepunits SI}

    \begin{table}[ht]
        \centering
        \begin{tabular}{ll}
            \toprule
            Unit command & Example \\

            \midrule
            Lengths & \\
            \texcmd{nm} & \unit{1.0}{\nm} \\
            \texcmd{micron} & \unit{1.0}{\micron} \\
            \texcmd{mm} & \unit{1.0}{\mm} \\
            \texcmd{cm} & \unit{1.0}{\cm} \\

            \midrule
            Times & \\
            \texcmd{ns} & \unit{1.0}{\ns} \\
            \texcmd{ps} & \unit{1.0}{\ps} \\
            \texcmd{fs} & \unit{1.0}{\fs} \\
            \texcmd{as} & \unit{1.0}{\as} \\

            \midrule
            Rates & \\
            \texcmd{mHz}   & \unit{1.0}{\mHz} \\
            \texcmd{Hz}    & \unit{1.0}{\Hz} \\
            \texcmd{kHz}   & \unit{1.0}{\kHz} \\
            \texcmd{MHz}   & \unit{1.0}{\MHz} \\
            \texcmd{GHz}   & \unit{1.0}{\GHz} \\
            \texcmd{THz}   & \unit{1.0}{\THz} \\

            \midrule
            Misc. & \\
            \texcmd{mrad} & \unit{1.0}{\mrad} \\
            \texcmd{gauss} & \unit{1.0}{\gauss} \\

            \bottomrule
        \end{tabular}
        \caption{List of non-HEP specific units provided by \hepunits}
        \label{tab:normunits}
    \end{table}

    \begin{table}[ht]
        \centering
        \begin{tabular}{ll}
            \toprule
            Unit command & Example \\
            \midrule
            Luminosities & \\
            \texcmd{invcmsqpersecond} & \unit{1.0}{\invcmsqpersecond} \\
            \texcmd{invcmsqpersec} & \unit{1.0}{\invcmsqpersec} \\
            \texcmd{lumiunits} & \unit{1.0}{\lumiunits} \\

            \midrule
            Cross-sections & \\
            \texcmd{barn} & \unit{1.0}{\barn} \\
            \texcmd{invbarn} & \unit{1.0}{\invbarn} \\
            \texcmd{nanobarn}    & \unit{1.0}{\nanobarn} \\
            \texcmd{invnanobarn} / \texcmd{invnb} & \unit{1.0}{\invnanobarn} \\
            \texcmd{picobarn}    & \unit{1.0}{\picobarn} \\
            \texcmd{invpicobarn} / \texcmd{invpb} & \unit{1.0}{\invpicobarn} \\
            \texcmd{femtobarn}    & \unit{1.0}{\femtobarn} \\
            \texcmd{invfemtobarn} / \texcmd{invfb} & \unit{1.0}{\invfemtobarn} \\
            \texcmd{attobarn}    & \unit{1.0}{\attobarn} \\
            \texcmd{invattobarn} / \texcmd{invab} & \unit{1.0}{\invattobarn} \\

            \bottomrule
        \end{tabular}
        \caption{List of HEP-specific units provided by \hepunits}
        \label{tab:hepunits}
    \end{table}

    \begin{table}[ht]
        \centering
        \begin{tabular}{ll}
            \toprule
            Unit command & Example \\
            \midrule
            \eV-based units & \\
            \texcmd{eV} & \unit{1.0}{\eV} \\
            \texcmd{inveV} & \unit{1.0}{\inveV} \\
            \texcmd{eVoverc} & \unit{1.0}{\eVoverc} \\
            \texcmd{eVovercsq} & \unit{1.0}{\eVovercsq} \\
            \texcmd{meV} & \unit{1.0}{\meV} \\
            \texcmd{keV} & \unit{1.0}{\keV} \\
            \texcmd{MeV} & \unit{1.0}{\MeV} \\
            \texcmd{GeV} & \unit{1.0}{\GeV} \\
            \texcmd{TeV} & \unit{1.0}{\TeV} \\
            \texcmd{minveV} & \unit{1.0}{\minveV} \\
            \texcmd{kinveV} & \unit{1.0}{\kinveV} \\
            \texcmd{MinveV} & \unit{1.0}{\MinveV} \\
            \texcmd{GinveV} & \unit{1.0}{\GinveV} \\
            \texcmd{TinveV} & \unit{1.0}{\TinveV} \\
            \texcmd{meVoverc} & \unit{1.0}{\meVoverc} \\
            \texcmd{keVoverc} & \unit{1.0}{\keVoverc} \\
            \texcmd{MeVoverc} & \unit{1.0}{\MeVoverc} \\
            \texcmd{GeVoverc} & \unit{1.0}{\GeVoverc} \\
            \texcmd{TeVoverc} & \unit{1.0}{\TeVoverc} \\
            \texcmd{meVovercsq} & \unit{1.0}{\meVovercsq} \\
            \texcmd{keVovercsq} & \unit{1.0}{\keVovercsq} \\
            \texcmd{MeVovercsq} & \unit{1.0}{\MeVovercsq} \\
            \texcmd{GeVovercsq} & \unit{1.0}{\GeVovercsq} \\
            \texcmd{TeVovercsq} & \unit{1.0}{\TeVovercsq} \\

            \bottomrule
        \end{tabular}
        \contcaption{List of HEP-specific units provided by \hepunits (cont.)}
        \label{tab:hepunits2}
    \end{table}

    \section{hepnames}

\end{document}


\subsection{Comparison: GRASP vs BRKGA}

In this section we are going to compare the performance of both metaheuristic algorithms applied to the assignment problem.\\
In order to do that, we are first going to choose the best parameters for each algorithm using the large set of problem instances described previously to execute several times each algorithm. The procedure consists of executing the same subset of samples drawn from the large set of problem instances for different proposed values of each parameter tested. The executions can be performed in different computers since the time is not important, only the objective function. The only caveat, is that all parameter values have to solve the same set of instances, since we use the average of objective functions. Otherwise the results would not be coherent from one parameter value to another. We record the objetive function for each execution and compute its average for each parameter value. Then we plot its evolution. We choose the parameter that produces the minimum objective function average.\\
Finally, we will use the best parameter values for each algorithm, to  compare the performance of both algorithm solving the same problem instance.

\subsubsection{Tuning GRASP parameters}

For the parameters of the GRASP algorithm, we have tested the $\alpha$, the $maxIterations$ of the main loop and the $failedIterations$ for the final and more intensive local search. The results of the tests are shown in figure~\ref{fig_grasp_params} on page~\pageref{fig_grasp_params} and figure~\ref{fig_grasp_brkga_params} on page~\pageref{fig_grasp_brkga_params}.

\begin{figure}[h!]
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-alpha.png}
\caption{GRASP Parameter $\alpha$}\label{fig1a}
\end{subfigure}\hfill
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-maxiter.png}
\caption{GRASP Parameter $maxIterations$ }\label{fig1b}
\end{subfigure}\vfill
\caption{Average objective function for different (\subref{fig1a}) $\alpha$ and (\subref{fig1b}) $maxIterations$ values of the GRASP model}
\label{fig_grasp_params}
\end{figure}

\pagebreak

\subsubsection{Tuning BRKGA parameters}

For the parameters of the BRKGA algorithm, we have tested the number of generatons ($generations$), the number of individuals in the population ($population$), the inheritance probability ($inheritance$), the proportion of elite individuals in each generation ($eliteprop$) and the proportion of mutant individuals in each generation ($mutantprop$). The results of the tests are shown in figure~\ref{fig_grasp_brkga_params} on page~\pageref{fig_grasp_brkga_params}, figure~\ref{fig_brkga_params} on page~\pageref{fig_brkga_params} and  figure~\ref{fig_brkga_params2} on page~\pageref{fig_brkga_params2} .\\

\begin{figure}[h!]
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-lsiteration.png}
\caption{GRASP Parameter $failedIterations$ }\label{fig1c}
\end{subfigure}
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-mutantprop.png}
\caption{BRKGA Parameter $mutantprop$ }\label{fig2e}
\end{subfigure}\vfill
\caption{Average objective function for different (\subref{fig1c}) $failedIterations$ of the GRASP model and (\subref{fig2e}) $mutantprop$ values of the BRKGA model}
\label{fig_grasp_brkga_params}
\end{figure}

\begin{figure}[H]
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-generation.png}
\caption{ Parameter $generations$}\label{fig2a}
\end{subfigure}\hfill
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-population.png}
\caption{Parameter $population$ }\label{fig2b}
\end{subfigure}\vfill
\caption{Average objective function for different (\subref{fig2a}) $generations$ and (\subref{fig2b}) $population$ values for the BRKGA model}
\label{fig_brkga_params2}
\end{figure}

\begin{figure}[H]
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-inheritance.png}
\caption{Parameter $inheritance$ }\label{fig2c}
\end{subfigure}%
\begin{subfigure}[b]{.49\linewidth}
\centering
\includegraphics[width=0.8\linewidth]{./img/best-eliteprop.png}
\caption{Parameter $eliteprop$ }\label{fig2d}
\end{subfigure}\vfill
\caption{Average objective function for different (\subref{fig2c})$inheritance$ and (\subref{fig2d}) $eliteprop$ values for the BRKGA model }
\label{fig_brkga_params}
\end{figure}

\subsubsection{Comparative results of meta-heuristics performance}

Finally, we execute the same problem instance from the large set with both GRASP and BRKGA models. The selected problem instance is the following: \textbf{i-ng-60-4096-2560-24h-16mxP-4mxc-10mxH-1mnH-3Cnt-20180109\_08-04-50394.dat }

\begin{table}[h!]
  \centering
  \begin{tabular}{ m{5cm}  c   }

  	\textbf{GRASP}
	\begin{itemize}
		\item $\alpha$ = 0.25
		\item $maxIterations$ = 10
		\item $failedIterations$ = 4
	\end{itemize}

	\textbf{BRKGA}
	\begin{itemize}
		\item $generations$ = 12
		\item $population$ = 200
		\item $inheritance$ = 0.8
		\item $eliteprop$ = 0.1
		\item $mutantprop$ = 0.15
	\end{itemize}

	&

  	\begin{minipage}{\textwidth}
	%\begin{figure}[h!]
	%\centering
	\begin{subfigure}[b]{.8\linewidth}
	%\centering
	\includegraphics[width=0.8\linewidth]{./img/metah_comparison_objfunc.png}
	\end{subfigure}
	\end{minipage}

	 \\

  \end{tabular}
  \captionof{figure}{Objective function evolution by GRASP and BRKGA models using the best parameter setup.}\label{meta_comparison}
\end{table}

In the figure~\ref{meta_comparison} we observe that it takes the GRASP almost two more hours than BRKGA to finish. However, it finds a better local optimum (3190) than BRKGA(3209), except that both models find a local optimum around 3200 and the optimum is 2560.
The evolution of the objective function for the GRASP model shows a series of steps, that are combinations of the result of the Randomized Greedy constructive algorithm and then the Localsearch (which in most cases does not improve the solution). Then, around 2 hours from the beginning the objective function of the GRASP model starts to decrease. This is where the final intensive Localsearch algorithm is improving the solution (from the best pure Greedy or randomized Greedy constructive result). Because of the construction of the graph, the last Localsearch seems to improve from the last iteration of the Grasp ( Constructive plus Local search) but in fact it starts from the pure Greedy result at the very beginning. The final Localsearch does 36 iterations, starting at the best incumbent 3225 and decreasing slowly from 3222 to finally get an objective function value of 3190.

As we can observe in the chart, the BRKGA model finds the a local optimum in the fourth generation, but as it is setup to do twenty generations, it continues for 30 more minutes. This is caused by the fact that we have tested the parameters in isolation. We have not taken into account their interactions and strange results can appear like this early optimal finding of the BRKGA. An improvement that could be implemented is, as is done in the intensive localsearch, to introduce a limited number of non improving iterations upon which the algorithm stops.
Looking at the diversity for each breed of individuals of the BRKGA model, we find that it starts with a rate of 30\% (61 different fitness values out of 200 individuals), increases to 41\% in the third generation then decreases to around 10\% and stays there. In the last generations it reaches 17\%, but the objective function stays the same as in the third generation where it finds the local optimum 3209.

In terms of intensification we can say that the final Localsearch of the GRASP algorithm does a good job, as well as the mating in the BRKGA's decoder. However the lightweight Localsearch during the GRASP iterations hasn't found improvements.
In terms of diversification, this problem instance hasn't yield very impressive results. For example, the GRASP starts from 9 different constructive phases but they are close in terms of objective function. Moreover, the randomized constructive phases do not improve the pure Greedy approach so the space exploration capabilities of GRASP are not exploited as they could be.

\pagebreak


\subsection{\enabled\ and the Module System}
\myframe{\hfill \enabled\ and the Module System }
{
Remember I said \enabled\ doesn't commute with substitution?
\vspace{45pt}

Let me also say: \\
\hfill
 the Module System is implemented as   substitution.

\vspace{45pt}
}

\subsection{Liveness Properties: Proving Diamonds}
\myframe{proving things about \tla\ specs: \hfill liveness proofs}
{
For some lifeness property $P$,  the thing to prove is generally:
\vspace{25pt}
\begin{theorem}[Liveness]
\begin{center}
$ \Box (Spec\ \Rightarrow\  \Diamond\, P) $
\end{center}
\end{theorem}

\vspace{75pt}
}

\myframe{proving things about \tla\ specs: \hfill liveness proofs}
{
For some liveness property $P$,  the thing to prove is generally:
\vspace{25pt}
\begin{theorem}[Liveness]
\begin{center}
$\Box (Init \wedge \Box\, [Next]_V  \wedge \kw{WF}_V (Next) \  \Rightarrow \ \Diamond\, P)$
\end{center}
\end{theorem}

\vspace{75pt}
}

\myframe{proving things about \tla\ specs: \hfill liveness proofs}
{
For some liveness property $P$,  the thing to prove is generally:
\vspace{25pt}
\begin{theorem}[Liveness]
\begin{center}
$\Box (Init \wedge \Box\, [Next]_V  \wedge \kw{WF}_V (Next) \  \Rightarrow \ \Diamond\, P)$
\end{center}
\end{theorem}
\vspace{20pt}
{\color{Maroon} Question:} \\
\hfill How does one prove a $\Diamond$ ?
\vspace{27pt}
}

\myframe{proving things about \tla\ specs: \hfill liveness proofs}
{
For some liveness property $P$,  the thing to prove is generally:
\vspace{25pt}
\begin{theorem}[Liveness]
\begin{center}
$\Box (Init \wedge \Box\, [Next]_V  \wedge \kw{WF}_V (Next) \  \Rightarrow \ \Diamond\, P)$
\end{center}
\end{theorem}
\vspace{20pt}
{\color{Maroon} Question:} \\
\hfill How does one prove  $\Box( A \Rightarrow \Diamond B)$ ?
\vspace{27pt}
}

\myframe{proving things about \tla\ specs: \hfill proving leads-to}
{
\hspace{-18pt} {\color{Maroon}There are three rules that `make' a $\Diamond$:}
\vspace{15pt}
\footnotesize
\begin{rl}[$\kw{WF}$ -- and similarly for $\kw{SF}$]
\begin{prooftree}
         \AxiomC{$I, I', P, [N]_V \seq P' \vee Q'$}
         \AxiomC{$I, I', P, \langle N \wedge A\rangle_V \seq  Q'$}
         \AxiomC{$I, P \seq \enabled\ \langle A \rangle_V$}
        % \RightLabel{\rlable{\kw{WF}}}
         \TrinaryInfC{$\Box \,I,  \Box\, [N]_V, \kw{WF}_V(A)  \seq \Box( P \Rightarrow \Diamond Q)$}
\end{prooftree}
\end{rl}

\vspace{20pt}

\begin{rl}[Lattice]
\begin{prooftree}
        \AxiomC{$(D, \succ) \ well-founded$}
        \AxiomC{$F, d \in D \seq \Box\big( G \Rightarrow \Diamond( H \vee \exists e \in D. \ d \succ e \wedge G[e/d] ) \big)  $}
%         \RightLabel{\rlable{Nec}}
        \BinaryInfC{$ F, d \in D \seq  \Box(G \Rightarrow \Diamond H) $}
\end{prooftree}
\scriptsize
\hfill $d$ not in $H$, $e$ not in $G$
\end{rl}
\vspace{45pt}

}

\myframe{proving things about \tla\ specs: \hfill liveness proofs}
{
\hspace{-18pt}{\color{Maroon} Therefore:}\\
\vspace{25pt}
If you want to prove liveness, we can:\\
\hspace{25pt} - tell you what you have to prove, \\
\hspace{25pt} - help you prove it (except the \enabled-bit),\\
\vspace{15pt}
\hfill but we cannot `tie the proof together' for you.

}

\subsection{Interaction between Temporal and Non-Temporal Reasoning}

\myframe{\hfill Necessication and Classical Logic}
{}

\myframe{\hfill Boxed and Non-Boxed Contexts}
{}

\subsection{Quantification in TLA}
\myframe{}{}


\subsubsection{Percentage of covered users}\label{subsubsec:hd2krcoverage}

As we can see from the table (see the Jupyter notebook), the lowest value for
the percentage of covered users is \(0.992883\!=\!99.2883\%\) found in two
experiments, meaning that there are two experiments where 1116 users out of
1124 (not counting the first one) have been reached (only 8 nodes have not heard
the message), while every other experiments gave higher results for the
coverage. The lowest mean of every repetitions is even higher:
\(0.997954\!=\!99.7954\%\). The coverage reaches its maximum value (\(100\%\))
in \(\frac{125}{160}\!=\!78.125\%\) of all the experiments.

Given these results, we can say that there is no need to analyze the percentage
of covered users in this scenario since it is almost always perfect (or nearly
perfect) and there is nothing to optimize. In any case, from common sense we can
derive that the most important factor to increase the coverage should be the
broadcast radius: higher radius allows each user to reach more users of the
network.


\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{subcaption}
\usepackage{caption}
\usepackage[margin=0.6in]{geometry}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\title{Feature Selection and Classification Methods}
\author{Derek Jones}

\begin{document}
\maketitle

\begin{center}
\includegraphics[scale=0.4]{/Users/derekjones2025/workspace/protein_binding/paper/figures/workflow_graphic.png}
\end{center}

\begin{abstract}
The following is a brief summary of the methods used in the prediction of active versus decoy drug-protein bindings for the full set of 26 protein kinases.
\end{abstract}

\section{Preprocessing}
Before learning on the input data, it was necessary to preprocess the input. At least one column \textbf{(be more specific here)} contained missing values for a subset of the input training examples. One solution would be to simply drop any column with missing values, however it may be unwise to do this if the feature column has a small portion of missing values. (It has been shown that) Retaining the feature column and replacing the missing values via some strategy (here we use the mean of the non-empty values for all empty feature column values of the input training examples ) may improve classifier performance.

It was also noted that a subset of feature columns contained relatively large values, increasing the computational burden of the learning algorithms given the size of our dataset. Here we normalize each feature column to unit vector length \textbf{(insert more details here)}.

\section{Feature Selection}
The full dataset contains 5432 feature vectors per training example (~360,000). The ration of active versus decoy class labels in the set of trianing examples was approximately 1:50, with the decoys greatly outnumbering the actives in the training set. We use an 80/20 training testing split of our data. In the context of machine learning modles such as deep networks, adding more features to datasets with a large number of training examples may yield increasing returns due to the ability of deep networks to learn complex non linear relationships between feature maps and output labels. However this power requires the sacrifice of model interpretability, a property that is crucially important in the application field of bioinformatics. Due to this limitation as well as the difficulty that comes with training a network on a highly imbalanced dataset, it was decided that other less complicated models were more appropriate for our problem.

A challenge in feature selection is finding a balance between computation time and the space of relationships one desires to consider to between the input feature maps and output labels. For example, variance thresholding (insert citation?) is a straightforward algorithm from which one may specify a minimum value of variance for which to tolerate the presence of a feature in the input, call this $\alpha$. The assumption here is that features that are \emph{near constant} in the input feature set are less informative than those features that vary by a greater amount. While this may be a valid quick and simple solution to the feature selection problem, it is impossible to capture any other relationship between feature value and class label, which the class label is not considered in the feature selection process of the variance thresholding method. For our problem this is a limitation that was not tolerable. Another option would be to use a \emph{LASSO} regression, aka Logistic Regression trained with an $L_{1}$ penalty term added to the loss function:
\begin{equation}
\mathcal{L}_{LASSO}(y,\bar{y}) = \mathcal{L}(y,\bar{y})+ \lambda \sum | ~ \theta  ~ |
\end{equation}
The $L_{1}$ penalty term encourages the machine learning model to learn a set of weights for the input feature vectors that is sparse and may contain near and or absolute 0 entries. The weights obtained from adding this term to the loss function can be used to remove features that are not informative in the prediction of the target label. However one must take more care in using the LASSO regression as a feature selection method as it is possible that the model simply assigns weight 0 to all but 1 or a subset of weights for problems in which the negative and positive class values do not differ greatly in certain feature values. An alternative to LASSO regression is to take bootstrap samples from the trianing set and train LASSO regression models on each, then select a set of features that tend to not have 0 or small coefficient values (insert stability selection citation). However Randomized LASSO can be computationally expensive for problems with large input feature spaces, and large numbers of training examples, which makes the method impractical for our problem.

% intro to random forests and their uses in classification and feature selection.
Random Forests \textbf{(citation, 2001)} are known to produce robust classifiers that are less prone to overfitting than ordinary decision trees or neural networks. For a brief review, a random forest is an ensemble method that uses a set of decision trees that are trained on samples from the training data (we use bootstrap sampling), each on a subset of the full feature set \textbf{(provide details on the number, sklearn has this)}. Upon test time, the input training example is fed to each tree and the mode across the decision trees (most common label) is taken to be the predicted output label of the forest. By using subsets of the data and feature space, random forests are much quicker to train than a deep neural network and other linear models such as logistic regression, and come with the benefit of being robust classifiers that tend to generalize as well or better as the aforementioned methods. From training a random forest, one can compute feature importances by the following equation:
\begin{equation}
Imp(X_{m}) = \frac{1}{N_{T}}\sum_{T}\sum_{t \in T:v(s_{t}) = X_{m}}p(t)\Delta i(s_t,t)
\end{equation}

Alternative to both variance thresholding, which does not allow for the relationship between feature values and target labels to be considered in the feature selection process, and randomized LASSO which requires large computational resources to train multiple logistic regression on a number of bootstrap samples from the dataset, the feature importances given by the random forest can be used instead. This method may be much quicker and possibly more informative than other feature selection methods.

For our problem we make use of an iterative method to perform feature selection. Rather than simply training a random forest and extracting the relevant features from the input feature space, we use the output most important features of each previous step (defined to be the features whose importances are greater than the mean importance, i.e. importance greater than $1/n$) as the input space for the next step. We do this until a stopping criterion is achieved (decrease of metric of interest, f1-score, by greater than .001). We are able to reduce the input feature space by 2 orders of magnitude, from 5432 features to a set of 59 features, while retaining nearly the same performance across our metric of interest on each iteration of the evaluation step, in which we train and evaluate both a logistic regression and an additional random forest. A summary of the results are given in the next section.

%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step1.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step2.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step3.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step4.png}

\section{Classification Results}
\subsection{Experiment Details}
\begin{enumerate}
	\item input data (after preprocessing) partitioned into train test sets using an 80/20 stratified split. This was done in order to ensure the presence of positive labeled examples in the test set. (Try other splits?)
	\item  Model selection using randomized grid search. sampling from the distributions of hyperparameter values rather than trying an exhaustive search of all combinations of an input grid is more efficient and yields similar performance (possibly better, insert reference to bengio).
	\item starting with 5432 features, a reduced set of (~1200) features are generated by extracting the feature importances from the forest, computing the mean importance ($1/n$), and removing all features that fall below the mean importance (could possibly try using different levels of confidence, one for each case of greater than or less than $1/n$).
	\item A random forest and logistic regression are trained on top of the reduced feature set (~1200). Confusion matrices as well as accuracy, f1-score, precision, and recall are computed for each classifier, the scores are broken down by class and given globally.
	\item From the trained random forest, the feature importances are extracted via the same method as before
	\item These experiments were run using the experimental NERSC jupyter server on CORI at Berkeley Labs.
\end{enumerate}
In general, the classifier performance remains nearly the same across iterations suggesting that this method of feature selection is successful in ruling out extra information with marginal benefit to the classification power of the given method.

The Random Forest tends to perform quite well on each iteration of reduced features along with a tendency to misclassify positive examples as negatives. This corresponds to labeling a drug as not binding to a protein. This may cause a hypothetical user to forego a promising candidate drug molecule.

The Logistic Regression performs better at correctly classifying positive training examples, however the method tends to misclassify negative training examples as positive. This may cause a hypothetical user to spend investment resources to develop a candidate drug molecule that does not in actuality inhibit the target receptor.

\begin{algorithm}
\caption{Iterative Selection Forest}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State $\textit{stringlen} \gets \text{length of }\textit{string}$
\State $i \gets \textit{patlen}$
\BState \emph{top}:
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $j \gets \textit{patlen}$
\BState \emph{loop}:
\If {$\textit{string}(i) = \textit{path}(j)$}
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\EndProcedure
\end{algorithmic}
\end{algorithm}

\subsection{Results: Classifier Metric Comparison}

\subsection{Results: Confusion Comparsion}
%\pagebreak

\begin{center}
\begin{figure}[htpb!]
\includegraphics[scale=0.5, width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_full_set.png}
\end{figure}
\end{center}

\begin{center}
\begin{figure}[htpb!]
\includegraphics[scale=0.5, width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step1.png}
\end{figure}
\end{center}

\begin{center}
\begin{figure}[htpb!]
\includegraphics[scale=0.5, width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step2.png}
\end{figure}
\end{center}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step1.png}
  \caption*{$i=1$}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step2.png}
  \caption*{$i=2$}
  \label{fig:sub2}
\end{subfigure}
%\caption*{$i=1$}
\label{fig:test}
\end{figure}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step3.png}
  \caption*{$i=3$}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/feature_importance_curve_step4.png}
  \caption*{$i=4$}
  \label{fig:sub2}
\end{subfigure}
%\caption*{$i=1$}
\label{fig:test}
\end{figure}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step1_confusion.png}
  \caption{Logistic Regression}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step1_confusion.png}
  \caption{Random Forest}
  \label{fig:sub2}
\end{subfigure}
\caption*{$i=1$}
\label{fig:test}
\end{figure}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step2_confusion.png}
  \caption{Logistic Regression}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step2_confusion.png}
  \caption{Random Forest}
  \label{fig:sub2}
\end{subfigure}
\caption*{$i=2$}
\label{fig:test}
\end{figure}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step3_confusion.png}
  \caption{Logistic Regression}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step3_confusion.png}
  \caption{Random Forest}
  \label{fig:sub2}
\end{subfigure}
\caption*{$i=3$}
\label{fig:test}
\end{figure}

\begin{figure}[htpb!]
%\centering
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step4_confusion.png}
  \caption{Logistic Regression}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
%  \centering
  \includegraphics[width=1\linewidth]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step4_confusion.png}
  \caption{Random Forest}
  \label{fig:sub2}
\end{subfigure}
\caption*{$i=4$}
\label{fig:test}
\end{figure}

%\section{Classification}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step1_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step2_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step3_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/log_reg_step4_confusion.png}

%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step1_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step2_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step3_confusion.png}
%\includegraphics[scale=0.2]{/Users/derekjones2025/workspace/protein_binding/results/full_kinase_set/random_forest_step4_confusion.png}
\end{document}


\documentclass{article}
\usepackage{color}
\usepackage{bussproofs}

\begin{document}

\paragraph{Exercise 3.3.4}
\color{red} TODO \color{black}

\paragraph{Exercise 3.5.5}
Proof 3.3.4 uses structural induction.

\paragraph{Exercise 3.5.10}

\AxiomC{$t \longrightarrow t'$}
\UnaryInfC{$t \longrightarrow^* t'$}
\DisplayProof
\hspace{3em}
\AxiomC{$t \longrightarrow^* t'$}
\AxiomC{$t' \longrightarrow^* t''$}
\BinaryInfC{$t \longrightarrow^* t''$}
\DisplayProof
\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Short Sectioned Assignment
% LaTeX Template
% Version 1.0 (5/5/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[paper=a4, fontsize=9pt]{scrartcl} % A4 paper and 11pt font size

\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[english,francais]{babel} % Français et anglais
\usepackage[utf8]{inputenc}

\usepackage{amsmath,amsfonts,amsthm} % Math packages

\usepackage{enumitem}
\usepackage{lmodern}
\usepackage{url}
\usepackage{eurosym} % signe Euros
\usepackage{geometry} % Pour passer au format A4
\geometry{a4paper} %
\usepackage{graphicx} % Required for including pictures
\usepackage{float} % Allows putting an [H] in \begin{figure} to specify the exact location of the figure

\usepackage{multicol}

\usepackage{verbatim}

\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps

%----------------------------------------------------------------------------------------
%	Pied de Page
%----------------------------------------------------------------------------------------

\setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text

%----------------------------------------------------------------------------------------
%	Titre
%----------------------------------------------------------------------------------------

\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height

%----------------------------------------------------------------------------------------
%	Début du document
%----------------------------------------------------------------------------------------

\begin{document}

%----------------------------------------------------------------------------------------
% RE-DEFINITION
%----------------------------------------------------------------------------------------
% MATHS
%-----------

\newtheorem{Definition}{Définition}
\newtheorem{Theorem}{Théorème}
\newtheorem{Proposition}{Propriété}

% MATHS
%-----------
\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\circ$}
%----------------------------------------------------------------------------------------
%	Titre
%----------------------------------------------------------------------------------------

%\maketitle % Print the title
\setlength{\columnseprule}{1pt}

\begin{multicols}{2}

  \subsection*{Factorisation - A}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 -2x + 1$
  \item[2.] $2(x + 1) - 7y(x + 1)$
  \item[3.] $-x^2 + 9y^2$
  \item[4.] $x - 4 - 7(x - 4) + y(x - 4)$
  \item[5.] $x^2 - x(2x - 1)$
  \end{enumerate}

  \subsection*{Factorisation - B}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 + 2x + 1$
  \item[2.] $3(x + 1) - 6y(x + 1)$
  \item[3.] $-x^2 + 25y^2$
  \item[4.] $(x + 2) - 8(x + 2) + 2y(x + 2)$
  \item[5.] $x^2 - (x + 2)x$
  \end{enumerate}

\end{multicols}

\vspace{1cm}

\begin{multicols}{2}

  \subsection*{Factorisation - C}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 -2x + 1$
  \item[2.] $-4(x+1) + 7y(x+1)$
  \item[3.] $-x^2 + 4y^2$
  \item[4.] $(x - 4) - 2(x - 4) + 2y(x - 4)$
  \item[5.] $x^2 - x(x - 3)$
  \end{enumerate}

  \subsection*{Factorisation - D}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 + 2x + 1$
  \item[2.] $2(3x + 1) - 7y(3x + 1)$
  \item[3.] $-x^2 + 36y^2$
  \item[4.] $(x - 1) - 5(x - 1) + 3y(x - 1)$
  \item[5.] $x^2 - (x + 5)x$
  \end{enumerate}

\end{multicols}

\vspace{1cm}

\begin{multicols}{2}

  \subsection*{Factorisation - E}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 -2x + 1$
  \item[2.] $5(z + 1) - 2y(z + 1)$
  \item[3.] $-x^2 + 16y^2$
  \item[4.] $(x - 4) - 2(x - 4) + 3y(x - 4)$
  \item[5.] $x^2 -  x(2\pi + 1)$
  \end{enumerate}

  \subsection*{Factorisation - F}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 +2x + 1$
  \item[2.] $3(x + 2) - 6y(x + 2)$
  \item[3.] $-x^2 + 9y^2$
  \item[4.] $(x - 8) - 6(x - 8) + z(x - 8)$
  \item[5.] $x^2 - x(\pi + 8)$
  \end{enumerate}

\end{multicols}

\vspace{1cm}

\begin{multicols}{2}

  \subsection*{Factorisation - H}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 -2x + 1$
  \item[2.] $2(y + 1) - x(y + 1)$
  \item[3.] $-x^2 + 9y^2$
  \item[4.] $(x - 3) - 4z(x - 3) + 3(x - 3)$
  \item[5.] $x^2 - x(2\pi + 7)$
  \end{enumerate}

  \subsection*{Factorisation - I}
  \textit{Factoriser au maximum le calcul suivant.}

  \begin{enumerate}
  \item[1.] $x^2 +2x + 1$
  \item[2.] $9(x + 2) - 6y(x + 2)$
  \item[3.] $-x^2 + 4y^2$
  \item[4.] $(x - 3) - 6y(x - 3) + 4(x - 3)$
  \item[5.] $x^2 - (x + 4)x$
  \end{enumerate}

\end{multicols}

\end{document}


Here we look closer at the \textit{PageRank} and \textit{Label propagation} experiment, first we detail the authors work then expand on my implementation before dicussing the extensions to their work I apply.

\subsection{Original Design} \label{sec:hilbert}
To determine the \textit{COST} a best in class single threaded implementation is needed. The authors wrote their own implementation for both experiments in \textit{Rust}. Their implementation initially loaded the graphs edges in vertex order, loading all edges for one vertex before moving to the next. \textit{GraphLab} and \textit{GraphX} save on data exchange by partition the edges between workers without this requirement \cite{graphlab,graphx}. To remove this disadvantage they wrote and tested a second implementation where the edges are pre ordered using Hilbert order improving cache coherency. They report the run time for both vertex orders.

Both experiments where originally ran on two graphs, \textit{twitter\_rv} \cite{twitter} and \textit{uk-2007-05} \cite{uk2007}. For ease of replication I deviate and run on different graphs.

\subsection{Implementation} \label{sec:hilbert}
As mentioned I will be using different graphs for this replication, I pipeline for using the original graphs was set up however these graphs turned out to be to large to run with the available storage as they had to be converted to huge edge lists for the papers authors conversion program to process them.
Instead I use graphs provided by LDBC Graphalytics \cite{graphs}. I properties of the graphs used are listed in \cref{graphprops}.

\ctable[
	caption = The graphs used throughout this reproduction sourced from \cite{graphs},
	label = graphprops,
	pos = h,
]{llccc}{}
{
\FL
			& wiki-Talk & dota-league & datagen-8\_0-fb & graph500-25 \ML
edges       & 5,021,410 & 50,870,313  & 107,507,376     & 523,602,831 \NN
vertices    & 2,394,385 & 61,170      & 1,706,561       & 17,062,472  \NN
}

\begin{figure}
  \includegraphics[width=\linewidth]{pagerank}
  \caption{Runtime of the Spark static \textit{Pagerank} method against number of cores for three different graphs. Pagerank was ran for 20 iterations. Individual run times are indicated with dots.}
  \label{fig:pagerank}
\end{figure}

\subsubsection{PageRank}
The pagerank algorithm works by iteratively updating a rank for each vertex in a directed graph. Each iteration the rank is divided between a vertex neighbours. Then the vertex rank is updated to the sum of its neighbours with a dampening factor applied. It was the originally algorithm used by Google to rank a websites significance. For this experiment I use the authors \textit{PageRank} implementation for the single threaded part. For \textit{GraphX} a slightly modified version of the \textit{GraphX} pagerank example\footnote{https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark /examples/graphx/PageRankExample.scala} written in scala is used. I remove all operations after the call to \textit{pageRank} and replace the \textit{pageRank} call with \textit{staticPageRank} given the argument to perform 20 iterations to match the authors single threaded implementation.

\subsubsection{Label Propagation}
In distributed computing label propagation is often used to find connected components. Each individual vertex gets a label then it is iteratively updated. Each update the label is set to the minimum of all the neighbours and itself. Eventually all components have the smallest label of that component. For the single threaded part of this experiment I use the authors code unmodified. For \textit{GraphX} there is no label propagation example there is however a label propagation function a member of the \textit{graph class}. Using this function I wrote the basic implementation seen in listing \ref{labelprop}. The part after line 22 was added to verify correctness versus the authors implementation.

\begin{lstlisting}[caption={Scala Label Propagation for spark},language=Scala,numbers=left,breaklines=true, label={labelprop}]
import org.apache.spark.graphx.GraphLoader
import org.apache.spark.graphx.lib.LabelPropagation
import org.apache.spark.sql.SparkSession

object LabelProp {
  def main(args: Array[String]): Unit = {
    // Creates a SparkSession.
    val spark = SparkSession
      .builder
      .appName(s"${this.getClass.getSimpleName}")
      .getOrCreate()
    val sc = spark.sparkContext

    // $example on$
    // Load the edges as a graph
    val edgeListPath = args(0)
    println("edgeListPath: %s", edgeListPath)
    val graph = GraphLoader.edgeListFile(sc, edgeListPath)
    println("graph loaded")
    // Run LabelProp, second arg is max numb of iterations
    val labels = LabelPropagation.run(graph, 1)
    println("test")

    // count non root labels
    // scala tuple access: tuple_.n with n in {1...tuple_len)
    val non_roots = labels.vertices.filter(x => x._1 != x._2).count()
    println("non roots: ", non_roots)

    spark.stop()
  }
}
\end{lstlisting}

\subsection{GraphX}
To use GraphX we need a Spark cluster since Spark contains GraphX and GraphX runs on Spark. TO build this cluster a standalone version of Spark was placed into a folder accessible to each compute node. Then using the, by Spark provided, submit script the master and driver are started. The script automatically sets up all the workers from a file of ips provided in the Spark config directory, called 'slaves'.

We vary the values determining the parallism only the memory is set to a fixed amount. The variables set (excluding which program to run and the master node url):

\begin{multicols}{2}
\begin{enumerate}
	\item number executors
	\item total cores used by the executors
	\item cores per executor
	\item cores for the driver
	\item memory per executor: 48GB
	\item memory for the driver: 48GB
\end{enumerate}
\end{multicols}

The number of executors is locked to the total number of cores in use, allow spark itself to determine the needed parallism. The number of cores is varyed from 2 to 256. Before deployment the needed data is moved to high speed ssd storage on the workers and driver.
Allocating nodes, moving the data and submitting the program via the spark submit script while timing its run is done through various shell scripts detailed in \cref{howToRun}.

The software versions used are: Spark 3.0.1 standalone which includes Hadoop 2.7, Scala 2.12.12 with spark-graphx\_2.12 version 3.0.1 and spark-sql version 3.0.1.

\subsection{Extension}
The exact configuration of the platforms or the specification on which either parallel or single-threaded implementations where tested are unknown. This could be an issue as the cores on which the single threaded code was timed could be significantly slower or faster then the used cluster. The authors must have done this to illustrate how a laptop can be faster then a distributed solution for some problems and care must be taken. Here I adress this by running the single-threaded code on one of the compute nodes part of the cluster on which \textit{GraphX} is run. The full specification of the used system is reported in \cref{res}.

As described in \cref{sec:hilbert} the authors converted the vertex order before starting running one variant of their implementation. The conversion time is mentioned in the paper for the smaller of the graphs. For completion we include the conversion time for all the graphs.
Further more it is unclear if measured times mentioned throughout the paper are averages or single data points, I improve upon this by running the experiments multiple times and reporting the standard deviation next to the means.


\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{amsmath}
% add packages you want to use
% you will submit generated .pdf file on odtuclass
% not the .tex file
% mind that your .pdf file can contain only
% searchable images

\usepackage[hmargin=3cm,vmargin=6.0cm]{geometry}
%\topmargin=0cm
\topmargin=-2cm
\addtolength{\textheight}{6.5cm}
\addtolength{\textwidth}{2.0cm}
%\setlength{\leftmargin}{-5cm}
\setlength{\oddsidemargin}{0.0cm}
\setlength{\evensidemargin}{0.0cm}

\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\section*{Student Information}
% Write your full name and id number between the colon and newline
% Put one empty space character after colon and before newline
Full Name : Zeynep Özalp \\
Id Number : 2237691 \\

% Write your answers below the section tags
\section*{Answer 1}
Let $\Sigma=\{0,1\}$. $A_k$ is clearly finite since $A_k$ has a partitioning $S_1,S_2...S_k$ where each $S_i$ is the set of strings of length $i$. The cardinality of $S_i$ is $i^2$. All $S_i$'s are finite. Union of these finite sets are also finite. $B$ is a language and it is countably infinite. The set of strings $\Sigma^*$ is countably infinite and $2^{\Sigma^*}$ is uncountable by theorem 1.5.2 on page 28. So, C is uncountable.
\subsection*{a.}
The difference of an uncountable set and a finite set is uncountable.
\subsection*{b.}
$$L^*=\Sigma^*$$
1) $L\subseteq\Sigma^* \rightarrow L^*\subseteq \Sigma^{**}=\Sigma^*$. Therefore, $ L^*\subseteq \Sigma^*$.\\
2) $(\{0,1\}\subseteq L) \rightarrow (\{0,1\}^* \subseteq L^*) \rightarrow (\Sigma^* \subseteq L^*)$\\

So, $B^*=\{0,1\}^*$. Thus, the intersection of $2^{\Sigma^*}, \Sigma^*$ and $A_7$ is $A_7$ and it is finite. $|A_7|=49$
\subsection*{c.}
Countably infinite since $\bigcup C =\{0,1\}^*$, $A_2 \times K$ is the set of tuples and $\bigcup C \cap (A_2 \times K) = \{\} $. So, $\bigcup C - (A_2 \times K) = \bigcup C$.
\subsection*{d.}
Countable and its cardinality is 0 since $\bigcup C =\bigcup _{k=1}^\infty A_k=\{0,1\}^*$.

\section*{Answer 2}

\subsection*{a.}
For $s$, there can be 4 different initial states. For $F$, there can be as many as the power set of $K$, which is $2^4$. For $\delta$, the transition function is from $K \times \Sigma$ to $K$. There are $2^3$ tuples in $K \times \Sigma$. These tuples can map to only one state.  So, there are $4^8=2^{16}$ different delta functions. Therefore, $2^2*2^4*2^5=2^{22}$ different DFA can be constructed.
\subsection*{b.}
For $s$, there can be 4 different initial states. For $F$, there can be as many as the power set of $K$, which is $2^4$. For $\Delta$, the transition function is $\Delta \subseteq K \times (\Sigma \cup \{e\})\times K$. There are $4.3.4=48$ different tuples and the transition function can be any subset of these tuples. So, there are $2^{48}$ different transition functions. Therefore, $2^2*2^4*2^{48}=2^{54}$ different NFA can be constructed.
\subsection*{c.}
In NFA's, one configuration can yield to many different configurations but in DFA's, one configuration can yield to only another configuration. Also, in NFA's, machine can pass to another state without reading an input symbol. Because of these reasons, the number of transition functions and the number of M's are clearly different.
\subsection*{d.}
The number of different FA's are equal to the number of different languages.

\section*{Answer 3}

\subsection*{a.}
$$0^*(100^*100^*100^*100^*)^*0^*\cup 0^*(0^*010^*010^*010^*01)^*0^*$$
\subsection*{b.}
$$(0\cup 1)(01\cup 00)^*\cup (10\cup 00)^*(0\cup 1)$$
\subsection*{c.}
$$1^*((00)(01\cup 10\cup 1)^*(00))^*1^*(e\cup 0)1^*$$

\section*{Answer 4}

\subsection*{a.}
$M=(K,\Sigma, \delta, s, F)$\\
$K=\{q_0,q_1,q_2,q_3,q_4,q_5,q_6,q_7\}$, $\Sigma=\{0,1\}$, $s=q_0$, $F=q_7$\\

 \begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid ,auto]
 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_1) [right=of q_0] {$q_1$};
 \node[state] (q_2) [right=of q_1] {$q_2$};
 \node[state] (q_3) [right=of q_2] {$q_3$};
 \node[state] (q_4) [below=of q_0] {$q_4$};
 \node[state] (q_5) [below=of q_1] {$q_5$};
 \node[state] (q_6) [below=of q_2] {$q_6$};
 \node[state,accepting] (q_7) [below=of q_6] {$q_7$};
 \path[->]
  (q_0) edge node {0} (q_1) edge node {1} (q_4)
  (q_1) edge node {0} (q_2) edge node {1} (q_5)
  (q_2) edge node {0} (q_3) edge node {1} (q_6)
  (q_3) edge [loop above] node {0,1} ()
  (q_4) edge node {0} (q_1) edge node [swap] {1} (q_7)
  (q_5) edge node {0} (q_2) edge node {1} (q_7)
  (q_6) edge node {0} (q_3) edge node {1} (q_7)
  (q_7) edge node {0} (q_3) edge [loop below] node {1} ();
 \end{tikzpicture}
\subsection*{b.}

 \begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid ,auto]
 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_1) [right=of q_0] {$q_1$};
 \node[state] (q_2) [right=of q_1] {$q_2$};
 \node[state] (q_3) [below=of q_1] {$q_3$};
 \node[state] (q_4) [below=of q_2] {$q_4$};
 \node[state] (q_5) [right=of q_4] {$q_5$};
 \node[state] (q_6) [right=of q_5] {$q_6$};
 \node[state] (q_7) [above=of q_6] {$q_7$};
 \node[state,accepting] (q_8) [below right=of q_7] {$q_8$};
 \node[state] (q_9) [right=of q_8] {$q_9$};
 \path[->]
  (q_0) edge node {0} (q_1) edge node {1} (q_3)
  (q_1) edge node {0} (q_2) edge [loop above] node {1} ()
  (q_2) edge [loop above] node {0,1} ()
  (q_3) edge [loop left] node {1} () edge node {0} (q_4)
  (q_4) edge node {0} (q_2) edge node {1} (q_5)
  (q_5) edge node {0} (q_7) edge node {1} (q_6)
  (q_6) edge [loop below] node {0,1} ()
  (q_7) edge node {0} (q_2) edge node {1} (q_8)
  (q_8) edge [bend left=90] node {1} (q_3) edge node {0} (q_9)
  (q_9) edge [loop above] node {0} () edge [bend left=90] node {1} (q_3);
 \end{tikzpicture}

\section*{Answer 5}

\subsection*{a.}
$$(q_0, abaa) \vdash _N (q_2, abaa) \vdash _N (q_4, baa) \vdash _N (q_4, aa) \vdash _N (q_1, a) \vdash _N (q_1, e)$$\\
$w_1\in L(N)$.
\subsection*{b.}
$$(q_0, babb) \vdash _N (q_1, abb) \vdash _N (q_1, bb)$$
$$(q_0, babb) \vdash _N (q_2, babb) \vdash _N (q_2, abb) \vdash _N (q_2, bb)\vdash _N (q_2, b)\vdash _N (q_2, e)$$
$$(q_0, babb) \vdash _N (q_2, babb) \vdash _N (q_2, abb) \vdash _N(q_4, bb) \vdash_N (q_4, b) \vdash_N (q_4,e)$$
$$(q_0, babb) \vdash _N (q_3, abb) \vdash _N (q_1, bb)$$
$$(q_0, babb) \vdash _N (q_3, abb) \vdash _N (q_4, abb) \vdash _N (q_1, bb)$$
$$(q_0, babb) \vdash _N (q_3, abb) \vdash _N (q_4, abb) \vdash _N (q_2, bb) \vdash _N (q_2,b) \vdash _N (q_2,e)$$
These are all possible configurations for $w_2$. Thus, $w_2\notin L(N)$.
\section*{Answer 6}
$E(q_0)=\{q_0,q_2\}$\\
$E(q_1)=\{q_1\}$\\
$E(q_2)=\{q_2\}$\\
$E(q_3)=\{q_3\}$\\
$E(q_4)=\{q_3,q_4\}$\\\\
$\delta(E(q_0), a)=E(q_0)=\{q_0,q_2\}$\\
$\delta(E(q_0), b)=E(q_0)\cup E(q_1)\cup E(q_3)=\{q_0,q_1, q_2, q_3\}$\\
$\delta(\{q_0,q_1, q_2, q_3\}, a)=E(q_0)\cup E(q_4)=\{q_0, q_2, q_3, q_4\}$\\
$\delta(\{q_0,q_1, q_2, q_3\}, b)=E(q_0)\cup E(q_1)\cup E(q_3)=\{q_0, q_1, q_2, q_3\}$\\
$\delta(\{q_0, q_2, q_3, q_4\}, a)=E(q_0)\cup E(q_4)=\{q_0, q_2, q_3, q_4\}$\\
$\delta(\{q_0, q_2, q_3, q_4\}, b)=E(q_0)\cup E(q_1)\cup E(q_3)=\{q_0, q_1, q_2, q_3\}$\\

 \begin{tikzpicture}[shorten >=1pt,node distance=4cm,on grid ,auto]
 \node[state ,initial] (X) {$\{q_0,q_2\}$};
 \node[state,accepting] (Y) [right=of X] {$\{q_0,q_1,q_2,q_3\}$};
 \node[state,accepting] (Z) [right=of Y] {$\{q_0,q_2,q_3,q_4\}$};
 \path[->]
 (X) edge [loop above] node {a} ()
 (X) edge node {b} (Y)
 (Y) edge [loop above] node {b} ()
 (Y) edge node {a} (Z)
 (Z) edge [loop above] node {a} ()
 (Z) edge [bend left] node {b} (Y);

 \end{tikzpicture}

\section*{Answer 7}
 \begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid ,auto]

 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_1) [right=of q_0] {$q_1$};
 \node[state] (q_3) [right=of q_1] {$q_3$};
 \node[state] (q_2) [right=of q_3] {$q_2$};
 \node[state,accepting] (q_4) [right=of q_2] {$q_4$};
 \path[->]
 (q_0) edge node {b} (q_1) edge [bend left=40] node {a} (q_3)
 (q_1) edge [loop below] node {a} () edge [bend left=20] node {a} (q_3)
 (q_2) edge [loop above] node {a,b} ()  edge node {e} (q_4)
 (q_3) edge [bend left] node {b} (q_1) edge node {b} (q_2)
 ;
 \end{tikzpicture}

\subsection*{a) Eliminate $q_1$}
$R(0,3,1)=ba^*a$\\
$R(3,3,1)=ba^*a$\\

\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid ,auto]

 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_3) [right=of q_0] {$q_3$};
 \node[state] (q_2) [right=of q_3] {$q_2$};
 \node[state,accepting] (q_4) [right=of q_2] {$q_4$};
 \path[->]
 (q_0) edge node {$a\cup ba^*a$} (q_3)
 (q_2) edge [loop below] node {a,b} () edge node {e} (q_4)
 (q_3) edge [loop below] node {$ba^*a$} () edge node {b} (q_2)
 ;
 \end{tikzpicture}

\subsection*{b) Eliminate $q_2$}
$R(3,4,2)=b(a\cup b)^*e=b(a\cup b)^*$\\

\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid ,auto]

 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_3) [right=of q_0] {$q_3$};
 \node[state,accepting] (q_4) [right=of q_3] {$q_4$};
 \path[->]
 (q_0) edge node {$a\cup ba^*a$} (q_3)
 (q_3) edge [loop below] node {$ba^*a$} () edge node {$b(a\cup b)^*$} (q_4)
 ;
 \end{tikzpicture}

\subsection*{c) Eliminate $q_3$}
$R(0,4,3)=(a\cup ba^*a)(ba^*a)^*(b(a\cup b)^*)$\\

\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid ,auto]

 \node[state ,initial] (q_0) {$q_0$};
 \node[state,accepting] (q_4) [right=of q_0] {$q_4$};
 \path[->]
 (q_0) edge [bend left] node {$(a\cup ba^*a)(ba^*a)^*(b(a\cup b)^*)$} (q_4)
 ;
 \end{tikzpicture}
 \\\\
 Regular expression is $(a\cup ba^*a)(ba^*a)^*(b(a\cup b)^*)$.

\section*{Answer 8}
Assume that $M_L=(K, \Sigma, \delta, q_0, F)$ and $M_H=(K', \Sigma, \delta ', s, F')$. I could not draw $M_L$ in a single picture as in our textbook on page 77 so I can just show the beginning part of it. \\

\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid ,auto]

 \node[state ,initial] (q_0) {$q_0$};
 \node[state] (q_2) [below right=of q_0] {$q_2$};
 \node[state] (q_1) [above right=of q_0] {$q_1$};
 \path[->]
 (q_0) edge node {0} (q_1) edge node {1} (q_2)
 ;
 \end{tikzpicture}
 \\\\
 The starting state of $M_H$ must be $q_1$ and the accepting states are the ones who have outgoing transition with symbol 1 to any of final states of $M_L$. If $0w1 \in L$, then $(q_0,0w1)\vdash_{M_L}^*(f,e)$ for some $f\in F$ if and only if $(q_1,w1)\vdash_{M_L}^*(f,e)$ and $(s,0w)\vdash_{M_L}^*(f',1)$ for some $f'\in F'$. Hence, $M_L$ accepts $0w1$ if and only if $M_H$ accepts $w$. Thus, $L(M_H)=H$.

\section*{Answer 9}

\subsection*{a.}
Assume L is regular. There is an integer $p \geq 1$ such that any string $w\in L$ with $|w|\geq p$ can be written as $w=xyz$ such that $y\neq e,|xy|\leq p$ and $xy^kz\in L$ for each $k\geq 0$.\\
Let
$$x=1^t0^i$$
$$y=0^j$$
$$z=0^{p!-i-j}1^{2^{(p+1)!}}$$
for $0<j\leq p$. Then,
$$xy^kz=1^t0^{p!+(k-1)j}1^{2^{(p+1)!}}$$
If $p!+(k-1)j=(p+1)!$ then $n=m$. Let's see if the first equation holds for any $k$.
$$k-1=\frac{p!p}{j}$$
Since $j\leq p$, we can divide $p!$ by $j$ and there exists an integer k. This is a contradiction. Thus, L is not regular.
\end{document}