\chapter{Models and Discretization}\label{chap:models_and_discretization}
In this chapter, the mathematical description of the multi-scale model and its discretization is presented.
We use the multi-scale chemo-electro-mechanical model that was introduced in literature \cite{Roehrle2012,Heidlauf2013,Heidlauf2015Diss,Mordhorst2015}. Additional models known from literature are incorporated that  were previously only simulated in isolation: The multidomain description for electrophysiology \cite{Klotz2020}, a model of neural stimulation \cite{Cisi2008} and sensory organ models such as the muscle spindle model of Mileusnic et al. \cite{Mileusnic2006Spindle}. Similarly, models of Golgi tendon organs can be added \cite{Mileusnic2006Golgi}.

% components of the multi-scale model
\begin{figure}%
  \centering%
  \includegraphics[width=\textwidth]{images/theory/model_schematic.pdf}%
  \caption{Interacting components of the multi-scale model.}%
  \label{fig:multi-scale-model}%
\end{figure}

\Cref{fig:multi-scale-model} shows an overview of the components of the implemented multi-scale model.
A pool of motor neurons drives the stimulation of the muscular system in \cref{fig:multi-scale-model} (a).
The axons of each motor neuron innervate the muscle fibers corresponding to the same MU and transmit rate-encoded stimulation signals.

In the muscle tissue, action potentials propagate starting at the neuromuscular junctions and subsequently reach the whole length of the muscle.
In our multi-scale model, two different formulations are available to describe this phenomenon. The multidomain description (\cref{fig:multi-scale-model} (b1)) models the MUs from a  homogenized 3D perspective. The description with muscle fibers (\cref{fig:multi-scale-model} (b2)) models action potential propagation explicitly with $n$ 1D muscle fibers.

Both of these descriptions of electrophysiology involve a subcellular model (\cref{fig:multi-scale-model} (c)). This model describes the ionic processes involving the fiber membranes and taking place within one half of a sarcomere as the smallest unit to generate muscle forces. A large number $m$ of instances of this model has to be computed.

In addition to the physiology of the muscle, a layer of body fat and skin on top of the muscle belly can be added to the model. This 3D fat layer (\cref{fig:multi-scale-model} (d)) is used to simulate EMG recordings on the skin surface. The model for the fat layer is unidirectionally coupled with the muscle fiber model (\cref{fig:multi-scale-model} (b2)) or bidirectionally coupled with the multidomain model (\cref{fig:multi-scale-model} (b1)). Using the multidomain model, it is, thus, possible to simulate external stimulation by electrodes on the skin, which is subject to research in neuroprosthetics.

The activated muscle generates force by subcellular processes on a molecular scale. They are computed on the cellular level by the half-sarcomere model (c). On the macroscopic scale, stresses lead to strains and contraction of the muscle. This effect is described by the muscle contraction model on a 3D domain (\cref{fig:multi-scale-model} (e)).
The description is coupled with the electrophysiology models (b1),(b2) by the geometry of the contracting muscle and fibers. It is coupled with the subcellular model by the generated active stresses of the half-sarcomere. Displacements and stresses can be computed for the muscle belly itself, but also for the connected body fat layer and for elastic tendons (\cref{fig:multi-scale-model} (f)). Depending on the research questions, the contraction model is either formulated quasi-static or fully dynamic taking into account inertia effects.

Sensory organs such as muscle spindles and Golgi tendon organs sense fiber stretch and contraction velocity (\cref{fig:multi-scale-model} (g)). They are connected with the motor neuron pool by layers of interneurons and modulate the stimulation in \cref{fig:multi-scale-model} (a).

In this chapter, \cref{sec:model_equations} presents mathematical descriptions of the electrophysiology model components in the multi-scale framework and \cref{sec:model_muscle_contraction} derives the solid mechanics models. Then, \cref{sec:discretization,sec:discretization_mechanics} address the spatial and temporal discretizations of the electrophysiology and mechanics descriptions, respectively.

\section{Electrophysiology Model Equations}\label{sec:model_equations}
In the following, more details and mathematical descriptions are given for the outlined models. The section begins with the 0D half-sarcomere model in \cref{sec:subcelullar_model}, followed by the bidomain and monodomain models in \cref{sec:bidomain_model,sec:monodomain_model}, which constitute the muscle fiber based model of electrophysiology. \Cref{sec:multidomain_model} continues with the multidomain model. Electric conduction in the body fat layer is described in \cref{sec:electric_conduction_body_domain}. An overview of the continuum mechanics model used for muscle contraction is given in \cref{sec:model_muscle_contraction}.
% ----------
\subsection{Subcellular Model}\label{sec:subcelullar_model}

Propagation of electric stimuli along muscle fibers involves activation and deactivation of ion channels and ion pumps in the fiber membrane  (the sarcolemma) and in the transverse tubules.
Functioning of these processes on the subcellular scale have first been suggested in 1952 by Hodgkin and Huxley after their studies of the squid giant axons \cite{Hodgkin1952,hodgkin1952propagation}. To date, their mathematical model still serves as the basis for electrophysiology models and some of their predictions, e.g., on gating currents that occur during opening of channels, were experimentally confirmed later.

The fiber membrane separates intra- and extracellular space and can be locally described by an electric circuit. The membrane voltage $V_m=\phi_i-\phi_e$ is the difference between the intra and extracellular potentials $\phi_i$ and $\phi_e$. The membrane stores charges $Q$, quantifiable by its electric capacitance $C_m$:
\begin{align}\label{eq:subcellular_model_helper1}
  Q = C_m\cdot V_m.
\end{align}
%
A change in the transmembrane potential, e.g., induced by an action potential leads to a change in $Q$, which is accounted for by an electric current $I$ over the membrane. This can be formally obtained by the derivative of \cref{eq:subcellular_model_helper1} with respect to time:%
\begin{align}\label{eq:subcellular_model_helper2}
  \d{Q}{t} = C_m \cdot \d{V_m}{t}.
\end{align}
%
The current $I=\d Q / \d t$ is realized by ions passing through the membrane.
Significant ions in this process are sodium $(\text{Na}^{+})$ and potassium ions $(\text{K}^{+})$.
Considering a particular point on the fiber, these ions diffuse through ion-specific channels in the membrane.
The diffusion is driven by an interplay of the ion concentration gradient and the electric field that is caused by action potentials.

Without any electric field imposed by action potentials, the equilibrium state of the diffusion process for sodium and potassium ions is given by their Nernst potentials $E_{\text{Na}^{+}}$ and $E_{\text{K}^{+}}$. These voltage levels depend on logarithmic relations between extra- and intracellular concentrations scaled by constants describing the thermal energy and the number of electrons.
In thermodynamic equilibrium, the membrane voltage is equal to the Nernst potential $E_i$ of the involved ions $i$.
At a higher membrane voltage $V_m$, the remainder ($V_m - E_i$) is the part of the electric field that drives the
ion fluxes and electric currents through the membrane. The currents depend on the conductivity $g_i$ of
the membrane for ion $i$.

Apart from sodium and potassium ions, the diffusion of less frequent ions and ionic pumps can be lumped by a leakage current $I_L$ that is modeled by a channel with constant conductivity $\bar{g}_L$.
With this, the total ionic membrane current $I_\text{ion}$ is formulated as
%
\begin{subequations}
\begin{align}\label{eq:subcellular_model_helper4}
  I_\text{ion}(V_m)  &= I_{\text{Na}^{+}} + I_{\text{K}^{+}} + I_L \\
  & = g_{\text{Na}^{+}}\,(V_m - E_{\text{Na}^{+}}) + g_{\text{K}^{+}}\,(V_m - E_{\text{K}^{+}}) + \bar{g}_L\,(V_m - E_L). \label{eq:subcellular_model_helper5}
\end{align}
\end{subequations}
%
The conductivities $g_{\text{Na}^{+}}$ and $g_{\text{K}^{+}}$ for the sodium and potassium channels depend on the transmembrane voltage $V_m$ and its history.

In addition to the ionic current $I_\text{ion}$, an externally driven current $I_\text{ext}$ can be modeled that occurs as a result of neural stimulation at the neuromuscular junctions. Substituting the current $I=\d Q / \d t$ in \cref{eq:subcellular_model_helper2}, we get the following differential equation for the membrane voltage $V_m$:
\begin{align}\label{eq:subcellular_model_helper3}
  C_m \cdot \d{V_m}{t} = -I_\text{ion}(V_m) + \dfrac{I_\text{ext}}{A}.
\end{align}
%
The negative sign of the ionic current $I_\text{ion}$ is in accordance with the definition of the membrane voltage as $V_m=\phi_i-\phi_e$. The external current $I_\text{ext}$ is divided by the surface area $A$ of the stimulating electrode or neuromuscular junction, as the description considers an infinitesimal area on the membrane.

Hodgkin and Huxley suggested that ion channels can be activated and deactivated. This molecular process requires independent \say{gating} particles to move to a new position in order for a channel to be activated. For the potassium channel, four of these independent events have to occur, each modeled by a probability $n$. The resulting probability for the channel to open is, thus, $n^4$. For the sodium channel, three such events are assumed for activation and another one for the deactivation of the channel, described by the probabilities $m$ and $h$, respectively. The values of the probabilities change over time and modulate the conductivities of the ion channels:
%
\begin{align*}
  g_{\text{Na}^{+}} &= \bar{g}_{\text{Na}^{+}} \cdot m(t)^3 \cdot h(t), \quad &g_{\text{K}^{+}} &= \bar{g}_{\text{K}^{+}} \cdot n(t)^4.
\end{align*}
%
Here, $\bar{g}_{\text{Na}^{+}}$ and $\bar{g}_{\text{K}^{+}}$ are channel specific constants. The gating variables $n,m$ and $h$ can be interpreted as probabilities for the events to occur or as the amount of occurred events related to all available gating particles.
The evolution of the activation probability $n$ is modeled by the following ordinary differential equation (ODE):%
\begin{align*}
  \d{n}{t} = \alpha_n(V_m) \cdot (1-n) + \beta_n(V_m) \cdot n,
\end{align*}
analogously for $h$ and $n$. The transition rates between activation probability $n$ and deactivation probability $(1-n)$ are nonlinearly dependent on the membrane voltage $V_m$.

For a constant $V_m$, this ODE has an analytical solution
\begin{align}\label{eq:subcellular_model_helper0}
  n(t) = n_\infty\big(1 - \exp(1 - \dfrac{1}{\tau_n}t)\big),
\end{align}
which for $t\to \infty$ converges to the equilibrium value $n_\infty := \alpha_n\,\tau_n$ as shown in \cref{fig:ode_solution}. The time constant $\tau_n := 1/(\alpha_n + \beta_n)$ indicates how fast the solution approaches the equilibrium, e.g., when starting from $n(0)=0$, half of the value of the equilibrium is reached after $t_{1/2}=\log(2)\,\tau_n$. The smaller $\tau_n$, the stiffer is the ODE, which needs to be considered in the choice of a suitable numerical solution scheme.

\begin{figure}%
  \centering%
  \def\svgwidth{0.4\textwidth}
  \input{images/theory/ode_solution.pdf_tex}%
  \caption{Subcellular model: Graph of the analytic solution (red) of the ordinary differential equation that is part of the activation model of ion channels for constant transmembrane voltage and initial condition $n(0)=0$, given in \cref{eq:subcellular_model_helper0}. The variables $n_\infty$ and $\tau_n$ can be interpreted as the equilibrium value and a characteristic timescale, respectively.}%
  \label{fig:ode_solution}%
\end{figure}

Because the transmembrane voltage $V_m$ changes over time, the ODEs for $n, m$ and $h$ have to be solved numerically. Then, the dependent ionic current $I_\text{ion}$ can be calculated. Thus, the model is a system of differential-algebraic equations (DAE).

The internal states in this model can be combined into a state vector $\bfy = (n,m,h)^\top$.
The combined right-hand side for all states is formulated as a vector-valued function $G(V_m,\bfy)$.
In summary, the system of DAEs for the subcellular model on a subcellular domain $\Omega_s$ can be written in the following form:
\begin{align}
  \dfrac{\partial\bfy}{\partial t} &= G(V_m,\bfy),& I_\text{ion}&=I_\text{ion}(V_m,\bfy) \quad \text{on }\Omega_s\label{eq:subcellular}.
\end{align}
For an exemplary solution that shows how the membrane potential changes over time, see \cref{fig:action_potentials}.

The system of equations in \cref{eq:subcellular} together with \cref{eq:subcellular_model_helper3} describe the subcellular processes on a single point $\Omega_s \subset \Omega_f$ on a muscle fiber $\Omega_f$.
It does not model the interaction between neighboring points that leads to propagation of action potentials.
To account for action potential propagation, ionic currents $I_\text{ion}$ on multiple points are coupled within the multidomain or fiber models that are formulated in the multi-scale framework. This is described in the following sections, \cref{sec:bidomain_model,sec:monodomain_model,sec:multidomain_model}.
Using these models, the system of ODEs in \cref{eq:subcellular} has to be solved for multiple subcellular points $\Omega_s^i$ in the muscle domain.

After Hodgkin and Huxley proposed this model in 1952, more detailed models were formulated that take into account more ion channels, ion pumps and more advanced biochemical processes within the cell. One particular model is the one proposed by Shorten et al. \cite{Shorten2007}, which adds the full pathway from activation to excitation-contraction coupling in the sarcomere. It has a state vector of $\bfy \in \R^{56}$ and is used to compute active stresses for simulations of muscle contraction.
It can also be written in the form given in \cref{eq:subcellular}.
Apart from $I_\text{ion}$, another value $\gamma = H(\bfy,\dot{\lambda}_f)$ is computed by an additional equation from the vector of states $\bfy$ and the fiber contraction velocity $\dot{\lambda}_f$, which is given to the model as a parameter.
The value $\gamma$ is a lumped activation parameter in the range $\gamma \in [0,1]$ that describes the amount of active stress generated in the sarcomere and can be linked to the continuum mechanics model of muscle contraction.

%and alter the ion concentration gradients across the membrane.
%ion-specific channels
%electrochemical gradient
%channels respond to a change in transmembrane potential
%altered ion concentration gradients

% ----------
\subsection{Bidomain Model}\label{sec:bidomain_model}

A description of electrophysiology on a general 3D muscle tissue is given by the bidomain model formulated by \cite{tung1978bi,peskoff1979electric}. The bidomain model considers the intra (index $i$) and extracellular spaces (index $e$) in a homogenized setting, such that the two domains coexist at every spatial point $\bfx \in \Omega\subset \R^3$. Similar to the setting of the subcellular model, the two domains in the bidomain model have locally varying electric potential fields $\phi_i$ and $\phi_e$ that yield a locally varying transmembrane voltage $V_m=\phi_i - \phi_e$. Electric conduction within the two domains is governed by conductivity tensors $\bfsigma_i$ and $\bfsigma_e$.

Assuming static conditions, a spatially varying electric potential $\phi$ induces the electric field $E=-\grad \phi$.
According to Ohm's law, the resulting current density $j$ is given by
%
\begin{align}\label{eq:bidomain_helper1}
  j = \bfsigma\,E = -\bfsigma\,\grad \phi \quad \text{in }\Omega.
\end{align}
This holds for both intra and extracellular domain, yielding expressions for $j_i$ and $j_e$.

The intracellular and the extracellular domain are electrochemically coupled. Thus, one assumption is that currents are preserved and a change in current density on one domain corresponds to the opposite change in current density in the other domain. This is expressed by the divergence of the current densities, which in one domain equals to the negated value in the other domain:
%
\begin{align}\label{eq:bidomain_helper2}
  \div(j_i) = -\div(j_e) \quad \text{in }\Omega.
\end{align}
%
This change in current density directly corresponds to a current flow over the membrane:%
%
\begin{align*}
  \div(j_i) = A_m\,I_m \quad \text{in }\Omega.
\end{align*}
%
Here, the factor $A_m$ describes the membrane area to domain volume relationship. It is needed to convert the units between current per volume and current per area. The membrane current $I_m$ is given by the subcellular model of Hodgkin and Huxley in \cref{eq:subcellular_model_helper3}. Neglecting the external current $I_\text{ext}$ in \cref{eq:subcellular_model_helper3} and using the formulation of the intracellular current density $j_i$ in \cref{eq:bidomain_helper1}, we get:
%
\begin{align*}
  \div\big(\bfsigma_i\,\grad(\phi_i)\big) = A_m\,\big(C_m\,\p{V_m}{t} + I_\text{ion}(V_m)\big) \quad \text{in }\Omega.
\end{align*}
%
The ionic current $I_\text{ion}$ can be computed by \cref{eq:subcellular_model_helper5}.
By plugging \cref{eq:bidomain_helper1} also into \cref{eq:bidomain_helper2} and rewriting the equations in terms of the extracellular potential $\phi_e$ and the transmembrane voltage $V_m = \phi_i-\phi_e$, we get the bidomain equations:%
\begin{subequations}
  \begin{align}
    \div\big((\bfsigma_i + \bfsigma_e)\,\grad(\phi_e)\big) + \div(\bfsigma_i\,\grad(V_m)\big) &= 0,\label{eq:bidomain1} \\[4mm]
    \div\big(\bfsigma_i\,\grad(V_m)\big) + \div(\bfsigma_i\,\grad(\phi_e)\big) &= A_m\,\big(C_m\,\p{V_m}{t} + I_\text{ion}(V_m)\big).  \label{eq:bidomain2}
  \end{align}
\end{subequations}
%
With appropriate boundary conditions, these equations are often used to model cardiac electrophysiology. They also serve as a basis for the fiber models in our multi-scale setting, which will be described in the next section.

% ----------
\subsection{Monodomain Model}\label{sec:monodomain_model}
% ----------
One approach to modeling skeletal muscle electrophysiology is to explicitly resolve muscle fibers and compute propagating action potentials on these spatial domains.
Propagation of action potentials can be described by the monodomain equation, which is a specialization of the bidomain equations for a one-dimensional intracellular space.

We assume a muscle domain $\Omega_M \subset \R^3$ with a number of embedded 1D manifolds $\Omega_f^j\subset \R^3$ for $j=1,\dots,n$ that represent muscle fibers. The domain $\Omega_M$ represents the extracellular space and each fiber domain $\Omega_f^j$ represents a separate  intracellular space.
It is further assumed that electric conduction in the extracellular space is directed equally to the embedded fibers. This can be stated as%
\begin{align}\label{eq:monodomain_helper1}
  \bfsigma_i = k\cdot \bfsigma_e.
\end{align}
%
The intracellular conductivity tensor $\bfsigma_i$ (here prolonged from the scalar value $\sigma_i$ on a fiber with tangent $\bfa \in \R^3$ to the 3D domain by $\bfsigma_i = \sigma_i \, \bfa \otimes \bfa$) and the extracellular conductivity $\bfsigma_e$ are multiples of each other with a scaling factor $k\in\R$.

Plugging \cref{eq:monodomain_helper1} into the first bidomain equation, \cref{eq:bidomain1}, and restricting the domain to a 1D fiber $\Omega_f^j$ allows to combine the terms related to $\phi_e$:
%
\begin{align*}
  \div\big(\sigma_i\,\grad(\phi_e)\big) = -\dfrac{k}{k+1} \div\big(\sigma_i\,\grad(V_m)\big) \quad \text{on }\Omega_f^j.
\end{align*}
%
Using the second bidomain equation, \cref{eq:bidomain2}, we get the expression
%
\begin{align*}
  \div\big(\sigma_\text{eff} \,\grad(V_m)\big) = A_m\big(C_m\,\p{V_m}{t} + I_\text{ion}(V_m,\bfy)\big) \quad \text{on }\Omega_f^j.
\end{align*}
%
The effective conductivity $\sigma_\text{eff}$ combines the intra and extracellular conductivities, $\sigma_i$ and $\sigma_e$, analog to a parallel circuit:
\begin{align*}
  \sigma_\text{eff} := \sigma_i \parallel \sigma_e = \dfrac{\sigma_i\,\sigma_e}{\sigma_i + \sigma_e}.
\end{align*}
%
Rearranging the terms yields the classical form of the monodomain equation:
%
\begin{align} %eq:monodomain
  &\dfrac{\partial V_m}{\partial t} = \dfrac{1}{A_m\,C_m}\big(\sigma_\text{eff}\dfrac{\partial^2 V_m}{\partial x^2} - A_m\,I_\text{ion}(V_m,\bfy)\big) \quad && \text{for }x \in \Omega_f^j. \label{eq:monodomain}
\end{align}
%

The multi-scale framework uses multiple instances of the monodomain equation \\\cref{eq:monodomain} together with the first bidomain equation \cref{eq:bidomain1} to model electrophysiology in the fibers and the extracellular domain \cite{Mordhorst2015}. In addition to the fiber domains $\Omega_f^j$, two instances of the muscle domain $\Omega_M$ are needed for the bidomain equation, one for the intracellular and one for the extracellular space. The transmembrane potential $V_m$ is unidirectionally coupled from the fiber meshes to the intracellular space of the first bidomain equation. The extracellular potential $\phi_e$ corresponds to the signals that are measured during intramuscular EMG recording.

Within the multi-scale framework, it is also possible to couple a model for electric conduction in an additional layer of body fat tissue. This is subsequently described in \cref{sec:electric_conduction_body_domain}.
Then, electric current fluxes between the muscle and body fat domains have to be modeled.

If no such additions should be made to the model, the following Neumann boundary conditions are used to close the description:
%
\begin{subequations}\label{eq:monodomain_bc}
\begin{align}
  \p{V_m}{x} &= 0 & \quad \text{on }∂\Omega_f^j, \label{eq:monodomain_bc1}\\[4mm]
  \big(\bfsigma_i\,\grad(V_m)\big) \cdot \bfn_m &= -\big(\bfsigma_i\,\grad(\phi_e)\big)\cdot \bfn_m & \quad\text{ on }∂\Omega_M, \label{eq:monodomain_bc2}\\[4mm]
  \big(\bfsigma_e\,\grad(\phi_e)\big) \cdot \bfn_m &=0  & \quad\text{ on }∂\Omega_M, \label{eq:monodomain_bc3}
\end{align}
\end{subequations}
with the outward normal vector $\bfn_m$.
\Cref{eq:monodomain_bc1} defines homogeneous Neumann boundary conditions for the monodomain equation \cref{eq:monodomain} at the two ends of each 1D muscle fiber domain.
The boundary conditions on $∂\Omega_M$ are related to the bidomain equations given in \cref{eq:bidomain1,eq:bidomain2}.
\Cref{eq:monodomain_bc2} is equivalent to a homogeneous Neumann boundary condition on the intracellular current density $j_i$ (cf. \cref{eq:bidomain_helper1}) and is expressed in terms of the transmembrane voltage $V_m$ and the extracellular potential $\phi_e$.
Another homogeneous Neumann boundary condition on $\phi_e$ as given by \cref{eq:monodomain_bc3} is required.

% ----------
\subsection{Multidomain Model}\label{sec:multidomain_model}

The multidomain model is an alternative approach to the description based on the monodomain and bidomain equations described in \cref{sec:bidomain_model,sec:monodomain_model}. It was proposed in \cite{Klotz2020} and describes the same physics. However, the muscle fibers are homogenized and all equations are formulated using a single 3D muscle domain $\Omega_M$.

The multidomain equations generalize the two bidomain equations and allow taking into account multiple MUs by defining a separate intracellular space for each MU. Thus, at every spatial point $\bfx \in \Omega_M$ one extracellular and  $N_\text{MU}$ intracellular domains or compartments coexist, where $N_\text{MU}$ is the number of MUs. As before, the extracellular domain has the electric potential $\phi_e$ and  conductivity tensor $\bfsigma_e$. For each compartment $k = 1, \dots, N_\text{MU}$, a separate electric potential $\phi_i^k$, transmembrane voltage $V_m^k = \phi_i^k-\phi_e$, conductivity tensor $\bfsigma_i^k$, surface to volume ratio of the membrane $A_m^k$ and membrane capacitance $C_m^k$ are defined.

Analog to the fibers of a MU that exhibit different densities at different locations in the muscle, each compartment occupies different locations within the domain to a different extent. This is described by the relative occupancy factor $f_r^k: \Omega_M \to [0,1]$ for MU $k$. The factors have different values in the domain according to the presence of the MU at the respective location. At every point, their sum is one, $\sum_{k=1}^{N_\text{MU}} f_r^k = 1$, if all MUs should be considered or less than one if the effect of remainder MUs that will not be activated in the simulation scenario is neglected.

The first multidomain equation is similar to the first bidomain equation \cref{eq:bidomain1} and balances the current flow between the extracellular space and the weighted sum of all intracellular spaces:%
\begin{align}\label{eq:multidomain_helper1}
  \div\big(\bfsigma_e\,\grad(\phi_e)\big)  + \ds\sum\limits_{k=1}^{N_\text{MU}} f_r^k\,\div\big(\bfsigma_i^k\,\grad(V_m^k + \phi_e)\big) = 0.
\end{align}
By defining a total intracellular conductivity tensor $\bfsigma_i = \sum_{k=1}^{N_\text{MU}}f_r^k\,\bfsigma_i^k$, \cref{eq:multidomain_helper1} can be restated as
%
\begin{align}\label{eq:multidomain1}
  \div\big((\bfsigma_e + \bfsigma_i)\,\grad(\phi_e)\big) + \sum\limits_{k=1}^{N_\text{MU}} f_r^k\,\div\big(\bfsigma_i^k\,\grad(V_m^k)\big) = 0.
\end{align}

The second multidomain equation equals the second bidomain equation \cref{eq:bidomain2}. It describes the current over the membrane and holds for every compartment:%
\begin{align*}
  \div(\bfsigma_i^k\,\grad(V_m^k + \phi_e)\big) = A_m^k\,\Big(C_m^k\,\p{V_m^k}{t} + I_\text{ion}(V_m^k)\Big) && \forall k \in \{1, \dots, N_\text{MU}\}.
\end{align*}
%
It is convenient to rearrange it for $\partial{}V_m^k / \p t$:
%
\begin{align}\label{eq:multidomain2}
  \p{V_m^k}{t} = \dfrac{1}{A_m^k\,C_m^k} \Big(\div\big(\bfsigma_i^k\,\grad(V_m^k + \phi_e)\big) - A_m^k I_\text{ion}(V_m^k)\Big) && \forall  k \in \{1, \dots, N_\text{MU}\}.
\end{align}
%
The current $I_\text{ion}$ over the membrane is again computed by the subcellular model given by \cref{eq:subcellular_model_helper5}.

The resulting system of \cref{eq:multidomain1,eq:multidomain2} constitutes the first and second multidomain equations and can be used to compute muscle electrophysiology.
The boundary conditions are defined analogously to \cref{eq:monodomain_bc2,eq:monodomain_bc3}:
\begin{subequations}\label{eq:multidomain_bc}
\begin{align}
  \big(\bfsigma_i^k\,\grad(V_m^k)\big) \cdot \bfn_m &= -\big(\bfsigma_i^k\,\grad(\phi_e)\big)\cdot \bfn_m && \quad\text{on }∂\Omega_M\quad && \forall k \in \{1,\dots,N_\text{MU}\},  \label{eq:multidomain_bc1}\\[4mm]
  \big(\bfsigma_e\,\grad(\phi_e)\big) \cdot \bfn_m &= 0, && \quad\text{on }∂\Omega_M \label{eq:multidomain_bc2}
\end{align}
\end{subequations}
where $\bfn_m$ is the outward normal vector on $∂\Omega_M$.

% ----------
\subsection{Electric Conduction in the Body Domain}\label{sec:electric_conduction_body_domain}

Surface EMG signals are the result of electric conduction in the electrically active muscle tissue as well as in surrounding inactive tissue such as adipose tissue and skin or connective tissue such as tendons and ligaments. This surrounding tissue is summarized by the body domain $\Omega_B$, which partly shares its boundary with the muscle domain $\Omega_M$.

\Cref{fig:body_domain_visualization} visualizes these domains and defines their names: The domains $\Omega_M$ and $\Omega_B$ have outward normals $\bfn_m$ and $\bfn_b$, the outer boundary is composed of $\Gamma_B^\text{out}$ and $\Gamma_M^\text{out}$ and the variables $\phi_e,V_m$ and $\phi_b$ are defined as shown within the domains $\Omega_M$ and $\Omega_B$.

\begin{figure}[t]
  \centering
  \includegraphics[width=50mm]{images/theory/computational_domains.png}
  \caption{Computational domains for the simulation of surface EMG. The body domain $\Omega_B$ and the muscle domain $\Omega_M$ share a part of their boundary, $\Gamma_M$, which has a normal vector $\bfn_m$. The outer boundary is composed of $\Gamma_B^\text{out}$ and $\Gamma_M^\text{out}$ and has the outward normal vector $\bfn_b$. }
  \label{fig:body_domain_visualization}
\end{figure}

The work of \cite{Mordhorst2015} proposes an isotropic conductivity $\bfsigma_b$ and a harmonic electric potential $\phi_b$ in the body domain $\Omega_B$:
\begin{align}\label{eq:body}
  \div \big(\bfsigma_b\,\grad (\phi_b)\big) = 0 \qquad \text{on } \Omega_B.
\end{align}

The electric potentials $\phi_e$ and $\phi_b$ of the neighboring domains $\Omega_M$ and $\Omega_B$ as well as the current densities are continuous on the shared boundary $\Gamma_M$. This is described by the following two coupling conditions:
\begin{subequations}\label{eq:body_domain_coupling}
  \begin{align}
    \phi_e &= \phi_b  \qquad &&\text{on } \Gamma_M, \label{eq:body_domain_bc1}   \\[4mm]
    \big(\bfsigma_e\, \grad( \phi_e)\big)\cdot \bfn_m &= \big(\bfsigma_b\, \grad(  \phi_b)\big)\cdot \bfn_m \qquad &&\text{on } \Gamma_M.\label{eq:body_domain_bc2}
  \end{align}
\end{subequations}
%
On the outer boundary $\Gamma_B^\text{out}$, homogeneous Neumann boundary conditions are assumed:
\begin{align}% eq:body_domain_bc3
  \big(\bfsigma_b\, \grad( \phi_b)\big)\cdot \bfn_b &= 0 \qquad &&\text{on } \Gamma^\text{out}_B.\label{eq:body_domain_bc3}
\end{align}

The description of the body domain has to be combined either with the fiber based description in \cref{sec:monodomain_model} or the multi-domain description in \cref{sec:multidomain_model}. In the literature, this combination was mathematically described for the fiber based model in \cite{Mordhorst2015} and for the multidomain model in \cite{Klotz2020}. Correspondingly, additional boundary conditions either given by \cref{eq:monodomain_bc} or \cref{eq:multidomain_bc} are assumed: For the fiber based description, which uses the bidomain equation for volume conduction, the boundary conditions are:%
\begin{subequations}
\begin{align}
  \big(\bfsigma_i\,\grad(V_m)\big) \cdot \bfn_m &= -\big(\bfsigma_i\,\grad(\phi_e)\big)\cdot \bfn_m && \quad\text{on }∂\Omega_M=\Gamma_M \cup \Gamma_M^\text{out}, \label{eq:monodomain_fat_bc1}\\[4mm]
  \big(\bfsigma_e\,\grad(\phi_e)\big) \cdot \bfn_m &=0  && \quad\text{on }∂\Gamma_M^\text{out}. \label{eq:monodomain_fat_bc2}
\end{align}
\end{subequations}
%
For the multidomain description with fat layer, the boundary conditions are:
\begin{subequations}
\begin{align}
  \big(\bfsigma_i^k\,\grad(V_m^k)\big) \cdot \bfn_m &= -\big(\bfsigma_i^k\,\grad(\phi_e)\big)\cdot \bfn_m && \quad\text{on }∂\Omega_M=\Gamma_M \cup \Gamma_M^\text{out},  \label{eq:multidomain_fat_bc1}\\[4mm]
  \big(\bfsigma_e\,\grad(\phi_e)\big) \cdot \bfn_m &= 0 && \quad\text{on }∂\Gamma_M^\text{out}. \label{eq:multidomain_fat_bc2}
\end{align}
\end{subequations}
The first condition in \cref{eq:multidomain_fat_bc1} is enforced for all compartments $k=1,\dots,N_\text{MU}$.
%

% ----------


\chapter{Registration procedure}

\section{\texttt{BAL\_PyramidalBlockMatching}}

\texttt{BAL\_PyramidalBlockMatching()}\footnote{\texttt{bal-blockmatching.c}}
manages the hierarchical/pyramidal registration loop.

As input, it has the two images, $I_{ref}$ and $I_{flo}$, and two
transformations, $T_{left}$ and $T_{init}$. The registration consists
in computing $T_{res}$ such that $I_{flo} \circ T_{left} \circ
T_{res}$ can be superimposed onto $I_{ref}$. The computation of
$T_{res}$ is iterative and $T_{init}$ is the initialization of $T_{res}$

\subsection{Initialization}
\label{sec:devel:doc:trsfs:initialization}
The computation of
$T_{res}$ is iterative, its initial value, say $T$, depends on both
$T_{left}$ and $T_{init}$.
\begin{itemize}
\item if $T_{init}$ is given, $T = T_{init}$
\item else
\begin{itemize}
\item if $T_{left}$ is given, $T = \mathbf{Id}$
\item $T$ is the translation that superimposes the
centers of the fields of view of the two images $I_{ref}$ and
$I_{flo}$ (computed by \texttt{BAL\_Compute\-ImageToImageTransformation()}\footnote{\texttt{bal-transformation-tools.c}}).
\end{itemize}
\end{itemize}

\subsection{Iterations over pyramid levels}

At each pyramid level $\ell$, images ${}^{(\ell)}I$ are computed with
the resampling transformation $T_{(\ell)} = T_{I \leftarrow
  {}^{(\ell)}I}$. This transformation is computed by
\texttt{BAL\_Compute\-ImageToImageTransformation()}\footnote{\texttt{bal-transformation-tools.c}}
(see also section \ref{sec:frame:resolution}).

A subsampled version of the reference image is computed by
${}^{(\ell)}I_{ref} = I_{ref} \circ T_{(\ell)}$.
Let $T$ be the current estimation of the transformation, thus for the
level $\ell$, we will compute (with \texttt{BAL\_BlockMatching()}) a transformation with $T \circ
T_{(\ell)}$ as initial estimate. Of course, the returned result will
be composed by $T_{(\ell)}^{(-1)}$ afterwards.

Parameters for \texttt{BAL\_BlockMatching()} are then the subsampled
reference image ${}^{(\ell)}I_{ref} = I_{ref} \circ T_{(\ell)}$, the
floating image $I_{flo}$, the left handed transformation $T_{left}$
and the current estimate of the transformation $T \circ
T_{(\ell)}$ that allows to superimpose $I_{flo}$ onto
${}^{(\ell)}I_{ref}$, $I_{flo}$ being resampled by
$I_{flo} \circ T_{left} \circ T \circ T_{(\ell)}$.

\section{\texttt{BAL\_BlockMatching}}

\texttt{BAL\_BlockMatching}\footnote{\texttt{bal-blockmatching.c}}
performs the registration for two given images $I_{ref}$ (note that
$I_{ref}$ can be a subsampled version of the original reference image)
and $I_{flo}$ (note that $I_{flo}$ is not subsampled, even if
$I_{ref}$ is), given the two transformations $T_{left}$ and $T^{(0)}$
which is the initial value for the transformation.

At each iteration $i$,
\begin{itemize}
\item resample $I_{flo}$ in the same geometry than $I_{ref}$, i.e. compute $I_{flo}^{(i)} = I_{flo} \circ T_{left} \circ T^{(i)}$
\item compute the incremental transformation from $I_{ref}$ to $I_{flo}^{(i)}$,
  i.e. $\delta T^{(i)} = T_{ I_{flo}^{(i)} \leftarrow I_{ref}}$
\item update the transformation $T^{(i+1)} = T^{(i)} \circ \delta T^{(i)}$
\end{itemize}


\chapter{Economic cost optimization}
\label{cha:eco_cost_opti}

% **************************** Define Graphics Path **************************
\ifpdf
    \graphicspath{{Chapter7/Figs/Raster/}{Chapter7/Figs/PDF/}{Chapter7/Figs/}}
\else
    \graphicspath{{Chapter7/Figs/Vector/}{Chapter7/Figs/}}
\fi

% **************************** Chapter Abstract ******************************
\leftskip=1cm
\noindent
\emph{Abstract of the chapter: problem, approach, main results and conclusions.}

\leftskip=0pt\rightskip=0pt

\section{Problem statement and the state of the art}

\section{Solution strategy}

\begin{equation}
 	{C_{{\mathrm{tot}}}} = {C_0} + {C_1} \cdot R + {C_{\mathrm{f}}} \cdot {P_{\mathrm{f}}}(R)
\end{equation}

\begin{equation}
 	{c_{\mathrm{tot}}} = R + \frac{{{C_{\mathrm{f}}}}}{{{C_1}}} \cdot {P_{\mathrm{f}}}(R)
\end{equation}

\section{Results and discussion}

\subsection{Comparison}

\subsubsection{Comparing partial factor and reliability based designs}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{cost_opti_ec_get_ratioeps_total.pdf}
	\caption{Total economic cost (blue) and reliability index (orange) as a function the mean resistance ($R_\mathrm{m}$); the designs obtained by partial factor and reliability based calculations are illustrated by a cross.}
	\label{fig:cost_opti_ec_total}
\end{figure}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{cost_opti_ec_get_ratioeps_zoom.pdf}
	\caption{Same as Fig. \ref{fig:cost_opti_ec_total} but zoomed to the economic optimum.}
	\label{fig:cost_opti_ec_zoom}
\end{figure}

\subsubsection{Comparing Gumbel (EC) and BMA based optimum points}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{cost_opti_compare_ec_bma.pdf}
	\caption{Optimum values with Gumbel and BMA models using the same ${C_{\mathrm{f}}}/{C_1}$ ratio.}
	\label{fig:cost_opti_ec_bma}
\end{figure}

Comparison of EC partial factor based design, EC cost optimization, both using Gumbel distribution and BMA cost optimization is summarized in Table \ref{tab:cost_opti_comp}.

% notes should be added
\begin{table}
\caption{Comparison of methods and models with different variable action model.}
\centering
\label{tab:cost_opti_comp}
\small
	\begin{threeparttable}
	\begin{tabular}{m{1cm} m{3cm} m{3cm} m{3cm}}
		\toprule
		  & EC partial factor, Gumbel  & EC opti, Gumbel & BMA opti \\
		\midrule
		$R_\mathrm{m}$ & 2.62 & 4.27 & 6.57  \\

		$\beta$ & 2.05\tnote{*} & 3.80\tnote{\textdagger} & 3.48 \\

		$c_\mathrm{tot}$ & 89.0 & 4.57 &  7.64 \\
		\bottomrule
	\end{tabular}
	\begin{tablenotes}
	    \item[*] assuming that $Q$ is Gumbel distributed.
	    \item[\textdagger] consequence of the initial assumption, Section ?.
	\end{tablenotes}
	\end{threeparttable}
\end{table}

\subsubsection{Reliability index for 1-year reference period}

\subsubsection{Comparing Gumbel and BMA models for different ${C_{\mathrm{f}}}/{C_1}$ ratios}

\begin{itemize}
	\item The difference between Gumbel and BMA economic optimal resistances is increasing with increasing $C_f/C_1$ ratio.
	\item RC2 and RC3 partial factors yield to design which is optimal for ${C_{\mathrm{f}}}/{C_1}$ ratio multiple order of magnitude smaller than the one calculated in Section ?? by inverse analysis.
	\item The optimal reli index varies significantly with the ${C_{\mathrm{f}}}/{C_1}$ ratio.
\end{itemize}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{comp_gumbel_bma_cf_c1_par.pdf}
	\caption{Mean resistances corresponding to economic optimum per different ${C_{\mathrm{f}}}/{C_1}$ ratios.}
	\label{fig:comp_gumbel_bma_res}
\end{figure}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{comp_gumbel_bma_cf_c1_par_beta.pdf}
	\caption{Mean resistances and reliability indices corresponding to economic optimum per different ${C_{\mathrm{f}}}/{C_1}$ ratios.}
	\label{fig:comp_gumbel_bma_res_beta}
\end{figure}

\begin{figure}[htbp!]
	\centering
	\includegraphics[width=0.7\textwidth]{comp_gumbel_bma_cf_c1_par_c_opt.pdf}
	\caption{Mean resistances and optimum costs corresponding to economic optimum per different ${C_{\mathrm{f}}}/{C_1}$ ratios.}
	\label{fig:comp_gumbel_bma_res_cost}
\end{figure}

\subsection{Partial factor for snow action}

Comments could be made on how the partial factor would change by incorporating parameter estimation uncertainty and by switching from Gumbel to GEV or other distribution types.
This a delicate question since it is well known that the current Eurocode recommendations do not provide the target reliability stipulated in \citep{EN0}. It is hard to separate the effects, though I believe it would convey interesting information.
Maybe Chapter \ref{cha:stat_unc} suits better for this analysis.

%\section{Extension to other random variables}

\section{Application example}

\section{Summary and conclusions}


\chapter{Conclusion} \label{sec:Conclusion}
Our models for the Identification and the Pricing Problem outperformed previously studied ones \cite{Xue2016Avi2} and other baseline comparisons (\Cref{sec:IdProbRes - Optimization,sec:PriProbRes - Optimization,tab:Loss Values Calculated for Different Models for Identification Problem,tab:Loss Values Calculated from Different Sets of Rewards}). For the Identification Problem, the average loss value was 0.14 units lower than that of the previous 2-layered model, and 0.12 units lower than that of the 4-layered model, giving us better results than any other tested model. While we did not test deeper networks, we contend that using more hidden layers will only aggravate overfitting and won't provide better results --- as is partly the case with the 4-layered network. The Pricing Problem's model also delivered at least $3\times$~lower loss values than other baseline comparisons for reward distribution.

On the other hand, we can definitively conclude that the Identification Problem ran $0.94$~to~$10.32$~times~faster on the GPU than the CPU, mainly because the model was based on tensors and a neural network, accelerated by a GPU and NVIDIA's APIs. With the increasing GPU Speedup of the Identification Problem with bigger datasets, we can scale to large datasets more efficiently on the GPU than the CPU. The Pricing Problem's neural network only performed better with higher batch-sizes, with transfer times hampering performance on smaller datasets. Although the Pricing Problem's full model did not deliver a noticeable speedup (with the LP problem heavily impacting the runtime), the 2-layered network for finding rewards gave a speedup between $0.28-2.81$. This shows that neural network are inherently quick to optimize on a GPU only if the batch-sizes are large enough. This issue of high transfer times was observed for the Identification Problem too (though not so starkly), and is also discussed in \Cref{sec:Computation Using GPUs} and recent literature \cite{ParallelNVIDIA,DemystifyingGPU} \cite[Appendix~B]{PattersonARM}. One may infer that one can witness GPU Speedups only when transfer overheads are tiny compared to computation time. To obtain even better performance with GPUs, faster GPUs like NVIDIA Quadro GP100, and those based on the newer Volta architecture will most likely decrease the models' runtimes and help scale better. Clearly, there still exists enormous scope for improvement in both more optimized results and faster computation.

\section{Interesting Inferences}
One may also notice compelling reflections from the results:
\begin{itemize}
    \item One interesting observation in \Cref{tab:Loss Values Calculated from Different Sets of Rewards} is that the loss value from the Proportional Distribution ($0.0235\%$) and Random Initialization ($0.0331\%$) are very close, highlighting that the set of weights obtained from the Identification Problem are dependent on other factors ($\matr{f}, \matr{D}$) as well. In other words, only incentivizing under-sampled locations more is as good as random distribution of rewards --- as agents strongly consider environmental features and distances between locations to make decisions.

    \item By looking at the model's generated rewards (\Cref{tab:Example Rewards Prediction by the Pricing Problem's Model}), one can infer that the model chooses to place large rewards in very under-sampled locations, rather than distributing more evenly over all locations. Although this non-uniform distribution is unintuitive to the human perspective, it gives much lower results than proportionally allocated rewards.

    \item Algorithms that use different libraries for sub-routines' implementation can have difficulty in parallelizing. As we saw with the unexpected GPU Speedup in LP runtimes in the Pricing Problem (\Cref{sec:PriProbRes - GPU,app:GPU Speedup in LP Computation}), na\"ive synchronization barriers can affect performance in CPUs' multi-threading mechanism as well as GPUs' threads. Therefore, one might consider threading the \textit{full} algorithm instead of using external libraries for threading some sub-routines.

    \item GPUs are not always effective in executing all kinds of models. Factors that affect the performance include the size of the model and datasets, extent of conditional statements in the program, requirement of synchronization barriers, data transfer frequency between RAM and GPU etc. When the models are increasingly simple and small, CPUs can do a much better job than GPUs.
\end{itemize}
\begin{table}[!htbp]
    \centering
    \caption[Example Rewards Prediction by the Pricing Problem's Model]{Example Rewards Prediction by the Pricing Problem's Model: The prediction is relatively sparse and non-uniform. Parameters: $\mathcal{R} = 1000$, Loss value = $0.0068\%$, Epochs = 1000, Learning Rate = $5 \times 10^{-5}$, Weights: Set-2. (values rounded)}
    \label{tab:Example Rewards Prediction by the Pricing Problem's Model}
    \setlength\tabcolsep{2pt}
    \begin{tabular}{|*{15}{c}|}
        \hline
        0.00 & 38.02 & 0.00 & 0.00 & 0.00 & 0.00 & 14.12 & 0.00 & 24.63 & 4.43 & 3.18 & 24.35 & 0.00 & 19.53 & 0.00\\
        1.63 & 6.40 & 0.00 & 0.00 & 0.00 & 36.31 & 31.15 & 0.00 & 0.00 & 29.16 & 2.22 & 6.02 & 23.12 & 0.00 & 16.42\\
        0.00 & 0.00 & 28.45 & 0.00 & 37.50 & 0.00 & 20.04 & 34.19 & 0.00 & 0.00 & 18.29 & 0.00 & 0.00 & 21.33 & 0.00\\
        0.00 & 23.73 & 24.77 & 0.00 & 23.18 & 1.75 & 0.00 & 20.78 & 22.60 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 4.79\\
        4.67 & 0.00 & 0.00 & 34.82 & 0.00 & 9.47 & 0.00 & 0.00 & 31.43 & 0.00 & 4.35 & 16.55 & 28.51 & 6.02 & 0.00\\
        21.24 & 21.38 & 0.00 & 22.95 & 27.17 & 21.44 & 24.16 & 21.07 & 0.00 & 0.00 & 25.48 & 0.00 & 0.00 & 0.00 & 2.59\\
        12.28 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 22.09 & 0.00 & 0.00 & 16.50 & 0.00 & 2.88 & 1.57 & 0.00 & 43.45\\
        0.00 & 0.00 & 15.25 & 0.02 & 0.00 & 0.00 & 0.00 & 0.00 & 0.18 & 0.32 & 0.00&&&&\\ \hline
    \end{tabular}
\end{table}

\section{Limitations} \label{sec:Limitations}
We could not parallelize some sub-routines of \Cref{alg:Algorithm for the Identification Problem,alg:Solving the Pricing Problem} and had to rely on PyTorch's implementation for the most part. While PyTorch's implementation \cite{PTDocs} may be very efficient, we do not know if it suits our models best --- a typical problem when using external libraries.

On the other hand, we did not venture in adjusting the model's parameters much as the models took long time to tests. Tinkering with the models' characteristics might have optimized the models more if we had devised a way to experiment efficiently. This also remains a topic for future study.

We also could not venture in-depth of quirky behavior and ascertain reasons with high confidence. Our research project limited us to focus on improving the Avicaching game, restricting us from rigorously studying thread synchronization delays and GPUs' architecture.

\section{Further Research}
There exist numerous possibilities for solving the problems better and faster --- from more complex models to better preprocessing to more parallel algorithms with fewer synchronization barriers. Some important suggestions are listed below:

\subsubsection{Choice of Gradient-Descent Algorithm}
\Cref{fig:Plot for 3-layered Model} shows how the choice of Adam's algorithm \cite{Adam} for \textsc{Gradient-Descent}($\cdot$) helps the model to learn quickly. However, we also witness long periods of saturation after a few epochs. This was the case for several other algorithms (SGD \cite{SGD} and Adagrad \cite{Adagrad}) as well, but with different paces of learning. Since the organizers would want to further optimize the set of weights, research could be done on avoiding the long, unwavering saturation phase. This may involve using other algorithms for \textsc{Gradient-Descent}($\cdot$) (\Cref{alg:Algorithm for the Identification Problem}) and/or altering the loss function ($Z_P$ --- \Cref{eqn:iden_problem}).

\subsubsection{Modeling LP Differently to Reduce Runtimes}
LP is a simple tool for optimizing different problems, with various algorithms for solving LPs --- Simplex, Criss-Cross and other Interior Point techniques. While it gives optimal results, it can be computationally expensive if the matrices are large (as depicted in \Cref{fig:Restricted Finding Rewards - Time taken by the LP}). One can try several approaches to reduce computation time here:
\begin{itemize}
    \item Implement GPU or OpenMP backend for the LP.
    \item Constrain rewards differently (\Cref{sec:Constraining Rewards}). Parallelized algorithms for constraining rewards can decrease the runtime for the Pricing Problem's model considerably as the current LP accounts for $\approx 94\%$ of the total runtime.
\end{itemize}


\documentclass[letterpaper]{article}

\usepackage[utf8]{inputenc}
\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{January 23, 2015}
\maketitle
$E$ is measurable if $\dots$

irrational numbers have a measure because rationals have measure 0 and the complement of a measurable set is 0

\section*{today}
explain why any open interval is measurable

if $E_1$ and $E_2$ are disjoint and measurable then $m*(A\cap(E_1\cup E_2)=m*(A\cap E_1)+m*(A\cap E_2)$ for any $A$

$E_1,E_2,E_3,\dots,E_n$ disjoint and measurable then $m*(A\cap(\bigcup\limits_{i=1}^nE_i))=\sum\limits_{i=1}^n{m*(A\cap E_i)}$

\subsection*{theorem}
if $\{E_i\}_{i=1}^\infty$ are measurable, countable then
\begin{enumerate}
\item
$\bigcup\limits_{i=1}^\infty$ measurable
\item
$\bigcap\limits_{i=1}^\infty$ measurable
\item
$m*(\bigcup\limits_{i=1}^\infty E_i)\le\sum\limits_{i=1}^\infty{m*(E_i)}$
\item
if $E_i\cap E_j=\emptyset$ for all $i,j$

$m*(\bigcup\limits_{i=1}^\infty E_i)=\sum\limits_{i=1}^\infty{m*(E_i)}$
\end{enumerate}
\subsubsection*{proof}
{\bfseries case 1}

$E_i\cap E_j=\emptyset, i\ne j$

$F_n=\bigcup\limits_{i=1}^n E_i$

we know that $F_n$ is measurable so $m*(A\cap F_n)=\sum\limits_{i=1}^n{m*(A\cap E_i)}$

$m*(A)=m*(A\cap F_n)+m*(A\cap F_n^C)$

for all $n$
\begin{align*}
  m*(A)&=m*(A\cap F_n)+m*(A\cap F_n^C)\\
  &\ge m*(A\cap F_n)+m*(A\cap(\bigcup_{i=1}^\infty E_i)^C)\\
\intertext{$m*(A\cap F_n^C)$ contains $m*(A\cap(\bigcup_{i=1}^\infty E_i)^C)$}
  &= \sum\limits_{i=1}^n{m*(A\cap E_i)}+m*(A\cap(\bigcup_{i=1}^\infty E_i)^C)\\
  m*(A)&\ge \sum\limits_{i=1}^n{m*(A\cap E_i)}+m*(A\cap(\bigcup_{i=1}^\infty E_i)^C)\\
  &\ge m*(A\cap \bigcup_{i=1}^\infty E_i)+m*(A\cap(\bigcup_{i=1}^\infty E_i)^C)
\end{align*}

{\bfseries case 2} not disjoint

$E_1=\Omega_1$ and $E_2\setminus\Omega_1=\Omega_2$ and $E_3\setminus(\Omega_1\cup\Omega_2)=\Omega_3$

$\{E_i\}_{i=1}^\infty\to \{\Omega_i\}_{i=1}^\infty$ and $\Omega_i\cap\Omega_j=\emptyset\forall i\ne j$
\begin{enumerate}
\item
$\bigcup\limits_{i=1}^\infty E_i=\bigcup\limits_{i=1}^\infty \Omega_i$
\item
$\Omega_i$ is measurable ($A\setminus B=A\cap B^C$)
\item
use case one to get
$\bigcup\limits_{i=1}^\infty \Omega_i$ is measurable and imply that
$\bigcup\limits_{i=1}^\infty E_i$ is measurable
\end{enumerate}

\begin{enumerate}
\item
union of countable measurable sets is measurable
\item
$\{E_i\}_{i=1}^\infty$ with $E_i$ measurable

$\bigcap_{i=1}^\infty E_i=\left(\bigcup\limits_{i=1}^\infty(E_i)^C\right)^C$
\item
we already knew that $m*(\bigcup\limits_{i=1}^\infty E_i\le \sum\limits_{i=1}^\infty{m*(E_i)}$
\item
$\{E_i\}_{i=1}^\infty$ disjoint and measurable

$m*(\bigcup_{i=1}\infty E_i$

\begin{enumerate}
\item
$m*(\bigcup\limits_{i=1}^\infty E_i\le \sum\limits_{i=1}^\infty{m*(E_i)}$

$m*(\bigcup\limits_{i=1}^n E_i= \sum\limits_{i=1}^n{m*(E_i)}$

$m*(\bigcup_{i=1}^\infty E_i)\ge m*(\bigcup\limits_{i=1}^n E_i= \sum\limits_{i=1}^n{m*(E_i)}$

and then

$m*(\bigcup_{i=1}^\infty E_i)\ge = \sum\limits_{i=1}^\infty{m*(E_i)}$

\end{enumerate}
\end{enumerate}

\subsection*{theorem}
any open set is measurable
\subsubsection*{proof}
based on homework we know that $(a,\infty)$ is measurable

\begin{enumerate}
\item
need to show that $[b,\infty)$ is measurable for any $b$

$[b,\infty)=\bigcap_{n=1}^\infty(b-\frac{1}{n},\infty)$
\item
$(-\infty,c)$ is measurable because it's the complement of $[c,\infty)$
\item
$(a,d)$ is measurable for any $a<d$

$(a,d)=(a,\infty)\cap(-\infty,d)$
\item
any open interval $\mathbb{O}$ is measurable

$\mathbb{O}=\bigcup_{i=1}^\infty(a_i,b_i)$
Lindlöfs theorem

or any closed set is measurable
\end{enumerate}

cantor set is the intersection of a countable number of closed sets

\subsection*{proposition}
if $E_i\supseteq E_{i+1}$ in $\{E_i\}_{i=1}^\infty$ and $m*(E_1)$ is finite then $m*(\bigcap_{i=1}^\infty E_i)=\lim_{n\to\infty}m*(E_n)$

$\{n,n+1)\}_{n=1}^\infty$ will not work, why?

$\bigcap_{i=i}^\infty E_i\subseteq E_n$ for all $n$. $m*(\bigcap_{i=1}^\infty E_i\le m*(E_n)$ for all $n$
\end{document}


\subsubsection{Gesture Notation} \label{gesture_notation}
The \textit{clockwise circle} gesture of slide (b) and (j) in figure \ref{fig:slides} is abbreviated with $GesA$, the
\textit{flipped Z} gesture on slide (c) and (k) of figure \ref{fig:slides} is abbreviated with $GesB$ and so on until
the \textit{W} gesture of slide (i) and (q) in figure \ref{fig:slides} shortened with $GesH$.

As the experiment was executed by different experimentees, a instance of gesture $GesC$ performed by the fourth
experimentee on slide (d) of figure \ref{fig:slides} will be abbreviated as $exp_{4}.GesC_{1}$. The same gesture by the
same experimentee on slide (l) of figure \ref{fig:slides} will be abbreviated as $exp_{4}.GesC_{2}$.


\section{Stereo Matching - needs work done}

\includegraphics[width=\columnwidth]{pictures/standardstereo}

\subsection{Occlusion}
In an image pair each pixel has at most one corresponding pixel – In general one corresponding pixel – In case of occlusion there is none

\includegraphics[width=\columnwidth]{pictures/stereobaseline}

\subsection{Deep Stereo Matching}

\subsection{3D convex hull}
The 3D convex hull of a set of 3D points is the smallest convex set which contains all 3D points.

\subsection{Visual hull}
The visual hull is the smallest volume which can be obtained by intersecting the generalized cones generated by all possible 2D shape projections ofa 3D object.\\
\\
In 3D, the visual hull is a subset ofthe convex hull.

\subsubsection{voxel-base, marching intersections, exact polyhedral}

\subsection{Photo hull}
The photo hull is the union ofall photo-consistent volumes and the tightest possible bound on the true scene.\\
\\
It is a subset of the visual hull and - in contrast to the 3D convex hull and the visual hull depends on the texture of the 3D object.
\subsubsection{Voxel coloring}

\subsubsection{Space Carving}

Step 1: Initialize V to volume containing true scene\\
Step 2: For every voxel on surface of V test photo-consistency of voxel if voxel is inconsistent, carve it\\
Step 3: Repeat Step 2 until all voxels consistent\\
\\

Convergence: Always converges to a photo-consistent model (when all assumptions are met)
Good results on difficult real-world scenes\\
\\
Properties of Volume Intersection\\
Pros – Easy to implement, fast – Accelerated via octrees [Szeliski 1993]\\
Cons – No concavities – Reconstruction is not photo-consistent – Requires identification of silhouettes


\section{Introduction}
This project describes a~selected \textit{operational research} problem according to the~particular published research paper~\cite{paper}.
A~given problem is defined in Chapter~\ref{sec:problem}.
Approaches to a~solution to the~problem from the~paper are re-implemented,~and experimental results are finally compared with the~results in the~paper and with the~student results from the~previous years.

The~rest of this documentation is organised as follows.
Chapter~\ref{sec:method} presents an~approach to the~solution to the~problem,~and there are also described appropriate methods.
Re-implementation of the method is then depicted in Chapter~\ref{sec:implementation}.
Experimental evaluation is discussed in Chapter~\ref{sec:experiments}.
Finally,~Chapter~\ref{sec:conclusion} concludes this documentation and achieved project results.

\section{University Course Timetabling Problem} \label{sec:problem}
\textit{University Course Timetabling Problem} (\textit{UCTP}) is known as an~\emph{NP-hard} problem.
It is defined as a~set of rooms,~events in the~schedule,~students and room features,~the~completion of which individual courses require.
The UCTP solution is then assigned free room and item in the~time-schedule for each of a~given number of courses for meeting all the~specified features and conditions.
In more precise,~an~UCTP is an~optimisation problem that deals with the~scheduling process.
The~aim is to find such a~distribution of the course into classrooms and schedule times,~which does not conflict with \textit{hard} constraints,~and at the~same has the~lowest possible score of \textit{soft} constraints.
Since this is a~problem that is often solved and analyzed in practice,~there are already countless methods used in implementing the~solution.
The~categories into which the~ways of solving optimisation problems can be divided are from the~various areas.
It is often a~method of \textit{simulated annealing},~the~application of \textit{genetic algorithms},~or generally inspired by \textit{nature},~such as optimising \textit{ants colonies} and last but not least \textit{genetic algorithms}.

\subsection{Formal Definition}
An instance of the UCT problem is defined as follows:
\begin{itemize}
    \item A set of $N$ courses, $e = \{ e_1, \dots, e_N\}$
    \item $45$ time-slots
    \item A set of $R$ rooms
    \item A set of $F$ room features
    \item A set of $S$ students
\end{itemize}
where tor each room,~its capacity and the~features it provides are also given.
For each student,~there is a~list of subjects to be enrolled in,~and for each course,~lists the~required features.
Further, this problem includes $4$ \textit{hard} constraints and $3$ \textit{soft} constraints as follows.
\paragraph{Hard Constraints:}
\begin{itemize}
    \item \textbf{Event Conflict} ($H_1$): no student can be assigned to more than one course at the~same time
    \item \textbf{Room Features} ($H_2$): the~room should satisfy the~features required by the~event
    \item \textbf{Room Capacity} ($H_3$): the~number of students attending the~event should be less than or equal to the~room capacity
    \item \textbf{Room Occupancy} ($H_4$): no more than one event is allowed at a time slot in each room
\end{itemize}
\paragraph{Soft Constraints:}
\begin{itemize}
    \item \textbf{Event in the Last Time Slot} ($S_1$): a~student shall not have to attend a~course that is scheduled in the~last time slot of the~day
    \item \textbf{Two Consecutive Events} ($S_2$): a~student shall not have more than two consecutive events
    \item \textbf{One Event a Day} ($S_3$): a~student shall not have to attend a~single course on a~day
\end{itemize}
Once the~solution of the~UCTP instance is found,~it is first assessed in terms of meeting the~inviolable (\textit{hard}) constraints.
If it does not conflict with any of these hard restrictions,~the~solution is marked as \textit{feasible},~so it is a~valid and usable solution.
Violent (\textit{soft}) constraints are then used to assess and compare the~quality of the actual results.
The~lower the~value of the~conflict with these constraints for the~given solution,~the higher the~quality of the~solution.
For \textit{genetic} algorithms,~this \textit{score} represents the~value of the~fitness function of a~given solution - the \textit{chromosome}.
This fitness function for the problem is defined in the
formula below
\begin{align*}
    \min \sum_{s=1}^{S}{s_1 + s_2 + s_3}
\end{align*}
where $s_1$, $s_2$ and $s_3$ represents the relevant soft constraints score individually for each student.

\section{Differential Evolution Algorithm} \label{sec:method}
The~proposed method is named \textit{Differential Evolution Algorithm}, which is based on the~principle of \textit{genetic algorithms},~but unlike them,~the~key operation is not a~\textit{cross} but a~\textit{mutation}.
The~implemented method can be logically divided into two phases.
In the~first part,~an~initial population is created,~representing a~set of valid schedules,~and then a~\textit{Differential Evolution Algorithm} is applied.
An~algorithm that aims to increase the~quality of the~solution while maintaining the~integrity of all inviolable (hard) constraints.

\subsection{Constructive Heuristic} \label{sec:const}
The first step of the~algorithm is creating the~\textit{initial population},~i.e. the~production of a~given number of \textit{chromosomes},~each of which represents a~valid solution of the~specified UCTP instance.
Creating one schedule consists of the~gradual assignment of rooms and part of the schedule to each of the~courses.
To increase the~success of this initial creation,~the~courses are first sorted according to the~number of rooms to which they can be assigned \,--\, which is determined based on the~capacity of the~room and its features.
Subsequently,~the~sorted courses are placed in the~schedule gradually from those to which the~smallest number of rooms can be assigned.
We note,~that in this process,~the~soft restrictions are not taken into account at all in this process.
When a~\textit{feasible} solution can be created in this way,~the current \textit{chromosome} is added to the~\textit{population}, and the~algorithm continues to create a~new solution or by moving to the~second part of the~algorithm.

Otherwise,~when the~algorithm gets into a~situation where there is no free time and room for the~currently placed course,~the~\textit{neighbourhood moves} are applied to the~yet placed courses.
The aim is to rearrange the finished part of the~schedule to free space for the~currently placed course.
First,~the~\textit{neighbourhood move} $N_1$ is performed several times. The algorithm continues by placing the~current course when the~schedule was successfully rearranged.
Otherwise,~the \textit{neighbourhood move} $N_2$ is performed repeatedly.
If it is still not possible to find a~place for the~currently placed course,~the~placement of the~following courses is continued.
The~different neighbourhood structures and their explanation can be outlined as follows:

\paragraph{Neighbourhood Move $N_1$.}
Choose a~single course at random and move to a~feasible time slot that can generate the~lowest penalty cost.

\paragraph{Neighbourhood Move $N_2$.}
Select two courses at random from the~same room (the room is randomly selected) and swap time slots.

\noindent\\
The~technique described above should lead to one valid solution to the~problem.
When the current schedule cannot be successfully filled, this solution is removed from the~\textit{population}.

\subsection{Improvement Algorithm}
Once the~complete initial population is generated,~the~second phase of the~whole algorithm can begin,~which is the~optimisation by the~\textit{evolutionary algorithm}.
\textit{Genetic algorithms} inspire the implemented differential evolution algorithm,~and its main emphasis is on \textit{mutation} operations.
One iteration of the~described algorithm consists of four parts:~\textit{mutations}, \textit{crossover},~\textit{evaluation},~and \textit{selection}.
This sequence of steps is applied repeatedly until at least one of the~terminating conditions is reached.
These are the~achievement of a~fixed number of iterations (generations) or the~acquisition of a~solution whose value of the~fitness function is equal to 0.
The~base schema of this algorithm is presented below:

\begin{align*}
    & Initialisation \\
    & Evaluation \\
    & \textbf{do while} \; (termination \; criteria \; are \; met) \\
    & \quad Mutation \\
    & \quad Crossover \\
    & \quad Evaluation \\
    & \quad Selection \\
    & \textbf{end do while}
\end{align*}

\begingroup\vspace*{-\baselineskip}
\captionof{figure}{Differential Evolution Algorithm.}
\vspace*{\baselineskip}\endgroup

\paragraph{Mutation.}
The~\textit{mutation} is a central part of the~implemented differential evolution algorithm.
The~first step of the~mutation is the~random selection of two parental chromosomes \,--\, i.e. two complete solutions \,--\, from the~population.
Then a~mutation is performed by selecting one of the~two mutation operators and then applying it to each of the~parents separately.
Mutation operators are the~same as neighbourhood moves described in Section~\ref{sec:const}.
This results in a~modified pair of \textit{parental chromosomes}.

\paragraph{Crossover.}
Crossover is an~operation whose purpose is to generate two new descendants.
The~input of this operation is two-parent chromosomes obtained by mutation operation.
For each parent,~one time is randomly generated in the~schedule,~and in the~parent chromosomes,~the courses planned for a~given time are interchanged.
In order to maintain the~validity of the~solution in the~offspring,~two conditions are placed on the~exchange of the~course.
The~course can be moved only if it is free in the~second schedule on the~moving position, and moving the course to a~new location will not cause any collisions between courses.

\paragraph{Evaluation and Selection.}
Evaluation is used to evaluate newly born offspring.
To evaluate each of the~offspring,~a \textit{fitness function} is used,~which calculates a~penalty for non-compliance with violable (\textit{soft}) restrictions.
If a~better offspring has a~lower value of \textit{fitness function} than the~best individual in the~population so far,~the worst-rated chromosome in the~population is replaced by the~better of the~offspring.

\section{Implementation} \label{sec:implementation}
The described algorithm has been implemented in Python programming language.
At least,~it is required Python version 3.6.
Python libraries NumPy\footnote{Python library for mathematics computation
NumPy\,--\,\url{https://numpy.org}.} and SciPy\footnote{Python library
for mathematics computation SciPy\,--\,\url{https://www.scipy.org}.} was used for mathematics computation and work with series and lists.
Required versions of these libraries,~as well as the~next needed libraries,~are specified in the~file \texttt{requirements.txt}.
The~implementation consists of several modules described in the~paragraphs below.

\noindent \\
The module \texttt{ucctp.py} severs an~entry point of the application.
It sets a~routine for logging,~parses arguments from the~command line and calls the~main function of the~whole application.
The module \texttt{input.py} reads and validates an input file with the specification of the problem.
It contains functions for reading and parsing input files with the~specification of the~problem,~and function for writing solutions to output file in the~appropriate format.

\noindent\\
A~class \texttt{UcctpInstance} represents the~University Course Timetabling Problem.
This class encapsulates the~specification of the~problem as well as its input parameters.
Moreover, it contains operations over the problem instance that cannot be derived directly from input data.
For instance,~there is implemented the~method for sorting the~events according to the~number of rooms which they can be assigned,~the~method for computing the~collision events,~so events that have one or more common students,~or the~method to compute available rooms for courses,~and some other auxiliary methods.

\noindent\\
The most interesting is module \texttt{differential\_e\-volution.py} which contains main functions.
The method \texttt{run} serves as the~wrapper over the~whole algorithm,~and it gradually performs all required operations.
Firstly,~it loads and parses the algorithm parameters from the~file \texttt{parameters.json} and save them into the~relevant program structure.
The~next step is to create an~initial population of the chromosomes.

This is done using the~\texttt{constructive\_heuri\-stics} method,~which creates a~population of the required size by repeatedly calling the~\texttt{construct\_e\-vent\_time\-table} method.
In the~way described above tries to place all the~courses one after the~other and thus create a~complete schedule.
If there is nowhere to place a~course,~the already mentioned neighbourhood moves are applied.
In particular,~the~\texttt{apply\_mo\-ve\_n1} and \texttt{apply\_move\_n2} methods are used for this purpose.
The~chromosomes that are not complete,~i.e. even after the~application of neighbourhood moves,~no suitable location was found for any course,~are not appended to the~population.
Moreover,~as the~fulfilment of inviolable constraints is che\-cked already during the~creation of the~schedule,~we do not have to incorrectly remove chromosomes after generation.

Subsequently,~the~\texttt{evaluate\_timetables} me\-thod calculates the~evaluation of all chromosomes in a~population-based on how much they do not satisfy the~violation (soft) constraints.
The \texttt{object\_func\-tion} method is implemented to calculate the penalty for violating restrictions $s_1$, $s_2$ and $s_3$.
The~quality of each individual is then given as the~sum of these three values.
According to the~evaluation of individual chromosomes,~the~entire population is sorted from the~highest quality to the~lowest quality in the~same method (\texttt{evaluate\_timetables}).

Now the~differential evolution algorithm itself can begin.
Until the~specified number of iterations is exceeded,~or the~best solution in the~population does not have a~zero value of the~fitness function,~the \texttt{differe\-ntial\_evolution\_algorithm} method is repeatedly called,~which performs one iteration implemented algorithm.
Thus,~the~\texttt{mutation} and \texttt{crossover} methods are gradually performed.
Then,~the~evaluation is performed,~and if one of the~offspring represents a~better solution than the best one so far,~the~new offspring replaces the~worst solution in the~population.

\subsection{Algorithm Enhancement}
The implementation of the~original algorithm often had a~problem finding a~\textit{feasible} solution.
Moreover,~the~paper does not contain a~strictly detailed description of how the~creation of the~original population should take place.
As a~result,~there was space in this area for change and improved the~existing algorithm.

The~placement of the~course is still gradual from the~most problematic one.
For the~selection of the room and the~time slot until which the~course will be filled,~we implemented the~\texttt{get\_timetable} method, which selects the~most suitable of all available locations.
In more precise,~the~method \texttt{get\_final\_ti\-metable} first selects the~most suitable time slots,~wh\-ich are the~ones in which there are already the~most occupied rooms.
The~reason is that such time slots will be the~hardest to fill in the~future,~as there is a~high probability that a~conflict rate will already be located here.
Therefore,~all possible course locations are limited to those that take place in the~most appropriate time slots selected.

Subsequently,~from the~remaining locations,~the~on\-es that take place in the~most suitable rooms are selected by the~\texttt{get\_final\_time\-table} method.
Th\-ese are the~rooms in which the~smallest number of courses that have not yet been filled can be placed.
Here the reason is clear,~again the~aim is to provide as many opportunities as possible for further courses.
From these locations that meet the~above conditions for both the~room and the~time slot is then randomly selected as the~final location.

\section{Experimental Evaluation} \label{sec:experiments}
The~reference to the~set of tests on which the~original implementation was tested is no longer functional and could not be traced on other servers.
However,~we found the GitHub repository\footnote{\url{https://github.com/tomas-muller/cpsolver-itc2007}} which contains the International Timetabling Competition data-sets.
From this data set,~we took a~set of instances with a~similar structure to the~one in the~original paper.
As well as the~original set,~the~new one contains a~total of 11 tests,~of which 5 correspond to the~specification of small test input,~the~other 5 are medium and 1 input problem falls into the~category of large inputs.
A~description of the~properties that the~input file of a~given size meets is given in the~following table:
\begin{table}[ht!]
\centering
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{Category} & \multicolumn{1}{l|}{\textbf{Small}} & \multicolumn{1}{l|}{\textbf{Medium}} & \multicolumn{1}{l|}{\textbf{Large}} \\ \hline
\textbf{N (courses)}        & 100                                 & 300-400                              & 400                                 \\ \hline
\textbf{R (rooms)}        & 5                                   & 10                                   & 10                                  \\ \hline
\textbf{F (features)}        & 5                                   & 5                                    & 10                                  \\ \hline
\textbf{S (students)}        & 80                                  & 200                                  & 200                                 \\ \hline
\textbf{max N per S}  & 20                                  & 20                                   & 20                                  \\ \hline
\textbf{max S per N}  & 20                                  & 50                                   & 100                                 \\ \hline
\textbf{max F per R}  & 3                                   & 3                                    & 5                                   \\ \hline
\textbf{\% usage of F}     & 70                                  & 80                                   & 90                                  \\ \hline
\end{tabular}
\caption{Description of the properties of individual categories of test inputs.}
\end{table}

To mimic the~experiments performed in the~original paper as much as possible,~all arguments were set to the~same values when experimenting as in the~original experiments performed by the~paper authors.
An overview of the parameters values used is as follows:
\begin{lstlisting}[language=json,firstnumber=1]
{
    "generations_number": 200000,
    "population_size": 50,
    "crossover_rate": 0.8,
    "mutation_rate": 0.5,
    "n1_applications": 100,
    "n2_applications": 100
}
\end{lstlisting}

\begin{table*}[ht!]
\begin{center}
\begin{tabular}{|l|c|c|c|c|c|c|}
\hline
\textbf{Input}   & \multicolumn{1}{l|}{\textbf{Paper}} & \multicolumn{1}{l|}{\textbf{xvitra00}} & \multicolumn{1}{l|}{\textbf{xmarus06}} & \multicolumn{1}{l|}{\textbf{xvales03}} & \multicolumn{1}{l|}{\textbf{xvales02}} & \multicolumn{1}{l|}{\textbf{xstupi00}} \\ \hline
\textbf{small1}  & 0                                   & \textbf{11}                            & 33                                     & 31.2                                   & 47                                     & 42                                     \\ \hline
\textbf{small2}  & 0                                   & 21                                     & 32                                     & 34.5                                   & 21                                     & \textbf{20}                            \\ \hline
\textbf{small3}  & 0                                   & \textbf{16}                            & 26                                     & 28.0                                   & 38                                     & 25                                     \\ \hline
\textbf{small4}  & 0                                   & 45                                     & 42                                     & \textbf{41.7}                          & 53                                     & 46                                     \\ \hline
\textbf{small5}  & 0                                   & \textbf{20}                            & 30                                     & 32.5                                   & 37                                     & 27                                     \\ \hline
\textbf{medium1} & 160                                 & \textbf{27}                            & 234                                    & 255.9                                  & 237                                    & 198                                    \\ \hline
\textbf{medium2} & 81                                  & 154                                    & 132                                    & 126.2                                  & \textbf{62}                            & 71                                     \\ \hline
\textbf{medium3} & 149                                 & \textbf{117}                           & 269                                    & 289.8                                  & 205                                    & 230                                    \\ \hline
\textbf{medium4} & 113                                 & \textbf{26}                            & 170                                    & 173.1                                  & 66                                     & 51                                     \\ \hline
\textbf{medium5} & 143                                 & \textbf{27}                            & 145                                    & 168.2                                  & 76                                     & 59                                     \\ \hline
\textbf{large}   & 735                                 & 369                                    & 468                                    & 408.4                                  & 342                                    & \textit{\textbf{325}}                  \\ \hline
\end{tabular}
\caption{Comparison of various algorithms on the individual input instances.}
\label{tab:compare}
\end{center}
\end{table*}

\subsection{Results Comparison}
As in the~original experiments,~a~total of 11 times were tested for each test problem,~and the~lowest value of the~result was always selected for this report.
Due to the absence of the~original set,~the~results of the~implementation were compared with the~implementations of the~algorithms implemented by the students in the previous years, which are available in their GitHub pages\footnote{\url{https://github.com/marusak/UCTPS/blob/master/doc.pdf}}\footnote{\url{https://github.com/Bihanojko/SNT/blob/master/doc.pdf}}.
A~comparison of the algorithms on the~
individual test inputs is given in Table~\ref{tab:compare}.
For each input instance of the~problem,~the~best of the~achieved values is marked here in bold,~i.e.~the~algorithm that achieved the~best solution on the~given input.
The~implemented algorithm achieved two times the~best result.
On the~contrary,~only in one case,~it turned out the~worst at all,~so it is a~competitive algorithm.
We note, that the~\textit{xvales02} implements the~same method as we.
Compared with the~original implementation,~Table~\ref{tab:compare} also shows the~values obtained by the authors of the original paper.
However,~this comparison is not very meaningful,~as the~input instances correspond in size,~but still be one-sided problems and values of the~best possible solutions can vary considerably.

\subsection{Influence of population-size parameter}
The~next part of the~experimenting deals with examining the~influence of the~value of the~\textit{population-size} parameter on the~population's quality.
This parameter certainly affects the~value of the~\textit{fitness function} of the~solution,~the~larger the~original population,~the~more parent chromosomes can be selected for crossbreeding,~and thus the~more diverse chromosomes we can obtain.
For each input set,~experiments were performed with a~\textit{population size} ranging from 10 to 100 individuals with a~step of 10.
The~number of generations was always set to 100 so that the~iterative increase in population quality was not reflected too much in the~results of the~experiment.
The~resulting characteristics for each of the 11 test inputs are shown in Figures~\ref{fig:smallp},~\ref{fig:mediump},~\ref{fig:largep}.
From the ~graphs,~it is clear that randomness greatly influences the~quality of the~population.
Still,~when looking at the~whole curve,~the~expected hypothesis is confirmed: The~greater the~number of individuals in the~population,~the higher the~quality of the~population.

\subsection{Influence of generations-number parameter}
The~last part of the~experiments is devoted to examining the effect of the~\textit{generations-count} parameter on the~quality of the~resulting solution.
This parameter significantly affects the~value of the~\textit{fitness function} of the~result,~as the~population can improve in each generation.
Its research can also be useful if we would like to use the~application for quality calculations in the~shortest possible time because,~for a~higher number of generations,~the~calculation time starts to increase significantly.
For each input set,~the~experiment has performed 10 times,~and then the~run that achieved the~greatest improvement over the~generations was plotted.
The~experiments were performed with a~population size of 50 individuals,~and the~quality of the~population was recorded in the~range from 0 to 20000 generations with step 1.
The~values of the~graph were obtained in an~excerpt from the application after each iteration.
The~resulting characteristics for each of the~11 test inputs are shown in Figure~\ref{fig:smallg},~\ref{fig:mediumg},~\ref{fig:largeg}.
There is a~clear improvement in all cases,~with a~near logarithmic decrease at the~beginning of the~curve,~and later primarily a~linear.

\noindent \\
These~experiments confirmed both the~correctness of the~re-implementation of the~algorithm and the~functionality and efficiency of the~original algorithm.

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/small_population.pdf}
\caption{Influence of population-size parameter for small problem instances.}%
\label{fig:smallp}%
\end{figure*}

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/medium_population.pdf}
\caption{Influence of population-size parameter for medium problem instances.}%
\label{fig:mediump}%
\end{figure*}

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/large_population.pdf}
\caption{Influence of population-size parameter for large problem instance.}%
\label{fig:largep}%
\end{figure*}

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/small_generation.pdf}
\caption{Influence of generations-number parameter for small problem instances.}%
\label{fig:smallg}%
\end{figure*}

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/medium_generation.pdf}
\caption{Influence of generations-number parameter for medium problem instances.}%
\label{fig:mediumg}%
\end{figure*}

\begin{figure*}[h]
\centering
\includegraphics[height=0.30\textheight]{figures/large_generation.pdf}
\caption{Influence of generations-number parameter for large problem instance.}%
\label{fig:largeg}%
\end{figure*}

\section{Conclusion} \label{sec:conclusion}

As part of this project,~an~algorithm called \textit{Differential Evolution Algorithm} was studied and re-implemented.
Subsequently,~several experiments were performed with the~implementation,~comparing this approach with other algorithms,~examining the~effect of population size on the~quality of solutions,~and the~number of generations on the~quality of the~total population.
The~functionality of the~re-implementation was verified by these experiments.


\providecommand{\main}{..}
\documentclass[\main/thesis.tex]{subfiles}

\begin{document}
\graphicspath{{img/}{02_theory/img/}}

% \chapterimage{chapter_head_1.pdf}
\chapter{Ultra-Wideband Signals}

This chapter provides a quick explanation of UWB along with its advantages and regulations. The later 2 sections also give a modulation scheme and the IEEE standard for UWB.

\section{Definition of Ultra-Wideband System}

With $f$\textsubscript{c} is the frequency in which the system has the maximum power density and the frequencies $f$\textsubscript{h} and $f$\textsubscript{L} determine the location where the power of spectral density is 10dB less then the $f$\textsubscript{c}. $B$\textsubscript{frac} is defined as
\begin{equation}
    B\textsubscript{frac}=\frac{B}{f\textsubscript{c}}
\end{equation} where $B$ is the bandwidth of the system.

In term of high and low frequencies, we have:
\begin{equation}
    B=(f\textsubscript{H} - f\textsubscript{L})
\end{equation}
and
\begin{equation}
    f\textsubscript{c} = \frac{f\textsubscript{H} + f\textsubscript{L}}{2}\
\end{equation}
so
\begin{equation}
    B\textsubscript{frac} = \frac{2(f\textsubscript{H} - f\textsubscript{L})}{f\textsubscript{H} + f\textsubscript{L}}
\end{equation}

The Federal Communication Commission (FCC) has define UWB systems as those which have an absolute bandwidth larger than 500Mhz and $f$\textsubscript{c} larger than 2.5 GHz, or have a $B$\textsubscript{frac} larger than 0.2 for system with $f$\textsubscript{c} lower than 2.5GHz \cite{ultra_wideband_positioning_systems}.

Ultra-Wideband radio is also referred as ‘impulse’, ‘short-pulse’, ‘non-sinusoidal’, ‘carrierless’, ‘time domain’, ‘super wideband’, ‘fast frequency chirp’ and ‘mono-pulse’ radio.

Very short pulse transmissions that result in an ultra-wideband spectrum are both utilized by impulse radio communication systems and impulse radars. Since the data modulation is introduced by pulse position modulation,  this communication manner is also classified as a pulse modulation technique (PPM).

Due to the low-power spectral density, the UWB signal is noise-like which make the interception and detection quite difficult. On the other hand, this makes UWB cause very little interference with existing narrow-band radio systems. Moreover, UWB might operate without license depend on the attitude of national and international regulatory bodies.

One result of the large bandwidth of UWB is that due to the inverse relationship of
time and frequency. Figure \ref{fig:uwb_versus_other_radio_communication_systems} shows the differences between UWB and other radio systems in the frequency band and power spectral density.

\begin{figure}[H]
    \centering
    \includegraphics[width=1\textwidth]{uwb_versus_other_radio_communication_systems.png}
    \caption{UWB versus other radio communication systems}
    \label{fig:uwb_versus_other_radio_communication_systems}
\end{figure}

\section{Advantages of Ultra-Wideband}

Below \cite{uwb_theory_and_applications} are some advantages that make it attractive for consumer communication applications.
\begin{itemize}
    \item Potentially low complexity and low cost
    \item Noise like signal
    \item Resistant to multi-path and jamming
    \item Good time-domain resolution allowing for localization and tracking application.
\end{itemize}

The base-band nature of signal transmission reduces the complexity and cost of UWB systems.
Unlike conventional radio systems, a very short time-domain pulse produced by the UWB transmitter is able to propagate without the need of an additional RF mixing stage.
% The RF mixing stage takes a base-band signal and `inject' carrier frequency or translates the signal to a frequency which has desirable propagation characteristic.
% The very nature of the UWB signal means it spans frequencies commonly used as carrier frequencies.
% The signal will propagate well without the need of additional up-conversion and amplification.
There is no need of additional up-conversion and amplification and the sender side.
The reverse process of down-conversion is also not required in the UWB receiver. This means the omission of a local oscillator in the receiver, and the removal of associated complex delay and phase tracking loop. Consequently, a UWB system can be implemented in low cost, low power, integrated circuit process.

One of the most important topics in current UWB research is the interference phenomenon between impulse radio and existing radio systems. While there is some debate in the literature, it appears that low power, noise-like, UWB transmission does not significantly interfere existing radio systems. The low energy of and the pseudo-random (PR) characteristics of the UWB signal, however, make it noise-like, thus making it quite difficult to detect unintended signals.

% Time-modulation systems offer a possibility for high data rates for communication. Hundreds of Mbps have been reported for communication links.

Using UWB technology, a very high multi-path resolution is achieved because of the large bandwidth of the transmitted signal. The large bandwidth offers huge frequency diversity which, together with the discontinuous transmission, make the UWB signal resistant to severe multi-path propagation and jamming/interference.

The very narrow time-domain pulse of UWB radios means that it is potentially able to offer timing precision much better than other radio systems. Together with good material penetration properties, UWB signals offer opportunities for short-range radar applications such as rescue and anti-crime operations, as well as in surveying and the mining industry. UWB does not provide precise timing and extreme penetration at the same time, but UWB waveforms present a better choice than do conventional radio systems.

\section{International Regulations for UWB Signals}

The effective isotropic radiated power (EIRP) which can be defined as the product of its gain and input power is one important feature of a radar and communications transmitter . Figure \ref{fig:fcc_spectral_mask_for_indoor_uwb_systems} shows the FCC spectral mask of the indoor UWB EIRP emission level. It is evidence that the maximum signal power is limited to -41.3 dBm per MHz throughout the whole UWB frequency range from 3.1 to 10.6 GHz. To comply with the FCC standards and regulations, all UWB systems and devices must work within this spectral mask for legal operation.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.7\textwidth]{fcc_spectral_mask_for_indoor_uwb_systems}
    \caption{FCC spectral mask for indoor UWB systems}
    \label{fig:fcc_spectral_mask_for_indoor_uwb_systems}
\end{figure}

\section{Relationship of Bandwidth with Data Rate and Power Consumption}
As indicated by the Shannon-Harley theorem, there is a direct relationship between capacity and bandwidth and an inverse relationship between bandwidth and power consumption. Their theorem states:
\begin{equation}
    C=B\log_2(1+\frac{S}{N})
\end{equation} where $C$ is the capacity ($bits/second$), $B$ is the bandwidth, $S$ is the average received signal power over $B$ and $N$ is the average noise over $B$.

For a specific capacity, it consumes less power with a larger bandwidth. Since $\frac{S}{N}$ is under a logarithm, it is easier to increase the capacity by increasing of the bandwidth instead of $\frac{S}{N}$. It is common to refer to $\frac{S}{N}$ as SNR, the Signal to Noise Ratio. Figure \ref{fig:capacity_versus_bandwidth_curves_for_uwb_systems_over_awgn_channels} \cite{ultra_wideband_positioning_systems} shows the relationship between the bandwidth and the capacity for five different SNRs.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.8\textwidth]{capacity_versus_bandwidth_curves_for_uwb_systems_over_awgn_channels}
    \caption{Capacity versus bandwidth curves for UWB systems over AWGN channels}
    \label{fig:capacity_versus_bandwidth_curves_for_uwb_systems_over_awgn_channels}
\end{figure}

\section{An UWB Modulation Scheme: Impulse Radio Scheme}

Time-modulated ultra wide-band (TM-UWB) communication is based on discontinuous emission of very short Gaussian pulses or other types of pulse waveforms (monocycles).

As in figure \ref{fig:an_ir_uwb_signal} \cite{ultra_wideband_positioning_systems}, data is transmitted by low duty UWB signals information of the symbol is conveyed by position and/or polarity of the signal. Each symbol corresponds to one or more signals. In the following example, two consecutive IR signals represent one symbol. The IR signal can occupy one of the chip-intervals($T\textsubscript{$c$}$) within a frame ($T\textsubscript{$f$}$). A time-hoping (TH) code is used for determining the accurate position of a signal in a dedicated time frame to decrease the chance of interference between UWB systems.

% In the following example, the TH codes for the symbols are \{2,1\}, \{2,3\} and \{1,0\} respectively,
% In this example, the information corresponds to the polarity of the signals, so the IR stream represents the binary data `101'. This technique is commonly known as Binary Phase Shifts Keying (BPSK).

\begin{figure}[H]
    \centering
    \includegraphics[width=1\textwidth]{an_ir_uwb_signal}
    \caption{An IR UWB signal}
    \label{fig:an_ir_uwb_signal}
\end{figure}

An IR UWB signal, in which two pulses are transmitted per information symbol, and information is conveyed by the polarities of the pulses (BPSK). Hence, +1, -1 and +1 are being transmitted in the example shown in figure \ref{fig:an_ir_uwb_signal}. Note that each pulse resides in an interval of $T\textsubscript{$f$}$ seconds, called a “frame’’, and the positions of the pulses in different frames are determined by a TH (Time-hoping) code, which is {2, 1, 2, 3, 1, 0} in the example, so the first and the second signals are shifted by two and one chip-interval respectively and so on.

\section{IEEE 802.15.4a Standard}
A new physical layer concept for low data rate applications utilizing UWB technology has been defined by the 802.15.4a study group \cite{IEEE_Std_802_15_4_2015}. Applications that require only moderate data throughput, but long battery life such as low-rate wireless personal area networks, sensors, and small networks are well-suited to UWB technology.

The IEEE 802.15.4a specifies two optional signaling formats based on  impulse-radio Ultra-Wideband (IR-UWB) and chirp spread spectrum (CSS). The IR-UWB option can use 250–750 MHz, 3.244-4.742 GHz, or 5.944-10.234 GHz bands; whereas the CSS uses the 2.4–2.4835 GHz band. For the IR-UWB there is an optional ranging capability, whereas the CSS signals can only be used for communications purposes. Only the IR-UWB option of the IEEE 802.15.4a standard is studied in this thesis.

\subsubsection{Channel allocations}
According to the IEEE 802.15.4 standard, a UWB device can transmit in one or more of the following bands:
\begin{itemize}
    \item Sub-GHz: 250 - 750 MHz
    \item Low band: 3.244- 4.742 GHz
    \item High band: 5.944 - 10.234 GHz.
\end{itemize}

Over these three bands, there are 16 channels supported for the UWB PHY: 1 in the sub-GHz band, 4 in the low band and 11 in the high band. These channels, their center frequencies as well as bandwidths are listed in table \ref{tab:uwb_channels_for_the_IEEE_802_15_4a_standard} together with mandatory channels in each band.

\begin{table}[H]
    \centering
    \begin{tabular}{ |c|c|c|c|c| }
        \hline
        Channel No. & Center freq. (MHz) & Bandwidth (MHz) & UWB band & Mandatory \\\hline
        0& 499.2& 499.2& Sub-GHz& Yes \\\hline
        1& 3494.4& 499.2& Low band& No \\\hline
        2& 3993.6& 499.2& Low band& No \\\hline
        3& 4492.8& 499.2& Low band& Yes \\\hline
        4& 3993.6& 1331.2& Low band& No \\\hline
        5& 6489.6& 499.2& High band& No \\\hline
        6& 6988.8& 499.2& High band& No \\\hline
        7& 6489.6& 1081.6& High band& No \\\hline
        8& 7488.0& 499.2& High band& No \\\hline
        9& 7987.2& 499.2& High band& Yes \\\hline
        10& 8486.4& 499.2& High band& No \\\hline
        11& 7987.2& 1331.2& High band& No \\\hline
        12& 8985.6& 499.2& High band& No \\\hline
        13& 9484.8& 499.2& High band& No \\\hline
        14& 9984.0& 499.2& High band& No \\\hline
        15& 9484.8& 1354.97& High band& No \\\hline
    \end{tabular}
    \caption{UWB channels for the IEEE 802.15.4a standard}
    \label{tab:uwb_channels_for_the_IEEE_802_15_4a_standard}
\end{table}

The DWM1001 module has a built-in antenna for UWB channel 5.
\bib
\end{document}