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

\begin{document}

\begin{abstract}
This paper presents ACROMUSE, a novel genetic algorithm (GA) which adapts crossover, mutation, and selection
parameters. ACROMUSEs objective is to create and maintain a diverse population of highly-fit (healthy) individuals,
capable of adapting quickly to fitness landscape change and well-suited to the efficient optimization of multimodal
fitness landscapes. A new methodology is introduced for determining standard population diversity (SPD) and an original
measure of healthy population diversity (HPD) is proposed. The SPD measure is employed to adapt crossover and mutation,
while selection pressure is controlled by adapting tournament size according to HPD. In addition to selection pressure
control, ACROMUSE tournament selection selects individuals according to healthy diversity contribution rather than
fitness. This proposed selection mechanism simultaneously promotes diversity and fitness within the population. The
performance of ACROMUSE is evaluated using various multimodal benchmark functions. Statistically significant results
are presented comparing ACROMUSEs fitness and diversity performance to that of several other GAs. By maintaining a
diverse population of healthy individuals, ACROMUSE responds to fitness landscape change by restoring better fitness
scores faster than other GAs. Analysis of the adaptive operators illustrates that the key benefit of ACROMUSE is the
synergy of the operators working together to achieve an effective balance between exploration and exploitation.
\end{abstract}

\begin{mdframed}
\fullcite{6036171}
\end{mdframed}

Premature population convergence about a local optimum is a common problem. It is usually caused by one of the
following reasons.

\begin{enumerate}
	\item \textbf{Incorrect application of selection pressure:} Whereby a ``super-performer'' in the population
	dominates the selection procedure and eliminates much of the population's diversity.
	\item \textbf{Too low mutation rate:} Diversity is lost trough selection and not recovered via mutation.
	\item \textbf{Loss of crossover efficacy:} As a population becomes more converged, recombination of similar
	individuals causes similar offspring (inbreeding).
\end{enumerate}

This papers presents \textbf{ACROMUSE} which adapts the crossover, mutation and selection parameters. The main goal is
maintaining a diverse population of healthy individuals. It employs two measures to of population diversity.

\begin{itemize}
	\item \textbf{Standard Population Diversity (SPD)} \\
	This measure describes the population's solution space diversity. The SPD measure is used to control mutation and
	crossover. Crossover employs SPD to divide the population into an \textbf{exploration section} and an
	\textbf{exploitation section}. The sizes of these sections are controlled by the SPD measure.
	\item \textbf{Healty Population Diversity (HPD)} \\
	This measure describes a population’s solution space diversity from a fitness perspective, i.e., a measure of the
	diversity of healthy individuals. HPD is used to regulate selection pressure. Tournament size is reduced when HPD
	is low permitting lower-fitness individuals to reproduce.
\end{itemize}

Maintaining a diverse population is very important for GA search. Not only does high-genetic diversity increase the
population's search coverage but it also endows the population with a degree of robustness in case of environmental
change.

\section{SPD \& HPD}

\subsection{Standard Population Diversity (SPD)}
The SPD describes the level of variation in a population. Genetic diversity is a very important component of
evolutionary exploration since a GA can only search the space offered to it by the genes present in the population.

Traditional GA's can suffer from early convergence. Individuals converge to a relatively fit area trough repeated
selection of similar individuals. This is of course undesirable when it's only a local optimum.

High mutation rate can scatter individuals to introduce novel genetic information. ACROMUSE implements such an adaptive
mutation operator. The trade-off is that high mutation rates are generally destructive from a fitness perspective.

\subsection{Calculating SPD}

SPD is calculated by finding the position of the average individual within the population and summing the gene-wise
Euclidean distances from this average point to the location of each individual. ACROMUSE’s population consists of $P$
individuals ($G_1$ to $G_P$) where each individual consist of $N$ genes: $G_i = (G_{i,1} \mathellipsis G_{i,N})$.

\begin{equation}
G_n^{\text{avg}} = \frac{1}{P} \sum_{i=1}^P G_{i,n}
\end{equation}

A simple summation for SPD is not used because is cannot be normalized, leading to the SPD measure varying immensely
for different problems and populations. Therefore, a gene-wise standard deviation is performed.

\begin{equation}
\text{SPD} = C_v(G^{\text{avg}}) = \frac{1}{N} \sum_{j=1}^N \left( \frac{\sigma (G^{\text{avg}}_j)}{G^{\text{avg}}_j}
\right)
\end{equation}

\subsection{Healthy Population Diversity (HPD)}
What SPD lacks is that it does not account for the position of individuals in the fitness space. It is possible that
the populations appears diverged, but that most highly-fit individuals lie within a converged localized area. Healthy
individuals are population members that achieve good fitness scores. HPD is a a fitness-weighted measure of population
diversity. It differs from SPD in that each individual's contribution to diversity in the solution space is influenced
according to its fitness.

\subsection{Calculating HPD}
In contrast to SPD that exclusively considers the solution space, HPD merges both fitness and solution spaces by
weighting each individual's distance contribution in the solution space according to its score in the fitness space.

HPD is calculated by finding the position of the weighted average individual within the population and summing the
gene-wise fitness-weighted distances from this weighted average point to the location of each individual.

\begin{equation}
\text{HPD} = C_V(G^{\text{W.avg}}) = \frac{1}{N} \sum_{j=1}^N \left( \frac{\sigma
(G^{\text{W.avg}}_j)}{G^{\text{W.avg}}_j} \right)
\end{equation}

Here, $G^{\text{W.avg}}$ is the weighted average individual, computed as the fitness-weighted gene-wise average across
all individuals.

\section{Adaptive Operation Implementation}

The performance or a traditional GA is highly dependent on the choice of fixed parameters. In contrast, adaptive GA's
parameters vary according to population statistics. Here, premature convergence is prevented by modifying the
crossover, mutation and selection operators according tot the population's diversity.

\subsection{Adaptive Crossover}

Crossover generally converges the population because no new genetic information is  added. The technique of adaptively
mutating individuals that do not undergo crossover divides the population into two sections:

\begin{enumerate}
	\item Exploitation Section
	\item Exploration Section
\end{enumerate}

The size of each section is determined by the SPD, with a larger exploration section for low SPD or and larger
exploitation section for a high SPD. The crossover probability is given by $P_c$.

\begin{equation}
P_c = \bigg[ \left( \frac{\text{SPD}}{\text{SPD}_\text{max}} \cdot (K_2 - K_1) \right) + K_1 \bigg]
\end{equation}

\subsection{Adaptive Mutation}
The adaptive mutation rate $P_m$ is an average of two mechanisms: SPD controlled mutation ($P_m^{\text{Diversity}}$)
and parent fitness controlled mutation ($P_m^{\text{Fitness}}$)

\begin{equation}
P_m^{\text{Diversity}} = \frac{\text{SPD}_\text{max} - \text{SPD}}{\text{SPD}_\text{max}} \cdot K
\end{equation}
\begin{equation}
P_m^{\text{Fitness}} = \left( \frac{f_{\text{max}} - f}{f_{\text{max}} - f_{\text{min}}} \right) \cdot K
\end{equation}
\begin{equation}
	P_m = \frac{P_m^{\text{Diversity}}  + P_m^{\text{Fitness}}}{2}
\end{equation}

\subsection{Adaptive Selection}

\subsubsection{Limitations Adaptive Crossover and Mutation} Most mutations have a negative impact on fitness. This is
because, for most problems, high-fitness areas are sparse in the fitness landscape. A nonadaptive selection operator
continued to choose from the same converged cluster of highly fit individuals (exploitation segment of the population),
neglecting the less-fit individuals scattered throughout the fitness landscape by the exploration segment.

\subsubsection{Rationale for Adaptive Selection} From a selection perspective, a diverged parent population does not
automatically result in diverged offspring.  A tournament size equal to the population size equates to elitism, while a
tournament size of 1 equates to random selection. Therefore, decreasing tournament size in a converged population
provides outlying individuals with a chance of selection. The SPD measure is unfortunately not a good indicator, as
selection pressure will increase in case of high SPD, but selection will return to a converged high fitness section due
to low HPD.

\subsubsection{Proposed Adaptive Selection Operator} The HPD measure controls tournament size. When the population is
converged from a fitness-based perspective, low-fitness outliers are offered a greater chance of selection.

\begin{equation}
\text{Tsize} = \left\lceil \frac{\text{HPD}}{\text{HPD}_\text{max}} \cdot \text{Tsize}_\text{max} \right\rceil
\end{equation}

\subsubsection{Traditional Tournament Selection}

Tournament selection involves selecting a number ($\text{Tsize}$) of individuals randomly from the population, with the
best individual from this group being selected as a parent. The best individual is the one with the highest fitness.

\subsubsection{Adaptive Tournament Selection} Rather than selecting the individual with the highest fitness, the individual
with the largest healthy diversity contribution is selected. This ensures that selection recognizes both diversity
contribution and fitness in choosing the best individuals for reproduction.

\section{GA Review}

\begin{itemize}
	\item \textbf{Traditional Genetic Algorithm (TGA)} \\
	The TGA does not employ adaptive operators. Default parameters are optimal in many cases but present a significant
	risk of premature convergence.

	\item \textbf{Fitness Sharing (FS)} \\
	Individuals within a certain ``share-radius'' of each other have their fitness penalized according to a sharing
	function. This limits the number of individuals that can successfully occupy a niche and, therefore, encourages
	exploration of other potential high-fitness areas.

	\item \textbf{Deterministic Crowding (DC)} \\
	DC is an elegant, elitist algorithm which insists that an offspring must be better than its most genotypically-
	similar parent in order to progress to the next generation.

	\item \textbf{CHC GA} \\
	Individuals are randomly selected for crossover, therefore, giving every individual an equal chance of
	reproduction. However, crossover is only allowed if individuals are sufficiently different genotypically. If no
	crossover is possible at the current threshold, the threshold is decremented and
	crossover is re-attempted.

	\item \textbf{Boltzmann Roulette Selection (BRS)} \\
	This method begins search with a lowselection pressure and increases the pressure steadily according to a
	predefined schedule. This approach affords greater exploration in the early stages of search, with increased
	exploitation later.
\end{itemize}

\section{Conclusion}
For the multimodal functions employed, ACROMUSE outperforms all other investigated algorithms with regard to locating
and recovering the best solution in the shortest time. For the multimodal functions employed, ACROMUSE outperforms all
other investigated algorithms with regard to locating and recovering the best solution in the shortest time.
Maintaining a diverse population is important for increasing population search coverage and for dealing with fitness
landscape change. Results demonstrate that through maintaining high HPD, ACROMUSE copes well with environmental change,
restoring better fitness scores faster than all other investigated algorithms.

\begin{itemize}

	\item \textbf{Traditional Genetic Algorithm (TGA)} \\
	TGA exhibits all the negative side effects associated with strong, nondynamic selection pressure and low- static
	mutation rates (i.e., loss of diversity/premature convergence at local optima).

	\item \textbf{Fitness Sharing (FS)} \\
	FS fails to maintain the same levels of SPD or HPD as ACROMUSE.

	\item \textbf{Deterministic Crowding (DC)}
	DC exhibits good fitness results, comparable to those obtained from FS, though DC diversity is lost much more
	steadily than with FS or ACROMUSE, due to genetic drift inherent within the algorithm. In addition to this drift,
	DC’s inability to introduce novel diversity results in poor performance in the event of environmental change.

	\item \textbf{CHC GA} \\
	CHC with its population re-initialization mechanism performs competitively (fitness and diversity-wise) with the
	other niching algorithms, particularly in introducing novel diversity after fitness landscape change.

	\item \textbf{Boltzmann Roulette Selection (BRS)} \\
	BRS demonstrates good performance in escaping local optima in the initial stages of search but can still become
	trapped at later generations, particularly after fitness landscape change. Indeed, BRS was not designed to maintain
	long-term diversity.

\end{itemize}

\end{document}


% Results
The results of the training process are presented in this chapter. We begin by first outlining the training network architecture and training process on simulated XANES in section \ref{sec:nn-sim-data}. Then, we discuss the plan and current status on expanding the model to make solid predictions on experimental data.

\section{Training with Simulation Data} \label{sec:nn-sim-data}

The 1000 simulated XANES spectra were first loaded into a Pandas dataframe \cite{pandas-1} \cite{pandas-2} of shape $ 1000\times82 $. Each of the 82 columns represents a discrete energy value, and each row represents the absorption coefficient for a given spectrum at those energies. The dataset was split into training and testing groups according to an 80-20 random split, respectively. All absorption columns were then scaled via the standard scalar (\ref{z-score}), and the training labels were scaled via a min-max scaler (\ref{eqn:min-max-scaler}). First, the model was trained to predict four descriptors: the mean squared displacement (MSD), the mean bond length distance, the standard deviation of the bond length distributions, and the skew of the bond length distribution. Note that the standard deviation is equal to the square root of the MSD. This feature was only included preliminarily in order to better understand the correlation in the network's predictions.

\bgroup
\def\arraystretch{1.5}%  1 is the default, change whatever you need
\begin{table}[h!]
    \centering
    \begin{tabular}{|l|l|l|}
    \hline
    \textbf{Layer  Type }   & \textbf{ Output Shape}  & \textbf{\# of Parameters} \\ \hline
    Normalization  & (None, 82)    & 165                  \\ \hline
    Dense          & (None, 128)   & 10,624               \\ \hline
    Dense          & (None, 128)   & 16,512               \\ \hline
    Dense          & (None, 512)   & 25,088               \\ \hline
    Reshape        & (None, 8, 64) & 0                    \\ \hline
    1D-Convolution & (None, 6, 32) & 6,176                \\ \hline
    Dropout        & (None, 6, 32) & 0                    \\ \hline
    1D-Max-Pooling & (None, 3, 32) & 0                    \\ \hline
    Flatten        & (None, 96)    & 0                    \\ \hline
    Dense          & (None, 128)   & 12,416               \\ \hline
    Dense          & (None, 48)    & 6,192                \\ \hline
    Dense          & (None, 512)   & 25,088               \\ \hline
    Flatten        & (None, 512)   & 0                    \\ \hline
    Dense          & (None, 4)     & 513                  \\ \hline
    \end{tabular}
    \caption[NN-Architecture Optimized for Simulations]{The model architecture for the network trained entirely on simulation data (which performed poorly on experimental data) relies primarily on affine (Dense) and convolutional layers. The model includes 108,966 total parameters, 108,801 of which are trainable.}
    \label{tb:nn-arch-sims}
\end{table}
\egroup

\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/pa_train-test-fixed.png}
    \caption[Simulation Test Set Predictions]{One configuration of the trained neural network includes four output nodes: MSD, Sigma, Mean, and Kurtosis. Sigma is the square root of the MSD and was included during training to confirm the patterns recognized by the network. Each point in each subplot represents a FEFF simulated spectrum in the test set. For each spectrum, the y-axis represents the MSD value predicted by the NN, and the x-axis represents the true MSD (label) for that spectrum. Hence, points on the $ y=x $ red line are perfect predictions.}
    \label{fig:train-test-split-all4}
\end{figure}

\section{Experimental Data} \label{ch:results}

Due to the visible differences between simulation and experimental data discussed in chapter 2, training a neural network entirely on simulation data and then making predictions on experimental data is unlikely to provide quality results. Using the trained network from Table (\ref{tb:nn-arch-sims}) that predicted the test set values in Figure \ref{fig:train-test-split-all4}, we predicted the MSD values from two experimental spectra. On the unpublished IMASC data, the network predicted an MSD of $0.0003724~\text{\AA}^2$ instead of the EXAFS equation fitted value of ${\sigma^2=0.0102(8)~\text{\AA}^2}$. This poor prediction suggests the network considers the experimental spectrum to look most similar to the lowest disorder FEFF spectra; the model is not generalizing to understand the disorder encoded in the spectral shape. In order to rectify this, we turn to data augmentation and include various forms of augmented experimental spectra in the training process. This approach is the topic of the following sections.

\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/quality-of-interpolation-skinny.pdf}
    \caption[Experimental Data Interpolation]{The experimental data is measured as a function of different energy values than those on which the neural network is trained. Consequently, the experimental spectrum must be mapped onto the proper energy mesh via linear interpolation.}
    \label{fig:interpolation-skinny}
\end{figure}

\subsection{Data Augmentation}
While there is ample data for training and predicting on exclusively simulation data, we only have two experimental spectra. In order to create more training and testing data for the neural network, two types of data augmentation were utilized: Gaussian noise inclusion and horizontal spectral shifting. While the motivation for utilizing data augmentation is to expand the size of the experimental training and testing set, the neural network must be trained to recognize the augmentation types prior to training or testing on the experimental data. As such, both the FEFF simulated dataset and experimental dataset are augmented.

Noise is artificially injected into the spectra by randomly shifting each absorption coefficient vertically. The shifted value for each energy level is selected from a Gaussian distribution with standard deviation $ \sigma=0.01 $. An exaggerated example of the injected noise is shown in Figure \ref{fig:data-aug-gauss-noise}.

\begin{figure}[h!]
    \centering
    \includegraphics[width=.75\linewidth]{Chapters/Figures/gaussian-noise-data-aug.pdf}
    \caption[Data Augmentation: Gaussian Noise]{Gaussian noise is added to the spectra to increase the variance of the training data. This helps the network to learn the low-level features of the spectra and ignore artifacts not caused by the structural disorder. For demonstration purposes, the scale of the noise in this figure has been increased beyond what was used in training.}
    \label{fig:data-aug-gauss-noise}
\end{figure}

The second form of data augmentation utilizes horizontal shifts. While this is common for signal processing and time series analysis, the inclusion here is more controversial. In XAFS, the edge location is dependent on the oxidation/reduction state of the species. Shifting the horizontal location is akin to shifting the species of the model; however, the neural network is not being tasked to determine the oxidation state of the sample. Instead, the model is merely tasked with predicting the mean squared displacement of the nanoparticle's bond lengths. The hypothesis is that the disorder information is encoded throughout the entire XANES spectrum, not from just a simple feature such as the edge placement.

\begin{figure}[h!]
    \centering
    \includegraphics[width=.75\linewidth]{Chapters/Figures/horz-shift-3way.pdf}
    \caption[Data Augmentation: Horizontal Shift]{In order to train the network to predict disorder from the overall shape of the spectra---as opposed to fixating on the edge location---we introduce horizontal-shift as a data augmentation technique.}
    \label{fig:data-aug-hor}
\end{figure}

\subsection{Transfer Learning}
In building the transfer learning model, we opted to begin with a new network architecture, which can be found in Table (\ref{tab:meta-1}). We hypothesized that applying convolutional layers before any affine layers may lead to a more consistent prediction between simulation and experimental spectra.

\begin{figure}
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/transfer-learning-breakdown.pdf}
    \caption[Transfer Learning Process]{The allocation of training and testing data is summarized above. At each stage, the network architecture remains unchanged; however, some of the network's parameters are retrained on new data. The different sets of data are color-coded for readability. Note that the network is never trained on the original experimental data---it is only used for the final stage of testing.}
    \label{fig:transfer-learning-databreakdown}
\end{figure}

\bgroup
\def\arraystretch{1.5}
\begin{table}[]
    \centering
        \begin{tabular}{|l|l|l|l|}
        \hline
        \multicolumn{1}{|c|}{\textbf{Name}} & \multicolumn{1}{c|}{\textbf{Type}} & \multicolumn{1}{c|}{\textbf{\# Parameters}} & \multicolumn{1}{c|}{\textbf{Output Shape}} \\ \hline
        normalization\_input                & InputLayer                         & 0                                           &                                            \\ \hline
        normalization                       & Normalization                      & 165                                         & None, 82                                   \\ \hline
        reshape                             & Reshape                            & 0                                           & None, 82, 1                                \\ \hline
        conv1                               & Conv1D                             & 128                                         & None, 82, 32                               \\ \hline
        max\_pooling1d                      & MaxPooling1D                       & 0                                           & None, 41, 32                               \\ \hline
        conv2                               & Conv1D                             & 3104                                        & None, 39, 32                               \\ \hline
        max\_pooling1d\_1                   & MaxPooling1D                       & 0                                           & None, 19, 32                               \\ \hline
        flatten                             & Flatten                            & 0                                           & None, 608                                  \\ \hline
        dense1                               & Dense                              & 58464                                       & None, 96                                   \\ \hline
        dout                                & DropOut                            & 0                                           & None, 96                                   \\ \hline
        dense2                              & Dense                              & 30264                                       & None, 312                                  \\ \hline
        output                              & Dense                              & 313                                         & None, 1                                    \\ \hline
    \end{tabular}
    \caption{A new network architecture was constructed for the transfer learning process. The new network only has one output node, representing the MSD of the input spectrum.}
    \label{tab:meta-1}
\end{table}
\egroup

Our approach for applying transfer learning involves two stages of fine-tuning. First, we primarily train the model on FEFF-simulated spectra, selecting an architecture and hyperparameters which are likely to be compatible with fine-tuning. We achieve this by weighting the validation set heavily (around $ 10\% $) with augmented experimental spectra and choosing a model which predicts unseen data-augmented experimental spectra as well as it predicts unseen simulated FEFF spectra. The training loss curves and selection process can be found in Figure \ref{fig:meta-1-sweep-loss}. One concern with this approach is that we are injecting biases into our model selection; however, we take this into account through the utilization of a third, unseen test set and the fact that the model does not update its parameters based on its validation set predictions. When training a model in machine learning, the parameters are continuously updated until a minimum is reached in the loss function. While the loss landscape will have a global minimum, it also contains local minima, some of which will be more agnostic to the differences in experimental spectra and be better candidates for transfer learning. In this first stage of learning, the intention is to teach the model to find broad predictive features from the simulation set while selecting a model at a local minimum that is likely to be a successful transfer-learning candidate.

\begin{figure}[h!]
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/10-sweep.png}
    \caption[Hyperparamater Sweep: Cost Curve]{The validation cost (mean squared error) for 10 out of the 50 hyperparameter combinations searched in this sweep are plotted above. Most hyperparameters result in a loss curve stabilizing around 0.08, which is significantly higher than the training cost (not shown) that stabilized around 0.01. A few of the validation loss curves, instead, stabilized around 0.01 (dulcet-sweep-41 and deep-sweep-40). Because the validation set is heavily weighted with augmented experimental spectra, these two spectra are likely to be good candidates for transfer learning onto experimental data.}
    \label{fig:meta-1-sweep-loss}
\end{figure}

\begin{figure}[h!]
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/new-hyperparameter-sweep-meta-1.png}
    \caption[Hyperpamater Sweep: Graphical Representation]{The hyperparameters are obtained through a ``sweep,'' where the entire training process (20 epochs) is repeated with different hyperparameters each time. The hyperparameter training process and figure generation was conducted with the aid of \cite{wandb}. Training cost was measured with mean squared error.}
    \label{fig:meta-1-sweep-params}
\end{figure}

\begin{figure}[h!]
    \centering
    \includegraphics[width=\linewidth]{Chapters/Figures/best-params-meta1.png}
    \label{fig:meta-1-best}
    \caption[Learning Curve for the best hyperparameters]{Both iterations of the training process were run with identical network architectures and hyperparameters; however, these two runs have significantly different validation losses. The discrepancy is due to the random weights initialization process. We mitigate this problem by setting global random seeds throughout the training process to select consistent pseudo-random values. The slight difference in initial parameters causes one iteration to become ``stuck'' in a different local minimum, which performed similarly with the training set but made substantially worse predictions on the validation set. The goal of the first stage of the transfer learning process is to identify hyperparameters that will lead to the best transfer learning candidates.}
\end{figure}

The next stage of transfer learning seeks to teach the model to ignore noise and focus on the broader shape of the spectrum. We achieve this by freezing the early stages of the model and retraining the later parameters on a new dataset comprised primarily entirely of data-augmented spectra. Often, models are trained with the augmented dataset in the initial stage, which helps act as a form of regularization. In the case of transfer learning, however, applying this regularization so early on in the process may lead to undesirable local minima for which transfer learning onto the experimental dataset would be impossible. By applying an initial stage of fine-tuning to a well-tuned base model, we increase the likelihood of a successful second fine-tuning stage.

The last stage of the fine-tuning process is to freeze even more layers and reduce the learning rate, then train the model using all of the data-augmented experimental spectra. If the process is successful, the model will have learned to predict the MSD and ignore horizontal and Gaussian noise in the spectra from the first stage. In this way, we have increased the number of possible training samples to use for the final fine-tuning stage from one to many, allowing us to withhold both of the un-altered experimental spectra from the training process and use them to evaluate the success of the transfer learning process. A visualization and specific breakdown of which data is allocated into each stage of the training process can be found in Figure \ref{fig:transfer-learning-databreakdown}.

As of the completion of this thesis, the transfer learning process is still ongoing. The first stage of training (as depticted in Figure \ref{fig:transfer-learning-databreakdown}) is complete, whereas stage two and stage three are the subject on ongoing work and discussed in Chapter 5.


% Template for EUSIPCO 2015 paper; to be used with:
%          spconf.sty  - LaTeX style file, and
%          IEEEbib.bst - IEEE bibliography style file.
% --------------------------------------------------------------------------
\documentclass[a4paper]{article}
\usepackage{spconf,amsmath,amsfonts,amssymb,amsthm,graphicx}
\usepackage{color}

% Example definitions.
% --------------------
\newcommand{\calA}{\mathcal{A}}
\newcommand{\calB}{\mathcal{B}}
\newcommand{\calD}{\mathcal{D}}
\newcommand{\calF}{\mathcal{F}}
\newcommand{\calL}{\mathcal{L}}
\newcommand{\calM}{\mathcal{M}}
\newcommand{\calP}{\mathcal{P}}
\newcommand{\calS}{\mathcal{S}}
\newcommand{\calT}{\mathcal{T}}
\newcommand{\calV}{\mathcal{V}}
\newcommand{\calW}{\mathcal{W}}
\newcommand{\calX}{\mathcal{X}}
\newcommand{\calY}{\mathcal{Y}}

\newcommand{\al}{\alpha}
\newcommand{\ga}{\gamma}
\newcommand{\De}{\Delta}
\newcommand{\ep}{\epsilon}
\newcommand{\tha}{\theta}
\newcommand{\ka}{\kappa}
\newcommand{\la}{\lambda}
\newcommand{\Om}{\Omega}
\newcommand{\rh}{\rho}
\newcommand{\Up}{\Upsilon}
\newcommand{\dUp}{\partial\Upsilon}
\newcommand{\ze}{\zeta}

\newcommand{\C}{\mathbb{C}}
\newcommand{\E}{\mathbf{ E}}
\newcommand{\Ex}{\mathbf{ E}}
\newcommand{\I}{\mathbb{I}}
\newcommand{\Lp}{\mathbb{L}_{p}}
\newcommand{\Lt}{\mathbb{L}_{2}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Pb}{\mathbf{ P}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\X}{\mathbb{X}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\W}{{\cal{W}}}

\newcommand{\bfi}{\mathbf{i}}
\newcommand{\bfj}{\mathbf{j}}
\newcommand{\bfk}{\mathbf{k}}
\newcommand{\bfu}{\mathbf{u}}
\newcommand{\bfv}{\mathbf{v}}
\newcommand{\bfx}{\mathbf{x}}

\newcommand{\Mbar}{\,\overline{\!M}}
\newcommand{\mbar}{\overline{m}}
\newcommand{\Zbar}{\,\overline{\!Z}}

% Example definitions.
% --------------------
\def\x{{\mathbf x}}
\def\L{{\cal L}}

% Title.
% ------
\title{Crossing-tree partition functions}
%
% Single address.
% ---------------
\name{Author(s) Name(s)\thanks{Thanks to XYZ agency for funding.}}
\address{Author Affiliation(s)}
%
% For example:
% ------------
%\address{School\\
%	Department\\
%	Address}
%
% Two addresses (uncomment and modify for two-address case).
% ----------------------------------------------------------
\twoauthors
  {Geoffrey Decrouez\sthanks{Thanks to the Centre for Advanced Studies for funding.}}
	{National Research University\\
	Higher School of Economics\\
	Moscow, Russia}
  {Pierre-Olivier Amblard}
	{GIPSAlab/CNRS UMR 5283\\
	Universit\'e de Grenoble\\
	Grenoble, France}
%
% Multiple author/addresses combination (use only in particular cases).
% ---------------------------------------------------------------------
%\name{A. Author-one$^*$, B. Author-two$^*$$^\dagger$, C. Author-three$^\dagger$, D. Author-four$^\ddagger$ %
%	\thanks{General thanks/acknowledgment}%
%	\thanks{$^*$ Thanks/acknowledgments for authors marked with *}%
%	\thanks{$^\dagger$ Thanks/acknowledgments for authors marked with $\dagger$}%
%	\thanks{$^\ddagger$ Thanks/acknowledgments for authors marked with $\ddagger$}%
%}
%\address{%
%    \tabular{c}
%		$^*$ Institute ABC\\
%		Group Group ABC\\
%		Address ABC
%	\endtabular
%	\hskip 0.5in
%    \tabular{c}
%		$^\dagger$ School DEF\\
%		Department DEF\\
%		Address DEF
%	\endtabular
%	\hskip 0.5in
%    \tabular{c}
%		$^\ddagger$ Company GHI\\
%		Department GHI\\
%		Address GHI
%	\endtabular
%}
%
% The symbol order for multiple author combination is:
%  $^*$, $^\dagger$, $^\ddagger$, $^\mathsection$, $^\mathparagraph$, $^\|$,
%  $^{**}$, $^{\dagger\dagger}$, $^{\ddagger\ddagger}$, ...
%
%
% Alternative multiple author/addresses combination (use only in particular cases).
% ---------------------------------------------------------------------------------
%\name{A. Author-one$^*$, B. Author-two$^*$$^\dagger$, C. Author-three$^\dagger$, D. Author-four$^\ddagger$ %
%	\thanks{General thanks/acknowledgment}%
%	\thanks{$^*$ Thanks/acknowledgments for authors marked with *}%
%	\thanks{$^\dagger$ Thanks/acknowledgments for authors marked with $\dagger$}%
%	\thanks{$^\ddagger$ Thanks/acknowledgments for authors marked with $\ddagger$}%
%}
%\address{%
%	$^*$ Institute ABC, Group Group ABC, Address ABC\\
%	$^\dagger$ School DEF, Department DEF, Address DEF\\
%	$^\ddagger$ Company GHI, Department GHI, Address GHI\\
%}
%
% The symbol order for multiple author combination is:
%  $^*$, $^\dagger$, $^\ddagger$, $^\mathsection$, $^\mathparagraph$, $^\|$,
%  $^{**}$, $^{\dagger\dagger}$, $^{\ddagger\ddagger}$, ...
%
\begin{document}

%
\maketitle
%
\begin{abstract}
A new multifractal formalism based on the crossing-tree for $H$-sssi processes was recently introduced \cite{DecrAJ13, DecrA15}.
The crossing-tree performs an ad-hoc decomposition of a signal based on its fluctuations, and thus represents a natural tool for the multifractal analysis of time series.
The estimation of the Hausdorff spectrum happens in the context of a multifractal formalism, where the spectrum is obtained from a transform of a partition function.
In this contribution, we introduce a new crossing-tree partition function, which differs from the original one presented in \cite{DecrA15}.
We show numerically that the new partition function improves the stability of the estimation in many cases, compared with the original crossing-tree partition function.
Estimation is further compared with state-of-the-art techniques, including wavelet and wavelet leaders.
\end{abstract}
%
\begin{keywords}
$H$-sssi processes, crossing tree, multifractal formalism, adaptative decomposition, wavelets
\end{keywords}
%
\section{Introduction}
\label{sec:intro}

{\bf Motivations.} Fractal and multifractal signals often occur in so-called complex systems (systems with a huge number of degrees of freedom in nonlinear interaction) as different as turbulent fluids, stock markets or the internet. An important concept underlying these signals is scale invariance: the laws that underpin the construction of the processes are the same at all scales. This has naturally led to the use of multiscale tools to analyse such signals, among which the wavelet machinary is the best known, and provide today's state-of-the art techniques for fractal and multifractal signal analysis.

In the wavelet paradigm, the notion of scale is introduced in the index set (time for signals, space for images).
The notion of scale can also be defined in the amplitude space of the signal. The crossing-tree decomposition then provides the corresponding multiscale decomposition: at  a given resolution, the amplitude set is cut into equal length intervals, the bound of which define the crossing levels. A crossing is defined as the path of the signal between two consecutive strictly different crossing levels. At a given resolution, the nodes of the tree contain the consecutive crossings. A multiscale representation is then provided by iterating the process on all crossings, by studying subcrossings at a finer resolution. To present the notation, we will formalize this later in this introduction.
A main difference between wavelet decomposition and the crossing tree is the fact that the latter is an adaptive technique.

 The crossing tree was introduced to generalize the mid-point deplacement method to construct the standard Brownian motion. In \cite{JoneS04} it was applied to self-similar processes, to test for self-similarity and stationary increments, and to obtain an asymptotically consistent estimator of the H\"older exponent. In \cite{ArrJon06} the crossing tree was used to estimate a time-change of a self-similar process, and in \cite{JonRol}, it was used to characterise and test if a process is a continuous local martingale. Later, it has been the basis to construct a class of monofractal and multifractal processes, see \cite{DecrJ12, DecrHJ}. This lead us to invert the point of view and use the crossing tree as an analysis tool for fractal and multifractal signals. Indeed, the crossing tree is a very general concept  and can easily be computed on real data.

In \cite{DecrAJ13,DecrA15} we showed how to use the crossing duration to estimate the H\"older exponent for several classes of monofractal signals. To do so we introduced a partition function using the crossing durations. A theoretical justification for it relies on  \cite{DecrJ12, DecrHJ} where multifractal formalism is proved for the so-called multifractal embedded branching processes (MEBP, processes that are constructed {\it via } the crossing tree). As many methods, the partition function suffers a lack of statistics for negative powers. {\em The aim of the present paper is to illustrate
how an easy modification of the partition function allows better estimation for negative powers. }

The remaining of the paper is organized as follows. We continue this introduction by presenting the crossing tree decomposition and the class of signals we study. Section 2 will present the partition functions we use to estimate the H\"older exponents, whereas section 3 will present the practical set up as well as simulations. One aim is to compare the crossing tree approach with the state-of-the-art provided by wavelet and wavelet leaders.

\medskip
\noindent{\bf The crossing tree.}
%\label{sec:xtree}
We consider a process $X: \R^+\rightarrow\R$. Without loss of generality, we assume $X(0)=0$ almost surely (a.s.) and we further suppose it has continuous sample paths (a.s.).
At a resolution $m\in \Z$, the vertical axis is cut into levels of size $2^m$, and a crossing at level $m$ is defined as the path between two successive different crossing levels. The first crossing starts at $t=0$ and is defined as the path betwen $t=0$ and the first time the signal crosses either $2^m$ or $-2^m$. Each crossing is characterized by two parameters: its duration and its direction.
The level-$m$ crossing times $T_k^m$ are defined as
\[
T_{k+1}^{m}= \inf\{t>T_{k}^{m}~|~X(t)\in  2^{m}\Z,~X(t)\not = X(T_{k}^{m}) \}\,,
\]
where  $T_0^m = 0$  and $2^{m}\Z=\{ x ~|~ x=2^m a \textrm{ for } a\in\Z\}$.
Thus, the $k$-th level-$m$ (equivalently scale $2^m$) crossing $C_k^m:= \{ (t,X(t))\mid T_{k-1}^m\leqslant t < T_k^m\}$ is the bit of sample path from $T_{k-1}^{m}$ to $T_{k}^{m}$.
Now the crossing tree is created by iterating the previous construction.
 Each crossing of size $2^m$ is decomposed into a sequence of crossings of size $2^{m-1}$.
The nodes of the crossing tree are crossings and the offspring of any given crossing is the corresponding set of subcrossings at the level below.
An example of a crossing tree and the main notation  are given in Figure~1.
The crossing-tree can easily be computed for irregularly time-sampled signals, and as such the formalism developed later is adapted to this kind of data.

\begin{figure}[]

\begin{minipage}[b]{0.4\linewidth}
  \centering
  \input descr-crossingtree.pdf_t
 % \centerline{\includegraphics[width=6.5cm]{descr-crossingtree.pdf}}
%  \vspace{2.0cm}
%  \centerline{(a) Result 1}\medskip
\end{minipage}

\caption{Formation of the crossing tree from a sample path, and crossing tree notation. Variables are defined in the text.}
\label{fig:ct}
%
\end{figure}

To code nodes in the tree we use
the address space $I = \cup_{k=0}^\infty \N^k$, where $\N^k$ is the set of words of $k$ integers and $\N^0=\emptyset$.
For the sake of simplicity, the root of the tree and  first crossing is supposed to go from $0$ to $\pm 1$.
It is labelled $\emptyset$ and its subcrossings (each of size $1/2$) are numbered from 1 to $Z_\emptyset$.
The subcrossings of a crossing $\bfi = i_1 i_2 \cdots i_n\in\N^n$ are then labelled $\bfi 1, \ldots, \bfi Z_\bfi$, where $Z_\bfi$ is the number of subcrossings of $\bfi$ and $\bfi j = i_1 i_2 \cdots i_n j$.
It is easy to show that  $Z_\bfi$ is an even integer larger or equal to 2.
We note as $N_n$ the size of generation $n$.
The second main parameter of a crossing $\bfi$   is its type, either up or down, which we denote by $\sigma_\bfi$.
The other parameter $W_\bfi$ is the duration of crossing $\bfi$. The sample path is completely described by $\{ (\sigma_\bfi, W_\bfi) \,:\, \bfi \in I \}$.

\medskip

\noindent{\bf Some scale invariant processes.} $X(t)$ is said to be a self-similar process if there exists an $H\in(0,\,1)$ such that  $X(ct)=c^H X(t)$ holds for all $c>0$ (in the finite-dimensional distribution sense).
If in addition the process $X(t)$ has stationary increments, then $X(t)$ is said to be $H$-sssi.

The most-studied $H$-sssi processes are fractional Brownian motions (fBm),
the only self-similar Gaussian processes with stationary increments.
Their sample paths are continuous (a.s.) but non differentiable (a.s.). However, they have a degree of regularity
and possess $H$ as  H\"older exponent almost everywhere.
A nonGaussian generalization of fBm is provided by Hermite processes.

Let ${\cal B}(u)$ denote a Brownian motion.
A Hermite process of order $k$ is defined as
\begin{align*}
{\cal H}^k_H(t) = \int_{\R^k}\int_0^t \left( \prod_{j=1}^k (s-u_i)_+^{-(1/2 + (1-H)/k)}\right)dsd{\cal B}({\bf u})\,,%&\\
%& \hspace{-2.5cm}ds\, d{\cal B}(u_1)\hdots d{\cal B}(u_k)\,,
\end{align*}
where $d{\cal B}({\bf u})=d{\cal B}(u_1)\hdots d{\cal B}(u_k)$,
for $k\geq 1$, with $H\in(1/2,\,1)$, and $x_+=\max(0,x)$.
The case $k=1$ corresponds to the case of an fBm.
${\cal H}^2_H(t)$ is usually referred to as the Rosenblatt process.

The Weierstrass function is defined as
\[
{\cal W}_H(t)= \sum_{k\in \Z} \lambda_0^{-k H} \Big(\cos(\varphi_k)-\cos(2\pi \lambda_0^k t +\varphi_k) \Big)\,,
\]
where $H$ stands for the H\"older exponent and $\lambda_0$ is a fundamental harmonic.
The definition is made to impose ${\cal W}_H(0)=0$.
The Weierstrass function exhibits discrete scale invariance (DSI), with ${\cal W}_H(\lambda_0 t)=\lambda_0^H {\cal W}_H(t)$, in distribution.
We consider here a stochastic version of this function, obtained by choosing the phases $\{\varphi_k\}_{k\in \Z}$ as a sequence of i.i.d. variables uniformly distributed over $[0,~2\pi]$.

\section{Partition functions}
\label{sec:majhead}

The estimation of the spectrum of singularities $D(h)$, defined as the Hausdorff dimension of the set of points with given H\"older regularity $h$, typically occurs in the context of the multifractal formalism.
The formalism relates the spectrum to a partition function $\zeta(q)$ via the (Legendre) transform
\[
D(h) = \inf\limits_{q\in\R} \{ 1- \zeta(q) + hq \}\,.
\]
This section reviews wavelet-based partition functions first, before introducing crossing-tree partition functions.

\subsection{Wavelet-based partition functions}
\label{ssec:wavform}

We first recall the wavelet decomposition of a signal $X(t)$.
Let $\psi$ be the mother wavelet.
Any square integrable signal can be decomposed as
\[
X(t)=\sum_{n,k\in\Z} c_{n,k}\psi(2^nt-k)\,,
\]
where $$c_{n,k}=2^n\int X(t)\psi(2^nt-k)dt\,.$$
We denote by $\lambda_{n,k}=[k2^{-n}, (k+1)2^{-n})$ a dyadic cube at scale $n$, with $k\in\Z$.
The wavelet-based structure function of $X$ is defined from the $q$-th moment of the wavelet coefficients,
$$S_{wc}(q,n) = 2^{-n} \sum_k \left| c_{n,k}  \right|^q\,,$$
where the sum is taken over all dyadic cubes $\lambda_{n,k}$ with non vanishing coefficients.
The wavelet partition function is then
\vspace{-.2cm}
\begin{equation}\label{partition_wav}
\zeta_{wc}(q) = \liminf_{n\to+\infty} \left( \dfrac{\log S_{wc}(q,n)}{\log 2^{-n}} \right)\,, \quad q\in\R \,,
\end{equation}
which leads to the multifractal formalism \cite{ParisiF85}
\begin{equation}\label{spectrum_wav}
D_X(h) = \inf\limits_{q\in\R} \{ 1- \zeta_{wc}(q) + hq \}\,.
\end{equation}
The wavelet-based partition function (\ref{partition_wav}) is known to be unstable for negative exponents, corresponding to $q<0$.
Indeed, wavelet coefficients can be arbitrary small, and a small error in their estimation can be multiplied when raised to a negative power.

To address this issue (amongst others), the wavelet leaders formalism was introduced \cite{JaffLA06}.
Put $3\lambda_{n,k}= \lambda_{n,k-1}\cup \lambda_{n,k}\cup \lambda_{n,k+1}$, which corresponds to the cube centered around $\lambda_{n,k}$, three times wider.
The wavelet leaders $d_{n,k}$ of a bounded function $X(t)$ are defined as
\vspace{-.2cm}
\[
d_{n,k} = \sup\limits_{\{m,i\,|\, \lambda_{m,i} \subset 3\lambda_{n,k}\}}|c_{m,i}|\,.
\]
It is then natural to introduce the wavelet leader structure function $$S_{wl}(q,n) = 2^{-n} \sum_k \left| d_{n,k}  \right|^q\,,$$ where the sum is taken over all non vanishing wavelet leader coefficients.
The scaling function is
\vspace{-.2cm}
\begin{equation}\label{partition_wl}
\zeta_{wl}(q) = \liminf_{n\to+\infty} \left( \dfrac{\log S_{wl}(q,n)}{\log 2^{-n}} \right)\,, \quad q\in\R \,,
\end{equation}
which leads to the multifractal formalism
\begin{equation}\label{spectrum_wl}
D_X(h) = \inf\limits_{q\in\R} \{ 1- \zeta_{wl}(q) + hq \}\,.
\end{equation}

\subsection{Crossing-tree partition functions}
\label{ssec:ctform}

A new formalism for the study of $H$-sssi processes was recently introduced \cite{DecrAJ13, DecrA15}.
The formalism relates the spectrum of singularities to a partition function computed from multi resolution quantities obtained from the crossing-tree of a signal.

Given $t$, let $\bfi \in \N^\infty$ be such that for each $n$, the size $2^{-n}$ crossing that contains $t$ is $\bfi|n$.
Then, our analogue of the multiresolution quantity is the crossing duration $W_{\bfi|n}$.
We say that the process $X(t)$ possesses scaling properties if time averages of the crossing durations follow a power law behaviour,
\begin{equation}\label{structure_ct}
S_{ct}(n,q) = \frac{1}{N_n}\sum\limits_{\bfi|n} |W_{\bfi|n}|^q \sim C_q' 2^{-n\zeta_{ct}(q)}\,,
\end{equation}
as $n\to \infty$,
where the sum is taken over all crossings of size $2^{-n}$.
We call $S_{ct}(n,q)$ the structure function and $\zeta_{ct}$ the crossing tree partition function.
The partition function can be obtained from the structure function as a limit,
\begin{equation}\label{partition_ct}
\zeta_{ct}(q) = \liminf_{n\to \infty}\frac{\log S_{ct}(n,q)}{-n \log 2}\,.
\end{equation}

The crossing-tree partition function (\ref{partition_ct}) was first introduced to obtain a theoretical expression of the Hausdorff spectrum of a class of processes called Multifractal Embedded Branching Processes (MEBP), see \cite{DecrJ12, DecrHJ}.
An MEBP process $X$ can be represented as the composition of a process $Y$ with constant modulus of continuity, and the inverse of an increasing process $\calM$, so that it can be written as $X = Y \circ \calM^{-1}$.
The increasing process $\calM$ is the integral of a multiplicative cascade defined on the boundary of the crossing tree of $Y$.
The multifractal analysis of $\calM$ requires deducing the local H\"older exponent at every point of its support from a discretised version of it. To do so, the support of a multifractal measure is typical divided into dyadic cubes, and a structure function is defined from the empirical $q$-th moments of measures
of cubes 3 times wider than the original partition, see e.g. Section 2 in \cite{JaffLA06}. This methodology was adapted in \cite{DecrHJ} to perform the multifractal analysis of $\calM$.
The analysis performed there requires the introduction of a novel partition function constructed on a random grid adapted to the process. The new partition function is defined in terms of the $q$-th moment of the sum of 3 consecutive crossing durations (instead of 3 consecutive dyadic cubes), and constitutes the starting point of the present study.

Let $\bfi|n-$ and $\bfi|n+$ denote respectively the left and right neighbours of $\bfi|n$. The corresponding crossing durations are denoted $W_{\bfi|n-}$ and $W_{\bfi|n+}$.
The discussion above motivates the definition of a new crossing-tree structure function,
\begin{equation}\label{structure_ct2}
{\cal S}_{ct}(n,q) = \frac{1}{N_n}\sum\limits_{\bfi|n} |W_{\bfi|n-}+ W_{\bfi|n}+W_{\bfi|n+}|^q \,,
\end{equation}
and its associated partition function
\begin{equation}\label{partition_ct2}
\eta_{ct}(q) = \liminf_{n\to \infty}\frac{\log {\cal S}_{ct}(n,q)}{-n \log 2}\,.
\end{equation}
The introduction of the right and left neighbours in the definition of ${\cal S}_{ct}(n,q)$ takes cares of problems that may arise when the local H\"older exponent is discretised at time $t$, when $t$ is a crossing time, since $t$ corresponds in that case to one of the endpoints of the crossing durations.

Wavelet leaders were introduced to address the flaws of a multifractal analysis based directly on wavelet coefficients. In particular, wavelet leaders are known to estimate the spectrum of singularities with greater accuracy for $q<0$. They are defined from the supremum of wavelet coefficients over dyadic cubes 3 times larger than the original dyadic partition, which is the key to their success.
We thus expect that defining a structure function from of the $q$-th moments of statistics defined on 3 consecutive intervals will also improve the stability properties of the structure function for $q<0$, compared to the original $S_{ct}(n,q)$.
The numerical work presented in the next section supports this claim.

Heuristic arguments presented in \cite{DecrA15} lead to conjecture that for self-similar processes, the multifractal spectrum is related to the crossing-tree partition function via the transform
\begin{equation}\label{ct_multifractal}
\zeta_{ct}(q) = \inf_h\{ (q+1)/h -D(h)/h \}\,.
\end{equation}
For monofractal processes with H\"older exponent $H$, one gets $\zeta_{ct}(q)=q/H$.
A similar reasoning yields $\eta_{ct}(q)=q/H$ for this class of processes.
This conjecture, proved for the Brownian motion, remains open.
The numerical work presented in the next section supports this conjecture.
The expression of the crossing-tree partition functions for monofractal processes should be compared with wavelet-based techniques, where we directly get from (\ref{spectrum_wav}) and (\ref{spectrum_wl}) that $\zeta_{wc}(q)=\zeta_{wl}(q)=qH$.
The partition function is still linear in $q$, but the slope is inverted.

\section{Numerical work}
\label{ssec:numwork}

For each process defined in the introduction, we compare the performance of the two crossing-tree partition functions.
Estimation based on wavelet coefficients is also presented.
The partition functions are estimated from an average of 1000 realizations of $2^{15}$ sample points each.
The wavelet partitions functions are estimated using Daubechies' wavelets with 3 vanishing moments, from scale $2^3$ to $2^{12}$ using Matlab routines from \cite{WendtSPM2007, WendtICASSP2008}.
The crossing tree partition function is estimated from scale $2^2$ to $2^5$.
The  range of scales differs for wavelet methods and the crossing tree, since they are calculated differently: the scales chosen to analyse the crossing tree are computed from the spatial fluctuations of the signal.

We focus our attention to the estimation of the negative moments, which is the main objective of the present contribution.
Figure \ref{fig:partition1} and \ref{fig:partition2} display the estimation of $\zeta_{ct}(q)$, $\eta_{ct}(q)$ and $\zeta_{wc}(q)$, $\zeta_{wl}(q)$ for $q$ varying between -10 and 0.
It is clear from Figure \ref{fig:partition2} that the partition function based on wavelet coefficients fails to work for negative $q$s, while the three other methods return stable results.
In particular, it can be seen from Figure \ref{fig:partition1} that an estimation based on the crossing tree returns a good estimation for negative $q$s, and the estimation bias is further reduced when considering $\eta_{ct}(q)$ instead of $\zeta_{ct}(q)$.
In most cases, the bias almost vanishes, while wavelet leaders return a small bias in some cases.
The estimation was repeated for other values of $H> 0.5$, and the modified formalism systematically improves the estimation compared to the original crossing-tree partition function.
Estimation for processes with $H< 0.5$ remains however challenging with the crossing tree, since the estimation of the crossing tree is all the more difficult as the process is rough (crossings are missed).

Following the seminal work of Castaing \cite{Cast93}, we considered in \cite{DecrA15} a polynomial expansion of the partition function, and we defined an estimator of $H$ from the first coefficient in the expansion, estimated from the cumulant of the crossing durations. We repeated the same procedure for $\eta_{ct}(q)$, and we found that the performances of the estimators based on $\eta_{ct}(q)$ and $\zeta_{ct}(q)$ are comparable in most cases.

\begin{figure}

\begin{minipage}[b]{.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{max_fbm}}
  \vspace{.12cm}
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{max_rosenblatt}}
  \vspace{.12cm}
\end{minipage}
%
\begin{minipage}[b]{.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{max_hermitte}}
  \vspace{-.12cm}
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{max_weierstrass}}
  \vspace{-.12cm}
\end{minipage}
%
\caption{Estimation of the partition function for $q$ varying between -10 and 0 using $\zeta_{ct}(q)$ ($\circ$) and $\eta_{ct}(q)$ ($\Box$).
The dashed line is the theoretical line $q/H$.
From top to bottom, left to right, fractional Brownian motion, Hermite with $k=2$ and 3, and Weierstrass function, with $H=0.6$.}
\label{fig:partition1}

\end{figure}

\begin{figure}

\begin{minipage}[b]{.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{leader_fbm}}
  \vspace{.12cm}
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{leader_rosenblatt}}
  \vspace{.12cm}
\end{minipage}
%
\begin{minipage}[b]{.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{leader_hermite}}
  \vspace{-.12cm}
\end{minipage}
\hfill
\begin{minipage}[b]{0.48\linewidth}
  \centering
  \centerline{\includegraphics[scale=.3]{leader_weierstrass}}
  \vspace{-.12cm}
\end{minipage}
%
\caption{Estimation of the partition function using wavelet leaders ($\circ$) and wavelet coefficients ($\Box$).}
\label{fig:partition2}

\end{figure}

\section{Concluding remarks}
\label{ssec:numwork}

The present contribution extends earlier work on the crossing-tree, by introducing a novel crossing-tree partition function.
We showed numerically that a simple modification of the crossing-tree partition function presented in \cite{DecrAJ13, DecrA15} allows a more stable estimation for negative powers.

This work further raises many challenges (both theoretically and numerically) and open conjectures.
The first step being formally proving that $\eta_{ct}(q)=q/H$ for monofractal $H$-sssi processes, before proving (\ref{ct_multifractal}) in all generality.
Estimation for rougher processes ($H<0.5$) should also be further investigated, since the estimation of the crossing tree is deteriorated in this case.
Finally, the crossing tree is defined so far only for one-dimensional processes.
Extending its definition to two-dimensional processes might lead to a new tool to analyse images, and in particular to perform their multifractal analysis.

% References should be produced using the bibtex program from suitable
% BiBTeX files (here: strings, refs, manuals). The IEEEbib.bst bibliography
% style file from IEEE produces unsorted bibliography list.
% -------------------------------------------------------------------------
\bibliographystyle{IEEEbib}
\bibliography{strings,refs}

\end{document}


\documentclass[12pt]{amsproc}
\usepackage[a4paper]{geometry}
\usepackage{float}
\usepackage{fouriernc}
\usepackage{verbatim}

\begin{comment}
  Where to publish this ? JOSS is merely a software journal.
  - CPC ?
  - WIAS TR
  - As part of documenter ?
    After all, yes

    Computing in Science \& Engineering (CiSE)

cite:  https://www.researchgate.net/publication/223773028_A_frequency-domain_approach_to_dynamical_modeling_of_electrochemical_power_sources
https://www.sciencedirect.com/science/article/abs/pii/S0013468697002387
https://www.gamry.com/application-notes/EIS/basics-of-electrochemical-impedance-spectroscopy/
https://iopscience.iop.org/article/10.1149/09401.0251ecst

\end{comment}

\title{Small signal analysis for nonlinear evolution equations\\ Draft.}
\author{J. Fuhrmann}
\newcommand{\CV}{{\mathcal{V}}}
\newcommand{\VV}{\mathbb{V}}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\TT}{\mathbb{T}}
\newcommand{\MM}{\mathbb{M}}
\newcommand{\RR}{\mathbb{R}}
\newtheorem{example}{Example}

\newcommand{\Exp}[1]{e^{#1}}
\begin{document}
\maketitle
%\begin{multicols}{2}
\section{Frequency response of an electrical network}

The  current  dependency  on  voltage   of  basic  basic  elements  of
electrical networks  can be subsummed  using the notion  of impedance.
Let $U(t)$  be a given  voltage difference  applied to as  device, and
$I(t)$ be the resulting current.  For a periodic voltage perturbation,
the  frequency dependent  impedance  describes the  ratio between  the
amplitudes  of the  voltagee and  the current  response, respecitvely.
Assuming a an applied  periodic voltage $U(t)=U_a\Exp{i\omega t}$ with
amplitude $U_a$ and frequency $\omega$, we get
\begin{table}[H]
  \begin{center}
\renewcommand{\arraystretch}{1.4}
\begin{tabular}{lllll}
Circuit Element     & Law     & Standard form & Complex Form & Impedance\\
Resistance  & Ohm     & $ I(t)=\frac1R U(t)$                                & $I(t)=\frac1R U(t)$       &  $Z(\omega)=R$ \\
Capacity    & Faraday & $ I(t)=C(t)\frac{d}{dt}U(t)$                        & $I(t)=Ci\omega U(t)$&          $Z(\omega)=\frac1{Ci\omega}$\\
Inductivity & Henry   & $ I(t)=I_0+\frac1L\int\limits_{t_0}^tU(\tau) d\tau$ & $I(t)=\frac1{Li\omega}$ U(t)&$Z(\omega)=Li\omega$ \\
\end{tabular}
\caption{\label{tab:impedance} Impedance of three basic elements of electric circuits}\hfill
\end{center}
\end{table}

Any  network consisting  of  these  elements can  be  analyzed in  the
complex domain  using Kirchoffs law  and regarding the impedance  as a
complex resistance.

\section{Impedance spectroscopy in nonlinear evolution equations}

Usually, the interpretations of impedance spectroscopy measurements of
other  systems,  e.g. electrochemical  systems  is  performed using  a
replacement circuit consisting of  electrical network elements.  Being
quite  successful  in many  cases,  this  interpretation basically  is
limited to compartment type models.

Here,  we discuss an  approach of  applying impedance  spectroscopy to
abstract evolution equations based on small signal analysis.

For a  given time  interval $\TT=[0,T]$, a  Banach space  $\CV$ called
{\em state space},  and a finite dimensional space  $\PP$, called {\em
parameter  space},  regard  the  abstract doubly  nonlinear  evolution
equation
\begin{equation}\label{eq:abstrevol}
 \frac{d S(v(t),\lambda)}{dt} + D(v(t),\lambda)=0
\end{equation}

The state of  the system is {\em measured} by  some functional $M: \CV
\rightarrow  \MM$,   where  $\MM$  is  the   finite  dimensional  {\em
measurement space}. We assume  $M(v)=M^{stdy}(v)+ d_t M^{tran}(v)$.

As an example, $\CV$ may  be a finite dimensional space containing the
solution of some discretized system of partial differential equations.

Given   a  steady   state  $(v_0,   \lambda_0)$  such   that  $D(v_0,
\lambda_0)=0$, measured  by $M_0=M(v_0)$, we  would like to  trace its
response  to  a small,  periodic  perturbation $\lambda(t)=  \lambda_a
\Exp{i\omega  t}   $.   Expressing   the measurement of this  response  as   $M(t)=  M_0+
M_a(\omega)  \Exp{i\omega  t}$,  we  yield the  impedance  $Z(\omega)=
M_a(\omega)^{-1} \lambda_a$.

In order to calculate the frequency response, we make the ansatz $v(t)=v_0+v_a\Exp{i\omega  t}$ for
the perturbation of the state variable and calculate the first order Taylor expansions
of the terms $S,D$:
\begin{equation*}
  \begin{split}
    S(v_0+v_a\Exp{i\omega  t},\lambda_0+\lambda_a\Exp{i\omega  t})\approx&S(v_0,\lambda_0)+
          S_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
          S_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}\\
    D(v_0+v_a\Exp{i\omega  t},\lambda_0+\lambda_a\Exp{i\omega  t})\approx&D(v_0,\lambda_0)+
          D_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
          D_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}
  \end{split}
\end{equation*}

Putting them into equation \eqref{eq:abstrevol}  and using the steady state condition yields
\begin{equation*}
  \begin{split}
    \frac{d}{dt}\left(
      S_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
      S_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}\right)+
    D_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
    D_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}&=0\\
    i\omega\left(
      S_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
      S_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}\right)+
    D_v(v_0,\lambda_0)v_a\Exp{i\omega  t}+
    D_\lambda(v_0,\lambda_0)\lambda_a\Exp{i\omega  t}&=0\\
    i\omega\left(
      S_v(v_0,\lambda_0)v_a+
      S_\lambda(v_0,\lambda_0)\lambda_a\right)+
    D_v(v_0,\lambda_0)v_a+
    D_\lambda(v_0,\lambda_0)\lambda_a&=0
  \end{split}
\end{equation*}

For the measurement, we have
\begin{align*}
      M(v_0+v_a\Exp{i\omega  t})\approx&M^{stdy}(v_0)+
    M^{stdy}_v(v_0)v_a\Exp{i\omega  t} +  i\omega M^{tran}_v(v_0)v_a\Exp{i\omega  t}
\end{align*}

Assuming $S_\lambda=0$, $\dim \MM =\dim \PP=1$ we arrive at solving
\begin{equation}\label{eq:impedsolve0}
    i\omega
      S_v(v_0)v_a+
    D_v(v_0,\lambda_0)v_a+
    \lambda_a D_\lambda(v_0,\lambda_0)=0
\end{equation}
for given $\omega$ for the  unknown $v_a$.
The corresponding measurement yields:
\begin{align*}
  M_a(\omega)= M^{stdy}_v(v_0)v_a + i\omega M^{tran}_v(v_0)v_a
\end{align*}

The impedance then can be calculated as
\begin{equation*}\label{eq:imped0}
  Z(\omega)= \frac{\lambda_a}{M_a(\omega)}
\end{equation*}

Dividing \eqref{eq:impedsolve0} by  $\lambda_a$ (and thus rescaling $v_a$) gives the final expressions
\begin{equation}\label{eq:impedsolve}
    i\omega
      S_v(v_0)v_a+
    D_v(v_0,\lambda_0)v_a+
    D_\lambda(v_0,\lambda_0)=0
\end{equation}
and
\begin{equation}\label{eq:imped}
  Z(\omega)= \frac{1}{ M^{stdy}_v(v_0)v_a + i\omega M^{tran}_v(v_0)v_a}.
\end{equation}

\subsection{Excited Dirichlet boundary condition}
This dicussion is based on the idea to implement Dirichlet boundary conditions using the
penalty method and provides an easy way to handle deriviatives with respect to
the Dirichlet boundary value. We assume that our problem corresponds to a (discretized) PDE
in a domain $\Omega$ with boundary $\Gamma=\partial\Omega$.
\begin{example}{Dirichlet Boundary Conditions}\\
  Assum that $\Gamma_0,\Gamma_1\subset \Gamma$  are two disjunct parts of
  the boundary.
  For (discretized) differential operator $D_i$ defined
  in $\Omega$ assume that $D_i(v)=0$ is the discretization of the
  homogeneous Neumann boundary value problem. Adding Robin boundary value terms
  for $\Gamma_0, \Gamma_1$ with Robin coefficient $\frac1\epsilon$ and boundary values
  0, resp. $\lambda$ can be formally
  written as
  \begin{align*}
  D(v,\lambda)= D_i(v)
  +\frac1\epsilon\delta_{\Gamma_0}(v)
  +\frac1\epsilon\delta_{\Gamma_1}(v-\lambda),
  \end{align*}
  where $\delta$ means delta functions with support at the corresponding boundary.
  The limit $\epsilon\to 0$  corresponds to the Dirichlet boundary condition.
  This covers the case of an
  applied voltage difference  and an excitation at $\Gamma_1$.

  Then
\begin{equation*}
  \begin{split}
    D_v(v,\lambda)= D_{i,v}(v)+ \frac1\epsilon\delta_{\Gamma_0}+ \frac1\epsilon\delta_{\Gamma_1}\\
    D_\lambda(v,\lambda)= -\frac1\epsilon\delta_{\Gamma_1}\\
   \end{split}
\end{equation*}
Therefore  for the impedance calculation we have to solve
\begin{equation*}
  i\omega S_v v_a + D_{i,v} v_a +\frac1\epsilon\delta_{\Gamma_0}v_a +\frac1\epsilon\delta_{\Gamma_1}(v_a-1) =0
\end{equation*}
which for $\epsilon\to 0$ corresponds to the Dirichlet problem  for the linearized equation
with boundary condition 0 on $\Gamma_0$ and 1 on $\Gamma_1$.
\end{example}

\subsection{Flux calculation via test function}
For a discussion, see e.g. [Gajewski, WIAS TR],  [Yoder, Gärtner], [Farrell et al, Handbook].

Assume that $D_i(v,\lambda) = \nabla \cdot J(v) + R(v)$. Let $T$ be be a test function
such that $\Delta T    +\frac1\epsilon\delta_{\Gamma_0}(T)
+\frac1\epsilon\delta_{\Gamma_1}(T-1)=0$, which for $\epsilon\to 0$  corresponds to
a mixed boundary value problem with $T=0$ on $\Gamma_0$, $T=1$ on $\Gamma_1$ and $\partial_n T=0$ on
$\partial\Omega \setminus  (\Gamma_0 \cup \Gamma_1)$.
Then the boundary flux integral as measurement can be calculated as
\begin{align*}
  M(v)&=\int_{\Gamma_1} J(v,\lambda)\cdot n ds
      =\int_{\Gamma_1} T J(v,\lambda)\cdot n ds
      =\int_{\Gamma} T J(v,\lambda)\cdot n ds\\
      &=\int_{\Omega} \nabla\cdot \left(T J(v,\lambda)\right) d\vec x
      =\int_\Omega \left(J(v) \nabla T + T (\nabla \cdot J)\right) d\vec x\\
      &=\int_\Omega \left(J(v) \nabla T + T (R(v,\lambda) + d_t S(v))\right) d\vec x
\end{align*}

Accordingly, $M^{stdy}(v)=\int_\Omega \left(J(v) \nabla T + T R(v)\right) d\vec x$ and
  $M^{tran}(v) = \int_{\Omega} S(v) T d\vec x$
and
$$M_a(\omega)= \int_\Omega \left(J_v(v_0)\nabla v_a \nabla T + T (R_v(v_0)v_a + i\omega S_v(v_0)v_a)\right) d\vec x$$

With a finite volume discretizatiom, this representation has a discrete counterpart.

\subsection{Examples with analytical impedance expressions}
These examples can be taken for benchmarking numerical methods.
\begin{example}{Current Response}
  We calculate the impedance of the current response at $L$ to voltage change in $0$ of the linear reaction  diffusion system in $(0,L)$
  \begin{equation*}
    \begin{cases}
      Cu_t - (Du_x)_x + Ru=&0\\
      u(0,t)=&\lambda\\
      u(L,t)=&0\\
    \end{cases}
  \end{equation*}
    As response functions we take the currents  $I_0=Du_x(0,t)$ and $I_L=-Du_x(L,t)$.
    The corresponding impedance equation is
    \begin{equation*}
      \begin{cases}
        Ci\omega v - (Dv_x)_x +Rv =&0\\
        v(0,t)=&1\\
        v(L,t)=&0.\\
      \end{cases}
    \end{equation*}
Setting $z=\sqrt{i\omega\frac{C}{D}+\frac{R}{D}}$, for the solution, we make the ansatz
\begin{equation*}
  v=ae^{zx}+be^{-zx}
\end{equation*}
which fulfills the differential equation.
Setting $e^+=e^{zL},e^-=e^{-zL}$, from the boundary
conditons we get the system
\begin{equation*}
  \begin{cases}
    a+b&=1\\
    ae^++be^-&=0\\
  \end{cases}
\end{equation*}
with the solutions $a=\frac{e^-}{e^--e^+},b=\frac{e^+}{e^+-e^-}$
Therefore, we have
\begin{equation*}
  Dv_x(0)=Dz(a-b)=Dz\frac{e^-+e^+}{e^--e^+}
\end{equation*}
and
\begin{equation*}
  Dv_x(L)=Dz(ae^+-be^-)=Dz\frac{e^-e^++e^+e^-}{e^--e^+}=\frac{2Dz}{e^--e^+}
\end{equation*}

Alternatively, we might be interested in e.g. $M(v)=\int_\Omega |\nabla v|^2$
as measurement. We have
\begin{align*}
  \nabla v&=a z e^{zx} - b z e^{-zx}\\
  |\nabla v|^2&=a z e^{2zx} -ab +  b z e^{-2zx}\\
  \int  |\nabla v|^2 \; dx &=  \frac{1}{2z}aze^{2zx}  -\frac{1}{2z}  b z e^{-2zx} - abx + C\\
          &= \frac{a}{2}e^{2zx}  -\frac{b}{2}  b e^{-2zx} -abx +C\\
  \int_0^L  |\nabla v|^2 \; dx &=   \frac{a}{2}e^{2zL}  -\frac{b}{2}  e^{-2zL} -abL
            -  \frac{a}{2}  +\frac{b}{2}\\
  \int_0^L  |\nabla v|^2 \; dx &=   \frac{a}{2}(e^{2zL}-1)  -\frac{b}{2} (e^{-2zL}-1) -abL\\
                               &=    \frac12\frac{e^{-zL}}{e^{-zL}-e^{zL}}(e^{2zL}-1)  -\frac12\frac{e^{zL}}{e^{zL}-e^{-zL}} (e^{-2zL}-1) -abL\\
          &=    \frac12\frac{e^{zL}-e^{-zL}}{e^{-zL}-e^{zL}}  -\frac12\frac{e^{-zL}-e^{zL}}{e^{zL}-e^{-zL}} -abL\\
              &=-abL\\
  &= \frac{L}{e^{2zL} + e^{-2zL}-2}
\end{align*}

But ... the measurement is different: it has to be the derivative at $v_0$ applied to the solution:
\begin{align*}
  2\int_\omega \nabla v_0 \nabla v_a
\end{align*}
Steady state: $u(0)=1$, $u(L)=0$. Let $d=\sqrt{\frac{R}{D}}$.
Set $u(x)=fe^{dx}+ ge^{-dx}$.
\begin{align*}
  u'(x) &= fd e^{dx} -gde^{-dx}\\
  u''(x) &= fd^2 e^{dx} +gd^2e^{-dx}=d^2 u(x)\\
  u(0)=f+g\\
  u(L)=fe^{dL}+ge^{dL}
\end{align*}
So for $d^+=e^{dL}$ and $d^-=e^{-dL}$ we get
$f=\frac{d^-}{d^--d^+}$ and $g=\frac{d^+}{d^+-d^-}$

So we have to calculate
\begin{align*}
  \nabla v_0 \nabla v_a&=  (aze^{zx}-bze^{-zx})(fde^{dx}-gde^{-dx})\\
                       &= azfde^{(z+d)x} -azgde^{(z-d)x}  - bzfde^{(d-z)x} + bzgde^{-(z+d)x}\\
  \int \nabla v_0 \nabla v_a &=   \frac{azfd}{z+d}e^{(z+d)x} -\frac{azgd}{z-d}e^{(z-d)x}  - \frac{bzfd}{d-z}e^{(d-z)x} - \frac{bzgd}{z+d}e^{-(z+d)x}\\
  &=  zd\left(\frac{af}{z+d}e^{(z+d)x} -\frac{ag}{z-d}e^{(z-d)x}  - \frac{bf}{d-z}e^{(d-z)x} - \frac{bg}{z+d}e^{-(z+d)x}\right)
\end{align*}

\end{example}

\begin{example}{Voltage response}
Regard the system
  \begin{equation*}
    \begin{cases}
      Cu_t - (Du_x)_x + Ru=&0\\
      u(0,t)=&\lambda\\
      (Du_x)(L,t)=&0\\
    \end{cases}
  \end{equation*}
  and observe the values $u(L)$ and $Du_x(0)$.
The same ansatz as in the previous example leads to
\begin{equation*}
  \begin{cases}
    a+b&=1\\
    izae^+-izbe^-&=0\\
  \end{cases}
\end{equation*}
with the solutions $a=\frac{e^-}{e^++e^-}$ and $b=\frac{e^+}{e^++e^-}$
Therefore,  $Du_x(0)=iDz\frac{e^--e^+}{e^++e^-}$ and
$u(L)=\frac2{e^++e^-}$.
\end{example}

\section{Algorithmic implementation}

Algorithmically, we proceed as follows:

\begin{description}
\item[1] Given $\lambda$, solve steady state equation $D(v,\lambda)=0$
\item[2] Obtain Jacobi matrix for stationary problem
\item[3] Obtain Jacobi matrix of time derivative
\item[4] Obtain Derivative of measurement (both steady state and transient parts)
\item[5] Prepare system for impedance problem
\item[6] For $\omega=\omega_0\dots\omega_1$:
  \begin{description}
  \item[6.1] set up complex matrix
  \item[6.2] solve complex system, take old solution as initial value if this is done iteratively
  \item[6.3]calculate impedance functional
  \end{description}
\end{description}

\end{document}


\chapter{Timestamping}
\label{chpr:timestamping}
Placing a certain date on some data is surprisingly useful \cite{Haber91howto, Bayer93improvingthe, Massias99designof, OTSannouncment}.
An inventor who had a patentable idea or a scientist who came to a relevant conclusion may want to create a verifiable proof that at a certain moment they discovered something. This can help them to protect their intellectual property, proving others their precedence over competing claims.
In a communication protocol having the possibility to attach a certain time to messages can improve the security of the transmission. However it is often difficult to come to an agreement on which is the correct time to use, so different security models yield to different practical schemes.
When storing documents in a third party cloud server, it could behave maliciously, for instance modifying their contents. Placing a certain and tamper resistant date on a document will make harder for the server provider to corrupt that file: the attacker should also be able to falsify the certificate stating the date.

Other practical applications of this technique are possible, however to have a complete understanding of the subject it is important to figure out which are its limits and which are the right choices to take to correctly put the concepts into practice. So we need to be a little more formal,
\begin{mydef}
	A timestamp is a proof that some data $d$ existed prior to time $t$.
\end{mydef}
To create such proof, $d$ has to cause an event that could not have been generated without the existence of $d$. Such event it is bound to time $t$ and can be observed by others, we call its record \textit{time attestation}. So a proof consists in the data $d$, the set of \textit{operations} that were applied to cause the event and the time attestation.

Proofs are useful if they are able to convince the verifiers. He must be able to check the correctness of the operations and must retain trustworthy the time attestation. Depending on the problem in exam one should properly choose which operations and attestations to use.

Let's consider the case of a sent letter. The data $d$ is the content of the letter, $d$ caused the palpable letter: if $d$ were different the letter would be different. When the letter went through the post office a postmark with the date $t$ was stamped on the letter, the postmark is the time attestation. If the post officer is trustworthy, a verifier who examines the letter may be convinced that the content of the letter existed prior to the time stated in the postmark. However a good counterfeiter could change the content of the letter or falsify the postmark placing a false date, thus for some cases such proof would not be appropriate.

In the case of a digital document new problems arises: it is not necessary to be a good counterfeiter to falsify a document without leaving any kind of tamper evidence, thus new solutions must be adopted. A timestamp for the data $d$ should guarantee that if even only a single bit of $d$ is modified the timestamp proof becomes invalid. To solve this problem cryptography tools are used \cite{Haber97securenames}. Digital data can also be shared easily and with little costs, this is among the features that enables the possibility to achieve distributed and decentralized consensus. Such an achievement would give user the chance to timestamp without any trust in a third party.

Resuming, at a certain moment $t_e$ some data $d$ exists, then at $t_c$ someone (or something) will have the necessity to prove the existence of $d$, so he implements the timestamp \textit{creation procedure} that results in a proof stating that $d$ existed priort to time $t$. Consequently at time $t_v$ a challenger implements the \textit{verification procedure} that ends in a binary result: true if he retains the proof correct, false otherwise. Naturally we have $t_e<t_c<t<t_v$.

To avoid common misunderstandings, it is important to clarify what a timestamp does not prove. The time $t$ is the first moment when $d$ went to existence, the creation procedure is not instantaneous and of course if the proof for $(d,t)$ is true then there exists a proof for $(d,t')$ which holds true for all $t'>t$. A timestamp is not necessarily linked to its creator and moreover it doesn't prove that who owns the timestamp (it can be owned by multiple entities) is the creator of the data $d$: it just proves that someone knew $d$. If an inventor comes up with a timestamp stating that he had a particularly smart idea prior to time $t$, it does not mean that he was the first one to have such idea, in fact he could have simply overheard the idea from a colleague and afterwards timestamped it. A timestamp does not prove that data $d' \neq d$ does not exist. Imagine someone stating that he knew the result of the elections prior to the vote, he provides a timestamp and claims that it proves he predicted the correct outcome. However he could be an imposter: he may had timestamped several different results and once he saw how the vote count ended he will provide only the proof which make him look as a visionary.
Although these limitations being able to timestamp is still useful. If stronger proofs are needed the used system must be endowed with other tools that actually provides what is asked.

In the following sections we analyse the two ingredients of timestamp proofs: operations and attestations.

\section{Commitment Operations}

The operations that compose a timestamp proof should be defined in a precise way, a verifier will check their correctness when evaluating the proof. An useful operation binds the data in a way that it is hard or impossible to modify the data after the creation of the timestamp. Being more general, such an operation commits the input to the output: the input cannot be changed without changing the output. The result of the operation is a commitment to the input, in the sense that it was caused by the input or, in other words, the input precede in time the output.
For instance in the case of a sent letter, the input is the content of the letter, the piece of paper that is sent is the output and physically writing the letter is the operation that commits the input to the output. We can say that a letter is a physical commitment to its content. If one wants to modify the content of the letter ex post it will change the letter itself. However, tamper evidence could be extremely hard to spot.

Digital document are easier to tamper, but they could be defined in a more precise way, representing each document with bits. To take full advantage of this, we need a formal definition,
\begin{mydef}
	A function $C:X \rightarrow Y$ is a commitment operation if given $x_1 \in X$ it is not feasible to compute $x_2 \in X$ s.t. $x_1 \neq x_2, C(x_1)=C(x_2)$.
\end{mydef}
The property required is sometimes referred as second pre-image resistance. For practical purposes $X$, $Y$ can be thought as bit string spaces, their element can be seen as bit strings or another of their representations, for instance in hexadecimal digits or using a conventional encoding.
The simplest examples are the append and prepend operations:

\begin{myexample}
	\textquotedblleft hello\textquotedblright, \textquotedblleft world\textquotedblright $\xrightarrow{\text{append()}}$ \textquotedblleft helloworld\textquotedblright.
\end{myexample}
It is impossible to change the inputs without changing the output: the output contains the inputs themselves.
In the example the function is a binary operation, however, by fixing one input, it is possible to turn these commitment operations into unary operations:
\begin{myexample}
	\textquotedblleft world\textquotedblright $\xrightarrow{\text{prepend(\textquotedblleft hello\textquotedblright)}}$ \textquotedblleft helloworld\textquotedblright.
\end{myexample}
Append and prepend have two problems: they reveal everything about the inputs and the size of the output is always greater than the size of the inputs.

Hiding the input of a commitment is often useful. For instance Robert Hooke \cite{Petroski96invention} in 1676 had formulated the spring law that will take his name. He wanted to prove that he knew that without revealing the law itself, so he published the latin anagram \textquotedblleft ceiiinosssttuv\textquotedblright. Later in 1678 he revealed the solution, \textquotedblleft ut tensio, sic vis\textquotedblright (\textquotedblleft as the extension, so the force\textquotedblright). However the anagram is not an optimal commitment operation: \textquotedblleft ut vis, sic tensio\textquotedblright is a solution too. For that time it was an acceptable solution, the verification procedure had minimal requirements and there was no real incentive in lying. Nowadays better solutions are available, hence using an anagram will make the verifier suspicious.

To address these problems cryptographic hash functions are used. Hash functions maps bit strings of arbitrary finite length into bit strings of fixed length \cite{Damgard:1989:DPH:118209.118248}.
\begin{mydef}
	$h : \{ 0, 1 \} ^* \rightarrow \{ 0, 1 \} ^n $ is a hash function if it is computable in polynomial time in the length of the input.
\end{mydef}
We will refer at the input of such functions as preimage, and the output as hash value. The codomain is strictly contained in the domain hence the presence of collisions (pairs of inputs with identical outputs) is unavoidable.
To give to these functions a practical use some of the following properties are required
\begin{mydef}
	\label{hash-prop}
	Let $h$ be a hash function, the following properties may hold:
	\begin{itemize}
		\item preimage resistance: given $h(x)$ it is not feasible to compute $x$;
		\item second-preimage resistance: given $x$ it is not feasible to compute $y$ s.t. $x \neq y$, $h(x)=h(y)$;
		\item collision resistance: it is not feasible to find $x, y$ s.t. $x \neq y$, $h(x)=h(y)$.
	\end{itemize}
\end{mydef}

A preimage resistant hash function hides the inputs, this property is sometimes referred as one-wayness.
A second-preimage resistant hash function is also a commitment operation, in addition it hides the input and create a fixed size fingerprint. A huge file can be mapped into a short bit string which is a commitment to it.
Collision resistance, although is a nice to have, is not necessary for timestamping purposes: when a collision ($x \neq y$ s.t $h(x)=h(y)$) is found, $x$ and $y$ are found at the same time \cite{SHA1}.

Such properties depend on the dimension of the codomain, which is given by the parameter $n$, precisely $2^n$. If it is too low it will be easy to produce examples that invalidates the properties, if it is too high the hash function is not a good tool for reducing the size of the input. A good compromise has to be found, it should be based on the current state of the art of cryptanalysis and computer science. However what is considered acceptable during a period may not be accepted in a subsequent one, in fact if new techniques that break an hash function are discovered, then its use will be considered insecure.
Several hashing functions has been proposed, we show a couple of examples:
\begin{myexample}
	SHA1 (Secure Hashing Algorithm) was designed by the National Security Agency (NSA), and released in 1995. It maps bit strings to a 160 bit space, it was considered preimage, second-preimage and collision resistant. In 2005 cryptanalysts discover a theoretical procedure to find collisions, later practical attacks were published \cite{cryptoeprint:2017:190}, hence it was declared insecure. However only collision resistance was broken, thus it can still be used for timestamping purposes.
	\begin{verbatim}
	SHA1(b'Hello World!\n') = a0b65939670bc2c010f4d5d6a0b3e4e4590fb
	                          92b
	SHA1(b'Hello World\n')  = 648a6a6ffffdaa0badb23b8baf90b6168dd16
	                          b3a
	\end{verbatim}
\end{myexample}

\begin{myexample}
	SHA256 belongs to the family SHA2, the generation of hash functions following SHA1\footnote{Currently, it is available SHA3, which contains, among others, KECCAK256.}. It outputs  strings 256 bit long and, at the moment, it is considered to satisfy all the properties in Definition \ref{hash-prop}.
	Several systems are built upon this assumption.
	In addition, as other hash functions, SHA256 could be modeled as a random oracle, a fixed input will provide always the same output, since hash functions are deterministic, but the outputs corresponding to new inputs will give results that are indistinguishable from a uniform distribution.
	Note how a little change in the input produces outputs very dissimilar in both hash functions, this feature helps to spot alterations in the inputs.
	\begin{verbatim}
	SHA256(b'Hello World!\n') = 03ba204e50d126e4674c005e04d82e84c21
	                            366780af1f43bd54a37816b6ab340
	SHA256(b'Hello World\n')  = d2a84f4b8b650937ec8f73cd8be2c74add5
	                            a911ba64df27458ed8229da804a26
	\end{verbatim}
	Since SHA256 is available, the use of SHA1 should be avoided unless there is a particular motivation.
\end{myexample}

More complex commitment operations are possible.
But they should be used only if there are some valid and shared motivations. Finding a badly motivated commitment operation in a proof will make verifiers suspicious.

Combining the examples we saw it is possible to implement a data structure that is useful to embed several commitments into a single hash value,
this structure is called \textit{Merkle tree} \cite{DBLP:conf/sp/Merkle80}. Let $h$ be a second-preimage resistant hash function, start from $k$ data to timestamp $\{d_i\}_{i=1}^k$, called \textit{leaves}, compute their hash values $\{h(d_i)\}_{i=1}^k=\{h_i\}_{i=1}^n$. The first step combines the couples of adjacent values (if there is one) by concatenating ($||$) the two values and computing the hash value of the concatenation: $h(h_i||h_{i+1})$ $\forall i \in [1,k]$ odd. The following steps proceed in an analogous manner, but starting from the results computed at the step before as described in Algorithm \ref{alg:merkle-tree}.

\begin{algorithm}
	\caption{Merkle tree construction}
	\label{alg:merkle-tree}
	\begin{algorithmic}[1]
		\Procedure{merklestep}{$\{h_i\}_{i=1}^k$}
		\State $S \gets \{\}$
		\For {$i\gets 1,k$ s.t. $i\equiv 1 (2)$}
		\State $S \gets S \cup \begin{cases}
		h(h_i||h_{i+1}) & i \neq k \\
		h(h_i) & i=k
		\end{cases}$
		\EndFor
		\State \textbf{return} $S$
		\EndProcedure
		\Statex
		\Procedure{merklelize}{$\{d_i\}_{i=1}^k$} \Comment{from the leaves to the Merkle tip}
		\State $S \gets \{\}$
		\For {$i\gets 1, k$}
		\State $S\gets S \cup h(d_i)$\Comment{hash the leaves}
		\EndFor
		\State $k\gets |S|$
		\While {$k \neq 1$}
		\State $S \gets$ \Call{merklestep}{S} \Comment{if necessary, store $S$}
		\State $k\gets |S|$
		\EndWhile
		\State \textbf{return} $S$ \Comment{Merkle tip}
		\EndProcedure
	\end{algorithmic}
\end{algorithm}

After at most $\lceil log(k) \rceil$ steps the algorithm ends and one hash value is returned, it is called \textit{Merkle tip} or \textit{Merkle root}.
Thanks to reiteration of $h$ the tip is a commitment to all the leaves $\{d_i\}_{i=1}^k$, moreover to prove that a element $d_i$ is committed it is not necessary to know all tree, in fact it's enough to show the \textit{Merkle path} starting from $d_i$ and ending in the tip.
For instance referring to Figure \ref{fig:merkle-tree} the minimal requirement to show the commitment of $data3$ in $MT$ is the ordered sequence of operations to apply is:
\begin{verbatim}
h, append(h4), h, prepend(A), h, append(E), h
\end{verbatim}
Merkle trees can aggregate several commitments into one hash value, giving a scalability solution: the length of a single proof grows logarithmically with the number of leaves.

\begin{figure}
	\begin{center}
		\includegraphics[width=\linewidth]{Images/merkle-tree.png}
		\caption[Merkle tree example]{Merkle tree example. The Merkle root is a commitment to the leaves $\{data_i\}_{i=1}^5$.}
		\label{fig:merkle-tree}
	\end{center}
\end{figure}

\section{Time Attestations}
Attestations are provided by a notary, which has the authority to state the time.
Notaries are sometimes referred as timestamp servers, who ask for creating or verifying that a timestamp is referred as client.
A time attestation binds some data $d$ to the time $t$, $d$ could be directly the data to timestamp or a commitment to them.
To properly design a timestamp scheme it is crucial to analyse which features an attestation should have and how to choose a notary that provides the desired security.

An attestation should be \textit{tamper resistant} or, even better, \textit{immutable}. Once created no one should be able to modify that, backdating the timestamp or changing the underlying data without making the attestation invalid.

In the case of a sent letter an important issue comes to the attention: the attestation (postmark) can be verified only if the letter is in our hands. This makes the task of a counterfeiter easier, few people will examine the postmark making the success of the attack more likely. A solution that mitigates this issue is \textit{widely publishing} the attestation, for instance inserting it in a newspaper. The attacker has an harder task, in most cases, to guarantee himself good chances of success he needs to modify several, or even all, attestations leading to a higher cost. Considering an attestation on a newspaper, an attacker could counterfeit only the exact copy the verifier is going to check. To prevent such situation the verifier should check multiple sources and should not expose any information on where he is retrieving the copies used to examine. Attestations should be \textit{easily accessible}, for instance a good solution is to publish them on the internet.

We call the service providing the attestations notary, it has the authority to state the time. To maintain such power it has to show itself as \textit{trustworthy}: it should place the correct time in the attestations, it should not trick the clients modifying the timestamp ex post and he should not collude with the creator of the timestamp to trick a verifier. Moreover a notary should be \textit{competent}: if it looses the information necessary to verify the timestamp, then its creator will be damaged.

A good notary does not make distinctions among clients or data to timestamp, in other words it does \textit{not censor}. An improvement would be if it is not aware of what it is timestamping, like the case of the commitments hiding their inputs, but even better if it is not aware of being used as a timestamp server, like the newspaper.

In the case of a sent letter, the notary is the post officer, he will place the postmark on the letter giving it a date.
Clients must trust such notary, which in theory can place a wrong date $t'$ instead of $t$, creating a false timestamp (if $t'<t$) or a deliberate weaker proof (if $t'>t$). Alternately he can decide not to timestamp a letter or modifying its content before timestamping. In addition the resulting timestamp is unique, thus if it gets damaged or lost the proof is gone forever.

A notary willing to show himself as more trustworthy can make its possibly dishonest behaviour harder to implement. A possible solution is to link all the timestamps so that changing one would implies changing all the subsequent ones. A timestamp proof $TS_i$ for the data $d_i$ at the time $t_i$ ($t_{i-1}<t_i<t_{i+1}$) would have the following structure:
\begin{equation}
	\label{singed-chain}
	\begin{cases}
		TS_0 =(d_0,t_0, \sigma_N((d_0,t_0))) &
		\\
		TS_i =(d_i,t_i,TS_{i-1}, \sigma_N((d_i,t_i,TS_{i-1}))) & i = 1, ..., i_{max}
	\end{cases}
\end{equation}
where $\sigma_N (x)$ is a commitment to the data $x$. Such commitment is created by the notary, who is (supposedly) the only one who is able to apply $\sigma_N$. We call this function \textit{signature}, it can be physical (as a postmark) or digital (with a public key cryptosystem). The signature $\sigma_N$ is a commitment operation, so if $TS_{i}$ changes then $\sigma_N((d_{i+1},t_{i+1},TS_i))$ changes, thus $TS_{i+1}$ changes resulting in $TS_j$ changing for all $j>i$. Starting from the \textit{genesis timestamp} $TS_0$, the linked timestamps $\{ TS_{i} \}_{i=0}^{i_{max}}$ form a \textit{chain}. A trusted notary which implement this scheme will be preferred by honest clients. Depending on each particular problem the designer of the system has to properly choose how to collect the timestamp requests, how to commit them into the chain, the time frequency, the signature procedure, how to publish the chain and how to distribute the timestamp proof to the clients.

Even though linking the timestamps is a great improvement with respect to the previous schemes, having a trusted notary still involves some issues. The notary may loose what he needs for signing (e.g. stamp, private key); if an attacker can sign in the place of the notary, it will no longer be considered authoritative; if no one can sign the clients will be damaged. In addition the notary can create more than one chain starting from the same genesis timestamp, then he can use different chains for different clients.
Anyhow nothing can guarantee that a trusted notary will behave honestly in the future, it can attack some clients in several ways and such bad behaviour can be hard to spot rapidly, a single client may realize that he has been tricked only when he needs the timestamp.

Trusted attestations has security issues hence, in some situations, they could be considered not enough appropriate, yet for years an efficient solution that does not involve a trusted third party was considered barely impossible.
In 2008 Satoshi Nakamoto proposed \cite{Nakamoto_bitcoin:a} which described a system to transfer value from one party to another without relying on the presence of a central authority. The system can be also used to timestamp arbitrary data without trusting any notary.