\section{The Mixed Weighted Straight Skeleton}
\label{sec:mwss}

% Do we want to say that the PWSS may not grow (if all theta zero),?

% todo: we had this for pwss, how can we work it in here? We note that in all situations, the region collapsing at any time is locally topologically equivalent to a disc immediately before the event. The disc may be bounded on some sides, and unbounded on others.  When this is the case, the collapsing area is again locally equivalent to the topological disc.

The final variation of the SS we will introduce is the \emph{mixed weighted straight skeleton} (MWSS). This structure allows the angle of the direction planes, $\theta$, to be positive and negative over edges in a single plan. As before we introduce some of the issues surrounding degeneracies, and present a partial algorithm for resolving them.

%: $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$. Inititively this allows the edges of the active plan to move towards the interior or exterior at the same time.
As in the PWSS case, $\theta$ is limited to avoid infinitely fast edges on the active plan, allowing only  $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$. Therefore a $\theta < 0$ implies that an active plan edge is moving away from the interior of the polygon, a $\theta = 0$ implies an edge that does not move, and a $\theta > 0$ implies an edge moving towards to interior of the polygon.
%The angle defines the slope of the face associated with that edge of the input plan. That is, $\theta$ defines the speed of the edge on the active plan as the sweep plan rises.

The MWSS enables more 3D terrains to be defined; The set of skeletons definable are a superset of the SS, PWSS and NWSS schemes. For example the active plan can grow, as well as shrink, or can be a mixture of both. Therefore certain MWSSs may not terminate after the final event, the enclosed area may continue growing indefinitely as the sweep plane rises. It is an open problem to determine if a given MWSS will terminate if it contains any values of $\theta < 0$, without executing the skeleton calculation itself. Fig.~\ref{fig:wss_unbounded} gives an example in which the resolution of a borderline case differentiates between an non-terminating skeleton, and a terminating one.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_unbounded}
  \caption[Unbounded MWSS]{\label{fig:wss_unbounded}MWSS that are bounded (left) and unbounded (right). The red face grows to an infinite area as the sweep plane rises. A small peturbation to the input plans is the only difference between these PWSS, which is sufficient to change the edge emerging from the orange intersection. }
\end{figure}

Given the additional degrees of freedom available in the MWSS we expect that to encounter the degenerate cases observed in the SS and PWSS cases. In addition there are are a new class of \emph{point degeneracies} observable.

\subsection{Point degeneracies}

% this is the +-WSS degeneracy section.
%As shown in Fig.~\ref{fig:Impossible} there are events where common sense does not easily give an solution to.

If all the edges are moving inwards or outwards, as with the PWSS or NWSS, the SS GIE introduced in Sec.~\ref{s:gie} is still suitable. However there is a complex set of degenerate events that may occur with some angles of $\theta > 0$ and some $\theta < 0$. An example is given in Fig.~\ref{fig:wss_strange}.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_strange}
  \caption[Degenerate events in the PWSS and MWSS]{\label{fig:wss_strange}. Left: A complex event in a PWSS, over a plan (green). Right: A MWSS in which four areas merge to become one. Note that the 3D models are the resulting meshes of a skeleton as some MWS Skeletons are difficult to illustrate in 2D. }
\end{figure}

A more complex example of a simple eventFig.~\ref{fig:wss_example_topology}, which shows a possible event with many edges colliding. Here we can see chains of edges representing bounded, as well as unbounded areas, loops, and \emph{enclosed chains} (Fig.~\ref{fig:wss_enclosing_chain}), all colliding at one point. Fig.~\ref{fig:wss_union_vs_gie} gives an example of the GIE failing to process an event. Indeed every edge of an arbitrary polygon may be coerced to collide at any point by altering the per edge values of $\theta$.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_example_topology}
  \caption[A point degeneracy]{\label{fig:wss_example_topology} Left: The active plan just before an event. A complex set of chains collide at a single event (orange). Right: after the intra-chain step and one-chain step of the GIE the topology is simplified. Note that the curved edges marked with an asterisk represent the topology of two colinear straight edges.}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{0.4\columnwidth}
  \includesvg{12-skeleton/images/wss_enclosing_chain}
  \caption[Enclosing chains]{\label{fig:wss_enclosing_chain} We describe the chain \emph{a} as enclosing chain \emph{b}, as $\phi < \pi$. The chains are shown here before a collision at the orange point.}
\end{figure}

We wish to have a consistent solution to these degenerate events, such as those at the bottom of Fig.~\ref{fig:wss_options}. That is, the plan remains well formed after the event.

We have been unable to find a elegant general solution to the problem!

Here we present an engineered solution that is as consistent as possible with the existing definition of the unweighted skeleton. Other characteristics that are desirable in a solution for such events include:
\begin{itemize}
\item{Similarity to the SS.}
\item{Consistency with the SS when all angles are a positive constant.}
\item{Consistency with the PWSS when all angles are positive.}
\item{Invariance to rotation of the plan. As with the the straight skeleton the result of an event should not depend on the orientation of the plan.}
\end{itemize}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_options}
  \caption[Several solutions to the MWSS]{\label{fig:wss_options}Above: Four chains collide at an event (orange point). The desired plan topology after the event is unclear. We must keep the input edges (red) in the same locations to remain consistent with the remainder of the plan. Below: There are many possible options for the topology change at the event. (Note that we show the active plan a time after the event.) Some use existing edges, others create new edges (initially these new edges are zero length, but subsequently grow) during the event.}
\end{figure}

In order to provide a suitable resolution to these events we simplify the edges by first removing zero length edges, and then removing zero area chains.

To simplify the active plan situation we can apply the SS intra chain step and one chain step, Fig.~\ref{fig:wss_example_topology} right, to remove edges that shrink to zero length. The intra chain step also removes loops of edges involved in the event; As they approach an event they shrink to zero length and area, and as such we may remove them from the active plan, and not consider them further in the event handling.

\subsection{Parallel Edges}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/skel_impossible}
  \caption[A MWSS event with four parallel edges]{\label{fig:skel_impossible}.}
\end{figure}

%We now define several features of the MWSS that help us. The major axis, approaching edges and the sector properties.

%The \emph{major axis} defines the direction that all chains of length one take. There may be more than one chain of length one in the MWSS, Fig.~\ref{fig:wss_example_topology}. However it is impossible for these chains to have more than one orientation in a single event as it occurs at a single point.

%\begin{figure}
%  \centering
%  \def\svgwidth{0.5\columnwidth}
%  \includesvg{12-skeleton/images/wss_major_axis}
%  \caption{\label{fig:wss_major_axis}At an event (orange) we may not have more than one orientation of chains of length one. %If this were the case (above), there would be a point (red) which the 1-chains (green and blue) arrived at before the event. There would, therefore, have been another (red) event which combines these edges before they arrive at the first event (orange).}
%\end{figure}

At an event all the edges involved in the collision approach the location at an angle defined by the edge's current orientation. Fig.~\ref{fig:wss_ordered_point}, left, shows the orientation-ordered points for Fig.~\ref{fig:wss_example_topology}. Any edges that do not approach according to their angle must have been removed by an earlier collision, Fig.~\ref{fig:wss_ordered_point}, right. This property is known as the \emph{$\ge$ approaching edges} property. This refers to the fact that the angle between consecutive edges around an intersection is equal to, or greater than, zero.

The situation that complicates further processing is approaching edges with the same angles. That is when two parallel edges, with different directions approach an event from the same side. The area between these edges approaches zero near the event, and should be removed by the loop of two rule. Therefore we remove these adjacent, parallel edges with the same orientation at the event, Fig.~\ref{fig:wss_equal_approach_killer}. After we remove these lines, we can say that the event has the \emph{$>$ approaching edges property} as all the angles between adjacent approaching edges are greater than zero.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_equal_approach_killer}
  \caption[Removing zero area chains]{\label{fig:wss_equal_approach_killer} After the intra-chain step we remove all the zero area chains, leaving the topology shown (top, left). We show the chains just before the event for clarity. The black lines connect (asterisked) edges which would become adjacent and parallel at the event. We convert these pairs of edges into single chains as shown. We either use the interior bias (top right) or exterior bias (bottom left).
%todo, does this work without loop of two?: After the corresponding events at remote sites, we will remove these chains using the loops of two rule (bottom right).
}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_linear_align}
  \caption[Global coordiation of a solution with parallel edges]{\label{fig:wss_linear_align} Given a plan (top left) that leads to a number of events (top middle, red blue and yellow circles) at the same height, which share a single edge (top middle, edge a), there are several possible solutions. We wish to avoid creating parallel, colinear edges that will immediately self-intersect again (top right), that is we must have a globally coordinated solution. Where there are an odd number of parallel edges approaching an intersection from the same direction we introduce two globally consistent options; Interior bias (bottom left) or exterior bias (bottom right).}
\end{figure}

To remove the edges, and keep the global-consistency property defined above, we must make a local choice that is globally consistent, Fig.~\ref{fig:wss_linear_align}. In a similar manner to the SS case, we connect these pairs of adjacent lines. At the other end of these parallel edges, another event at the same height must make consistent choices, such that we never have two coincident, overlapping, edges in the active plan, Fig.~\ref{fig:wss_linear_align} top right.

This situation presents another choice. More than two approaching edges can have the same angle, Fig~\ref{fig:wss_equal_approach_killer}. If there are an even number of such edges at one angle, the adjacent pairs of edges can be connected together. However if there are an odd number of edges, we have to choose which adjacent pairs to merge. Here we present two solutions:
\begin{itemize}
\item{\emph{interior bias:} The pairs of lines surrounding an interior region of the plan form a loop of two.}
\item{\emph{exterior bias:} The pairs of lines surrounding an exterior region of the plan form a loop of two.}
\end{itemize}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_ordered_point}
  \caption[Ordering chains around the event]{\label{fig:wss_ordered_point} As the chains of edges in the MWSS approach the event (orange) they become ordered (left). If this were not the case (right), they would have intersected during an separate earlier event (red).}
\end{figure}

\subsection{Other Observations}

include: multiple possible solutions
5 star constructive failures.

Another interesting fact can be observed by not handling an event, Fig.~\ref{fig:wss_sector}. If we ignore the rest of the plan away from the event, we may see that after the event the chains remain in the same configuration. More specifically the intersections of any edges remain at the same angle relative to the event location, Fig.~\ref{fig:skel_sector_2}, until another event may occur. We can see that this is true by recalling that the edges move in a direction parallel to themselves at a constant angle. They also all pass through the event location at the event at the same time. Therefore any intersections between these lines also move with constant speed directly away from the event location, that is they keep the same angle. We refer to this property as the \emph{sector property}.

The sector property can also be observed before an event, but after any preceding events. We can therefore view it as the trivial statement ``between events, no events occur''.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_sector}
  \caption[An example of the sector property]{\label{fig:wss_sector}The plan (green, blue and yellow areas) undergoes an event (orange). The sector property states that topology of the active plan corners remains unchanged immediately after the event (after 1, through after 2).}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{0.5\columnwidth}
  \includesvg{12-skeleton/images/wss_sector_2}
  \caption[The sector property]{\label{fig:skel_sector_2}After an event (orange), any intersection between two edges, such as a corner, remains at constant angle, $\gamma$, relative to the event location. This gives rise to the sector property.}
\end{figure}

It is unclear how to handle the chains further. In all examples examined, there is always a solution that does not introduce any new (initially 0-length) edges into the active plan during the event, Fig.~\ref{fig:wss_hand_examples}. However it remains an open problem to consistently calculate this solution. While some sort of search technique may give the correct answer, we feel that there is may be a more elegant solution.

\begin{figure}
  \centering %LOST?!
  \includegraphics[width=1.0\columnwidth]{wss_hand_examples.png}
  \caption[Manual examples of good MWSS solutions]{\label{fig:wss_hand_examples} Several example events and solutions that do not require 0-length edges to be introduced into the active plan. The chains (green dashed lines) are shown after the event (orange). Certain good solutions are shown in purple, although there may be more than one solution for each situation.}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{0.5\columnwidth}
  \includesvg{12-skeleton/images/wss_incremental}
  \caption[The sector property]{\label{fig:wss_incremental}FIXME.}
\end{figure}

\subsection{Multiple union approach}

This section presents an algorithm that does introduce zero length edges, the \emph{multiple union} approach. We analyse the topology immediately after an event, and perform area-unions with sets of edges to decide on an edge topology for after the event. Note that by the sector property, this topology of the chains is independent of time after the event. Therefore we define an ordering over the chains so that they can be added or subtracted from the \emph{output topology}. We use 2D Boolean geometry operations to build up this topology.

We start by ordering the chains into enclosed \emph{levels} of chains they contain before the event, Fig.~\ref{fig:wss_numbered_union}. The levels are enumerated from the location of the event, towards the deepest level. If the location (before the event) is inside (respectively outside) the region the output topology is initialised to be an inside (outside) region. Using the chains after the event, we iterate over the level, starting with the lowest-ordered level chains and add or subtract the union of all chains at that level them from the output topology as explained by Fig.~\ref{fig:wss_gie_example}.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_numbered_union}
  \caption[Identify the level of chains]{\label{fig:wss_numbered_union} The levels of two different events. Note how the location of the event changes the definition of the levels. A chain's level is $1$ if it is adjacent to the event, otherwise it is one higher than the enclosing chain.}
\end{figure}

Because the angles between consecutive chains around a point is always greater that zero (by the \emph{$>$ approaching edges} property), we can be sure that the output topology will be compatible with the global active plan.

While this is one solution to this relatively rare problem, there are situations where the result isn't equivalent to the SS, and other quite strange topologies can occur, Fig.~\ref{fig:wss_union_vs_gie}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_union_vs_gie}
  \caption[A comparison of the GIE and multiple union procedure]{\label{fig:wss_union_vs_gie} In the MWSS, the GIE and the multiple union procedure  have different advantages. In the top example, the GIE creates the best output, without 0 length edges, while in the bottom example it creates an undesirable inverted (red) region on the now badly formed active plan. The multiple union procedure adds additional zero length edges in the first example, but always creates valid geometry (top and bottom examples). Compare to ``perfect'' manual results in Fig.~\ref{fig:wss_hand_examples}.}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_gie_example}
  \caption[A multiple union calculation]{\label{fig:wss_gie_example} An example multiple union calculation. Given an input plan (a), several edges (marked with an asterisk) may collide (orange point). The edges involved can be split into levels, just before the event (b). After the event we can view the topology without intersections (d: green chains bound interior regions, white chains bound exterior regions). We can then use an union operation on those chains in the first level (e), before calculating the union of those chains in level 2 (f, yellow). We can then subtract the second level from the first (g). Because of the sector property, this new topology of edges will not intersect immediately after the event. It is also still compatible with the global geometry (h).}
\end{figure}

\FloatBarrier
\section{Summary}

This chapter has introduced four varieties of the straight skeleton - the unweighted straight skeleton, the positively weighted skeleton, the negatively weighted straight skeleton and the mixed weighted straight skeleton. Three of these skeletons form a chain of generalisation as the requirements on the angle of the direction planes are relaxed; SS $\subseteq$ PWSS $\subseteq$ MWSS. Each additional generalisation has brought with it additional degenerate cases that we have presented, and suggested solutions for. We have introduced a new general intersection event that gracefully handles the events encountered by the SS, PWSS and NWSS. Finally we introduced one flawed solution to the events encountered by the MWSS, and introduced an unproved theorem that a perfect solution always exists.


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{slashed}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{float}

\usepackage{subcaption}
\usepackage{cancel}

\hypersetup{
	%	bookmarks=true,         % show bookmarks bar?
	unicode=true,          % non-Latin characters in Acrobat's bookmarks
	pdftoolbar=true,        % show Acrobat's toolbar?
	pdfmenubar=true,        % show Acrobat's menu?
	pdffitwindow=false,     % window fit to page when opened
	pdfstartview={FitH},    % fits the width of the page to the window
	pdftitle={NSCFI},    % title
	pdfauthor={Author},     % author
	pdfsubject={Subject},   % subject of the document
	pdfcreator={},   % creator of the document
	pdfproducer={Producer}, % producer of the document
	pdfkeywords={dark matter} {freeze-in} {non standard cosmology}, % list of keywords
	pdfnewwindow=true,      % links in new PDF window
	colorlinks=true,       % false: boxed links; true: colored links
	linkcolor=blue,          % color of internal links (change box color with linkbordercolor)
	citecolor=red,        % color of links to bibliography
	filecolor=black,      % color of file links
	urlcolor=blue           % color of external links
}

%There are some definitions of macros in "macros.tex". So, import them!
\include{macros}%so I have to make it a tex, and load this it order for it to pickup the commands...
%NOTE: in case you define new macros, put them, and the required packages, in there.

\usepackage{authblk}

\author[ ]{Dimitrios Karamitros}

\affil[ ]{  }
\affil[ ]{\textit{E-mail: }
	\href{mailto:dkaramit@yahoo.com}{\bl{dkaramit@yahoo.com}}
}

\title{The Boltzmann Equation and ambiguous factors}

\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}

%detele this to have section.equation
%\renewcommand{\theequation}{\arabic{equation}}

\begin{document}

\maketitle
\begin{abstract}
We show the correct way to think of and use Boltzmann equations.
\end{abstract}
\flushbottom

\section{Introduction}\label{sec:intro}
\setcounter{equation}{0}
%
In the literature, the Boltzmann equation (BE) is usually presented for specific simple processes such as $1 \leftrightarrow 2$ or  $2 \leftrightarrow 2$, and then assumed that the generalization is obvious. This is not the case at all, and one needs to specify the rules of the game, so that  BEs describing a system  are correctly implemented.

\subsection{What {\em is} a Boltzmann equation}
General form of a BE for the evolution of the phase-space distribution (PSD) of a particle $\phi$ is
%
\begin{equation}
\dfrac{d}{dt} f_{\phi} (\vec{p}) = \sum_{A} \sum_{B} \ I_{A,B}(\vec{p}) \;,
\label{eq:GeneralBE}
\end{equation}
%
with the sums running in {\em all} possible processes that involve $\phi$ with initial states $A$ and final states $B$. The collision integral $I_{A,B}$, basically, is the rate at which $\phi$ states are created and destroyed.

To understand what the BE says, we start with the PSD, which is
%
\begin{equation}
	\dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3} \ f(\vec{p})  \equiv \# \text{particles (or states) inside volume $d^3 \vec{x}$ with momentum $d^3 \vec{p}$} \;.
	\label{eq:PSD_description}
\end{equation}
%
Then we can think of the BE as
%
\begin{align}
	\dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3}	\dfrac{d}{dt}  \ f(\vec{p})  &=
	\text{rate of creation of particles (or states)   inside volume $d^3 \vec{x}$ with momentum $d^3 \vec{p}$} \nonumber \\
	&-\text{rate of destruction of particles (or states)   inside volume $d^3 \vec{x}$ with momentum $d^3 \vec{p}$} \;.
	\label{eq:BE_description}
\end{align}
%
The transition rate per unit volume is
%
$$
\dfrac{d}{dt dV} P(i\to f) \equiv \prod_{i=1}^{n} \dfrac{1}{2E_{i}} \ \prod_{i=1}^{m} \dfrac{d^3\vec{k}_f}{(2\pi)^3 \ 2E_{f}}  w(i\to f)
f_{\rm fin}(t,\vec{k}_f)  \;,
$$
%
with $w(i\to f)$ the transition matrix, and $f_{\rm fin}(t,\vec{k}_f)$ a function that takes into account the occupation number. Before moving to the actual creation and destruction rates, we should first discuss $f_{\rm fin}$. This is different for bosons, fermion, and classical particles. For classical particles $f_{\rm fin} = 1$, since it doesn't matter whether a state is occupied or not. For fermions, we have $f_{\rm fin}(t,\vec{k}_f) =\lrb{1 -  f(t, \vec{k}_f ) }$, while for bosons $f_{\rm fin}(t,\vec{k}_f) = \lrb{1 +  f(t, \vec{k}_f) }$.

\subsubsection*{Bosonic states}
%
For the bosonic case, we show a simple example in order to discover what is called {\em bose enhancement}. Consider a system with two states ($\ket{1,2}$) and $N+1$ particles, and a transition operator
%
$$
\hat H = U \sum_{i=1}^{N+1} \ket{1}_i \bra{2}_i \;.
$$
%
Consider an initial state $\ket{\psi} = \dfrac{1}{\sqrt{N+1}} \lrBiggcb{ \ket{2}_1   \prod_{i=2}^{N+1} \ket{1}_i +
	\ket{2}_2 \ket{1}_1 \prod_{i=3}^{N+1} \ket{1}_i  + \cdots +  \ket{2}_{N+1} \prod_{i=1}^{N} \ket{1}_i } $, \ie a state where
one particle is in $\ket{2}$ and all others in $\ket{1}$.

The probability of one a transition to $\ket{\chi} = \prod_{i=1}^{N+1} \ket{1}_i$ (\ie all states to $\ket{1}$) is
%
\begin{align*}
	|\bra{\chi} \hat{H}  \ket{\psi} |^2 = (N+1) |U|^2 \;.
\end{align*}
%
This means that the probability increases with the number of occupation!

\subsubsection*{Fermionic states}
%
Similarly, assuming two particles in a two-state system with a transition matrix
%
$$
\hat H = U \lrb{ \ket{1}_1 \bra{2}_2 + \ket{2}_1 \bra{1}_2}\;,
$$
%
and an initial state $ \ket{\psi} = \dfrac{1}{\sqrt{2}} \lrb{  \ket{1}_1 \ket{2}_2 - \ket{2}_1 \ket{1}_2  }  $, we find that
the probability to transition to the state $\ket{\chi} = \ket{1}_1\ket{1}_2 $ is
%
\begin{align*}
	|\bra{\chi} \hat{H}  \ket{\psi} |^2 = (1-1) |U^2| = 0\;.
\end{align*}
%
Notice that a better illustration would be to show what happens with $N$-state system of $M \leq N$ particles, but the result would be the same since
each state would have a maximum occupation number of $1$.

\subsection*{Creation and destruction rates}
%
Let's assume we keep track of a specific system inside a phase-space volume element,$d^3 \vec{x} \ d^3 \vec{p}$, in order to find how the occupation
number evolves by interaction with another system.  To do this, we need to average over all states, except the one we are looking for. Meaning that the
creation rate is
%
\begin{align}
	\text{Creation rate of states inside $d^3 \vec{x} \ d^3 \vec{p}$ } =
	 \dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3} \dfrac{1}{2E_p}
	\dint  \prod_{i=1}^{n} \dfrac{d^3 \vec{p}_i}{(2\pi)^3 \ 2E_{i}} \ \prod_{i=1}^{m} \dfrac{d^3\vec{k}_f}{(2\pi)^3 \ 2E_{f}}  w_{\vec{p}}(i\to f)
	\ f(t,\vec{p}, \vec{p}_i , \vec{k}_f)   \; ,
	\label{eq:creation_rate}
\end{align}
%
where we do not integrate over $d^3 \vec{p}$, since we keep track inside this momentum range. This is the reason $w_{\vec{p}}( i\to f)$ depends on $\vec{p}$
explicitly.  Keep in mine that $f(t,\vec{p}, \vec{p}_i , \vec{k}_i)$ is used in order to average the number on transition taking place according to the
occupation number of all states.

In a similar fashion, we find the destruction rate to be the same by changing  $i \leftrightarrow f$, \ie
%
\begin{align}
	\text{Destruction rate of states inside $d^3 \vec{x} \ d^3 \vec{p}$ } =
	\dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3} \dfrac{1}{2E_p}
	\dint  \prod_{i=1}^{n} \dfrac{d^3 \vec{p}_i}{(2\pi)^3 \ 2E_{i}} \ \prod_{i=1}^{m} \dfrac{d^3\vec{k}_f}{(2\pi)^3 \ 2E_{f}}  w_{\vec{p}}(f \to i)
	\ \tilde{f}(t,\vec{p}, \vec{p}_i , \vec{k}_f)   \; ,
	\label{eq:destruction_rate}
\end{align}
%
where we note that in principle $f$ and $\tilde{f}$ can be different.

Both $f$ and $\tilde{f}$ are
%
\begin{align*}
	&f(t,\vec{p}, \vec{p}_i , \vec{k}_f) = f_{\rm ini}(t,\vec{p}, \vec{p}_i) \times f_{\rm fin}(t, \vec{k}_f)  \\
	&\tilde f(t,\vec{p}, \vec{p}_i , \vec{k}_f) = \tilde f_{\rm ini}(t, \vec{k}_f) \times \tilde f_{\rm fin}(t,\vec{p}, \vec{p}_f) \;,
\end{align*}
%
We note that the contribution due to the initial states can be decomposed into the product of the SPDs of the initial states, \ie
%
\begin{align*}
f_{\rm ini}(t, \vec{p},\vec{p}_i) &= f(t, \vec{p}) \times \prod_{i} f(t, \vec{p}_i)  \\
\tilde f_{\rm ini}(t, \vec{k}_f) &= \prod_{f} f(t, \vec{k}_f) \;.
\end{align*}

The final state SPD decomposition is the product of the different contributions depending on whether the statistics of the particles.That is
%
\begin{align*}
	f_{\rm fin}(t, \vec{p},\vec{p}_i) &= \lrb{ 1 +  \epsilon \   f(t, \vec{p}) } \times \prod_{i} \lrb{ 1 +  \epsilon \  f(t, \vec{p}_i) } \\
	\tilde f_{\rm fin}(t, \vec{k}_f) &= \prod_{f} \lrb{ 1 +  \epsilon \ f(t, \vec{k}_f) } \;,
\end{align*}
%
with $\epsilon = +1$ for bosons, $\epsilon = -1$ for fermions, and $\epsilon = 0$ for classical particles.

\subsubsection*{Definitions}

Before moving on, let's define some useful things.  In order to make things easier, we introduce the ``enhanced" matrix element squared for a
process $A \to B$
%
\begin{equation}
	w(A \to B) = |\tilde{ \mathcal{M} }_{A \to B}|^2 = (2\pi)^4 \ \delta^{(4)}\lrb{\sum_A p_A - \sum_B p_B}  \  \sum_{\rm idofs}|\mathcal{M}_{A \to B}|^2 \; ,
	\label{eq:tildeM}
\end{equation}
%
and the initial and final phase space volume element as
%
\begin{eqnarray}
	&d \Pi_i  \equiv \dfrac{d^3 \vec{q}}{ (2 \pi)^3 } \dfrac{1}{2\omega_q} \ f_{i}(\vec{q}) \nonumber \\
	&d \Phi_i  \equiv \dfrac{d^3 \vec{q} }{ (2 \pi)^3 } \dfrac{1}{2\omega_q} \ \lrb{1 \pm f_{i}(\vec{q})}
	\label{eq:PhaseSpaceVolume}
\end{eqnarray}
%

\subsection{The final form}
%
The BE, finally, takes the form
%
\begin{align*}
	\dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3}	\dfrac{d}{dt}  \ f(\vec{p})=&
		\lrb{  1+ \epsilon f(t,\vec{p} )} \dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3} \dfrac{1}{2E_p}
	\dint  \prod_{i=1}^{n} d \Pi_i \ \prod_{i=1}^{m} d \Phi_f
	\ w_{\vec{p}}(i \to f)    \\
	%
	-&f(t,\vec{p} ) \dfrac{d^3 \vec{x} \ d^3 \vec{p}}{(2\pi)^3} \dfrac{1}{2E_p}
	\dint  \prod_{i=1}^{n} d \Phi_i \ \prod_{i=1}^{m} d \Pi_f
	\ w_{\vec{p}}(f \to i)  \; ,
\end{align*}
%
or
%
\begin{align}
	2E_p	\dfrac{d}{dt}  \ f(\vec{p})=&
	\lrb{  1+ \epsilon f(t,\vec{p} )} \ \dint  \prod_{i=1}^{n} d \Pi_i \ \prod_{i=1}^{m} d \Phi_f
	\ w_{\vec{p}}(i \to f)    \nonumber \\
	%
	-&
	f(t,\vec{p} ) \ \dint  \prod_{i=1}^{n} d \Phi_i \ \prod_{i=1}^{m} d \Pi_f
	\ w_{\vec{p}}(f \to i)  \; .
	\label{eq:BE_general}
\end{align}

\section{How to figure out the correct factors}\label{sec:Factors}
\setcounter{equation}{0}
%
In \eqs{eq:BE_general}, we do not mention whether $i$ or $f$ belong to the species of the f we track down. Here, we try to address that.
\subsection*{A simple $2 \to 2$ process}
Suppose that in the system under study there exist only two particles, $\chi$ and $\psi$, with the only interactions being $\chi \psi \leftrightarrow \chi \chi$. The evolution of the phase-space distribution of $\psi$ is given with no ambiguity on what factors we should use, because there is only one $\psi$ created and destroyed in such processes. Labeling the momenta as  $$\chi(q_\chi) \psi(p) \leftrightarrow \chi(q_1)\chi(q_2) \;,$$ the BE becomes
%
\begin{equation}
\dfrac{d}{dt} f_{\psi }(\vec{p}) = \dfrac{1}{2E_p} \lrsb {
\dint  \lrb{\dfrac{1}{2} d\Pi_{1} d\Pi_{2}} d\Phi_{\chi}  \tM{\chi \chi }{\chi \psi} \lrb{1\pm f_{\psi }(\vec{p})}
-\dint d\Pi_{\chi} \lrb{\dfrac{1}{2} d\Phi_{1} d\Phi_{2}}   \tM{\chi \psi}{\chi \chi } f_{\psi }(\vec{p} )
}\;.
\label{eq:BE_22-psi}
\end{equation}
%
Notice that there is a factor of $\dfrac{1}{2}$ since we integrate  over the momenta of two identical particles. This is a simple and quite natural BE, with the only factors being the symmetry factors that should be there.

The problem arises when we try to write down a BE for $f_\chi$. The problem seems to be on the factors should we put. Surely, we don't create one particle but two... or maybe one? How do we count the ``$\chi$ states" we create in each process? A simple solution would be to say that we put the usual symmetry factors, but multiply with the net number of particles created. This can't be true, though. Consider for example a process like $\chi \chi \to \chi \chi$, which re-distributes energy in the system. Are all elastic scattering contributions vanish identically? This would mean that an isolated system of strongly integrating identical particles never reaches thermodynamic equilibrium. I think that Boltzmann would disagree with this.

So we need to think of what the BE says. The BE keeps track of $\chi$ states. Not one particular particle $\chi$, but all of them participating in all possible interactions. But it keeps track of the states created, one at a time. That is, in one process we only see what one $\chi$ that participates in the process does. If the $\chi$ we keep track  is created, then we add a $\chi$ state the system, otherwise we take away one. So, in the system at hand, both $\chi \psi \to \chi \chi $ and $\chi \chi \to \chi \psi $ can create and destroy $\chi$ states. Before writing the BE, we should choose how to label the momenta. We label the momenta according to
%
$$
\underline{\chi}(p) \psi(q_\psi) \leftrightarrow \chi(q_1)\chi(q_2) \; ,
$$
in the process where we keep track of the $\chi$ that appears in the same state as $\psi$, and
%
$$
\chi(q_\chi) \psi(q_\psi) \leftrightarrow \underline{\chi}(p)\chi(q_1) \; ,
$$
%
in the process where keep track of the $\chi$ appearing in the same state as another $\chi$. Notice that the underline indicates the particle at a definite momentum (we integrate over the others). One may think that we double-count the $\chi$ states produced, but we insist that this is not the case. The reason is that there is no clear way to choose which is the one which correctly keeps track of $\chi$.~\footnote{Notice also that we don't distinguish between the $\chi$s, we just distinguish when they appear in the interaction. This is the reason we don't include both   $\underline{\chi} \chi \to \chi \psi$ and $\chi\underline{\chi}  \to \chi \psi$. }  If we only choose the first one, we get a different equation than if we only choose the second. So these two are physically distinguishable, and they both need to be included. The BE for $f_\chi$, then, reads
%
\begin{eqnarray}
\dfrac{d}{dt} f_{\chi }(\vec{p}) &= \dfrac{1}{2E_p} \lrBiggsb{
	-\dint d\Pi_{\psi} \lrb{\dfrac{1}{2} d\Phi_{1} d\Phi_{2}}   \tM{\underline{\chi} \psi}{\chi \chi } f_{\chi }(\vec{p} )
	+ \dint d\Pi_{\chi} d\Pi_{\psi} d\Phi_{1}  \tM{\chi \psi }{\underline{\chi} \chi} \lrb{1\pm f_{\chi }(\vec{p})}
	\nonumber \\
	&- \dint d\Pi_{1} d\Phi_{\chi} d\Phi_{\psi}   \tM{\underline{\chi} \chi}{\chi \psi } f_{\chi }(\vec{p})
	+ \dint \lrb{\dfrac{1}{2} d\Pi_{1} d\Pi_{2}} d\Phi_{\psi}  \tM{\chi \chi }{\underline{\chi} \psi} \lrb{1\pm f_{\chi }(\vec{p})}
} \;,
%
\label{eq:BE_22-chi}
\end{eqnarray}
%
where we have denoted the $\chi$ we keep track in each term by an underscore in the matrix element. It should be clear at this point that all four terms contribute in a different way to $f_\chi$'s evolution, and they should be included. However, it would be very useful if one could actually determine if this is somehow correct, or at the very least not false.
%
To do this, we note that this system is by definition a closed system, and so its energy should be conserved. Furthermore, the energy conservation should not be  an emergent statistical effect, but it should be enforced by the 4-momentum conservation in each process separately. To check that this this is true, we integrate both~\eqs{eq:BE_22-psi,eq:BE_22-chi} over
$\dint \dfrac{d^3 p}{ (2\pi)^3} E_p$, in order to get the evolution of the respective energy densities. Assuming that the system evolves in a constant volume (the non-constant volume would only affect the \rhs of the BE, so this is just a simplification on notation), the above argument takes the form
%
$$
\dfrac{d\rho_\chi}{dt} + \dfrac{d\rho_\psi}{dt} = 0 \;,
$$
%
with
%
\begin{equation}
\dfrac{d\rho_\psi}{dt} =
\dfrac{1}{2} \dint d\Pi_{1}d\Pi_{2} d\Phi_{\chi} d\Phi_{\psi} \tM{\chi\chi}{\chi \psi} \ E_{\psi}
-\dfrac{1}{2} \dint  d\Pi_{\chi} d\Pi_{\psi} d\Phi_{1}d\Phi_{2}\tM{\chi \psi}{\chi\chi} \ E_{\psi}
\label{eq:rho_phi_22}
\end{equation}
%
and
%
\begin{eqnarray}
\dfrac{d\rho_\chi}{dt} &= \dfrac{1}{2} \lrBiggsb{
	-\dint d\Pi_{\psi} d\Pi_{\chi}  d\Phi_{1} d\Phi_{2}   \tM{\underline{\chi} \psi}{\chi \chi } \ E_{\chi}
	+ 2\dint d\Pi_{\chi} d\Pi_{\psi} d\Phi_{1}d\Phi_{2}  \tM{\chi \psi }{\underline{\chi} \chi} \ E_{q_2}
	\nonumber \\
	&- 2\dint d\Pi_{1}d\Pi_{2} d\Phi_{\chi} d\Phi_{\psi}   \tM{\underline{\chi} \chi}{\chi \psi } \ E_{q_2}
	+ \dint  d\Pi_{1} d\Pi_{2} d\Phi_{\psi} d\Phi_{\chi}  \tM{\chi \chi }{\underline{\chi} \psi} \ E_{\chi}
} \;.
\label{eq:rho_chi_22}
\end{eqnarray}
%
The above equation, then give us
%
\begin{eqnarray}
\dfrac{d\rho_\chi}{dt} + \dfrac{d\rho_\psi}{dt} &=   \dfrac{1}{2} \lrBiggsb{
\dint d\Pi_{1}d\Pi_{2} d\Phi_{\chi} d\Phi_{\psi} \tM{\chi\chi}{\chi \psi} \lrb{ -2 E_{q_2} + E_\chi + E_\psi } \\
&+
\dint d\Pi_{\chi} d\Pi_{\psi} d\Phi_{1}d\Phi_{2} \tM{\chi \psi }{\chi \chi} \lrb{2 E_{q_2} -E_\chi -E_\psi  }
} = 0 \;,
\end{eqnarray}
%
where we note that each process vanishes due to the conservation of 4-momentum. Also notice, that if we didn't include all four terms in~\eqs{eq:BE_22-psi}, this cancellation would be impossible unless someone put some extra factors by hand after integrating the original BE.

\subsection*{Working with more complicated processes}
%
Although, at this point, it should be clear what is the correct way to treat a more general BE, it would be helpful to see how this is done. To do this, consider the same system as before, but with the only allowed processes $\chi \psi \leftrightarrow \chi \chi \chi$. Following the same reasoning as before, the BE for $f_\psi$ is
%
\begin{eqnarray}
\dfrac{d}{dt} f_{\psi }(\vec{p}) = \dfrac{1}{2E_p} \lrBiggb {&
	\dint  \lrb{\dfrac{1}{3!}
		d\Pi_{1} d\Pi_{2}d\Pi_{3} } d\Phi_{\chi}  \tM{\chi \chi\chi }{\chi \psi} \lrb{1\pm f_{\psi }(\vec{p})} \nonumber \\
	-&\dint d\Pi_{\chi} \lrb{\dfrac{1}{3!} d\Phi_{1} d\Phi_{2}d\Phi_{3}}   \tM{\chi \psi}{\chi \chi\chi } f_{\psi }(\vec{p} )
}\;.
\label{eq:BE_23-psi}
\end{eqnarray}
%
This is not surprising, as the only thing that changes is that more $\chi$s appear. This results to an extra phase-space volume element and a different symmetry factor to take this element into account.

The situation is similar  also for the BE for $f_\chi$, which reads
%
\begin{eqnarray}\hspace{-0.95cm}
\dfrac{d}{dt} f_{\chi }(\vec{p}) &= \dfrac{1}{2E_p} \lrBiggsb{
	-\dint d\Pi_{\psi} \lrb{\dfrac{1}{3!} d\Phi_{1} d\Phi_{2}d\Phi_{3}}   \tM{\underline{\chi} \psi}{\chi\chi \chi } f_{\chi }(\vec{p} )
	+ \dint d\Pi_{\chi} d\Pi_{\psi} \lrb{\dfrac{1}{2}d\Phi_{1}d\Phi_{2}}  \tM{\chi \psi }{\underline{\chi} \chi\chi} \lrb{1\pm f_{\chi }(\vec{p})}
	\nonumber \\
	&- \dint \lrb{\dfrac{1}{2}d\Pi_{1}d\Pi_{2}}  d\Phi_{\chi} d\Phi_{\psi}   \tM{\underline{\chi} \chi\chi}{\chi \psi } f_{\chi }(\vec{p})
	+ \dint \lrb{\dfrac{1}{3!} d\Pi_{1} d\Pi_{2}d\Pi_{3}}  d\Phi_{\psi}  \tM{\chi\chi \chi }{\underline{\chi} \psi} \lrb{1\pm f_{\chi }(\vec{p})}
} \;,
%
\label{eq:BE_23-chi}
\end{eqnarray}
%
where we see again that we only need to include one additional phase-space element. it should be also be obvious that the energy is conserved exactly in the same way as in the previous example. Although this may be a trivial observation, we note that since the energy has to be conserved at each process separately, we should be able to determine if this is true without integrating.
%
That is, for the process $\chi \chi \chi \to \chi \psi$, the energy change in $\psi$ is $E_{\psi}$, and this term comes with a symmetry factor of $\dfrac{1}{3!}$. The energy change in $\chi$ from such processes is given by third and forth terms in~\eqs{eq:BE_23-chi}. The energy change coming from the third term is $-E_{3}$ with a symmetry factor $\dfrac{1}{2}$, while the forth term gives $E_{\chi}$ with a symmetry factor $\dfrac{1}{3!}$. Overall, the net energy change in the entire system by this process is
$$
\dfrac{1}{3!} E_\psi + \dfrac{1}{3!} E_\chi - \dfrac{1}{2} E_3 =  \dfrac{1}{3!} \lrb{E_\psi+E_\chi  - 3 E_3 } = 0 \;.
$$
%
Similarly, the net energy change for $\chi \psi \to \chi \chi \chi$  is
$$
-\dfrac{1}{3!} E_\psi -\dfrac{1}{3!} E_\chi + \dfrac{1}{2} E_3 = \dfrac{1}{3!} \lrb{3 E_3 - E_\psi - E_\chi  } = 0 \;.
$$

As a closing remark, we note that this procedure should hold for more complected processes and in complete models. For example, consider a case where the interaction allowed is $ \psi \chi \leftrightarrow \psi  \chi \chi \chi$. In this case, both the BE for $f_\psi$ and the BE for $f_\chi$ should have four terms each one tracking a   particle that is either created or destroyed. Schematically the BE for $f_\psi$ should look-like
%
$$\hspace{-0.9cm}
2E_p \ \dfrac{d}{dt} f_{\psi }(\vec{p}) =
\lrBiggcb{\psi \chi \to \underline{\psi}  \lrb{\dfrac{1}{3!}\chi \chi \chi}}
-\lrBiggcb{\underline{\psi} \chi \to \psi  \lrb{\dfrac{1}{3!}\chi \chi \chi}}
+\lrBiggcb{ \psi \lrb{\dfrac{1}{3!}\chi \chi \chi} \to \underline{\psi}  \chi}
-\lrBiggcb{ \underline{\psi}  \lrb{\dfrac{1}{3!}\chi \chi \chi} \to \psi \chi} \;,
$$
%
where we include the relevant symmetry factors that we need to include in the collision integral.
Similarly, the BE for $f_\chi$ of the form
%
$$\hspace{-0.9cm}
2E_p \ \dfrac{d}{dt} f_{\chi }(\vec{p}) =
\lrBiggcb{\psi \chi \to \psi  \lrb{\dfrac{1}{2} \chi \chi} \underline{\chi} }
-\lrBiggcb{\psi \underline{\chi}  \to \psi  \lrb{\dfrac{1}{3!}\chi \chi \chi}}
+\lrBiggcb{ \psi  \lrb{\dfrac{1}{3!}\chi \chi \chi}  \to \psi \underline{\chi}}
-\lrBiggcb{ \psi \lrb{\dfrac{1}{2}\chi \chi}\underline{\chi} \to \psi  \chi}
 \;,
$$
%

Observing that the first two terms in both BEs correspond to the process $\psi \chi \to \psi \chi \chi \chi $, we can determine the net energy change (including the symmetry factors) in the system (we label $E_{\psi_{1,2}}$ the energies for the  $\underline{\psi}$ that appear in initial and final states respectively) as
%
$$
\dfrac{1}{3!} E_{\psi_2} -  \dfrac{1}{3!} E_{\psi_1} + \dfrac{1}{2} E_3 - \dfrac{1}{3!} E_{\chi} =
\dfrac{1}{3!} \lrb{ E_{\psi_2} + 3 E_3 -  E_{\psi_1} -  E_{\chi}} =0 \;,
$$
%
while it is trivial to show that the energy is conserved also in the other process.

%\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\bibliography{refs}{}
%\bibliographystyle{JHEP}

\end{document}


\subsection{Pattern Prediction over Event Streams}

\par Several approaches have been proposed to formalize the task of event patterns (complex events) prediction over time-evolving data streams.  One common way to formalize this task is to assume that the stream is a time-series of numerical values, and the goal is to predict at each time point $t$ the next observations at some future points $t+1$, $t+2$, etc., (or even the output of some function of future values)~\cite{montgomery_introduction_2015}.

%The task of forecasting over time-evolving streams of data can be formulated in various ways and with varying assumptions.
%One common way to formalize this task is to assume that the stream is a time-series of numerical values, and the goal is to forecast at each time point $n$ the values at some future points $n+1$, $n+2$, etc., (or even the output of some function of future values).
% This is the task of time-series forecasting ~\citet{montgomery_introduction_2015}.

\par Another way to formalize the prediction task is to view streams as sequences of events,
i.e., tuples of multiple attributes, such as \textit{id}, \textit{event type}, \textit{timestamp}, etc., and the goal is to predict future events or patterns of events. In this work, we focus on the latter definition of forecasting (prediction of complex event patterns).

\par A relevant work of the detection of event patterns task has been established in the field of temporal pattern mining. The events are defined as 2-tuples of the form \((\mathit{EventType}, \mathit{Timestamp})\). The goal is to extract patterns of events in the form of association rules \cite{agrawal_mining_1993} or frequent episode rules \cite{mannila_discovery_1997}.

\par These rule-based methods have been extended in order to be able to learn rules for predicting event patterns. For instance, in \cite{vilalta_predicting_2002}, an association rule mining technique is introduced. This technique works as following. Firstly, it extracts sets of event types that frequently lead to a target event (i.e., a rare event) within a time window of a fixed size. Then, it uses them to build a rule-based prediction model. Also,  ~\citet{weiss1998learning} proposed another rule-based method to predict rare events in a stream, using a genetic algorithm to find all predictive patterns to form prediction rules.

\par On the other hand, ~\citet{laxman_stream_2008} have proposed a probabilistic model for calculating the probability of the immediately next event in the stream, which is achieved by combining each frequent episode \cite{mannila1997discovery} that presents a partially-ordered set of event types with a Hidden Markov Model (HMM). In addition, ~\citet{fahed_efficient_2014} have proposed episode rules mining algorithm which predicts distant events by generating a set of episode rules in the form \(P \rightarrow Q \) where $P$ and $Q$ are two episodes. These rules have a minimal antecedent (in number of events) and temporally distant consequent.

\par In \cite{zhou_pattern_2015}, a mining method is presented that finds the frequent sequential patterns in a stream of events, which are then used to generate prediction rules. The event stream is processed into batches, in each batch the events are consumed to find the prefix matches from the discovered frequent patterns, to predict future events using different strategies of prediction scoring.

% add more details about the cep
\par Event pattern prediction has also attracted some attention from the field of complex event processing (\ac{cep}), where the CEP system consumes a stream of low-level events to detect patterns of events (composite events) that are defined using pattern-based languages, these languages provide logic, sequence, and iteration operators such as SQL-like languages \cite{Cugola:2012:PFI:2187671.2187677}.

\par One such early approach is presented in \cite{muthusamy_predictive_2010}, which is based on converting the complex event patterns to automata, and subsequently, Markov chains are used in order to estimate when a pattern is expected to be fully matched.
\par Moreover, ~\citet{alevizos2017event} have recently presented a similar approach that uses the pattern Markov chain (\ac{pmc}) framework \cite{nuel_pattern_2008}, which is based on converting the pattern to \ac{dfa} and then to an associated Markov chain model. The constructed PMC model is employed to build a prediction model that provides future time intervals during which a full match of the pattern is expected with a probability above a confidence threshold.
\par  In this thesis, we leverage this method as the base prediction model for each input event stream (see Section ~\ref{sec:Event-Forecasting-PMC}).


\par
\chapter{{\tt Graph}: A Graph object}
\label{chapter:Graph}
\par
The {\tt Graph} object is used to represent the graph of a matrix.
The representation uses a set of adjacency lists, one edge list for
each vertex in the graph, and is implemented using an {\tt IVL}
object.\footnote{
The {\tt EGraph} object represents a graph of the matrix,
but stores a list of covering cliques in an {\tt IVL} object.
}
For the {\tt Graph} object,
the vertices and the edges can be either unit weight or non-unit
weight independently.
None of the algorithms in the package {\it at present} use weighted
edges, though most use weighted vertices.
The weighted edges capability is there, and the weighted edges are
also stored using an {\tt IVL} object.
\par
The {\tt Graph} object is not too sophisticated, i.e., we chose
{\bf not} to implement a method to find a separator of a graph
inside this object.
Such complex functionality is best left to higher level objects,
and our method based on domain decomposition \cite{ash97-DDSEP}
is found in the {\tt GPart} object.
\par
A graph can also be a subgraph of another graph --- nested dissection
is the natural recursive partition of a graph --- and it pays to
use the knowledge of the boundary of a subgraph.
We chose not to implement a ``sub''-graph object separately from a
graph object, thus our {\tt Graph} object can have a boundary.
One specifies {\tt nvtx}, the number of internal vertices,
and {\tt nvbnd}, the number of external or boundary vertices.
The labels for internal vertices are found in {\tt [0, nvtx)}
and those for boundary vertices are found in {\tt [nvtx, nvtx+nvbnd)}.
\par
It is easy to create a {\tt Graph} object: one specifies the number
of internal and boundary vertices, the type of graph (weighted or
unit weight vertices and edges), and then uses the methods for the
{\tt IVL} object to add adjacency lists and (possibly) lists of edge
weights.
The {\tt Graph} object relies strongly on the {\tt IVL} object.
\par
Weighted graphs are commonly used in partitioning and ordering
algorithm, and they normally arise from {\it compressing} the graph
in some manner.
Let us write the unit weight graph as $G(V,E)$ and the weighted
graph as ${\bf G}({\bf V}, {\bf E})$, and let $\phi : V \mapsto {\bf V}$
be the map from unit weight vertices to weighted vertices.
Let $u$ and $v$ be vertices and $(u,v)$ be an edge in $G(V,E)$,
and let ${\bf u}$ and ${\bf v}$ be vertices
and $({\bf u},{\bf v})$ be an edge in ${\bf G}({\bf V}, {\bf E})$.
The weight of a vertex is $w({\bf u})$, the number of unit weight
vertices in the weighted vertex.
The weight of an edge is
$w({\bf u},{\bf v})$, the number of $(u,v)$ edges in the
unit weight graph where $u \in {\bf u}$ and $v \in {\bf v}$.
\par
The natural compressed graph \cite{ash95-compressed-graphs},
\cite{dam92-compressed}
is very important for many matrices from structral
analysis and computational fluid mechanics.
This type of graph has one special property:
$$
w({\bf u}, {\bf v}) = w({\bf u}) \cdot w({\bf v})
$$
and it is the smallest graph with this property.
The compression is {\it loss-less},
for given ${\bf G}({\bf V},{\bf E})$ and $\phi$,
we can reconstruct the unit weight graph $G(V,E)$.
In effect, we can work with the natural compressed graph to find
separators and orderings and map back to the unit weight graph.
The savings in time and space can be considerable.
\par
The {\tt Graph} object has a method to find the $\phi$ map for the
natural compressed graph; it requires $O(|V|)$ space and $O(|E|)$
time.
There is a method to compress a graph
(i.e., given $G(V,E)$ and an arbitrary $\phi$,
construct ${\bf G}({\bf V}, {\bf E})$)
and a method to expand a graph
(i.e., given ${\bf G}({\bf V},{\bf E})$ and an arbitrary $\phi$,
construct $G(V, E)$).
\par
There are several utility methods to return information about the
memory in use by the {\tt Graph object}, to access adjacency lists
and edge weight lists, and to provide information about the
connected components of a graph.


% ----------------------------------------------------------------------
\lecture{Theory solving}{tsolving}
% ----------------------------------------------------------------------
\part{Theory solving}
% ----------------------------------------------------------------------
\input{theory-solving/motivation}
\input{theory-solving/tsolving-process}
% ----------------------------------------------------------------------
\section{Theory language}
% ----------------------------------------------------------------------
\input{theory-solving/tsolving-process-grounding}
\input{theory-solving/grammar-linear-constraints}
\input{theory-solving/send-more-money}
% ----------------------------------------------------------------------
\section{Intermediate format}
% ------------------------------
\input{theory-solving/aspif}
% ----------------------------------------------------------------------
\section{Theory propagation}
% ----------------------------------------------------------------------
\input{theory-solving/tsolving-process-solving}
\input{systems/architecture-one}
\input{theory-solving/tpropagation}
% ----------------------------------------------------------------------
\section{Exemplars}
% ----------------------------------------------------------------------
\subsection{Acyclicity checking}
% ------------------------------
\input{acyclicity}
% ----------------------------------------------------------------------
\subsection{Constraint answer set programming}
% ------------------------------
\input{casp}
% ----------------------------------------------------------------------
\section{Summary}
% ------------------------------
\input{theory-solving/summary}
% ----------------------------------------------------------------------
%
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\documentclass[11pt]{article}

\usepackage[
top    = 2.50cm,% presumably you don't want it to be 0pt as well?
bottom = 2.50cm,
left   = 2cm,
right  = 2cm,
marginparsep = 0pt,
marginparwidth=0pt,
]{geometry}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage[most]{tcolorbox}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{decorations.markings}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{multicol}
\pagestyle{fancy}
\fancyhead[l]{Electromagnetism - Abridged edition}
\fancyhead[r]{Giorgio Grigolo {\textcopyright}}
\tikzset{
	mypath/.style={
		postaction=decorate,
		decoration={markings,
			mark=at position #1 with {\coordinate (x);\arrow{>}}},
		thick},
	>=stealth
}
\begin{document}
\section{Magnetic fields: }
\subsection{Total flux equation: }
\begin{equation}
	\phi = \mathrm{B}A\tag{\si\weber}
\end{equation}

  \section{Tesla}
  \begin{center}
  	\textit{The flux density of the field that exerts a force of 1\si{\newton} on a 1\si{\meter} long wire, placed at right angles to the field and carrying a current of 1\si{\ampere}.}
  \end{center}
\begin{equation}
	F=BIl\tag{\si{\tesla}}
\end{equation}
\begin{center}
	Where $B$ is the component of the field that is \textbf{perpendicular} to the current, $I$ the \textbf{current} (\si\ampere) in the system and $l$ the \textbf{length} (\si\meter).
\end{center}
\section{Lorentz Force: }
\begin{equation}
	F=Bqv\tag{\si{\newton}}
\end{equation}
Where $F$ is the force on a moving charge in a magnetic field, $B$ is the \textbf{total flux} (\si\weber) in the magnetic field, $q$ is the \textbf{charge} (\si{\coulomb}) of the moving particle and $v$ its \textbf{velocity} (\si{\meter\per\second}).

\section{The Laws of Electromagnetic Induction: }

\subsection{Faraday's Law}

\begin{center}
	\textit{An e.m.f. is induced in a conductor whenever the magnetic flux taht links with that conductor changes. The size of the e.m.f. is equal to the rate of change of the flux linkage.}
\end{center}

\subsection{Lenz's Law}

\begin{center}
	\textit{The direction of the induced e.m.f./current is always such as to oppose the change causing it.}
\end{center}

\subsection{Equation: }

\begin{equation}
	E = \frac{\Delta N \phi}{\Delta t}\tag{\si\volt}
\end{equation}
\begin{center}
	Where $E$ is the \textbf{induced e.m.f.} (\si{\volt}), the product $N\phi$ is the \textbf{flux linkage} (\si\weber), $N$ is the number of turns of the coil and  $\phi$ is the \textbf{magnetic flux} (\si{\weber}).
\end{center}
\subsection{Conductor Cutting Lines of Flux: }
\begin{equation}
	E=Blv\tag{\si\volt}
\end{equation}
\begin{center}
	Where $E$ is the induced e.m.f. $l$ is the length of the conductor cutting the field and $v$ is the speed at which the conductor cuts the field.
\end{center}

\section{A.C. Generation: }
\subsection{Rotating rectangular coil: }
\subsubsection{Diagram : }

\begin{center}
	\includegraphics[width=0.5\linewidth]{"pictures/coi"}
\end{center}

\begin{multicols}{2}
	\begin{center}
		perpendicular $\implies$ peak e.m.f.
	\end{center}
	\begin{center}
		parallel $\implies$ no e.m.f.
	\end{center}
\end{multicols}

\subsubsection{Induced e.m.f. formula: }
\begin{equation}
	E=2\pi f\cdot BAN \cdot\sin(2\pi f t)\tag{\si{\volt}}
\end{equation}

\subsubsection{Peak induced e.m.f formula: }
\begin{equation}
	E_0 = 2\pi fBAN\tag{\si\volt}
\end{equation}
\section{R.M.S. value of an A.C. current: }
\begin{equation}
	I_{RMS} = \frac{I_0}{\sqrt2}
\end{equation}
\end{document}
\begin{center}
	\includegraphics[width=0.5\linewidth]{pictures/solenoid}
\end{center}

Physics/11. Electromagnetism and A.C/electromagnetism.tex


\documentclass[journal,hidelinks]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[
  pdftitle={Assignment \#2},
  pdfauthor={Andrei Purcarus},
  pdfsubject={ECSE-526 -- Artificial Intelligence}
]{hyperref}
\usepackage{graphicx}
\usepackage[all]{hypcap}
\usepackage{cleveref}
\usepackage{indentfirst}
\usepackage[per-mode=symbol]{siunitx}

\title{ECSE-526 \\ Artificial Intelligence \\ Assignment \#2}
\author{Andrei~Purcarus,~260631911,~\IEEEmembership{McGill~University}}

\begin{document}
\sloppy

\maketitle

\begin{abstract}

An agent capable of classifying songs into 10 genres (classical, country, edm dance, jazz, kids, latin, metal, pop, rnb, and rock) was created and tested using cross-validation. Several methods of classification were tried, such as a Gaussian classifier, a k-nearest neighbours (kNN) classifier, and a random decision forest classifier. Cross-validation showed that the kNN classifier with $k = 1$ was the best classifier for the given task of music classification.

\end{abstract}

\section{Introduction}

\IEEEPARstart{T}{his} report describes the creation of an agent capable of classifying songs into one of 10 genres (classical, country, edm dance, jazz, kids, latin, metal, pop, rnb, and rock).
To achieve this goal, we were provided with data in the form of a set of 12-dimensional floating point feature vectors for each song. In addition, we were provided with labels classifying each song with the correct genre.
The goal was therefore to use this data to train an agent that can classify the songs in a test set as accurately as possible.
We first describe the creation of a Gaussian classifier and present an analysis of its expected performance. We also look at the underlying assumptions we make when we model the data using a Gaussian normal distribution.
Then, we describe a k-nearest neighbours (kNN) classifier and look at the values of k for which this classifier works best.
Next, we describe the other types of classifiers that we implemented.
Finally, we compare the performance of each classifier using cross-validation to find the one best suited to the task of music classification.

\section{Gaussian Classifier}
\label{sec:gauss}

First, we implemented a Gaussian classifier. In this classifier, training consists of grouping all the training data by genre and computing the average vector and covariance matrix for each set. Then, to classify new feature vectors, we use the unnormalized log likelihood to compute a measure of how closely the feature vector fits into each genre's normal distribution. Given an average vector $\mu$ and a covariance matrix $\Sigma$, we thus find the genre $i$ with the minimum value of
\[ UNLL_{i} = (x - \mu_{i})^T \Sigma_{i}^{-1} (x - \mu_{i}) \]

We implemented two versions of this model. The first one, which we call the Gaussian classifier, takes the set of averages of each song's features as the training set. When it has to classify a new song, it computes the average feature vector for said song and compares it to the normal distributions of the averages of other songs. The second model, which we call the Total Gaussian classifier, uses the raw feature vectors to compute the normal distribution for each genre and then classifies new songs by first classifying all their feature vectors and then taking the plurality vote among the results.

In using this model, we make several assumptions about the data. We assume that the feature vectors for each genre are produced by a single statistical model. In addition, we assume that this model is one in which features are normally distributed around a mean value. Essentially, this means that we assume each genre has a "true" value, with Gaussian noise spreading the data around that point. In addition, we assume that the data points are independent. This last assumption, combined with the fact that feature vectors within a song might be correlated, helps explain why the Gaussian classifier performs so much better than the Total Gaussian classifier during cross-validation (\Cref{tab:results}): By taking the average feature vector for each song, it better satisfies the third assumption of independence.

With these three assumptions in mind, we can see where we might expect the Gaussian classifier to perform well and where it might fall short. In situations such as classifying factory parts into different types, where the parts can be modeled as ideal parts with manufacturing error that is normally distributed, a Gaussian classifier can be expected to perform very well. However, there are many situations where the model can perform poorly. One such situation is where the data for a class actually consists of many local clusters of data points at different locations. Then, the average will have nothing to do with the actual distribution of the data, and a nearest neighbour approach will likely outperform it since it uses a more local classification method. Another example where the Gaussian fails is when two classes have the same averages. Then, the UNLL will depend only on the covariance matrix. Thus, a class with a strictly greater covariance matrix will always be chosen over one with a smaller one.

\section{K-Nearest Neighbours Classifier}
\label{sec:knn}

Next, we implemented two types of kNN classifiers. One is the standard kNN classifier that selects the prediction based on a plurality vote of the k nearest neighbours. The other is a weighed kNN classifier that assigns to each nearest neighbour a weight $w = 1 / d^2$, where $d$ is the distance between the feature vector to be classified and the neighbour. It then normalizes these weights for each feature vector and averages them over all feature vectors in a song to make a prediction.

In order to speed up predictions, we used two different implementations of a KD tree. One is a standard KD tree that splits the data into two equal sets at each node such that one set has lower values than a threshold for a given feature and the other has higher values. Search can then be sped up by eliminating subtrees that cannot contain nearest neighbours. The other is an implementation of a best bin first KD tree that uses a priority queue to keep track of which nodes to visit next. This approach visits closer nodes sooner, and thus it lends itself to early cutoff with much better results \cite{beis_shape_1997}.

As shown in \Cref{tab:results}, the best value of $k$ found during experimentation was $k = 1$ for both the standard and weighed implementations. For standard kNN, the performance experiences a peak at $k = 1$, then drops drastically and starts climbing back up slowly as $k$ increases. A possible explanation of this phenomenon is that the nearest neighbours are evenly distributed among genres. When a single neighbour is used, it will always be the nearest one that classifies a feature vector. With $k = 3$, if the three neighbours disagree the prediction will choose a random classification among the three. As $k$ increases, the presence of more neighbours allows the predictions to reach an actual plurality and improves the accuracy. With weighted selection, we can see that the results are more normalized since more distant neighbours contribute less to the prediction.

\section{Other Classifiers}

We also implemented a classifier called the random decision forest classifier. In this type of classifier, $N$ decision trees are each trained on a subset of the data and a subset of the features. These subsets are randomly chosen with replacement. In our implementation, we used sizes of $2 * D / 3$ and $2 \sqrt{F}$, respectively, where $D$ is the total number of training examples and $F$ is the total number of features. The forest then selects the best prediction based on a plurality vote of the trees. The trees themselves were built by splitting the data at each node into two subsets based on whether they lie above or below a threshold value for a given feature. All such splits are tried for each randomly selected feature and the one that minimizes entropy is selected.

\section{Results}

To evaluate the different classifiers, we used a cross-validation method where the training data was randomly split into 10 subsets of equal size. Then, the classifiers were allowed to train on 9 of these subsets and tested against the 10th. This process was repeated for each possible 9-1 split and the results were averaged to give a final performance metric. The results are plotted in \Cref{fig:results}, with the corresponding data shown in \Cref{tab:results}. Note that to speed up the search, a best bin first KD tree was used for both kNN and weighed kNN with a cutoff set at $400 * k$ leaf nodes.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=\columnwidth]{cross_validation.eps}
  \caption{Cross-validation results for the implemented music classifiers.}
  \label{fig:results}
\end{figure}

\begin{table}[!htb]
	\centering
	\caption{Cross-validation results for the implemented music classifiers.}
	\label{tab:results}
	\resizebox{0.8\columnwidth}{!}{\begin{tabular}{l|l}
		\textbf{Classifier} & \textbf{Performance (\%)} \\ \hline
		Gaussian & 50.8 \\
		Total Gaussian & 27.8 \\
		1NN & 59.6 \\
		3NN & 46.4 \\
		5NN & 51.2 \\
		7NN & 51.2 \\
		Weighed 1NN & 60.2 \\
		Weighed 3NN & 60.0 \\
		Weighed 5NN & 59.3 \\
		Weighed 7NN & 59.5 \\
		Decision Forest (3) & 53.9 \\
		Decision Forest (5) & 55.8 \\
		Decision Forest (10) & 57.2 \\
	\end{tabular}}
\end{table}

From these figures, it is clear that the kNN and weighed kNN classifiers are the best at classifying music genres, followed closely by the random decision forest, then the Gaussian, and finally the Total Gaussian.

The fact that the nearest neighbour approach is the best classifier for this data set can be seen as an indicator that feature vectors for a genre tend to cluster together such that they are close to other members of the same genre. We looked at the best values of $k$ back in \Cref{sec:knn}.

The next best performer, the random decision forest, can be viewed as similar to the nearest neighbour classifiers, since a decision tree cuts up the N-dimensional space into local subspaces and assigns each subspace a genre. It is therefore more coarse than kNN since it lumps together groups in the same subspace. In fact, we can see from \Cref{fig:results} that the decision forest performance increases with the number of trees. Therefore, we might reasonably expect that with sufficient trees, its performance might exceed that of the kNN. One additional thing to keep in mind is that the trees were not pruned. Given pruning, the forest might perform even better by reducing the extent of overfitting for individual trees.

As mentioned in \Cref{sec:gauss}, the poor performance of the Total Gaussian classifier can be explained by the correlation present between feature vectors in the same song, which violates our assumptions in modeling the data as a Gaussian distribution. Indeed, we can see that when we average the feature vectors for each song, we get almost twice the performance out of a Gaussian classifier. Even so, the kNN outclasses the Gaussian classifier, indicating that the data is better represented by local clusters than a global normal distribution.

\section{Conclusions}

In conclusion, we created an agent capable of classifying songs into 10 genres and tested it using cross-validation. We tried several classification methods including the Gaussian classifier, the kNN classifier, and the random decision forest classifier. We then found that the kNN classifier with $k = 1$ is the best classifier for the given task of music classification.

\bibliographystyle{IEEEtran}
\bibliography{IEEEabrv,references}

\end{document}