%\section{Land Physics}
{\bf \Large
\begin{tabular}{ccc}
\hline
  Corresponding author & :\\
  Tsuyoshi Yamaura and Seiya Nishizawa\\
\hline
\end{tabular}
}

\subsection{Bucket model}

The land bucket model estimates the soil temperature and soil moisture tendencies using a multi-layered bucket model.

\subsubsection{Soil moisture equation}

The conservation equations of the specific mass of the liquid and ice water (kg/m$^3$), $M_w$ and $M_i$, respectively, are
\begin{align}
  \frac{\partial M_w}{\partial t}
  &= - \frac{\partial}{\partial z} \left( F_w + F_{rain} - F_{evap} \right)
     - m_{frz} - m_{ro,w}, \label{eq:MwDt} \\
  \frac{\partial M_i}{\partial t}
  &= - \frac{\partial}{\partial z}\left( F_{snow} - F_{subl} \right) + m_{frz} - m_{ro,i}, \label{eq:MiDt}
\end{align}
where $\nu_w$ is the constant water diffusivity (m$^2$/s);
$\rho_w$ and $\rho_i$ are the dencity of liquid and ice water (kg/m$^3$), respectively;
$F_{rain}, F_{snow}, F_{evap}$ and $F_{subl}$ are the surface flux of rain, snow, evapolation, and sublimation (kg/m$^2$/s), respectively;
$m_{frz}$ and $m_{ro}$ are the mass change by freezing and the runoff of the water from the system (kg/m$^3$/s), respectively.
Note that the $F_{rain}$ and $F_{snow}$ are positive for the downward direction and the $F_{evap}$ and $F_{subl}$ are positive for the upward.
$F_w$ is the vertical flux due to the diffusion, and
\begin{align}
  F_w &= - \rho_w \nu_w\frac{\partial W}{\partial z}.
\end{align}
$W$ and $I$ are the soil moisture content (m$^3$/m$^3$) of liquid and ice water, respectively, and are
\begin{align}
 W &= \frac{M_w}{\rho_w}, \\
 I &= \frac{M_i}{\rho_i}.
\end{align}

The bucket model has the maximum soil mositure content $W_\mathrm{max}$, so if the moisture content is larger than the maximum, the moisuter runs off to the out of the system:
\begin{align}
 W + I \le W_\mathrm{max}.
\end{align}
Therefore, The amount of the runoff (kg/m$^3$) is estimated as
\begin{align}
 M_{ro} &= M_{ro,w} + M_{ro,i},
\end{align}
where
\begin{align}
 M_{ro,w} &= \int_t^{t+ \Delta t} m_{ro,w} dt = \rho_w \min\{W_{ro},W\}, \\
 M_{ro,i} &= \int_t^{t+ \Delta t} m_{ro,i} dt = \rho_i (W_{ro} - \min\{W_{ro},W\}),
\end{align}
and $W_{ro} = \max\{W + I - W_\mathrm{max}, 0\}$.

\subsubsection{Thermodynamical equation}

The total internal energy is the sum of that of the soil, liquid water and ice water, $U_s, U_w$ and $U_i$, respectively:
\begin{align}
 U &= U_s + U_w + U_i, \\
 U_s &= C_s T, \\
 U_w &= c_l T \rho_w W, \\
 U_i &= ( c_i T - L_f ) \rho_i I,
\end{align}
where $T$ is the soil temperature (K).
Note that, the temperature is
\begin{align}
 T &= \frac{U + L_f \rho_i I }{C_L},
\end{align}
where $C_L$ is the total heat capacity (J/K/m$^3$) and
\begin{align}
 C_L &= C_s + c_l \rho_w W + c_i \rho_i I.
\end{align}

The conservation equation of the total internal energy is
\begin{align}
 \frac{\partial U}{\partial t} &=
 - \frac{\partial}{\partial z} \left[
   - \kappa \frac{\partial T}{\partial z}
   + c_l T F_w  + F_{surf} \right]  \nonumber \\ &
 - c_l T M_{ro,w}
 - ( c_i T - L_f ) M_{ro,i}, \label{eq:UDt}
\end{align}
where $\kappa$ is the thermal conductivity (J/K/m/s).
$F_{surf}$ is the ground surface flux, and
\begin{align}
 F_{surf} &= G
 + c_l T_{rain} F_{rain}
 - c_l T_{evap} F_{evap} \nonumber \\&
 + ( c_i T_{snow} - L_f ) F_{snow},
 - ( c_i T_{subl} - L_f ) F_{subl},
\end{align}
where $G$ is the downward ground heat flux (J/m$^2$/s); and $T_{rain}, T_{evap}, T_{snow}$ and $T_{subl}$ are the temperature of the rain, evaporation water, snow, and sublimation ice, respectively.
These ground surface fluxes are calculated in the surface scheme.

The thermal conductivity depends on the moisture content, and Kondo and Saigusa 1994) gived it empirically as
\begin{align}
  \kappa &= \kappa_s + 0.5 W^\frac{1}{3},
\end{align}
where $\kappa_s$ is the thermal conductivity of the soil particle.

\subsubsection{Phase change}
The liquid water and ice water can exist instantenously only at the temperature $T_0$.
If the internal energy is lower than $C_sT_0 + (c_i T_0 - L_f) M$, all the moisutre is ice, where $M$ is the total moisture $M=M_w+M_i$.
On the other hand, the internal energy is larther than $C_sT_0 + c_lT_0M$, all the moisture is liquid.
Otherwize,
\begin{align}
 M_i &= \frac{U - ( C_s + c_l M ) T_0}{ (c_i-c_l)T_0 - L_f}, \\
 M_w &= M - M_i.
\end{align}
That is,
\begin{align}
 M_i &= \min\left\{ \max\left\{ \frac{U-(C_s+c_lM)T_0}{(c_i-c_l)T_0-L_f}, 0 \right\}, M \right\}, \\
 M_w &= M - M_i.
\end{align}

\subsubsection{Temporal integration}
Eqs. (\ref{eq:MwDt}, \ref{eq:MiDt} and \ref{eq:UDt}) are solved by a splitting method.
In the first step, the moisture mass and internal energy changes are calculated without the diffusion, runoff, and phase change.
In the second step, the phase change is calculated.
In the third step, the moisture diffusion equation is solved.
In the fouth step, the temperature diffusion is calculated with the thermal conductivity with the moisture content obtained in the second step.
At the last step, the runoff is calculated.

The followings are the summary of the sequence of calculation.
Here, the superscript ``$n$'' indicates the quantites at the time step $n$, ``$n_1$'', ``$n_2$'', ``$n_3$'', ``$n_4$'', and ``$n+1$'' are those after calculation of the first, seccond, third, fourth, and the last steps, respectively.
The vertical diffusion terms are calculated by the implicit scheme for numerical stability.

\begin{description}

\item[First step]

\begin{align}
 M^{n_1} &= \rho_w W^n + \rho_i I^n + \Delta t \frac{\partial}{\partial z}( F_{rain} + F_{snow} - F_{evap} - F_{subl} ), \\
 U^{n_1} &= C_L^n T^n - L_f \rho_i I^n + \Delta t \frac{\partial F_{surf}}{\partial z},
\end{align}
where $M$ is the total moisture mass (kg/m$^3$) and $M = M_w + M_i$.

\item[Second step]
\begin{align}
 M_i^{n_2} &= \min\left\{ \max\left\{ \frac{U^{n_1}-(C_s+c_lM^{n_1})T_0}{(c_i-c_l)T_0-L_f}, 0 \right\}, M^{n_1} \right\}, \\
 M_w^{n_2} &= M^{n_1} - M_i^{n_2}, \\
 W^{n_2} &= \frac{M_w^{n_2}}{\rho_w}, \\
 I^{n_2} &= \frac{M_i^{n_2}}{\rho_i}, \\
 T^{n_2} &= \frac{U^{n_1} + L_f M_i^{n_2}}{C_s + c_l M_w^{n_2} + c_i M_i^{n_2}}.
\end{align}

\item[Third step]
\begin{align}
 F_w &= - \rho_w\nu_w\frac{\partial W^{n_3}}{\partial z}, \\
 W^{n_3} &= W^{n_2} - \frac{\Delta t}{\rho_w} \frac{\partial F_w}{\partial z}, \\
 U^{n_3} &= U^{n_1} - \Delta t \frac{\partial c_l F_w T^{n_2}}{\partial z}, \\
 C_L^{n_3} &= C_s + c_l \rho_w W^{n_3} + c_i M_i^{n_2}.
\end{align}

\item[Fourth step]
\begin{align}
 \kappa &= \kappa_s + 0.5 (W^{n_3})^\frac{1}{3}, \\
 C_L^{n_3} T^{n+1} &= U^{n_3} + L_f M_i^{n_2}
 - \Delta t \frac{\partial}{\partial z} \left( -\kappa \frac{\partial T^{n+1}}{\partial z} \right).
\end{align}

\item[Fifth step]
\begin{align}
 I^{n+1} &= \min\{ I^{n_2}, W_\mathrm{max} \}, \\
 W^{n+1} &= \min\{ W_\mathrm{max} - I^{n+1}, W^{n_3} \}, \\
 M_{ro,w} &= \rho_w ( W^{n+1} - W^{n_3} ), \\
 M_{ro,i} &= \rho_i ( I^{n+1} - I^{n_2} )
\end{align}

\end{description}

\subsubsection{Descretization}
The moisture diffusion in the third step is solved as
\begin{align}
 W_1^{n_3} &= W_1^{n_2} + \frac{2\Delta t \nu_w }{\Delta z_1}\frac{W_2^{n_3} - W_1^{n_3}}{\Delta z_2 + \Delta z_1}, \\
 W_k^{n_3} &= W_k^{n_2} + \frac{2\Delta t \nu_w }{\Delta z_k}\left( \frac{W_{k+1}^{n_3} - W_k^{n_3}}{\Delta z_{k+1}+\Delta z_k}  - \frac{W_k^{n_3} - W_{k-1}^{n_3}}{\Delta z_k+\Delta z_{k-1}} \right), \\
 W_m^{n_3} &= W_m^{n_2} - \frac{2\Delta t \nu_w }{\Delta z_m}\left( \frac{W_m^{n_3} - W_{m-1}^{n_3}}{\Delta z_m+\Delta z_{m-1}} \right),
\end{align}
where the subscription $k$ represents that $W_k$ is the moisture content in the $k$-layer, and $k = 1, \cdots, m$, where $m$ is the number of the layers.
This can be written in the matrix form as
\begin{equation}
\begin{pmatrix}
  c_1  & b_1    &        &        &        &         &         \\
       & \ddots & \ddots & \ddots &        &         &         \\
       &        & a_k    & c_k    & b_k    &         &         \\
       &        &        & \ddots & \ddots & \ddots  &         \\
       &        &        &        &        & a_m     & c_m     \\
\end{pmatrix}
\begin{pmatrix}
  W_1^{n_1}   \\
  \vdots      \\
  W_k^{n_1}   \\
  \vdots      \\
  W_m^{n_1}   \\
\end{pmatrix}
=
\begin{pmatrix}
  V_1 \\
  \vdots        \\
  V_k \\
  \vdots        \\
  V_m
\end{pmatrix}
,
\end{equation}
where
\begin{align}
 V_k &= W_k^{n_2}, \\
 a_k &= - \frac{2\Delta t\nu_w}{\Delta z_k (\Delta z_k + \Delta z_{k-1})}, \\
 b_k &= - \frac{2\Delta t\nu_w}{\Delta z_k (\Delta z_{k+1} + \Delta z_k)}, \\
 c_k &= 1 - a_k - b_k.
\end{align}
This matrix can be solved by the Thomas algorithm (tridiagonal matrix algorithm).

The thermodynamical diffusion in the fourth step is discretized as
\begin{align}
  \kappa_k &= \kappa_s + 0.5 (W^{n_3}_k)^\frac{1}{3}, \\
%
  (F_w)_{k+\frac{1}{2}} &= - 2\rho_w\nu_w\frac{W^{n_3}_{k+1}-W^{n_3}_k}{\Delta z_{k+1}+\Delta z_k}, \\
%
  (C_L^{n_3})_1 T^{n+1}_1 &= U^{n_3}_1 + L_f(M_i)^{n_2}_1
  + \frac{\Delta t}{\Delta z_1} (\kappa_2+\kappa_1) \frac{T^{n+1}_2-T^{n+1}_1}{\Delta z_2+\Delta z_1}, \\
%
  (C_L^{n_3})_k T^{n+1}_k &= U^{n_3}_k + L_f(M_i)^{n_2}_k  \nonumber\\&
  + \frac{\Delta t}{\Delta z_k} \left( (\kappa_{k+1}+\kappa_k) \frac{T^{n+1}_{k+1}-T^{n+1}_k}{\Delta z_{k+1}+\Delta z_k} - (\kappa_k+\kappa_{k-1}) \frac{T^{n+1}_k-T^{n+1}_{k-1}}{\Delta z_k+\Delta z_{k-1}} \right), \\
%
  (C_L^{n_3})_m T^{n+1}_m &= U^{n_3}_m + L_f(M_i)^{n_2}_m
  - \frac{\Delta t}{\Delta z_m} (\kappa_m+\kappa_{m-1}) \frac{T^{n+1}_m-T^{n+1}_{m-1}}{\Delta z_m+\Delta z_{m-1}}.
\end{align}

As in the case of the soil moisture, the tendency equations can be solved using the Thomas algorithm.
\begin{align}
 V_k &= U^{n_3}_k + L_f (M_i)^{n_2}_k, \\
 a_k &= - \frac{\Delta t (\kappa_k+\kappa_{k-1})}{\Delta z_k(\Delta z_k+\Delta_{k-1})}, \\
 b_k &= - \frac{\Delta t (\kappa_{k+1}+\kappa_k)}{\Delta z_k(\Delta z_{k+1}+\Delta_k)}, \\
 c_k &= (C_L^{n_1})_k - a_k - b_k.
\end{align}


% This is part of the TFTB Tutorial.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file tutorial.tex for copying conditions.

\section{The affine class}
%~~~~~~~~~~~~~~~~~~~~~~~~~

Important note\,: in all the following section, we will consider that the
signal (often denoted $x$) is analytic (see section \ref{anasig} for the
definition and the computation of the analytic signal).

For this part, more information can be found in \cite{FLA93}, \cite{BER92},
\cite{GON93}, \cite{GON96}, \cite{OVA94} and \cite{RIO92}.

\subsection{Axiomatic definition}
%''''''''''''''''''''''''''''''''
\subsubsection{The affine group}

  The Cohen's class, as presented in the previous section, is based on the
properties of covariance by shifts in time and in frequency. One important
element of this class is the Wigner-Ville distribution, noteworthy for its
numerous properties.

   In order to favor a time-scale approach of the signal, one can also
choose to put forward, among these desirable properties, the {\it
covariance by translation in time and dilation}. The corresponding group of
transforms, counterpart of the Weyl-Heisenberg group (see section
\ref{WHG}), is the {\it affine group}\index{affine group}, noted $A$,
already introduced in the context of wavelet transform (see section
\ref{affinegroup}). Its action induced on a signal $x(t)$ is given by
\[x(t) \ \rightarrow\
x_{a',b'}(t)={1\over\sqrt{|a'|}}\ x\left({t-b'\over a'}\right),\]
and on its Fourier transform by
\[X(\nu) \ \rightarrow\  X_{a',b'}(\nu)=\sqrt{|a'|}\ e^{-j2\pi\nu b'}
X(a'\nu).\]

\subsubsection{General expressions}

  It is possible to show that if a bilinear time-scale distribution
$\Omega_x(t,a)$ is covariant to affine transformations, i.e.
\[\Omega_{x_{a',b'}}(t,a)=\Omega_x\left(\frac{t-b'}{a'},\frac{a}{a'}\right),\]
then, it is necessarily parameterized as
\begin{eqnarray}
\label{omega}
\Omega_x(t,a;\Pi)=\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}
\Pi\left(\frac{s-t}{a},a \xi\right)\ W_x(s,\xi)\ ds\ d\xi
\end{eqnarray}
where $\Pi(t,\nu)$ is an arbitrary smoothing function. This distribution
will also preserve the signal energy provided that
\[\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty} \Pi(t,\nu)\ dt\
\frac{d\nu}{|nu|} = 1.\] The set of such representations defines the {\it
affine class}\index{affine class}, which is the class of time-frequency
energy distributions covariant by translation in time and dilation. From
expression (\ref{omega}), it is straightforward that the Wigner-Ville
distribution is an element of the affine class\,: if we introduce an
arbitrary non-zero frequency $\nu_0$, and identify the scale with the
inverse of the frequency\,:
\[a=\frac{\nu_0}{\nu},\]
then the WVD corresponds to the element for which
\[\Pi(t,\nu)=\delta(t)\ \delta(\nu-\nu_0).\]

  A consequence of (\ref{omega}) is that the choice of an element in the
affine class can be reduced to the choice of an affine correlation kernel
$\Pi(t,\nu)$. When $\Pi$ is a two-dimensional low-pass function, it plays
the role of an affine smoothing function which tries to reduce the
interferences generated by the WVD.

  Another equivalent expression for a generic element can be found in terms
of ambiguity\,:
\begin{eqnarray}
\label{omega2}
\Omega_x(t,a;\Phi)=\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty} \Phi(a
\xi,\tau/a)\ A_x(\xi,\tau)\  e^{-j2\pi \xi t}\ d\xi\ d\tau,
\end{eqnarray}
where $\Phi(\xi,\tau)$ is the weighting function corresponding to $\Pi$\,:
\[\Phi(\xi,\tau)=\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}
\Pi(t,\nu)\ e^{j2\pi(\nu \tau+\xi t)}\ dt\ d\nu,\]
and $A_x(\xi,\tau)$ is the narrow-band ambiguity function already defined in
section \ref{NBAF}.

  Finally, an alternative characterization of the class (\ref{omega}) may
be given by using the {\it bi-frequency kernel}\index{bi-frequency kernel}
$\Psi(\nu,f)$
\begin{eqnarray}
\label{omega3}
\Omega_x(t,a;\Pi) = \frac{1}{|a|}\int\int_{-\infty}^{+\infty} \Psi(\nu,f)
X\left(\frac{f-\frac{\nu}{2}}{a}\right)
X^*\left(\frac{f+\frac{\nu}{2}}{a}\right) e^{-j2\pi\nu t/a}\ d\nu df
\end{eqnarray}
with
\[\Psi(\nu,f) = \int_{-\infty}^{+\infty} \Pi(t,f)\ e^{-j2\pi\nu t}\ dt,\]
where $X(\nu)$ is the Fourier transform of $x(t)$. We will take advantage of
these different (but equivalent) expressions of the affine class in the
following.

\subsubsection{Properties}

  As for the Cohen's class, it can be useful to impose further constraints
on the class defined by (\ref{omega}), to obtain a sub-class of
distributions which validate particular properties (see page
\pageref{propertieswvd}). We detail here some of the most important ones.

\begin{enumerate}
\label{propertiesaff}
\item {\it Energy conservation}\index{energy conservation}\,: by
integrating $\Omega_x$ all over the time-scale plane, we obtain the energy
of $x$\,:
\[E_x = \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty}
\Omega_x(t,a;\Pi)\ dt\ \frac{da}{a^2}\]

\item {\it Marginal properties}\index{marginal properties}\,: the energy
spectral density and the instantaneous power can be obtained as marginal
distributions of $\Omega_x$\,:
\begin{eqnarray*}
\int_{-\infty}^{+\infty} \Omega_x(t,a;\Pi)\ dt = |X(\frac{\nu_0}{a})|^2 \\
\int_{-\infty}^{+\infty} \Omega_x(t,a;\Pi)\ \frac{da}{a^2} = |x(t)|^2
\end{eqnarray*}

\item {\it Real-valued}\,:
\[\Omega_x(t,a;\Pi) \in \Rset,\ \forall t,\ a\]

\item {\it Time localization}\index{time localization}\,:
\[X(\nu)=\frac{1}{\sqrt{\nu}}\ e^{-j2\pi\nu t_0}\ U(\nu)\ \Rightarrow\
 \Omega_x(t,\frac{\nu_0}{\nu};\Pi)=\nu\ \delta(t-t_0)\ U(\nu)\]
where $U(\nu)$ is the Heaviside step function.

\label{propunit}
\item {\it Unitarity}\index{unitarity}\,: conservation of the scalar
product from the time domain to the time-scale domain (apart from the
squared modulus)\,:
\[ \left|\int_{-\infty}^{+\infty} x(t)\ y^*(t)\ dt\right|^2 =
\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} \Omega_x(t,a;\Pi)\
\Omega_y^*(t,a;\Pi)\ dt\ \frac{da}{a^2}\]

\item {\it Group delay}\index{group delay}\,: we may want to obtain the
group delay of $x$ as the first order moment in time of $\Omega_x$\,:
\[t_x\left(\frac{\nu_0}{a}\right)={\int_{-\infty}^{+\infty} t\
\Omega_x(t,a;\Pi)\ dt\over\int_{-\infty}^{+\infty} \Omega_x(t,a;\Pi)\ dt}\]

\item {\it Narrow-band limit}\index{narrow-band limit}\,: it can also be
desirable that, for narrow-band signals, the affine distribution $\Omega_x$
coincides with the Wigner-Ville distribution\,:
\[\Omega_x(t,a;\Pi)=W_x\left(t,\frac{\nu_0}{a}\right).\]

\end{enumerate}

\subsection{Some examples}
%'''''''''''''''''''''''''
\subsubsection{The scalogram}
\index{scalogram} A first example of affine distribution is given by the
  {\it scalogram} (see section \ref{SCALO}). Indeed, it is possible to
  express it as a smoothed version of the WVD\,:
\begin{eqnarray}
\label{scalo}
 |T_x(t,a;\Psi)|^2 = \int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}
W_x(s,\xi)\ W_{\Psi}\left(\frac{s-t}{a},a \xi\right)\ ds\ d\xi.
\end{eqnarray}
Thus, the scalogram corresponds to the distribution of the affine class for
which $\Pi(t,\nu)=W_{\Psi}(t,\nu)$. Expression (\ref{scalo}), to be compared
with expression (\ref{spectro}), shows that the scalogram is the affine
counterpart of the spectrogram. The scalogram validates properties 1. and
3. and is always positive.

  To illustrate the importance of the smoothing operated by $\Pi$ on the
WVD of $x$, let us consider the case of a Morlet wavelet $\Psi$. If we note
$\delta_T$ and $\delta_B$ the respectively time and frequency widths of the
smoothing operated by the spectrogram of window $\Psi$ ($\delta_T$ and
$\delta_B$ are constant values), these widths become variable with the
frequency in the case of the scalogram\,:
\[\delta_T(\nu)=\nu_0\ \delta_T/\nu\ ;\ \delta_B(\nu)=\nu\ \delta_B/\nu_0\]
($\nu_0$ is the central frequency of the wavelet). This result, already made
out in the context of the wavelet transform analysis, is a characteristic
of any constant-Q analysis (see section \ref{Qana})\,: at a high frequency,
since the signal changes rapidly, a short analysis window is sufficient,
whereas at a low frequency, a large window is necessary to identify
correctly the pulsation of the signal which changes slowly. However, the
importance of the joint smoothing operated by the scalogram is still
equivalent to the one of the spectrogram\,:
\[\delta_T(\nu)\ \delta_B(\nu)\ =\ \delta_T\ \delta_B.\]
Besides, the trade-off between time and frequency resolutions, following from
the Heisenberg-Gabor inequality and which applies to the spectrogram, is
also valid for the scalogram.

  So as to see the effect of this frequency-dependent smoothing, we analyze
with the scalogram (Morlet wavelet) a signal composed of two gaussian
atoms, one with a low central frequency, and the other one with a high one
(see fig. \ref{En2fig1})\,:
\begin{verbatim}
     >> sig=atoms(128,[38,0.1,32,1;96,0.35,32,1]);
     >> tfrscalo(sig);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig1.eps}}
\caption{\label{En2fig1}Morlet scalogram of 2 atoms : the time- and
frequency- resolutions depend on the frequency (or scale)}
\end{figure}
By default, the file \index{\ttfamily tfrscalo}{\ttfamily tfrscalo.m} uses
an interactive mode in which you have to specify, from the plot of the
spectrum, the approximate lower and higher frequency bounds, as well as the
number of samples you wish in frequency (you should indicate here a lower
frequency lower than 0.05 and a higher frequency greater than 0.4). The
result obtained brings to the fore dependency, with regard to the
frequency, of the smoothing applied to the WVD, and consequently of the
resolutions in time and frequency.

\subsubsection{The product kernel distributions}
\index{product kernel distributions}
  The formal identification "scale=inverse of the frequency" can be
extended to other distributions than the WVD. If we consider kernels of the
form
\[\Phi(\xi,\tau)=\Phi(\xi \tau)\ e^{-j2\pi\nu_0 \tau}\]
where $\nu_0$ is some nonzero frequency, we then have the following
equivalence between the Cohen's class and the affine class\,:
\[\Omega_x(t,a;\Phi)=C_x\left(t,\frac{\nu_0}{a};\Phi\right).\]
The corresponding representations, and in particular the Wigner-Ville,
Born-Jordan, Rihaczek and Choi-Williams distributions, are elements of the
intersection of these two classes.

\subsubsection{The affine smoothed pseudo Wigner distribution\,: separable
kernel} \label{aspwd}\index{affine smoothed pseudo Wigner distribution} One
way to overcome the trade-off between time and frequency resolutions of the
scalogram is, as for the smoothed-pseudo-WVD, to use a smoothing function
which is separable in time and frequency. The resulting distribution is
called the {\it affine smoothed pseudo Wigner distribution} (noted ASPWD),
and writes
\begin{eqnarray}
\label{ASPW}
ASPW_x(t,a) = \frac{1}{a} \int\int_{-\infty}^{+\infty}
h\left(\frac{\tau}{a}\right)g\left(\frac{s-t}{a}\right)\ x(s+\frac{\tau}{2})\
x^*(s-\frac{\tau}{2})\ ds\ d\tau.
\end{eqnarray}
It allows a flexible choice of time and scale resolutions in an independent
manner through the choice of the windows $g$ and $h$. Properties 1. and
3. (see page \pageref{propertiesaff}) are satisfied by this distribution
provided that $g$ is real and $h$ is hermitian.

  As for the SPWVD (see section \ref{SPWVD}), the ASPWD allows a continuous
passage from the scalogram to the WVD, under the condition that the
smoothing functions g and h are gaussian. The time-bandwidth product then
goes from 1 (scalogram) to 0 (WVD), with an independent control of the time
and frequency resolutions. This is illustrated by the function
\index{\ttfamily movsc2wv}{\ttfamily movsc2wv.m}, which considers different
transitions, on a signal composed of four atoms. To visualize these
snapshots, load the mat-file {\ttfamily movsc2wv} and run {\ttfamily movie}
(see fig. \ref{En2fig2})\,:
\begin{verbatim}
     >> load movsc2wv
     >> clf; movie(M,10);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=10cm
\centerline{\epsfbox{figure/en2fig2.eps}}
\caption{\label{En2fig2}Different transitions between the scalogram and the
WVD thanks to the ASPWD. The analyzed signal is composed of 4 gaussian atoms}
\end{figure}
Here again, the WVD gives the best resolutions (in time and in frequency),
but presents the most important interferences, whereas the scalogram gives
the worst resolutions, but with nearly no interferences\,; and the ASPWD
allows to choose the best compromise between these two extremes.\\

  To summarize, we have seen that on one hand, the spectrogram is a
time-frequency distribution obtained from the WVD by smoothing, and that on
the other hand, the scalogram is a time-frequency distribution obtained
from the WVD by affine smoothing. The WVD is therefore at the intersection
of both classes of time-frequency and time-scale distributions. Besides, it
is possible to construct a continuous transition from the spectrogram to
the scalogram via the WVD, by changing the smoothing function $\Pi$ acting on
the WVD. The equivalent area of such function $\Pi$ will vary from zero (we
then obtain the "unsmoothed" WVD) to a limit fixed by the Heisenberg-Gabor
uncertainty principle (spectrogram and scalogram). This choice corresponds
to using the SPWVD's or the ASPWD's with gaussian smoothing functions.
The time-bandwidth product then runs from 0 (WVD) to 1 (spectrogram or
scalogram) and truly controls both transitions.

  Figure \ref{En2fig3} illustrates different transitions between the
spectrogram and the scalogram on a synthetic signal composed of three
gaussian atoms, for different values of $BT$.
\begin{figure}[htb]
\epsfxsize=14cm
\epsfysize=12cm
\centerline{\epsfbox{figure/en2fig3.eps}}
\caption{\label{En2fig3}From the spectrogram to the scalogram via the WVD}
\end{figure}

  This analysis brings us to the conclusion that, instead of looking at the
two extreme representations (spectrogram and scalogram) separately, a
deeper insight can be gained by considering a whole continuum between the
two extremes, with the WVD as a necessary intermediate step. Moreover, the
transition allows a trade-off between joint resolutions and interferences
reduction.

\subsubsection{The localized bi-frequency kernel distributions}
\index{localized bi-frequency kernel distributions}
\label{LBFKD}
  A useful subclass of the affine class consists in characterization
functions which are perfectly localized on some curve $f=H(\nu)$ in their
bi-frequency representation (see (\ref{omega3}))\,:
\[\Psi(nu,f)=G(\nu)\ \delta(f-H(\nu))\ \Leftrightarrow\
\Phi(\nu,\tau)=G(\nu)\ e^{j2\pi H(\nu) \tau}\] where $G(\nu)$ is an
arbitrary function. The corresponding time-scale distributions, which are
referred to as {\it localized bi-frequency kernel distributions}, then read
\[\Omega_x(t,a;\Pi)=\frac{1}{|a|}\ \int_{-\infty}^{+\infty} G(\nu)\
X\left(\frac{H(\nu)-\nu/2}{a}\right)\
X^*\left(\frac{H(\nu)+\nu/2}{a}\right)\ e^{-j2\pi\nu t/a}\ d\nu.\]

  Actually, it has been shown that the only group delay laws on which a
localized bi-frequency kernel distribution can be perfectly localized are
power laws (i.e. $t_x(\nu)=t_0+c\nu^{k-1}$) and logarithmic laws
(i.e. $t_x(\nu)=t_0+c \log{\nu}$).

  As for the product-kernel distributions, with the formal identification
$a=\nu_0/\nu$, we can associate to every time-scale distribution of that kind a
time-frequency distribution according to
\[C_x(t,\nu;\Phi)=\Omega_x(t,\nu_0/\nu;\Phi).\]
We give in the following particular examples of such distributions.

\begin{itemize}
\item {\it Bertrand distribution}
\label{bertdist1}

\index{Bertrand distribution}
  If we further impose to these distributions the {\it a priori} requirements of
time localization and unitarity, we obtain
\[G(\nu)=\frac{\nu/2}{\sinh\left(\frac{\nu}{2}\right)}\ \mbox{  and  }\
H(\nu)=\frac{\nu}{2}\ \coth\left(\frac{\nu}{2}\right),\]
which leads to the {\it Bertrand distribution}, defined as
\begin{eqnarray}
\label{bertrand}
B_x(t,a)=\frac{1}{|a|}\int_{-\infty}^{+\infty}
\frac{\nu/2}{\sinh\left(\frac{\nu}{2}\right)}\
  X\left(\frac{\nu\ e^{-\nu/2}}{2a
\sinh\left(\frac{\nu}{2}\right)}\right)\hspace*{3cm}\nonumber\\
\hspace*{1cm}\times X^*\left(\frac{\nu\ e^{+\nu/2}}{2a
\sinh\left(\frac{\nu}{2}\right)}\right)\ e^{-j2\pi\nu t/a}\ d\nu
\end{eqnarray}
It validates properties 1. to 7., except the time-marginal property (see
page \pageref{propertiesaff}). Besides, we can show that this distribution
is the only localized bi-frequency kernel distribution which localizes
perfectly the hyperbolic group delay signals\,:
\[X(\nu)=\frac{e^{j\Phi_x(\nu)}}{\sqrt{\nu}}\ U(\nu)\]
\[\mbox{with }\ \Phi_x(\nu)=-2\pi\left[\nu t_0+\alpha
\log\frac{\nu}{\nu_c}\right]\ \Rightarrow\ B_x(t,a=\frac{\nu_0}{\nu})=\nu\
\delta(t-t_x(\nu))\ U(\nu) \] where $t_x(\nu)=-\frac{1}{2\pi}\
\frac{d\Phi_x(\nu)}{d\nu}$ is the group delay. To illustrate this property,
consider the signal obtained using the file \index{\ttfamily
gdpower}{\ttfamily gdpower.m} (taken for $k=0$), and analyze it with the
file \index{\ttfamily tfrbert}{\ttfamily tfrbert.m} (see
fig. \ref{En2fig4})\,:
\begin{verbatim}
     >> sig=gdpower(128);
     >> tfrbert(sig,1:128,0.01,0.22,128,1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig4.eps}}
\caption{\label{En2fig4}Bertrand distribution of an hyperbolic group delay
signal}
\end{figure}

Note that the distribution obtained is well localized on the hyperbolic
group delay, but not perfectly\,: this comes from the fact that the file
{\ttfamily tfrbert.m} works only on a subpart of the spectrum, between two
bounds $f_{min}$ and $f_{max}$. Note that the larger the frequency
bandwidth, the more needed samples, and consequently the longer the
computation time.

\item {\it D-Flandrin distribution }
\index{D-Flandrin distribution}\label{DFLA}

  If we now look for a localized bi-frequency kernel distribution which is
real, localized in time and which validates the time-marginal property, we
obtain
\[G(\nu)=1-(\nu/4)^2\ \mbox{  and  }\ H(\nu)=1+(\nu/4)^2.\]
The corresponding distribution then writes\,:
\begin{eqnarray*}
D_x(t,a)=\frac{1}{|a|}\ \int_{-\infty}^{+\infty} (1-(\nu/4)^2)\
X\left(\frac{[1-\nu/4]^2}{a}\right)\hspace*{3cm}\nonumber\\
\hspace*{1cm}\times  X^*\left(\frac{[1+\nu/4]^2}{a}\right)\
e^{-j2\pi\nu t/a}\ d\nu,
\end{eqnarray*}
which defines the {\it D-Flandrin distribution}. It validates properties
1-4., 6. and 7. (see page \pageref{propertiesaff}), and is the only
localized bi-frequency kernel distribution which localizes perfectly
signals having a group delay in $\frac{1}{\sqrt{\nu}}$\,:
\[X(\nu)=\frac{e^{j\Phi_x(\nu)}}{\sqrt{\nu}}\ U(\nu)\]
with
\[\Phi_x(\nu)=-2\pi[\nu t_0+2\alpha \sqrt{\nu}]
 \ \Rightarrow\ D_x\left(t,a=\frac{\nu_0}{\nu}\right)=\nu\
\delta(t-t_x(\nu))\ U(\nu).\] This can be illustrated using the files
\index{\ttfamily gdpower}{\ttfamily gdpower.m} with $k=1/2$ and
\index{\ttfamily tfrdfla}{\ttfamily tfrdfla.m}, as following (see
fig. \ref{En2fig5})\,:
\begin{verbatim}
     >> sig=gdpower(128,1/2);
     >> tfrdfla(sig,1:128,0.01,0.22,128,1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig5.eps}}
\caption{\label{En2fig5}D-Flandrin distribution of a signal with a group
delay in $1/\nu^{1/2}$}
\end{figure}
Here again, the distribution is almost perfectly localized.

\item {\it Unterberger distributions}
\index{Unterberger distributions}\label{UNTER}

  Finally, the choice of
\[G(\nu)=1\ \mbox{  and  }\ H(\nu)=\sqrt{1+\left(\frac{\nu}{2}\right)^2}\]
corresponds to the {\it active Unterberger distribution}\,:
\begin{eqnarray*}
U^{(a)}_x(t,a)=\frac{1}{|a|}\ \int_0^{+\infty} (1+\frac{1}{\alpha^2})\
X\left(\frac{\alpha}{a}\right)\  X^*\left(\frac{1}{\alpha a}\right)\
e^{j2\pi (\alpha-1/\alpha)\frac{t}{a}}\ d\alpha,
\end{eqnarray*}
which verifies properties 1-4., 6-7. (see page \pageref{propertiesaff})
except the time-marginal\,; and the choice of
\[G(\nu)=\frac{1}{\sqrt{1+\left(\frac{\nu}{2}\right)^2}}\ \mbox{  and  }\
H(\nu)=\sqrt{1+\left(\frac{\nu}{2}\right)^2}\]
corresponds to the {\it passive Unterberger distribution}\,:
\begin{eqnarray*}
U^{(p)}_x(t,a)=\frac{1}{|a|} \int_0^{+\infty} \frac{2}{\alpha}\
X\left(\frac{\alpha}{a}\right)\ X^*\left(\frac{1}{\alpha a}\right)\
e^{j2\pi (\alpha-\frac{1}{\alpha})\frac{t}{a}}\ d\alpha,
\end{eqnarray*}
which verifies properties 1-3., 6-7. The active Unterberger
distribution is the only localized bi-frequency kernel distribution which
localizes perfectly signals having a group delay in $1/\nu^2$\,:
\[X(\nu)=\frac{e^{j\Phi_x(\nu)}}{\sqrt{\nu}}\ U(\nu)\]
with
\[\Phi_x(\nu)=-2\pi[\nu t_0-\alpha/\nu]
\ \Rightarrow\ U^{(a)}_x(t,a=\nu_0/\nu)=\nu\ \delta(t-t_x(\nu))\ U(\nu).\]

The files \index{\ttfamily gdpower}{\ttfamily gdpower.m}, considered for
$k=-1$, and \index{\ttfamily tfrunter}{\ttfamily tfrunter.m} give us (see
fig. \ref{En2fig6})\,:
\begin{verbatim}
     >> sig=gdpower(128,-1);
     >> tfrunter(sig,1:128,'A',0.01,0.22,172,1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig6.eps}}
\caption{\label{En2fig6}Active  Unterberger distribution of a signal with a
group delay in $1/\nu^2$}
\end{figure}
\end{itemize}

  We will go back over these distributions later on (sub-section \ref{AWD})
in a different context.

\subsection{Relation with the ambiguity domain}
%''''''''''''''''''''''''''''''''''''''''''''''

\subsubsection{Need of specific tools for broad-band signals}

  The WVD, as we have seen in the previous chapter, is a very satisfactory
distribution when applied to narrow-band signals. Its use for the
description of broad-band signals is also possible, but can lead to
surprising images. For example, for an analytic signal whose real part is
$\delta(t-t_0)$, the WVD equals to
\[W(t,\nu)=4{\sin(4\pi\nu(t-t_0))\over\pi(t-t_0)}\ U(\nu)\]
where $U(\nu)$ is the Heaviside function, and thus is not well localized in
the neighborhood of $t=t_0$ (see fig. \ref{En2fig7})\,:
\begin{verbatim}
     >> sig=anapulse(128);
     >> tfrwv(sig);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig7.eps}}
\caption{\label{En2fig7}WVD of a Dirac impulse at time $t=64$}
\end{figure}
Actually, the group of translations in time and frequency (the
Weyl-Heisenberg group, see section \ref{WHG}) on which the WVD is based,
and more generally all the Cohen's class, is responsible for these bad
localization properties on broad-band signals\,: since the use of the
analytic signal is admitted, the translation in frequency of broad-band
signals fails to preserve the frequency support of the signal (the support
of its Fourier transform can not be limited to the positive frequency
axis). This suggests to replace the WVD by a distribution more
fundamentally based on the affine group.

\index{Doppler effect} The {\it Doppler effect}, which is an important
physical phenomenon, provides an additional motivation to use specific
methods based on the affine group to analyze broad-band signals. Indeed, it
characterizes the fact that a signal returned by a moving target is dilated
(or compressed) and delayed compared to the emitted signal. If, for
narrow-band emitted signals and low-speed targets (compared to the sound
speed in the medium) this phenomenon can be approximated by a translation
in time and frequency, for broad-band signals, the dilation of the spectrum
has to be taken into account. This is particularly the case in radar and
sonar problems where the time-bandwidth product of the emitted signal is
important and where the speed of the moving target is often not negligible
compared to the wave speed in the medium.

\subsubsection{From the Fourier transform to the Mellin transform}
\index{Mellin transform}

  A second argument encourages one to find more specific tools to analyze
broad-band signals\,: the eigenvectors of the Weyl-Heisenberg group are the
familiar complex exponentials, on which the Fourier transform decomposes a
signal, whereas for the affine group, the eigenvectors are hyperbolas. From
a slightly different point of view, the Fourier transform is invariant in
modulus to translations in frequency, but not to dilations. Therefore, the
Fourier transform is no longer the appropriate transform to change the
representation space of these signals. It has to be replaced by a new
transform, the {\it Mellin transform}, which is invariant in modulus to
dilations, and decomposes the signal on a basis of hyperbolic signals. This
transform can be defined as\,:
\[M_X(\beta)=\int_0^{+\infty} X(\nu)\ \nu^{j2\pi \beta-1}\ d\nu\]
where $X(\nu)$ is the Fourier transform of the analytic signal corresponding
to $x(t)$. We can show easily that
\[Y(\nu)=X(a\nu)\ \Rightarrow\ M_Y(\beta)=a^{-j2\pi \beta}\ M_X(\beta),\]
which demonstrates the invariance by dilation. The basic elements are waves
of the form $\nu^{-j2\pi \beta}$, whose group delay is hyperbolic\,:
\[t_x(\nu)={\beta\over\nu}.\]
Thus, the $\beta$-parameter can be interpreted as a {\it hyperbolic
modulation rate}, and has no dimension\,; it is called the {\it Mellin's
scale}.\index{Mellin's scale}

In the discrete case, the Mellin transform can be calculated rapidly using
a fast Fourier transform. Its algorithm, called the {\it fast Mellin
transform}\index{fast Mellin transform}, is computed thanks to the file
\index{\ttfamily fmt}{\ttfamily fmt.m}. For further details on this
transform, see for example \cite{OVA94}. This transform is often used in
the Time-Frequency Toolbox to implement functions which are connected to
the affine class.

\subsubsection{From the narrow-band AF to the wide-band AF}
\index{wide-band ambiguity function} When the signal under analysis can not
  be considered as narrow-band (i.e. when its bandwidth $B$ is not
  negligible compared to its central frequency $\nu_0$), the narrow-band
  ambiguity function is no longer appropriate since the Doppler effect can
  not be approximated as a frequency-shift. We then consider a {\it
  wide-band ambiguity function} (WAF), which can be defined as\,:
\begin{eqnarray*}
\Xi_x(a,\tau) = \frac{1}{\sqrt{a}}\ \int_{-\infty}^{+\infty} x(t)\
x^*(t/a-\tau)\ dt = \sqrt{a} \int_{-\infty}^{+\infty} X(\nu)\ X^*(a\nu)\
e^{j2\pi a \tau\nu}\ d\nu.
\end{eqnarray*}
It corresponds to the wavelet transform of the signal $x$, whose mother
wavelet is the signal $x$ itself. It is then an affine correlation
function, which measures the similarity between the signal and its
translated (in time) and dilated versions. This ambiguity function can be
easily calculated using two Mellin transforms. The M-file \index{\ttfamily
ambifuwb}{\ttfamily ambifuwb.m} of the Time-Frequency Toolbox computes this
expression of the wide-band ambiguity function. To see how it behaves on a
practical example, let us consider an Altes signal (see the M-file
\index{\ttfamily altes}{\ttfamily altes.m}) (see fig. \ref{En2fig8})\,:
\begin{verbatim}
     >> sig=altes(128,0.1,0.45);
     >> ambifuwb(sig);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig8.eps}}
\caption{\label{En2fig8}Wide-band ambiguity function of an Altes signal}
\end{figure}
The WAF is maximum at the origin of the ambiguity plane.

We can also introduce a symmetric form of the WAF\,:
\begin{eqnarray*}
\Xi_x^{(s)}(\alpha,\tau) = \sqrt{1-\alpha^2/4}\
 \int_{-\infty}^{+\infty} x\left((1+\alpha/2)t+\frac{\tau}{2}\right)\
x^*\left((1-\alpha/2)t-\frac{\tau}{2}\right)\ dt
\end{eqnarray*}
where $a=(1+\alpha/2)(1-\alpha/2)$. This expression can be related to the WVD
by the following formula\,:
\begin{eqnarray*}
\Xi_x^{(s)}(\alpha,\tau) = \int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}
\sqrt{1-\alpha^2/4}\ e^{j2\pi(\tau+\alpha t)\nu}\ W_x(t,\nu)\ d\nu.
\end{eqnarray*}

\subsubsection{From the WVD to the Bertrand distribution}
\index{Bertrand distribution}\label{bertdist2}
  Now that we defined the symmetric wide-band ambiguity function, it would
be interesting to obtain an expression equivalent to the one linking the
WVD and the narrow-band ambiguity function, but replaced in the affine
context. This can be done by applying a Fourier transform to the delay
variable of the symmetric WAF, and a Mellin transform to the $\alpha$
variable\,:
\begin{eqnarray}
\label{bertrand2}
B_x(t,\nu) = \int_0^{+\infty} \int_{-\infty}^{+\infty}
\Xi_x^{(s)}(\alpha,\tau)\ e^{-j2\pi\nu \tau}\ \alpha^{j2\pi t-1}\ d\tau\
d\alpha\nonumber\\
=\nu \int_{-\infty}^{+\infty} \frac{u/2}{\sinh\left(\frac{u}{2}\right)}\
  X\left(\frac{\nu\ u\ e^{-u/2}}{2 \sinh\left(\frac{u}{2}\right)}\right)\
X^*\left(\frac{\nu\ u\ e^{+u/2}}{2 \sinh\left(\frac{u}{2}\right)}\right)\
e^{-j2\pi\nu ut}\ du
\end{eqnarray}
which corresponds to the Bertrand distribution, already introduced in
section \ref{bertdist1} (the equivalence between formula (\ref{bertrand}) and
(\ref{bertrand2}) is obtained by identifying $\nu$ as the inverse of the
scale\,: $\nu={\nu_0\over a}$ with $\nu_0=1$\,Hz).

\subsection{The affine Wigner distributions}
%'''''''''''''''''''''''''''''''''''''''''''
\label{AWD}\index{affine Wigner distributions}
\subsubsection{Introduction}

  The Bertrand distribution $B_x$ given by (\ref{bertrand}) or
(\ref{bertrand2}) is in fact covariant by a larger group than the affine
group $A$\,: this group, $G_0$, of transformations $g=(a,b,c)$, where $(a,b)$
is an element of $A$ and $c$ is real, acts on the signal $X$ as\,:
\[X(\nu)\ \rightarrow\  X_g(\nu) = \sqrt{|a|}\ e^{-j2\pi(\nu b+c \ln(\nu))}\
X(a\nu).\]
The resulting change on $B_x$ is\,:
\[B_x\ \rightarrow\ B_x^g(t,\nu)=B_x\left(\frac{t-b-c/\nu}{a},a\nu\right).\]
Actually, it is possible to generalize this extended covariance property to
a sub-class of affine distributions, not only restricted to the Bertrand
distribution. It can be shown that the only three-parameter groups, noted
$G_k$, including the affine group, are defined as follows\,: for $k\neq1$,
$G_k$ is the group of elements $g=(a,b,c)$ with composition law\,:
\[gg'=(a a',b+a b',c+a^k c').\]
Group $G_1$ has a slightly different composition law\,:
\[gg'=(a a',b+a b'+a \ln(a) c',c+a c').\]
The action of these groups on the analytic signal $X(\nu)$ is then dependent
on $k$ according to\,:
\begin{eqnarray*}
X(\nu)\ \rightarrow\ X_g(\nu)=\sqrt{|a|}\ X(a\nu) & e^{-j2\pi(\nu
b+c\nu^k)}\  &\mbox{ for } k\neq 0,1\ ;\\
X(\nu)\ \rightarrow\ X_g(\nu)=\sqrt{|a|}\ X(a\nu) & e^{-j2\pi(\nu b+c
\ln(\nu))}\  &\mbox{ for } k=0\ ;\\
X(\nu)\ \rightarrow\ X_g(\nu)=\sqrt{|a|}\ X(a\nu) & e^{-j2\pi(\nu b+c\nu
\ln(\nu))}\  &\mbox{ for } k=1.
\end{eqnarray*}
The distributions $P_x^k$ covariant by these three-parameter solvable
groups $G_k$, and satisfying the time-reversal invariance
($Y(\nu)=X^*(\nu)\ \Rightarrow\ P_y^k(t,\nu)=P_x^k(-t,\nu)$), are then
found to be\,:
\begin{eqnarray}
\label{wigaff}
P_x^k(t,\nu)=\int_{-\infty}^{+\infty}\nu\ \mu_k(u)\ X(\lambda_k(u)\nu)\
X^*(\lambda_k(-u)\nu)\ e^{j2\pi(\lambda_k(u)-\lambda_k(-u))t\nu}\ du,
\end{eqnarray}
\[\mbox{where }\
\lambda_k(u)=\left({k(e^{-u}-1)\over e^{-ku}-1}\right)^{\frac{1}{k-1}}\]
and $\mu_k(u)$ is a real positive and even function. The definition
(\ref{wigaff}) is valid for any real $k$ provided that $\lambda_k(u)$ is
defined by continuity for $k=0$ and $k=1$\,:
\[\lambda_0(u)=-\frac{u}{e^{-u}-1} \ \mbox{ and }\
  \lambda_1(u)=\exp\left(1+\frac{ue^{-u}}{e^{-u}-1}\right). \] Expression
(\ref{wigaff}) defines the {\it class of affine Wigner distributions}. As
we will see in the next section, this class, introduced on mathematical
considerations, is equivalent to the class of localized bi-frequency kernel
distributions (see section \ref{LBFKD}). We now investigate special cases of
$\mu_k$ leading to distributions satisfying unitarity and/or localization
properties.

\subsubsection{Some examples}

  Two special families of affine Wigner distributions can be determined by
imposing constraints on $P_x^k$. The first one is unitarity (see page
\pageref{propunit}, property 5.), which is satisfied if $\mu_k$ is
given by
\[\mu_k(u)=\sqrt{\lambda_k(u)\ \lambda_k(-u)\
{d(\lambda_k(u)-\lambda_k(-u))\over du}}.\]
The second one is time-localization (property 4.), which implies that
\[\mu_k(u)=\sqrt{\lambda_k(u)\ \lambda_k(-u)}\
{d(\lambda_k(u)-\lambda_k(-u))\over du}.\]

\begin{itemize}
\item $k=0$\,: {\it the Bertrand distribution}\index{Bertrand distribution}

  The choice of $k=0$ under one or the other (or both) constraints leads
to the Bertrand distribution, already defined in sections \ref{bertdist1}
and \ref{bertdist2}\,: $P_x^0(t,\nu)=B_x(t,\nu)$. In fact, it is the only
affine Wigner distribution which satisfies simultaneously the unitarity and
the time localization.

\item $k=2$\,: {\it the Wigner-Ville distribution}\index{Wigner-Ville
distribution}

  The unitary affine Wigner distribution corresponding to $k=2$ is the
Wigner-Ville distribution (see section \ref{WVD}) provided that $x$ is
analytic\,: $P_x^2(t,\nu)=W_x(t,\nu)$.

\item $k=1/2$\,: {\it The D-Flandrin distribution}\index{D-Flandrin
distribution}

  The time-localization constraint together with the choice $k=1/2$ leads to
the D-Flandrin distribution, already defined in section \ref{DFLA}\,:
$P_x^{1/2}(t,\nu)=D_x(t,\nu)$.

\item $k=-1$\,: {\it The active Unterberger distribution}
\index{Unterberger distributions}

  Another known example of time-localized distribution is obtained for
$k=-1$\,: it corresponds to the active Unterberger distribution (see section
\ref{UNTER}). While this form is non-unitary, it cooperates with its passive
form to produce an isometry-like relation\,:
\[\int_{-\infty}^{+\infty} \int_0^{+\infty} U^{(a)}_x(t,\nu)\
U^{(p)*}_y(t,\nu)\ d\nu\ dt = \left|\int_{-\infty}^{+\infty} x(u)\ y^*(u)\
du\right|^2.\]

\item $k\ \rightarrow\ \pm\infty$\,: {\it The Margenau-Hill
distribution}\index{Margenau-Hill distribution}

  Finally, under the unitarity constraint, it is interesting to consider
the two distributions obtained for $k\rightarrow -\infty$ and $k
\rightarrow +\infty$\,: if we note respectively $P_-$ and $P_+$ these two
distributions and take their arithmetic mean, we obtain exactly the
Margenau-Hill distribution (see section \ref{MHD})\,:
\[{P_x^+(t,\nu)+P_x^-(t,\nu)\over 2}=\Re\left\{R_x(t,\nu)\right\}.\]
\end{itemize}

\subsubsection{Interference structure}
\index{interference}
  The interference structure of the affine Wigner distributions can be
determined thanks to the following geometric argument\,: two points
$(t_1,\nu_1)$ and $(t_2,\nu_2)$ belonging to the trajectory on which a
distribution is localized interfere on a third point $(t_i,\nu_i)$ which is
necessarily located on the same trajectory. Consequently, using the result
of section \ref{LBFKD} which says that the localized bi-frequency kernel
distributions are localized on power law group delays of the form
$t_x(\nu)=t_0+c\nu^{k-1}$, one can show that the coordinates $(ti,\nu_i)$
are determined by the relation (\cite{GON92})
\[\omega_i=\left({\omega_2^k-\omega_1^k\over k(\omega_2-\omega_1)}\right)
^{\frac{1}{k-1}}\] where $\omega=\nu$ or $\omega=(t-t_0)^{\frac{1}{k-1}}$.
These "mid-point" coordinates can be computed using the M-file
\index{\ttfamily midpoint}{\ttfamily midpoint.m} of the Time-Frequency
Toolbox. Figure \ref{En2fig9} represents the location of interference point
corresponding to two points of the time-frequency plane $(t_1,f_1)$ and
$(t_2,f_2)$, for different values of $k$.
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig9.eps}}
\caption{\label{En2fig9}Locus of the interferences between 2 points for the
affine Wigner distributions (parameterized by $k$). For $k=2$, which
corresponds to the Wigner-Ville distribution, we obtain the geometric
mid-point}
\end{figure}
In particular, for $k=2$, corresponding to the Wigner-Ville distribution, we
obtain the geometric mid-point.

  To illustrate this interference geometry, let us consider the case of a
signal with a sinusoidal frequency modulation\,:
\begin{verbatim}
     >> [sig,ifl]=fmsin(128);
\end{verbatim}
The file \index{\ttfamily plotsid}{\ttfamily plotsid.m} allows one to
construct the interferences of an affine Wigner distribution perfectly
localized on a power-law group-delay (specifying $k$), for a given
instantaneous frequency law (or the superposition of different
instantaneous frequency laws). For example, if we consider the case of the
Bertrand distribution ($k=0$) (see fig. \ref{En2fig10}),
\begin{verbatim}
     >> plotsid(1:128,ifl,0);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig10.eps}}
\caption{\label{En2fig10}Theoretical diagram of the interferences of the
Bertrand distribution for a sinusoidal frequency modulation}
\end{figure}
we obtain an interference structure completely different from the one
obtained for the Wigner-Ville distribution ($k=2$) (see
fig. \ref{En2fig11})\,:
\begin{verbatim}
     >> plotsid(1:128,ifl,2);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig11.eps}}
\caption{\label{En2fig11}Theoretical diagram of the interferences of the
Wigner-Ville distribution for a sinusoidal frequency modulation}
\end{figure}
For the active Unterberger distribution ($k=-1$), the result is the
following (see fig. \ref{En2fig12})\,:
\begin{verbatim}
     >> plotsid(1:128,ifl,-1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig12.eps}}
\caption{\label{En2fig12}Theoretical diagram of the interferences of the
active Unterberger distribution for a sinusoidal frequency modulation}
\end{figure}

We can notice the presence of an inflexion point (corresponding to the
intersection of an infinite number of lines joining two symmetric points
from the sinusoid) in the case of the WVD distribution, which disappears in
the other distributions.

\subsection{The pseudo affine Wigner distributions}
%''''''''''''''''''''''''''''''''''''''''''''''''''
\index{pseudo affine Wigner distributions}
  The affine Wigner distributions (\ref{wigaff}) show great potential as flexible
tools for time-varying spectral analysis. However, as for some distributions of
the Cohen's class, they present two major practical limitations\,: first the
entire signal enters into the calculation of these distributions at every
point $(t,\nu)$, and second, due to their nonlinearity, interference
components arise between each pair of signal components. To overcome these
limitations, a set of (smoothed) pseudo affine Wigner distributions has
been introduced recently. We present here the main results relative to this
new class of affine distributions.

\subsubsection{Derivation}

  Recall from section \ref{PWVD} that we obtained the pseudo Wigner-Ville
distribution by introducing a window function into the Wigner-Ville
distribution. An analogous windowing operated on the affine Wigner
distributions (\ref{wigaff}) leads to the {\it pseudo affine Wigner
distributions}. But in contrast to the pseudo Wigner-Ville case, this
windowing must be frequency-dependent, to ensure that the resulting
time-scale distribution remains scale-covariant. As a result, the smoothing
in frequency is constant-Q, rather than constant-bandwidth as in the pseudo
Wigner-Ville distribution. The general expression of this new class of
distributions, expressed in the time-domain, writes:
\begin{eqnarray}
\tilde{P}_x^k(t,\nu)=\nu\ \int_{-\infty}^{+\infty} \mu_k(u)\
\left[\int_{-\infty}^{+\infty} x(\tau)\ h[\nu \lambda_k(u) (\tau-t)]\
e^{-j2\pi\lambda_k(u)\nu (\tau-t)}\ d\tau\right]\nonumber\\
\label{Pk}
\times\left[\int_{-\infty}^{+\infty} x(\tau_p)\ h[\nu
\lambda_k(-u) (\tau_p-t)]\ e^{-j2\pi\lambda_k(-u)\nu (\tau_p-t)}\
d\tau_p\right]^* du\ \
\end{eqnarray}
where $h$ is the time-windowing function. By analogy with the pseudo
Wigner-Ville distributions, we call these distributions the pseudo affine
Wigner distributions.

  An efficient online implementation can be obtained if we reorder
(\ref{Pk}) to yield
\begin{eqnarray}
\label{Ptk}
\tilde{P}_x^k(t,\nu)=\int_{-\infty}^{+\infty}
{\mu_k(u)\over\sqrt{\lambda_k(u)\lambda_k(-u)}}\
T_x(t,\lambda_k(u)\nu;\Psi)\ T_x^*(t,\lambda_k(-u)\nu;\Psi)\ du,
\end{eqnarray}
where $T_x(t,\nu;\Psi)$ is the continuous wavelet transform (see section
\ref{CWT}), and $\Psi(\tau)=h(\tau)\ e^{j2\pi \tau}$ is a bandpass wavelet
function.

\subsubsection{Time-frequency smoothing interpretation}

  The time-windowing function $h$ introduced in (\ref{Pk}) or (\ref{Ptk})
attenuates interference components that oscillate in the frequency
direction. To suppress interference terms oscillating in the time
direction, we must smooth in that direction with a low-pass function
$G$. The resulting distributions
\begin{eqnarray}
\tilde{P}_x^k(t,\nu)=\int_{-\infty}^{+\infty} G(u)\
\frac{\mu_k(u)}{\sqrt{\lambda_k(u)\lambda_k(-u)}}\
T_x(t,\lambda_k(u)\nu;\Psi)\hspace*{2cm}\nonumber\\
\label{Ptk2}
\times T_x^*(t,\lambda_k(-u)\nu;\Psi)\ du,
\end{eqnarray}
are called the \index{smoothed pseudo affine Wigner distributions}{\it
smoothed pseudo affine Wigner distributions}. It is important to notice
that, like the (smoothed) pseudo Wigner-Ville case with the localization on
linear chirps, (smoothed) pseudo affine Wigner distributions are no longer
localized on power-law group delays. Nevertheless, as $Q$ (the quality
factor of the wavelet $\Psi$) tends towards infinity and $G(u)$ to the
all-pass function, this localization property is asymptotically recovered
since $\tilde{P}_x^k$ converges to $P_x^k$. Besides, since (\ref{Ptk2}) can
be implemented efficiently, this convergence property provides us with an
efficient-implementation approximation of any affine Wigner distribution
(by considering the corresponding pseudo affine Wigner distribution with a
large $Q$).

  Expression (\ref{Ptk2}) is used in the function \index{\ttfamily
tfrspaw}{\ttfamily tfrspaw.m} which computes these (smoothed) pseudo affine
Wigner distributions.

\subsubsection{Examples}

  Finally, we present two examples of such distributions for different
values of $k$, and analyze the results obtained on a real echolocation
signal from a bat. This signal is obtained from the file {\ttfamily
bat.mat}\,:
\begin{verbatim}
     >> load bat; N=128;
     >> sig=hilbert(bat(801:7:800+N*7)');
\end{verbatim}
For each value of $k$, we compute the corresponding affine Wigner
distribution and smoothed pseudo affine Wigner distribution.
\begin{itemize}
\item $k=2$\,: {\it affine smoothed pseudo Wigner distribution }

  In this case, (\ref{Ptk2}) becomes the affine smoothed pseudo Wigner
distribution, already introduced in section \ref{aspwd} on separable kernel
considerations.
\begin{verbatim}
     >> tfrwv(sig);
     >> tfrspaw(sig,1:N,2,24,0,0.1,0.4,N,1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig13.eps}}
\caption{\label{En2fig13}WVD of a bat sonar signal}
\end{figure}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig14.eps}}
\caption{\label{En2fig14}Affine smoothed pseudo Wigner distribution of the
bat sonar signal}
\end{figure}
On figure \ref{En2fig13}, the WVD presents interference terms because of
the non-linearity of the frequency modulation, whereas on figure
\ref{En2fig14}, the affine frequency smoothing operated by the affine
smoothed pseudo Wigner distribution almost perfectly suppresses the
interference terms.

\item $k=0$\,: {\it pseudo Bertrand distribution}

  This value of $k$ reduces (\ref{Ptk2}) to a simple expression
\[\tilde{P}_x^0(t,\nu)=\int_{-\infty}^{+\infty} G(u)\
T_x(t,\lambda_k(u)\nu;\Psi) \ T_x^*(t,\lambda_k(-u)\nu;\Psi)\ du\] which is
called the (smoothed) pseudo Bertrand distribution.
\begin{verbatim}
     >> tfrbert(sig,1:N,0.1,0.4,N,1);
     >> tfrspaw(sig,1:N,0,32,0,0.1,0.4,N,1);
\end{verbatim}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig15.eps}}
\caption{\label{En2fig15}Bertrand distribution of the bat sonar signal}
\end{figure}
\begin{figure}[htb]
\epsfxsize=10cm
\epsfysize=8cm
\centerline{\epsfbox{figure/en2fig16.eps}}
\caption{\label{En2fig16}Pseudo-Bertrand distribution of the bat sonar
signal}
\end{figure}
Figure \ref{En2fig15} represents the Bertrand distribution. The approximate
hyperbolic group delay law of the bat signal explains the good result
obtained with this distribution (compared to the WVD). However, it remains
some interference terms, which are almost perfectly cancelled on figure
\ref{En2fig16} (pseudo Bertrand distribution).
\end{itemize}

\subsection{Conclusion}
%''''''''''''''''''''''
    The constraint of affine covariance has been shown in this part to
be relevant for the derivation of time-frequency representations. It
leads to a class of affine distributions which is the counterpart of
the Cohen's class associated to time and frequency translations. These
two classes can also be seen as a result of some 2D correlation acting
on the WVD. We have thereby derived a large class of time-scale and
time-frequency representations, on which many possible (and sometimes
exclusive) properties may be imposed. We have studied several specific
requirements (such as energy normalization, time marginals \ldots) and
associated parameterization of the representation. There is obviously
a great versatility for the choice of representations, which may be
appropriate for various applications. Each one is appropriate to
describe properly specific characteristics of a signal, and one has to
benefit from the complementarity of these tools. Vice versa, a good
interpretation of the time-frequency and time-scale images
necessitates a deep knowledge of the mechanisms of information's
allocation in the plane.


In this section we detail our reference scenario for MRS coordination and as well
as the formalization of the problem we addressed and the solutions we propose.

\section{Problem description}
Our reference scenario is based on a warehouse that stores items of various types.
Such items must be composed together to satisfy orders that arrive based on customers’ demand.
The items of various types are stored in particular sections of the building (\textit{loading bay})
and must be trasported to a set of \textit{unloading bays} where such items are then
packed together by human operators. The set of items to be trasported and where they should
go depends on the orders.

In our domain a set of robots is responsible for transporting items from
the loading bay to the unloading bays and the system goal is to maximize the
throughput of the orders, i.e., to maximize the number of orders completed in
the unit of time. Now, robots involved in transportation tasks move around
the warehouse and are likely to interfere when they move in close proximity,
and this can become a major source of inefficiency (e.g., robots must slow down
and they might even collide causing serious delays in the system).
Hence, a crucial aspect to maintain highly efficient and safe operations is to minimize the
possible spatial interferences between robots.

The main goal of our system is composing simple tasks to create a subset of complex tasks
to improve the productivity and minimize the robot's time travel and the paths distance.

To manage the merging of the task we can use a range of different techniques.
In the setion \ref{solution} there are the strategies used to create subsets of tasks.
After the composing step, we have varieties of tasks subsets. At the end to validate which is the best
subset we propose an heuristic. This heuristic function normalize the overall path of the subset of tasks
based on the number of items that each robot can carry.
Furthermore the purpose is to maximize the number of items in the same journey.

\section{Problem fomalization}
In this section we formalize the MRS coordination problem described above as a task allocation problem
where the robots must be allocated to transportation tasks.

In our formalization we have a finite set of tasks. A robot can execute a task if it is available else the robot will go at start position.
For how the system is built, a robot to request a task must arrive at the previous vertex of the loading bay.

In more detail, our model considers a set of items of different types $E = \{ e_1,...,e_N\}$,
stored in a specific loading bay ($L$). The warehouse must serve a set of orders
$O=\{o_1,...,o_M\}$. Orders are processed in one or more than one of the unloading bays ($U_i$).
Each order is defined by a vector of demand for each item type (the number of required
items to close the order). Hence, $o_j = < d_{1,j},...,d_{N,j}>$, where $d_{i,j}$ is the
demand for order $j$ of items of type $i$. When an order is finished a new one arrives,
until the set of task is finished.
The orders induce a set of $N \times M$ trasportation tasks $T = {t_{i,j}}$, with
$t_{i,j} = < d_{i,j}, P_{i,j}>$, where $t_{i,j}$ defines the task of transporting
$d_{i,j}$ items of type $i$ for order $o_j$ (hence to unloading bay $U_j$).
Each task has a destination bay for centralized coordination the $t_{i,j}$ has a set of edges
$P_{i,j}$ which respects the strategy used.
We have a set of robot $R = \{r_1,...,r_K \}$ that can execute transportation tasks, where
each robot has a defined load capacity for each item type $C_k = <c_{1,k},...,c_{N,k}>$,
hence $c_{i,k}$ is the load capacity of robot $k$ for items of type $i$.

We consider in our logistic scenario, homogenous robots, which have the same radius
and the same capacity. Because often in the logistic environments robots are all
equal.

% formalizzare la euristica
Since the main of this thesis is composing subsets of tasks we formalize what is
a subset of tasks and what we mean for merging paths of a subset of tasks and
which is the heuristic funcion used for differentiate the subests of tasks or simple tasks.

Specifically given a set of tasks $\mathcal{T}$ it define intrinsically a set of orders $O$.
One order perform a subset of $\mathcal{T}$. A subest of tasks $S$, denoted by $S\subseteq\mathcal{T}$.

Where $S = \{T_1,\cdots,T_k\}$ for each element of the subset we combine their paths $P$ to form a single path $\pi$.
For $\pi$ define a path that perform the travel order such as a vector of vertices $\pi = \{v_1,\cdots,v_i\}$.
% figure dell'unione di due path

\begin{figure}[hbt]
    \begin{multicols}{2}
        \includegraphics[width=\linewidth]{img/p1p2_cut.png}
        \includegraphics[width=\linewidth]{img/p3_cut.png}
    \end{multicols}
    \caption{Comparison of the union of two paths $P$ and $P'$ to form a single path $\pi = P \cup P'$.}
\end{figure}

% funzione che calcola il percorso distaza

The function $p(\cdot)$ is used to join the paths, this funcion return the vector of vertices $\pi$.

For calculate the cost of the paths we used a function $f(\cdot)$ that return the path distance.

Because we maximize the total demand ($d_S$) we calculate the sum the single demand for each element in the subset.
More formally:
\[d_S =demand(T_1) + \cdots + demand(T_k)\]

where $demand(\cdot)$ return the single demand of the specific task.

Another function used in our system is $dst(\cdot)$ that return the euclidean distances between loading and unloading bays.

Finally we define our heuristic function $v(\cdot)$ which
can be defined for any task $T$ or subsets $S$:
\[ v(T) = \frac{f(P)}{demand(T)}\]

This heuristic function is used for normalize the cost of path (path distance)
on the demand (cost of the item/items) of the order.

For compute the best partition of tasks the heuristic is based on the concept of loss $L$,
which can be defined for any pair of subset $S_i$, $S_j$ as:
\[L(S_i,S_j) = v(\{ S_i \cup S_j\}) - v(S_i) - v(S_j)\]
where $v(S)$ is value of the characteristic function $v(\cdot)$ for subset $S$.
In other worlds, this loss funcion captures the value of synergies between subsets
and is computed in constant time.

The function $v$ for a subset $S$ is defined as:
\[ v(S) = \frac{f(\pi)}{d_S}\]
where $f(\pi)$ is the path distance between the loading bay $L$ and the unloading bays $U_j$ and the distance
to return to the initial vertex and the $d_s$ is the total demand of the tasks.

We want minimize the cost of the loss, that can be defined as:
\[L(S_i,S_j) < 0 \]
if the loss $L$ is less than 0 then we allocate the pair and delete the element which
form the subset.


\chapter{Particle system}
\label{cha:particlesystem}

Particle system is one of most commonly used techniques to simulate smoke, fire, rain and other groups of discrete objects, usually independent from each other. The system consists of a defined number of emitters, producing lightweight particle objects with certain parameters. Each emitter has a defined production ratio, and each particle a certain lifespan, resulting in the upper limit of total particles on the screen. Some systems also use attraction points, which enable better control over particles, using equations often similar to those of electrostatic forces.
Such simulation is independent from rendering. The same particle system can be used for different effects with proper configuration.

\begin{figure}[h!]
  \caption{Example rendering of tested particle system}
  \label{img:particles}
  \centering
	\includegraphics[width=16cm]{particles}
\end{figure}

\section{System parameters}
\label{sec:emittersparameters}

The tested system works on the two-dimensional Cartesian plane. For the purpose of performance analysis, movements are calculated based only on frames rather than actual flow of time. This means that systems with a different framerate will result in different visualisations, but requesting a given amount of frames rendered will result in the same lifespan and total number of particles in both systems.

Emitter supports the following parameters:

\begin{itemize}
	\item position -- initial position of created particles
	\item angle -- angle counting clockwise from the vector [0, 1]
	\item spread -- parameter controlling random differences in the initial angle of particles
	\item velocity -- initial velocity of particles, in pixels per frame
	\item velocity spread -- parameter controlling random differences in the initial velocity of particles
	\item lifespan -- initial lifespan of particles
	\item productionRate -- amount of particles initialized in each frame
\end{itemize}

A Particle has similar properties:
\begin{itemize}
	\item position
	\item velocity
	\item lifespan
	\item age -- counted in frames, when for given particle it is higher than its lifespan, particle is removed from the system
\end{itemize}

Source code of both implementations is attached in the Appendix \ref{cha:sourcecode}.

\section{Implementation with high memory allocation}
\label{sec:particlesinitial}

The initially tested implementation has one very important property of a particle emitter. Whenever new particles are created, a new array of pointers is allocated and returned from the emitter. The system appends new particles to the existing array. In each frame, the particle system creates a new, empty array of particles and adds only particles that are still alive. The array from the previous frame and all dead particles are removed from the system and deallocated. This is clearly a suboptimal solution that allocates and deallocates plenty of memory in each frame. The purpose of this exercise is to show how both languages handle a bad code, and how big impact it has compared to the optimal solution.

\lstinputlisting[caption=Time measurement of unoptimized particle system in JavaScript,label=listing:timejs1]{particles/timejs1.txt}
\lstinputlisting[caption=Time measurement of unoptimized particle system in C++,label=listing:timecpp1]{particles/timecpp1.txt}

Time measurement shows that the JavaScript version is almost 8 times slower than the native one. To analyse the situation --prof and --log-timer-events flags may be used. The output file v8.log is parsed using an available online tool.\cite{v8-profile-plotter}

\lstinputlisting[caption=Profiler output for unoptimized particles,label=listing:particles1profile]{particles/particles1-profile.txt}

Methods prefixed with ~ are unoptimized, the ones prefixed with * are JIT compiled. As seen in the profiler log, most of the time is spent in unoptimised versions of verifyIfAlive and stepParticle methods.

\lstinputlisting[caption=Annotated part of source,label=listing:particles1stepannotated,language=JavaScript]{particles/particleSystemstep.js}

The same methods are also used in optimised versions, where they take significantly less ticks to run. It is clear that the presented code not only allocates and deallocates too much memory, but also fails to run in optimised mode. It is visible on the chart obtained from the same tool -- stripe labelled "code kind in execution" shows multiple kinds of code running and is interrupted often with garbage collection cycles.

\begin{figure}[h!]
  \caption{Chart of time used in unoptimised verion of JavaScript}
  \label{img:particles1profile}
  \centering
	\includegraphics[width=16cm]{particles/particles1-profile.png}
\end{figure}

Garbage collection cycles blocking execution are also visible with --trace-gc flag.

\lstinputlisting[caption=Garbage collection in unoptimised particle system,label=listing:particles1gc]{particles/particles1gc.txt}

\section{Implementation with object pool}
\label{sec:particlesobjectpool}

To improve performance, a different approach to particles allocation is used. Each particle has a flag "isDead" telling if it may be safely reused for a new particle. The particle pool is kept along with a list of pointers to dead particles. This way, when the system reaches its maximum congestion (around 15000 particles in the given example) no new allocations occur.
The creation of new particles is moved from the particle emitter to the particle system, to avoid allocation of the new array. The emitter works now as a structure describing behaviour, but not implementing one.

\lstinputlisting[caption=Time measurement of optimized particle system in JavaScript,label=listing:timejs2]{particles/timejs2.txt}
\lstinputlisting[caption=Time measurement of optimized particle system in C++,label=listing:timecpp2]{particles/timecpp2.txt}

The optimised version shows overall improvement of 85\% for JavaScript and 45\% for C++ making the JavaScript version only 2.2 times slower than the native one. It is clearly visible that JavaScript is more sensitive to unwise memory management.

\lstinputlisting[caption=Profiler output for optimized particles,label=listing:particles1profile]{particles/particles2-profile.txt}

Profiling shows that the step method of the particle system is now always running in optimised mode, and almost no time is spent on other methods. The same is visible on the profiling chart, where the "code kind in execution" stripe shows only the optimised code.

\begin{figure}[h!]
  \caption{Chart of time used in optimised verion of JavaScript}
  \label{img:particles2profile}
  \centering
	\includegraphics[width=16cm]{particles/particles2-profile.png}
\end{figure}

The situation has also improved in the garbage collection log.

\lstinputlisting[caption=Garbage collection in optimised particle system,label=listing:particles2gc]{particles/particles2gc.txt}


\documentclass{article}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{color}
\usepackage{float}
%\include{macros}
%\usepackage{floatflt}
%\usepackage{graphics}
%\usepackage{epsfig}
\newcommand{\reals}{{\mathbb{R}}}
\newcommand{\dom}{{\bf{dom}}}
\newcommand{\symm}{{\bf{S}}}
\newcommand{\Tr}{{\bf{tr}}}
\usepackage{pdfpages}
\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

\theoremstyle{definition}
\newtheorem*{defition}{Definition}
\newtheorem*{example}{Example}

\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{note}{Note}
\newtheorem*{exercise}{Exercise}

\setlength{\oddsidemargin}{-0.25 in}
\setlength{\evensidemargin}{-0.25 in} \setlength{\topmargin}{-0.25
in} \setlength{\textwidth}{7 in} \setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.25 in} \setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

\newcommand{\homework}[4]{
\pagestyle{myheadings} \thispagestyle{plain}
\newpage
\setcounter{page}{1} \setcounter{section}{#4} \noindent
\begin{center}
\framebox{ \vbox{\vspace{2mm} \hbox to 6.28in { {\bf
VE485,~Optimization~in~Machine~Learning (Summer 2020) \hfill Homework: #1} }
\vspace{6mm} \hbox to 6.28in { {\Large \hfill #1 \hfill} }
\vspace{6mm} \hbox to 6.28in { {\it Lecturer: #2 \hfill} }
\vspace{2mm} \hbox to 6.28in { {\it Student: #3 \hfill} }
\vspace{2mm} } }
\end{center}
\markboth{#1}{#1} \vspace*{4mm} }

\begin{document}

\homework{7. Duality}{Xiaolin Huang \hspace{5mm} {\tt
xiaolinhuang@sjtu.edu.cn}}{Chongdan Pan
\hspace{5mm} {\tt panddddda@sjtu.edu.cn } }{9}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Section 2.  Problem
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Problem 1}
Consider the following \emph{non-convex} problem,
\begin{eqnarray*}
\min & & -3x_1^2 + x_2^2 + 2x_3^2 + 2(x_1+x_2+x_3)\\
\mathrm{s.t.} & & x_1^2 + x_2^2 + x_3^2 = 1.
\end{eqnarray*}
Please give the KKT conditions, find all $x$ and $\nu$ that satisfy the KKT conditions, give the optimal solution, and verify the strong duality.

{\bf{Answer.
\\First we can construct a Lagrange function:
$$L(x_1,x_2,x_3,v)=-3x_1^2 + x_2^2 + 2x_3^2 + 2(x_1+x_2+x_3)+v(x_1^2 + x_2^2 + x_3^2-1)$$
Then the KKT condition is:
$$\frac{\partial L}{\partial x_1}=(2v-6)x_1+2=0\rightarrow x_1=-\frac{1}{v-3}$$
$$\frac{\partial L}{\partial x_2}=(2v+2)x_2+2=0\rightarrow x_2=-\frac{1}{v+1}$$
$$\frac{\partial L}{\partial x_3}=(2v+4)x_3+2=0\rightarrow x_3=-\frac{1}{v+2}$$
$$\frac{\partial L}{\partial v}=x_1^2 + x_2^2 + x_3^2-1=0\rightarrow \frac{1}{(v-3)^2}+\frac{1}{(v+1)^2}+\frac{1}{(v+2)^2}=1$$
}}
\\Through mathematica we get four sets of solutions:
$$\left\{\begin{array}{c}
    v=4.035 \\
    x_1=-0.966 \\
    x_2=-0.199 \\
    x_3=-0.166
\end{array}\right.\text{ with }f(x)=-5.367$$
$$\left\{\begin{array}{c}
    v=-3.149 \\
    x_1=0.163 \\
    x_2=0.465 \\
    x_3=0.87
\end{array}\right.\text{ with }f(x)=4.647$$
$$\left\{\begin{array}{c}
    v=1.892 \\
    x_1=0.903 \\
    x_2=-0.346 \\
    x_3=-0.257
\end{array}\right.\text{ with }f(x)=-1.592$$
$$\left\{\begin{array}{c}
    v=0.224 \\
    x_1=0.36 \\
    x_2=-0.450 \\
    x_3=-0.817
\end{array}\right.\text{ with }f(x)=-1.13$$
Hence the optimal solution is achieved through the first solution with value equals to -5.367, which is the optimal solution for $L^*$. If we plug the solution into $f(x_1,x_2,x_3)$ we can get the same value -5.367 as well.
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{p1.png}
    \caption{Solution from Gurobi, which is same to the dual problem}
\end{figure}
We can verify the solution through Gurobi package in python, and it gives the same solution hence it's strong duality.
\section*{Problem 2}
Consider the following problem
\begin{eqnarray*}
\min_{x,z,\xi,\rho} & & \frac{1}{2} x^\top x - \nu \xi + \frac{1}{m} \sum_{i=1}^m\nolimits \rho_i \\
\mathrm{s.t.} & & b_i (x^\top \phi(a_i) + z) \geq \xi - \rho_i, \forall i = 1, 2, \ldots, m\\
& & \xi \geq 0, \rho_i \geq 0, \forall i = 1, 2, \ldots, m,
\end{eqnarray*}
and denote its optimal solution as $x^*, z^*, \xi^*, \rho^*$.

You are asked to prove that $\nu$ is an upper bound on the fraction of margin errors, i.e., the number of samples falling in the margin is less than $\nu m$:
\[
\#\{i: b_i f^*(a_i) < \xi^* \} \leq \nu m,
\]
where $f^*(a) = {x^*}^\top \phi(a) + z^*$

{\bf{Answer.
Aaccording to the process for SVM:
$$L(x,z,\rho,\xi,\lambda,v,u)=\frac{1}{2}x^Tx-\nu\xi+\frac{1}{m}\sum_i^m\rho_i+\sum_i^m\lambda_i(\xi-\rho_i-b_i(x^\top\phi(a_i)+z))-\sum_i^mv_i\rho_i-u\xi$$
Then for the original problem, our object becomes:
$$\min_{x,z,\rho,\xi}\max_{\lambda_i,v_i,u}\frac{1}{2}x^Tx-\nu\xi+\frac{1}{m}\sum_i^m\rho_i+\sum_i^m\lambda_i(\xi-\rho_i-b_i(x^\top\phi(a_i)+z))-\sum_i^mv_i\rho_i-u\xi$$
s.t. $$\lambda_i,v_i,u\geq0,\forall i$$
We can first calculate the minimization problem through gradient:
$$\frac{\partial L}{\partial x}=0\rightarrow x=\sum_i^m\lambda_ib_i\phi(a_i)$$
$$\frac{\partial L}{\partial z}=0\rightarrow \sum_i^m\lambda_ib_i=0$$
$$\frac{\partial L}{\partial \rho}=0\rightarrow v_i=\frac{1}{m}-\lambda_i$$
$$\frac{\partial L}{\partial \xi}=0\rightarrow \sum_i^m\lambda_i=u+\nu$$
Plug it back we get:
$$\max_{\lambda_i}-\frac{1}{2}\sum_j^m\sum_i^m\lambda_ib_i\phi(a_i)\phi(a_j)b_j\lambda_j$$
s.t. $$\frac{1}{m}\geq\lambda_i\geq0,\forall i$$
$$\sum_i^m\lambda_ib_i=0$$
$$\sum_i^m\lambda_i\geq \nu$$
For the KKT condition we have:
$$\left\{\begin{array}{c}
    \lambda_i,v_i,u_i,\rho_i\geq0,\xi\geq0,\forall i\\
    b_i(x^\top\phi(a_i)+z)+\rho_i-\xi\geq0\\
    \lambda_i(\xi-\rho_i-b_i(x^\top\phi(a_i)+z))=0\\
    u\xi=0\\
    \sum_i^mv_i\rho_i=0
\end{array}\right.$$
Assume $n=\#\{i: b_if(a_i)<\rho\},\text{ for them } \xi=\rho-b_if(a_i)>0\rightarrow u=0\rightarrow \nu=\sum_i^m\lambda_i\geq\frac{n}{m}$
\\Hence, $\nu\text{ is the upper bound for }n$, which is the fraction of margin errors.
}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reference
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\section*{Python Code for P1}
\begin{verbatim}
    from gurobipy import *
    WW = Model()
    WW.Params.NonConvex = 2
    s = WW.addVars(3,lb=-GRB.INFINITY, ub=GRB.INFINITY, vtype='C', name="x") # m sets
    WW.setObjective(-3*s[0]*s[0]+s[1]*s[1]+2*s[2]*s[2]+2*(s[0]+s[1]+s[2]), GRB.MINIMIZE)
    WW.addQConstr(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]==1)
    WW.optimize()
    print('s=',WW.getAttr('X',s).values())
\end{verbatim}
\section*{Mathematica Code for P1}
\begin{figure}[H]
    \centering
    \includegraphics[scale=1]{Code.png}
    \caption{Mathematica Code to solve root for $v$ in P1}
\end{figure}
\end{document}


\documentclass[orivec]{llncs}

\usepackage{algorithm, algpseudocode}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{epsfig}
%\usepackage{subfigure}
\usepackage{listings}
\usepackage{verbatim}
\usepackage{stmaryrd}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[hyphens]{url}
\usepackage[caption=false]{subfig}
\usepackage{wrapfig}

\lstset{
numbers=left,
numberstyle=\tiny,
language={Java},
mathescape=true,
flexiblecolumns=true,
morekeywords={call,method,var,assert,share,unshare,acquire,release,fork,join,free,invariant,requires,ensures,acc,rd,old},
basicstyle=\sffamily\scriptsize,
moredelim=[is][\itshape]{@}{@},
stepnumber=1,
numbersep=2pt,
numbers=none}

\urldef{\mailpietro}\path|pietro.ferrara@inf.ethz.ch|
\urldef{\mailgiuseppe}\path|maggiore.g@nhtv.nl|
\urldef{\mailgiuliatino}\path|{costantini, cortesi}@dsi.unive.it|
\newcommand{\keywords}[1]{\par\addvspace\baselineskip
\noindent\keywordname\enspace\ignorespaces#1}

\makeatletter
\newcommand*\sbigtimes{\mathop{\mathpalette\@sbigtimes\relax}\displaylimits}
\newcommand*\@sbigtimes[2]{%
  \vcenter{\hbox{\sffamily\@nameuse{\string#1bt}X}}\vphantom{\prod}}
\@namedef{\string\displaystyle bt}{\huge}
\@namedef{\string\textstyle bt}{\Large}
\@namedef{\string\scriptstyle bt}{\small}
\@namedef{\string\scriptscriptstyle bt}{\footnotesize}
\makeatother

\pagestyle{plain}

\input{pietromacro}

\title{The Domain of Parametric Hypercubes for Static Analysis of Computer Games Software}
%\subtitle{An efficient and disjunctive static analysis of physics simulations}

\author{Giulia Costantini\inst{1} \and Pietro Ferrara\inst{2} \and Giuseppe Maggiore \inst{3} \and Agostino Cortesi\inst{1}}

\institute{University Ca' Foscari of Venice, Italy\\\mailgiuliatino \and ETH Zurich, Switzerland\\\mailpietro \and IGAD, NHTV University of Breda, The Netherlands\\\mailgiuseppe}

\begin{document}

\maketitle

\begin{abstract}
\input{Sections/0_abstract}
\end{abstract}

\section{Introduction}
\label{sec:introduction}
\input{Sections/1_introduction}

\section{Language syntax} \label{sec:syntax}
Let $\mathcal{V}$ be a finite set of variables, and $\mathcal{I}$ the set of all real-valued intervals. Figure \ref{fig:syntax} defines the language.
We focus on programs dealing with mathematical computations over real-valued variables. Therefore, we consider expressions built through the most common mathematical operators (sum, subtraction, multiplication, and division). An arithmetic expression can be a constant value ($c \in \real$), a non-deterministic value in an interval ($I \in \mathcal{I}$), or a variable ($V \in \mathcal{V}$). We also consider boolean conditions built through the comparison of two arithmetic expressions. Boolean conditions can be combined as usual with logical operators (and, or, not). As for statements, we support the assignment of an expression to a variable, \statement{if-then-else}, \statement{while} loops, and concatenation.
Even though this syntax is simple and limited, many physical simulations can be built through it \cite{B12}, since their complexity lies mostly in their logic and not in the used constructs.

\begin{figure}
\vspace{-15pt}
$$V \in \mathcal{V}, I \in \mathcal{I}, c \in \real$$
$$E :=  c | I | V | E\ <aop>\ E \textrm{ where }<aop> \in \{+, -, \times, \div \}$$
$$B := E <bop> E | B\ and\ B | not\ B | B\ or\ B \textrm{ where } <bop> \in \{\geq, >, \leq, <, \neq \}$$
$$P := V = E | \statement{if}(B)\ \statement{then}\ P\ \statement{else}\ P | \statement{while}(B)\ P | P;P $$
\caption{Syntax}
\label{fig:syntax}
\end{figure}
\vspace{-20pt}

\section{The case study of bouncing balls}
\label{sec:case_study}
\input{Sections/2_case_study}

\section{The Parametric Hypercubes domain}
\label{sec:hyper_cubes_domain}
\input{Sections/3a_hypercubes_domain}

\vspace{-10pt}
\section{Abstract semantics}
\vspace{-5pt}
\label{sec:semantics}
\input{Sections/3b_abstract_semantics}

\vspace{-10pt}
\section{Experimental results}
\vspace{-5pt}
\label{sec:experimental}
\input{Sections/5_experimental_results}

\vspace{-10pt}
\section{Related work}
\vspace{-5pt}
\label{sec:related}
\input{Sections/7_related_work}

\vspace{-10pt}
\section{Conclusions and future work}
\vspace{-5pt}
\label{sec:conclusions}
\input{Sections/8_conclusions}

\bibliographystyle{plain}
\bibliography{Sections/10_references}

%\cite{}

\end{document}


\documentclass[a4paper,UKenglish]{article}
\usepackage[margin=1.5cm, includefoot, footskip=30pt]{geometry}
\input{preamble}
\title{Races in Classical Linear Logic}
\author{%
  Wen Kokke\\
  Supervised by Philip Wadler and J.\ Garrett Morris\\
  Graduate student (8450698)}
\affil{%
  LFCS, University of Edinburgh\protect\\
  Informatics Forum, 10 Crichton St, Edinburgh EH8 9AB, UK\protect\\
  \email{wen.kokke@ed.ac.uk}
  }
\date{}
%
\begin{document}
\maketitle

\section*{Problem and motivation}
Consider the following scenario:
\begin{quote}
  John and Mary are working from home one morning when they get a craving for a
  slice of cake. Being denizens of the web, they quickly find the nearest store
  which does home deliveries.
  Unfortunately for them, they both order their cake at the \emph{same} store,
  which has only one slice left. After that, all it can deliver is
  disappointment.
\end{quote}
This is an example of a race condition. We can model the scenario in the
\textpi-calculus, assuming \john, \mary\ and \store\ are three processes
modeling John, Mary and the store, and \sliceofcake\ and \nope\ are two channels
giving access to a slice of cake and disappointment, respectively.
As expected, this process has two possible outcomes: either John gets the cake,
and Mary gets disappointment, or vice versa.
\[
  (\piPar{%
    \piSnd{x}{\sliceofcake}{\piSnd{x}{\nope}{\store}}
  }{%
    \piPar{\piRcv{x}{y}{\john}}{\piRcv{x}{z}{\mary}}
  })
  \quad
  \Longrightarrow
  \quad
  (\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\john}}{\piSub{\nope}{z}{\mary}}})
  \quad
  \text{or}
  \quad
  (\piPar{\store}{\piPar{\piSub{\nope}{y}{\john}}{\piSub{\sliceofcake}{z}{\mary}}})
\]
While John or Mary may not like all of the outcomes, it is the store which is
responsible for implementing the online delivery service, and the store is happy
with either outcome. Thus, the above is program we would like to be able to
write.
\\[1ex]
\noindent
Now consider another scenario, which takes place \emph{after} John has already
bought the cake:
\begin{quote}
  Mary is \emph{really} disappointed when she finds out the cake has sold out.
  John, always looking to make some money, offers to sell the slice to her for a
  profit. Mary agrees to engage in a little bit of back-alley cake resale, but
  sadly there is no trust between the two.
  John demands payment first.
  Mary would rather get her slice of cake before she gives John the money.
\end{quote}
This is an example of a deadlock. We can also model this scenario in the
\textpi-calculus, assuming that \bill\ is a channel giving access to some
adequate amount of money.
\[
  (\piPar{%
    \piRcv{x}{z}{\piSnd{y}{\sliceofcake}{\john}}
  }{%
    \piRcv{y}{w}{\piSnd{x}{\bill}{\mary}}
  })
\]
The above process does not reduce. As both John and Mary would prefer the
exchange to be made, this program is desired by \emph{neither}. Thus, the above
is a program we would \emph{somehow} like to exclude.
\\[1ex]\noindent
Session types can provide a static guarantee that concurrent programs, such as
those above, respect communication protocols.
Session-typed calculi with logical foundations, such as
\pidill~\cite{caires2010} and CP~\cite{wadler2012}, obtain deadlock freedom as a
result of the close correspondence with logic.
The same correspondence, however, also rules out non-determinism and race conditions.

There is some work on reintroducing non-determinism~\cite{caires2014, atkey2016,
  caires2017}.
This work all relies on some variant of non-deterministic local choice, an
operator which joins two processes of the same type and non-deterministically
chooses to run \emph{one} of them:
\begin{center}
  \begin{minipage}{0.5\linewidth}
    \begin{prooftree}
      \AXC{$\seq[ P ]{ \Gamma }$}
      \AXC{$\seq[ Q ]{ \Gamma }$}
      \SYM{$+$}
      \BIC{$\seq[ P + Q ]{ \Gamma }$}
    \end{prooftree}
  \end{minipage}%
  \begin{minipage}{0.5\linewidth}
    \[\!
      \begin{aligned}
        P + Q &\Longrightarrow P\\
        P + Q &\Longrightarrow Q
      \end{aligned}
    \]
  \end{minipage}
\end{center}
While this allows us to describe any non-deterministic program we wish, we have
to do so by enumerating the possible outcomes. For example, we have to write our
first example as the program in which either John or Mary gets the cake:
\[
  (\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\john}}{\piSub{\nope}{z}{\mary}}})
  +
  (\piPar{\store}{\piPar{\piSub{\nope}{y}{\john}}{\piSub{\sliceofcake}{z}{\mary}}})
\]
In general, rewriting processes with races in this style results in an
exponential blowup the size of the program.
In this abstract, we propose a novel method of assigning types to racy processes
with channels shared between more than two processes, based on bounded linear
logic~\cite{girard1992} with exact instead of affine bounds.

\section*{Background and related work}
The \textpi-calculus is a process calculus which models concurrent computation,
which we informally describe below:
\[\!
  \begin{aligned}
    \text{Term} \; P, Q, R
    ::=   &\;\piSnd{x}{y}{P} &&\text{send a value $y$ over $x$, then run $P$}
     &\mid&\;(\piPar{P}{Q})  &&\text{run $P$ and $Q$ in parallel}
    \\\mid&\;\piRcv{x}{y}{P} &&\text{receive a value $y$ over $x$, then run $P$}
     &\mid&\;\piNew{x}{P}    &&\text{create a new channel $x$, then run $P$}
    \\\mid&\;\piEnd          &&\text{halt}
  \end{aligned}
\]
CP~\cite{wadler2012} is a session-typed process calculus which takes the rules
of classical linear logic as prescribing the typing rules of a process
calculus.\footnote{%
  As more readers may be familiar with the \textpi-calculus, we will present CP
  as a type system for \textpi-calculus terms, instead of using the notation
  used by Wadler~\cite{wadler2012}.
}
For instance, the rule for \llTens\ types two parallel, independent processes --
meaning they do not share any communication channels -- and the rule for
\llParr\ types a single process which may communicate with two processes in any
order it pleases:
\begin{center}
  \begin{prooftree*}
    \AXC{$\seq[ P ]{ \Gamma , \tm[y]{A} }$}
    \AXC{$\seq[ Q ]{ \Delta , \tm[x]{B} }$}
    \SYM{\llTens}
    \BIC{$\seq[{
        \piNew{y}{( \piSnd{x}{y}{( \piPar{P}{Q} ) )}}
      }]{ \Gamma , \Delta , \tm[x]{A \llTens B} }$}
  \end{prooftree*}
  \begin{prooftree*}
    \AXC{$\seq[ P ]{ \Gamma , \tm[y]{A} , \tm[x]{B} }$}
    \SYM{\llParr}
    \UIC{$\seq[ \piRcv{x}{y}{P} ]{ \Gamma , \tm[x]{A \llParr B} }$}
  \end{prooftree*}
\end{center}
The rules for \llWith\ and \llPlus\ type a process offering and making a choice,
respectively. The axiom and cut rules can both be eliminated, and doing so
corresponds to reduction in the \textpi-calculus, with the axiom elimination
corresponding to forwarding~\cite{boreale1998,wadler2012} and cut elimination
corresponding to communication~\cite{wadler2012}.

\section*{Approach and uniqueness}
We extend CP with two new types, inspired by bounded linear
logic~\cite{girard1992}, written \llTake[n]{A} and \llGive[n]{A}. The typing
rules for \llTake[n]{A} construct a pool of a known size, filled with parallel,
independent client-like processes. Logically, \llTake[n]{A} is akin to an
$n$-length vector of the form $A \llTens\dots\llTens A$:
\begin{center}
  \begin{prooftree*}
    \AXC{$\seq[{ P }]{ \Gamma , \tm[y]{A} }$}
    \SYM{\llTake[1]{}}
    \UIC{$\seq[{ \piRcv{x}{y}{P} }]{ \Gamma , \tm[x]{\llTake[1]{A}} }$}
  \end{prooftree*}%
  \begin{prooftree*}
    \AXC{$\seq[{ P }]{ \Gamma , \tm[x]{\llTake[m]{A}} }$}
    \AXC{$\seq[{ Q }]{ \Delta , \tm[x]{\llTake[n]{A}} }$}
    \NOM{Pool}
    \BIC{$\seq[{ (\piPar{P}{Q}) }]{ \Gamma , \Delta , \tm[x]{\llTake[m+n]{A}} }$}
  \end{prooftree*}
\end{center}
The typing rules for \llGive[n]{A} construct a single, server-like process,
which communicates with $n$ processes in any order it pleases. Logically,
\llGive[n]{A} is akin to an $n$-length vector of the form $A \llParr\dots\llParr A$:
\begin{center}
  \begin{prooftree*}
    \AXC{$\seq[{P}]{ \Gamma , \tm[y]{A} }$}
    \SYM{\llGive[1]{}}
    \UIC{$\seq[{
        \piNew{x}{( \piSnd{x}{y}{P} )}
      }]{ \Gamma , \tm[x]{\llGive[1]{A}} }$}
  \end{prooftree*}%
  \begin{prooftree*}
    \AXC{$\seq[{ P }]{ \Gamma , \tm[x]{\llGive[m]{A}} , \tm[y]{\llGive[n]{A}} }$}
    \NOM{Cont}
    \UIC{$\seq[{ \piSub{x}{y}{P} }]{ \Gamma , \tm[x]{\llGive[m+n]{A}} }$}
  \end{prooftree*}
\end{center}
The novel insight is that because all elements of these vectors have the same
type, we can let any client communicate with any of the server interactions, and
we can let this choice be made non-deterministically while running the process
-- or, similarly, while eliminating the cuts.
On the term level, this means we can now assign types to some processes in which
channels are used by more than two processes concurrently.

\section*{Results and contributions}
The system \cpnd -- CP extended with \llTake[n]{A} and \llGive[n]{A} -- offers
the same guarantees of deadlock-freedom as CP.
The new system, however, has some limited form of non-determinism.

When compared with CP extended with non-deterministic local choice ($+$), we
find that translations exists in both ways, implying the systems are equally
expressive -- as long as we are allowed to perform whole-program
transformations.
However, as mentioned before, translating from \cpnd\ into CP with `$+$' results
in an exponential blowup in the size of the program.
Furthermore, \cpnd\ allows us to capture our example program with as-is.
This implies that while \cpnd\ and CP with `$+$' are equally expressive in the
strict sense, \cpnd\ is locally more expressive, and thus allows us to capture
programs more naturally and more succinctly.

The type system of \cpnd, together with all the aforementioned properties,
has been mechanized using the proof assistant Agda~\cite{norell2009}.
As a consequence of that, there is a verified interpreter for the language.

\clearpage
\bibliographystyle{plain}
\bibliography{main}
\end{document}
%%% Local Variables:
%%% TeX-master: "main"
%%% fill-column: 80
%%% End:


\section{Background}
\label{sec:background}

\subsection{Big data stream processing and NewSQL databases}

To process continuous streams of big data, we consider the emerging stream processing platforms~\cite{leskovec2014mining}, as depicted in Figure~\ref{fig:newsql_data_stream}. In these platforms, streams of data are processed by two complementary systems: the fast stream processing system and big archival engine. The former manages high-speed data streams to provide real-time analytics and data-driven decisioning, providing services like fraud heuristics, market segmentation, or optimal customer experience; while the latter computes huge volumes of historical data for long-term data analytics, such as scientific results, seasonal predictions, and capacity planning. Big archival engines are built on data warehouse technologies like Hadoop and column-stores. In contrast, fast stream processing technologies are still emerging. Among these technologies are NewSQL databases like VoltDB~\cite{stonebraker2013voltdb} and S-Store~\cite{cetintemel2014s}. To support incremental, stateful ingest of data streams into a scalable system, NewSQL databases provide low-latency via in-memory distributed processing and a strong support for transaction management with ACID guarantees. However, as NewSQL databases are deployed on cloud infrastructures to scale to large clusters, cloud performance anomalies may undermine their capacity of fast stream processing.

\begin{figure}[!h]
  \centering
     \includegraphics[width=.8\textwidth]{inputs/img/simple_newsql_data_stream}
  \caption{The emerging stream processing platforms for big data.}
  \label{fig:newsql_data_stream}
\end{figure}

\subsection{Anomaly detection using statistical learning}
\label{subsec:anomaly}

Statistical learning has been a widely used technique to predict performance anomalies in large-scale distributed systems~\cite{chandola2009anomaly}. It makes prediction by processing feature vector $\inpseq$ with a fixed
  number of dimensions $d$ ($\inpseq \in \inpspace \subset \Re^d$) from the input space $\mathcal{X}$. There are two main methods: \emph{supervised} and \emph{unsupervised learning}.

The \emph{supervised learning method} couples each input with a $\rel$, a label, from the output space  $\mathcal{Y}$. To learn, we have $N$ pairs ($\inpseq,\rel$) drawn \emph{independent and identically distributed} (i.i.d.) from a fixed but unknown joint probability density function $\distspace$. This method searches for a function $\fscore$ : $\mathcal{X} \rightarrow \Re$  in a fixed function class $\fspace$ in the learning dataset. State-of-the-art algorithms, like \emph{random forests}~\cite{breiman2001random}, aim to find $\fscore^\star$ in $\fspace$ with the lowest empirical risk $\fscore^\star \in \argmin_{\fscore \in \fspace} \qm_{emp}(\fscore)$,
where $\qm_{emp}(\fscore) = \frac{1}{N} \sum_{i=1}^N \indic{\fscore(\inpseq) \neq \lab_i}$ is computed over the training set, and $\indic{.}$ is the indicator function which returns $1$ if the predicate $\{.\}$ is true and $0$ otherwise. Similarly, an \emph{unsupervised learning method} relies on $N$ unlabelled samples having probability density function $\distspacex$. Unlike supervised learning, predictions provide insights into how the data is organized or clustered.

Most of the anomaly detection approaches for distributed systems are based on a general-purpose, unsupervised learning method~\cite{gujrati2007meta,lan2010toward,guan2013adaptive}. However, prediction efficiency remains the main drawback of this method~\cite{love2002comparing}. Results in our previous work~\cite{silvestre2014anomaly} confirm that a supervised learning method outperforms an unsupervised one in cloud anomaly detection. In this document, we describe Tejo our anomaly detection framework based on a supervised learning method.