\chapter{Production data}\label{appen:proddata}

\begin{table}[htbp]
\begin{center}
\resizebox{4in}{!}{
\begin{tabular}{llll}
   \hline
  feature & grammatical & quotative & discourse particle \\
  \hline

  total tokens & 198  & 217 & 305 \\
  followed by C & 143 & 77 & 176 \\
  followed by pause &  10 & 56 & 59 \\
  followed by V & 45 & 84 & 70 \\
  min EucD (Hz) & 1.5 & 0.0 & 10.9 \\
  mean EucD (Hz) & 416.3 & 304.9 & 415.4 \\
  max EucD (Hz) & 1173.0 & 1099.0 & 1498.0 \\
  min nuc F2 (Hz) & 1028 & 1040 & 1234  \\
  mean nuc F2 (Hz) & 1549 & 1599 & 1603 \\
  max nuc F2 (Hz) & 2349 & 2286 & 2057 \\
  full glott & 46 & 47 & 75 \\
  mid glott & 21 & 29 & 49 \\
  no glott & 131 & 141 & 181 \\
  min pitch & 77.0 & 84.0 & 76.5 \\
  mean pitch & 203.2 & 224.2 & 202.2 \\
  max pitch & 352.5 & 352.1 & 342.0 \\
  min duration ratio & 0.00 &  0.00 &  0.00 \\
  mean duration ratio & 0.47 & 0.32 & 0.43 \\
  max duration ratio & 1.57& 1.55 & 1.76 \\
  /k/ not realised & 64 & 96 & 98 \\
  /k/ realised & 134  & 121 & 207 \\

  \hline

  \end{tabular}
}
\caption{Counts of tokens with particular phonetic features, by type.}\label{tab:appenprodfeatures}
\end{center}
\end{table}


There can be a large number of computational tools within a given field of
study.  They are typically developed with a single aspect of analysis in mind,
so one must understand the simplifying assumptions the developers made for
their purposes. Thus, choosing a computational tool is not always obvious. This
section introduces the choices for the various experimental components.

\subsection{Fuel Cycle Simulation}

Nuclear fuel cycle studies involve tracking the material flow of nuclear fuel.
This can be anywhere from mining to waste management, or focus on a process
step in between. Fuel cycle studies are not necessarily nuclear-specific. For
example, they can be used to evaluate economic predictions, environmental
impact, transportation planning, etc.  In order to draw conclusions from these
studies, it is common to use a nuclear fuel cycle simulator that tracks the
quantities of interest. These allow the comparison of different fuel types,
reactor technologies, material processing steps, etc.

There are simplifications researchers need to make in order to experiment in a
controlled way. Fuel cycle simulators, built for a specific needs, must remove
complicating factors that are less relevant to the study.  For example, one
tool might be suited well to large-scale systems analysis with little nuclear
physics included in the models, and another might focus on detailed isotopics
within a system to track plutonium.

Because a large portion of a nuclear forensics investigation relies on
measuring isotopics, this work used \gls{ORIGEN} \cite{origen}, which is a part
of the \gls{SCALE} 6.2 modeling and simulation suite of computational tools
developed for nuclear design and safety \cite{scale}. \gls{ORIGEN} was chosen
for its physically detailed models of activation, depletion, and decay.
Specifically, the ARP module of the code was used: \gls{ORIGEN-ARP}.

\gls{ORIGEN} calculates time-dependent nuclide concentrations (or quantities
derived from these) that result from activation and depletion calculations. The
physics (i.e., neutron transport and decay) calculations are carried out in
other \gls{SCALE} modules that solve the depletion equations.  This generates
libraries for \gls{ORIGEN} that include the probabilities of reaction (i.e.,
cross sections) for the system.

To obtain an \gls{SNF} recipe from a reactor simulation, \gls{ORIGEN} uses the
desired input power generation with the cross section library to calculate a
flux, the resulting depletion, and the end composition (i.e., isotopic recipes
or nuclide vectors).  Another output is decay; the composition is computed
using decay equations with nuclear data \cite{endf}. These compositions provide
source terms for other calculations, such as decay emission spectra from
neutrons, alpha particles, beta particles, and gamma rays. Other derived
quantities like activity, decay heat, or radiological hazard factors are also
an option.

\gls{ORIGEN-ARP} allows users to access a wider range of simulations by
interpolating between the pre-calculated libraries instead of creating new
libraries.  It is known to be validated for \gls{LWR} \gls{SNF}
\cite{lwr_valid}. Additionally, recycled \gls{SNF} in the form of mixed oxide
fuel has been benchmarked for the relevant reactors \cite{mox_valid}.  Through
\gls{ORIGEN}, given an initial material composition, some reactor operation
parameters, and a reactor type, one can quickly perform many different nuclear
reactor simulations and obtain \gls{SNF} recipes.

\subsection{Statistics Toolkit}

The statistics toolkit chosen for this work is scikit-learn \cite{scikit}, a
machine learning package in python.  Virtually all modern \gls{ML}
toolkits will have acceptably fast and reliable algorithms, but the use of
python provides a platform for seamless integration of all the tools in the
workflow.

\subsection{Computational Gamma Spectra}

Although the data modification shown later in Section \ref{sec:inforeduc} does
not use any standalone tool, the code \gls{GADRAS} \cite{gadras} developed at
Sandia National Laboratories will provide information reduction in a physically
valid manner.  Test studies will be carried out using the gamma energies
available from \gls{ORIGEN} simulations, but the detector response will need to
be varied more than this tool can provide. Thus, given the gamma energies from
\gls{ORIGEN} and a user-chosen \gls{DRF}, \gls{GADRAS} computationally
generates gamma spectra.  This will enable a more robust study of statistical
performance with respect to information reduction.


\documentclass{llncs}
\usepackage{CJK}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage{multirow}
\begin{document}

\title{Algorithm Description}
%
\titlerunning{Hamiltonian Mechanics}  % abbreviated title (for running head)
%                                     also used for the TOC unless
%                                     \toctitle is used
%
\author{}

%
\institute{HIT WI}

\maketitle              % typeset the title of the contribution

\begin{abstract}
For this ccks named entity recognition task, we mainly use two methods.The single CRF and the LSTM-CRF neural network model.We use the gold label data
set to do the unsupervised learning for both model,and the unlabel data set to do the embedding and supervised learning.Finally get the  \dots
\keywords{Name entity recognition,CRF,LSTM}
\end{abstract}
%
\section{LSTM-CRF method}
\subsection{Neural Network Architecture}
In this section, we describe the components (layers) of our neural network architecture. We introduce the neural layers in our neural network one
by-one from bottom to top.
\subsubsection{Char Embedding}
We use the char level vector to represent the Chinese words,by using the word2vec in the unlabeled dataset,the embedding dimension is 100.
\subsubsection{Bi-directional-LSTM}
For many sequence labeling tasks it is beneficial to have access to both past (left) and future (right) contexts.The solution whose effectiveness has been proven by previous work (Dyer et al., 2015) is bi-directional LSTM
(BLSTM). The basic idea is to present each sequence forwards and backwards to two separate hidden states to capture past and future information, respectively. Then the two hidden states are concatenated to form the final output.
\subsubsection{CRF}
For sequence labeling (or general structured prediction) tasks, it is beneficial to consider the correlations between labels in neighborhoods and jointly decode the best chain of labels for a given input sentence.Therefore, we model
label sequence jointly using a conditional random field (CRF) (Lafferty et al., 2001), instead of decoding each label independently.
In our code,we try to use the negative log likelihood function and the
labelwise function to get the loss of the CRF layer.Using the marginal decode
and viterbi decode.

\floatname{algorithm}{Algorithm}
\renewcommand{\algorithmicrequire}{\textbf{input:}}
\renewcommand{\algorithmicensure}{\textbf{output:}}
	\begin{algorithm}
		\caption{CRF loss Negative log likelihood}
		\begin{algorithmic}[1]
			\Require feature from BiLSTM,Tags
			\Ensure Loss
			\Function {Likelihood loss}{$feature,self,tags$}
			\State $forward score \gets CRFlayer.forward(feature)$
			\State \# Do the forward algorithm to compute the partition function
			\State $gold score \gets CRFlayer.score_sentence(feature,tags)$
			\State \# Gives the score of a provided tag sequence
			\State \Return{$forward score - gold score$}
			\EndFunction
		\end{algorithmic}
	\end{algorithm}

\subsubsection{BLSTM-CRF}
\
The basic train step is as fellow:
\begin{algorithm}
	\caption{Network train step}
	\begin{algorithmic}[1]
		\Require Sequences of context C,Sequences of BIEO tags T
		\Ensure Model
		\State Initialize the word-embedding layer$\gets$ Separating text by char and do Word2vec
		\State model$\gets$LstmCrfModel.BiLSTM CRF(Model parameters)
		\State optimizer $\gets$ optim.SGD(model.parameters(), lr$\gets$0.01, weight decay$\gets$1e-4)
		\For {in range(epcho)}
		 \ForAll {$sentence \in context$}
		 \State model.LSTMtrain(sentence)
		 \State Input to the CRFlayer
		 \EndFor
		 \State Get loss(T,predict tags)
		 \State SGD Optimize the loss
		 \EndFor
		\State \Return{$Model$}
	\end{algorithmic}
\end{algorithm}
\section{Parameter Initialization}
The Parameter Initialization is as fellow:
\begin{table}[!hbp]
	\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
		\hline
		 Optimizer & Embedding & Dropout & Learning rate& Weight dercay&CRF loss \\
		\hline
		 SGD & Word2Vec & 0.5 & 0.01 & 1e-4 &lablewise\\
		\hline
	\end{tabular}
\end{table}

\section{Single CRF method}
\subsection{feature chose}
Chose the pos tag to be the extra feature,to do the crf in char level.
\subsection{Parameter Initialization}
The Parameter Initialization is as fellow:
\begin{table}[!hbp]
	\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
		\hline
		Optimizer & Embedding & Dropout & Learning rate& Weight dercay&CRF loss \\
		\hline
		SGD & Word2Vec & 0.5 & 0.01 & 1e-4 &lablewise\\
		\hline
	\end{tabular}
\end{table}

%
% ---- Bibliography ----
%
\begin{thebibliography}{5}
%
\bibitem {clar:eke}
Schölkopf B, Platt J, Hofmann T. Training Conditional Random Fields for Maximum Labelwise Accuracy[C]// Advances in Neural Information Processing Systems 19, Proceedings of the Twentieth Conference on Neural Information Processing Systems, Vancouver, British Columbia, Canada, December. DBLP, 2006:529-536.

\bibitem {clar:eke:2}
Ma X, Hovy E. End-to-end Sequence Labeling via Bi-directional LSTM-CNNs-CRF[J]. 2016.
\bibitem {clar:eke:3}
Goldberg Y, Levy O. word2vec Explained: deriving Mikolov et al.'s negative-sampling word-embedding method[J]. Eprint Arxiv, 2014.

\end{thebibliography}
\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                 %
%  GEANT manual in LaTeX form                                     %
%                                                                 %
%  Michel Goossens (for translation into LaTeX)                   %
%  Version 1.00                                                   %
%  Last Mod. Jan 24 1991  1300   MG + IB                          %
%                                                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Origin{L.Urb\'{a}n}
\Version{Geant 3.16}  \Routid{PHYS450}
\Submitted{24.03.86}  \Revised{16.12.93}
\Makehead{Total cross-section and energy loss for e-e+ pair
production by muons}
\section{Subroutines}
\Shubr{GPRELA}{}
\Rind{GPRELA} adds to the muon energy loss tables the contribution
due to $\mu$-nucleus interactions and \Pep\Pem-pair production in
which the energy of the pair is below threshold (see later).
For the contribution of pair production, it calls the function
\Rind{GPRELM}. The energy binning is in the array {\tt ELOW} (common
\FCind{/CGMULO/}). The following pointers are used:

\begin{DLtt}{MMMMMMMMMMMMMMMMMMMM}
\item[JMA  = LQ(JMATE-I)] pointer to the I$^{th}$ material;
\item[JEL2 = LQ(JMA-2)]  pointer to $dE/dx$ for $\mu^+\mu^-$.
\end{DLtt}

\Rind{GPRELA} is called during initialisation by \Rind{GPHYSI}.

\Sfunc{GPRELM}{VALUE = GPRELM(Z,T,CUT)}

\begin{DLtt}{MMMMMMMM}
\item[Z] ({\tt REAL}) atomic number of the material;
\item[T] ({\tt REAL}) kinetic energy of the muon;
\item[CUT] ({\tt REAL}) maximum energy for the pair considered by the routine.
\end{DLtt}
\Rind{GPRELM} calculates the energy loss due to the direct
production by muons of \Pem\Pep pairs with energy below {\tt CUT}
({\tt PPCUTM} in common \FCind{/GCCUTS/}).
Above this cut, the direct pairs are produced as discrete processes
(see {\tt [PHYS451]}). \Rind{GPRELM} is called by \Rind{GPRELA}.
\Shubr{GPRSGA}{}
{\tt GPRSGA} calculates the total cross-section for
the pair production by photons and the direct pair production by muons.
It tabulates the mean free path
in cm as a function of medium and energy.
For the direct pair production of muons, it calls
the function \Rind{GPRSGM}. The energy
binning is in the array {\tt ELOW} (common \FCind{/CGMULO/}).
The following pointers are used:
\begin{DLtt}{MMMMMMMMMMMMMMMMMMMM}
\item[JMA = LQ(JMATE-I)]  pointer to the I$^{th}$ material;
\item[JPAIR = LQ(JMA-10)] pointer to photon pair production cross-sections;
\item[JPAIR+NEK1]      pointer to muon pair production.
\end{DLtt}
{\tt GPRSGA} is called during initialisation by {\tt GPHYSI}.

\Sfunc{GPRSGM}{VALUE = GPRSGM(Z,T,CUT)}

\begin{DLtt}{MMMMMMMM}
\item[Z] ({\tt REAL}) atomic number of the medium;
\item[T] ({\tt REAL}) kinetic energy of the muon;
\item[CUT] ({\tt REAL}) minimum energy for the \Pem\Pep pair.
\end{DLtt}
\Rind{GPRSGM} calculates the total cross-section for
muon direct pair production where the energy of the pair is greater
than {\tt CUT} ({\tt PPCUTM} in common \FCind{/GCCUTS/}). It is called
by \Rind{GPRSGA} (see {\tt [PHYS451]}).

\section{Method}
When a muon of energy $E$ moves in the field of
an atom of charge $Z$, it can radiate a \Pep\Pem-pair
($4^{th}$ order QED process) with
differential cross-section \cite{bib-LOHM}:
\begin{equation}
\frac{\partial^2 \sigma}{\partial \nu \; \partial \rho}=
\alpha^4 \frac {2}{3 \pi}   (Z \lambdar)^2 \frac{1-v}{v}
\left [ \phi_e + \left(\frac{m_{e}} {m_{\mu}}\right)^2 \phi_{\mu} \right ]
\end{equation}
where
\[
\nu = \frac{ E^+ + E^-}{E} \mbox{\quad and\quad}\rho =
\frac{E^+ - E^-}{E^+ + E^-}
\]
and
\begin{DLtt}{MMMMMMMM}
\item[$\alpha$]   1/137, fine structure constant;
\item[$\lambdar$] $3.8616 \times 10^{-11}$ cm, electron Compton wavelength;
\item[$v$]        $k/E$ fraction of energy transferred to the pair;
\item[$T$]        $E-M$ kinetic energy of the muon.
\item[$E^{\pm}$]  the energy of the $e^{\pm}$.
\end{DLtt}

The explicit form of the terms $\phi_e$ and $\phi_{\mu}$
can be found in \cite{bib-LOHM}. The kinematic ranges of $\nu$ and $\rho $ are:
\begin{equation}
\begin{array}{RCCCCCL}
\frac{4m_{e}}{E}=\nu_{min} & \leq & \nu & \leq  & \nu_{max} & = &
1 -0.75 \sqrt{e}\frac{m_{\mu}}{E} Z^{1/3}       \\ [0.7cm]
0=\rho_{min} & \leq & |\rho (\nu) | & \leq & \rho_{max} (\nu) &
= & \left [1-\frac{6m_{\mu}^2}{E^2 (1-\nu)}\right]
         \sqrt{1- \frac{4m_{e}}{\nu E}}
\end{array}
\end{equation}

where   $e = 2.718\dots$.

$E_c$ ({\tt PPCUTM} in the program) is the energy cut-off; below this
energy \Pep\Pem-pair are treated as continuous energy loss,
and above they are explicitly
generated and $v_c = E_c/E$.
The mean value of the energy lost by the incident muon due to
\Pep\Pem-pair with energy below $E_{c}$ is:
\begin{equation}
\label{eq:phys450-1}
 E_{loss}^{pair}(Z,T,E_c ) =
 2E \int_{\nu_{min}}^{\nu_c}{ d\nu\;\nu \int_{0}^{\rho_{max}(\nu)}{
 d\rho \;
\frac{\partial^2 \sigma}{\partial\nu \; \partial\rho}}}
\mbox{\hspace{0.5cm} GeV barn/atom}
\end{equation}
whereas the total cross-section for the emission of a hard \Pep\Pem-pair is:
\begin{equation}
\label{eq:phys450-2}
\sigma (Z,T,E_c) =
 2 \int_{\nu_c}^{\nu_{max}} d \nu\;
   \int_{0}^{\rho_{max}(\nu)}
 d \rho  \; \frac{\partial^2\sigma}{ \partial\nu \; \partial\rho}
\mbox{\hspace{0.5cm} barn/atom}
\end{equation}

\subsection{Parameterisation of energy loss and total cross-section}
Instead of using the explicit formula (\ref{eq:phys450-1}) and
(\ref{eq:phys450-2}), we have chosen to parameterise directly
$E_{loss}^{pair}(Z,T, E_c $) and $\sigma(Z,T,E_c)$ as:
\begin{eqnarray}
\label{eq:phys450-3}
\sigma (Z,T,E_c) & = & Z [Z+ \xi_{\sigma} (1+ \gamma \ln Z)]
     \left [\ln \frac{E_{max}}{E}\right]^{\alpha}
      F_{\sigma} (Z,X,Y)                           \\
E_{loss}^{pair}(Z,T,E_c)      & = & Z [Z+ \xi_l (1+ \delta \ln Z)] E
\label{eq:phys450-4}
      \left [ \frac{E_c - E_c^{min}}{E}\right]^{\beta}
     F_l(Z,X,Y)
\end{eqnarray}
where  $\xi_{\sigma,l}$, $\alpha$, $\beta$, $\gamma$ and $\delta$
are parameters obtained by a fitting procedure and
$ E_c^{min} = E\:v_{min} = 4 m_{e}$ and
$ E_{max} = E\:v_{max}$

The functions $ F_i $ (Z,X,Y) ($ i=\sigma,\;l $) have the form:
\begin{equation}
 F_i(Z,X,Y) = F_{i0}(X,Y)+ZF_{i1}(X,Y)
\end{equation}
where $F_{ij}(X,Y)$ denotes a function constructed from two polynomials
\begin{equation}
 F_{ij}(X,Y) = \left\{ \begin{array}{LlL}
                   P_{ij}^{neg}(X,Y)  & \mbox{if} & Y \leq 0 \\ [0.3cm]
                   P_{ij}^{pos}(X,Y)  & \mbox{if} & Y > 0
                   \end{array} \right.
\end{equation}
and $P_{ij}^{neg}$, $P_{ij}^{pos}$ fulfil the conditions:
\[
P_{ij}^{neg}(X,Y)_{Y=0} = P_{ij}^{pos}(X,Y)_{Y=0}
\hspace{2cm}
\left . \frac{\partial P_{ij}^{neg}}{\partial Y } \right |_{Y=0}  =
\left . \frac{\partial P_{ij}^{pos}}{\partial Y } \right |_{Y=0}
\]
The detailed form of the $P_{ij}$ polynomials is:
\begin{eqnarray}
P_{i0}^{neg}(X,Y)& = &
        (C_1+C_2X+\cdots+C_6X^5)+(C_7+C_8X+\cdots+C_{12}X^5)Y
\nonumber \\
  & + &(C_{13}+C_{14}X+\cdots+C_{18}X^5)Y^2+\cdots+(C_{31}+\cdots+C_{36}X^5)Y^5
\nonumber\\
P_{i0}^{pos}(X,Y)& = &
        (C_1+C_2X+\cdots+C_6X^5)+(C_7+C_8X+\cdots+C_{12}X^5)Y
\nonumber\\
\label{eq:phys450-5}
  & + &(C_{37}+C_{38}X+\cdots+C_{42}X^5)Y^2+\cdots+(C_{55}+\cdots+C_{60}X^5)Y^5
         \\
P_{i1}^{neg}(X,Y)& = &
  (C_{61}+C_{62}X+\cdots+C_{65}X^4)+(C_{66}+C_{67}X+\cdots+C_{70}X^4)Y
\nonumber \\
  & + &(C_{71}+C_{72}X+\cdots+C_{75}X^4)Y^2+\cdots+(C_{81}+\cdots+C_{85}X^4)Y^4
\nonumber \\
 P_{i1}^{pos}(X,Y)& = &
  (C_{61}+C_{62}X+\cdots+C_{65}X^4)+(C_{66}+C_{67}X+\cdots+C_{70}X^4)Y
\nonumber \\
  & + &(C_{86}+C_{87}X+\cdots+C_{90}X^4)Y^2+\cdots+(C_{96}+\cdots+C_{100}X^4)Y^4
\nonumber
\end{eqnarray}
with
\[
X = \ln \frac{E}{m_{\mu}} \hspace{2cm} Y = \ln \frac{E_{c}}{v_{j} E}
\hspace{2cm} j = \sigma, l
\]
where $v_{\sigma,l}$ are additional parameters of the fit.
By a numerical (twofold) integration of the formulae (\ref{eq:phys450-3})
and (\ref{eq:phys450-4})
above, we have calculated  1800 {\it data points} in the range
$Z = 1, 6, 13, 26, 50, 82, 92$ and the energy ranges 1GeV $ \leq T \leq $ 10
TeV and $ 4m \leq E_c \leq T$
and performed a least-squares fit to determine the parameters.
The fitted values of the parameters are in the {\tt DATA} statements in the
functions \Rind{GPRSGM} and \Rind{GPRELM}, which compute the formulae
(\ref{eq:phys450-3}) and (\ref{eq:phys450-4}) respectively.
The accuracy of the fit is:
\[ \begin{array}{LL}
\frac{\Delta \sigma}{\sigma} & \leq  \left\{
\begin{array}{RcLl}
10\% & \mbox{if} & T\leq 5 & \mbox{GeV} \\
5\%  & \mbox{if} & T > 5 & \mbox{GeV}
\end{array} \right . \\ [0.5cm]
\frac{\Delta E_{loss}^{pair}}{E_{loss}^{pair}}  & \leq \left\{
\begin{array}{RcLl}
10\% & \mbox{if} & T\leq 5 & \mbox{GeV} \\
4\%  & \mbox{if} & T > 5 & \mbox{GeV}
\end{array} \right.
\end{array} \]

The function \Rind{GPRELM} contains a second formula to calculate the total
energy lost by the muon due to direct \Pep\Pem-production
used when $E_c\geq E_{\mbox{max}} = E-0.75 \surd e m_{\mu}Z^{1/3}$.
This formula describes the total energy loss with an error less than 1\%:
\begin{eqnarray}
E_{loss}^{pair}(Z,T) & = &
E_{loss}^{pair}(Z,T,E_c=E_{max}) \\
& = & Z(Z+1) E_{max} [d_1+(d_2X+d_3Y)+(d_4X^2+d_5XY+d_6Y^2)+ \nonumber\\
&+ & \cdots+(d_{22}X^6+d_{23}X^5Y+\cdots+d_{28}Y^6)] \nonumber
\end{eqnarray}
where $ X=\ln(E/m_{\mu}) $ and $Y=Z^{1/3}$.
The fitted parameters $d_i$ can be found in the {\tt DATA}
statement in the function \Rind{GPRELM}.


\section{Introduction}
One of the possible sources of the high-energy cosmic rays are the shock waves in astrophysical collisionless plasma due to the diffusive shock acceleration (DSA) mechanism, see \cite{Bell1978}, \cite{Blandford1978}. The particle acceleration on the shock front is a sophisticated and nonlinear problem, because the cosmic rays have a strong influence on the shock wave. The pressure of cosmic rays is comparable with the pressure of background plasma and significantly modifies the front (see, e.g., \cite{Bykov2014}).
Also the instabilities in the anisotropic plasma can yield a strong field amplification, and according to the observations of synchrotron emission from supernova remnants (SNRs), the magnetic field there is about 100 times stronger than the interstellar field (see, e.g., \cite{Berezhko2003},\cite{Uchiyama2007}).
One of the most powerful methods to explore the processes in collisionless plasma is the Particle-in-Cell simulation.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Definitions
%\pagestyle{empty}
\documentclass[12pt,preprint]{aastex}
%\documentstyle[emulateapj,danonecolfloat]{article}
%\usepackage{emulateapj,danonecolfloat}
\usepackage{rotating}

\begin{document}

\subsection{Extraction}

We utilize an optimal extraction procedure to transform a 2-dimensional image of
the fiber spectrograms to a set of 320 1-dimensional spectra (per spectrograph).
We use the same procedure on all processed frames,
and will describe the details in processing the flat-field frames, the
arc lamp frames, and finally the science frames.
The extraction is performed row-by-row, so each frame requires an
outside loop over 2048 individual rows.
The counts in each row of 2048 columns are modeled with a linear
combination of 320 profiles plus a low-order
polynomial background.  In addition, deviations to the trace centers and
the profile widths are calculated as linear basis modes (reflecting the first
and second spatial derivatives, respectively).  The compiled routine
we implement to fit the profiles in a single row (extract\_row.c) can
be invoked with any combination of these parameters.

We decided to perform profile fitting to the
SDSS spectral images for the following reasons:

\begin{enumerate}

\item{The fiber profiles overlap significantly with their nearest neighbors.}

\item{The profiles are relatively stable and smoothly vary over
location on the CCDs.  They result from the convolution of the fiber
illumination pattern + the point-spread function
of the optics in the SDSS spectrographs + the window funciton of the
Site CCD 24 micron square pixels. }

\item{A least-squares fit with the true profile delivers an
unbiased and minimum variance estimate of the counts (e.g. Horne et al. 1995).}

\item{A model profile fit leads to a model image of the SDSS data,
and iteration allows cosmic-ray rejection and goodness-of-fit tests.}

\end{enumerate}

The major obstacle to actual optimal extraction is the determination of
the exact shape and position of the underlying profile.
We investigated a range of symmetric, analytic profiles with a
minimum number of free parameters.  In the end, we found the best
results using a simple Gaussian or a slightly steeper profile
characterized by $e^{-|x|^3/\sigma^3}$.  The profiles are defined to be
normalized to unity, so the amplitude of the profile fit is a
direct estimator of the counts at a single spectral position.

Extraction is first carried out on all flat-field exposures
(typically 10 second observations of 4 quartz lamps projected on petals covering the entrance aperture of the telescope) which were observed
with a common plug plate configuration (a spectroscopic sequence).
The flat-field extraction is used to determine the shape of
the profile as a function of wavelength and position on the CCD.
The resulting spectral extractions are also used to
determine the empirical fiber-to-fiber variations in throughput
as a function of wavelength.
A flat-field frame is rejected by the pipeline if one of the
following conditions is met:  1) More the 2\% of the CCD pixels are labeled
bad by sdssproc, 2) More than 100 rows of the image show saturation,
3) The 80th percentile count level is less than 1000 counts,
4) Fewer than all 8 flat-field telescope petals were closed,
5) Fewer than all 4 flat-field lamps were on,
6) More than 10000 pixels were rejected during fiber tracing,
7) Fiber tracing fails, or traces are seperated by less than 3 pixels anywhere
on the flat-field image.

The first very critical step is to robustly determine the fiber positions
in CCD pixel coordinates.
This is performed by identifying peaks in a cross-sectional cut of across
the center row (actually a median cross-section of the central 9 rows).
The correct identification of the 320 fibers per frame can be
uniquely determined by demanding a wider spacing between the bundles
of 20 fibers (spaced by about 10 pixels) relative to the nominal inter-fiber
spacing (6.1 pixels on average).  Once the starting peaks and
identification have been determined, we trace the fiber centers
by performing flux-weighted centroids on subsequent rows
using the previous row's center as the intial guess.  This has proven to
work well on SDSS flat-fields, and we have yet to uncover a failure
mode in over 10000 flat-field frames.
The flux-weighted centroids do have scatter from shot noise,
so we fit a 7th order polynomial to each set of fiber centroids,
and the best-fit coefficients are stored to represent the fiber positions
on each flat-field frame.

Each flat-field frame is extracted twice, once assuming a Gaussian
profile and again assuming the steeper $|x|^3$ profile.  In both cases,
the width is allowed to vary freely.  The total number of free parameters
per row in the flat-field extractions is equal to 2 per fiber plus 10
parameters to represent a smooth polynomial background.  After the extractions
are complete, $\chi^2$ is computed by directly comparing the model fit
to the flat-field image.  The median $\chi^2$ for each case is compared
directly, and the better fit and profile (lower median $\chi^2$) are retained
and implemented for the extraction of the remaining frames.  Also retained
is a smooth polynomial fit the average profile width in each fiber bundle
as a function of CCD row number.

After all flat-field frames for a given sequence have been extracted
and stored, the arc-lamp frames in the same sequence are extracted.
Each arc-lamp frame is matched with the nearest (in time)
non-rejected flat-field frame.  The matched flat-field gives the
initial trace centers to
be assumed, as well as the profile shape and width determined from the
flat-field.  To account for any flexure between the frames, the trace
centers are allowed to shift/stretch to the arc-lamp image given a
3x3 polynomial distortion kernel over the entire extent of the image
(match\_trace.pro).

The arc-lamp frames are extracted row-by-row, in the same
manner as the flat-fields, the number of free parameters assumed
for the model fit is 2 per fiber (profile area and width) and 1 parameter
to fit for a constant background per row.  The restricted freedom in the
background parameterization reflects the lower scattered light levels in
the images of the arc-lamps.

\subsection{(or arc-lamp spectra -> wavelength map)}

We determine an initial wavelength solution for every arc-lamp frame
successfully extracted in the following manner:

For the appropriate side of each spectrograph (red or blue), we
construct a list of suitable unblended lines from a parent list including
known lines of Mercury, Cadmium, Neon and (a trace of) Argon
that are readily observable in the standard set of SDSS arc-lamps.
A representative spectrum is calculated as the median extracted spectrum
of the 5 closest "unflagged" spectra falling near the central columns
of the arc-lamp image.  This median arc-spectrum is matched with
cross-correlation to a simulated spectrum of suitable arc-line positions and
strengths by systematically searching a small volume of
parameter space which conservatively covers
the polynomial coefficients of the SDSS wavelength solution.
In the first iteration, we search a set of
100 coefficient vectors allowing for quadratic changes and return
the best match.  In the second iteration, we search in a smaller region
about the previous best match, and search a list of 125 coefficient vector
allowing for cubic deviations.  The coefficient vector with the best
match from the second iteration is returned as an initial guess along with
the cross-correlation coefficient.

We apply the best guess coefficients to predict the approximate pixel
positions of the suitable list of arc lines.  The arc line centroids
are traced across extracted spectra (along the axis of 320 fibers).
The centroids are fit to a smooth polynomial as a function of fiber
position on the arc-lamp image, and subsequently fit through 6 iterations
with simple flux weighting to arrive at a converged measure of line
centroids in each extracted spectrum.  Lines are excluded from the resulting
list if the flux-weighted centroids are bad in more than 10\% of the
spectra or if the RMS residuals are larger than 20\% of a pixel.
We perform an iterative 4th order Legendre polynomial fit of
logarithmic wavelength as a function of pixel in each spectrum,
and retain a list of rejected centroids,
which have deviations relative to the model of
10\% of a pixel width.  An additional requirement is applied to each
suitable arc line, wherein the line is rejected in no more than 3 fibers
per bundle of 20.  Rejected centroids are replaced with the appropriate
positions based on a linear interpolation of the differences of non-masked
centroids relative to updated polynomial fits per spectrum.
The final set of positions, where the same number of line positions have
reliable centroids per spectrum, are fit with equal weighting per line
position to produce the final wavelength
coefficients which give the logarithmic (base 10) wavelengths as a function
of spectral pixel.

An arc-lamp image is declared unacceptable using the first 4 tests as employed
in tests of the flat-field images.  In addition, an arc-lamp exposure
is declared unacceptable ("BAD") if any of these following criteria are met:
5) All 8 arc-lamps must be on, 4 Neon lamps and 5 Mercury-Cadmium lamps,
6) The initial cross-correlation coefficient is less than 0.5,
7) Less than 6 arc lines are acceptable after quality assurance checks.

The width of unblended arc lines are determined as an average over
each bundle of 20 spectra.  In short, the arc-lamp emission lines
are extracted (with a Gaussian spectral profile)
allowing free parameters for the area and width of each suitable line.
The resulting Gaussian widths per fiber bundle are fit
with a low order polynomial as a function of average line position
(the fit is quadratic and cubic for the blue and red side respectively).
The fitted quantity is referred to as the arc-lamp dispersion,
but the values reflect the standard deviation of a Gaussian
profile in pixel units and represents the line-spread function of the
arc-lamp spectra.

(or just refer to data model appendix instead of the paragraph below:)

The arc-lamp reductions are written to disk at this stage, and
stored in an extended FITS file:  HDU \#0 contains the processed
and extracted arc-lamp spectra as counts per pixel, HDU \#1 contains
the identified arc line wavelengths and the measured line centroids
(including replaced positions of rejections), HDU \#2 contains a single
structure with the Legendre polynomial coefficients applicable to each
of the 320 arc-lamp spectra, HDU \#3 contains the maskbits for each spectrum,
and HDU \#4 contains the polynomial coefficients to describe the arc-lamp
Gaussian widths as a function of spectral pixel.

\subsection{Constructing fiber flats}

The final step in the reduction of the calibration frames in a given
sequence is the construction of the fiber flat vectors.  Each flat-field
frame is matched to the nearest arc-lamp frame as before, and the
final flat-field fiber spectra are extracted in two steps.  The first
step uses the preferred spatial profile and width determined above,
and the extraction procedure produces a model of the flat-field frame.
The model is used to subtract a diffuse scattered background given
by an exponential point-spread function of :  (CCD halo PSF).
We apply a 1-dimensional version of this 2-d PSF as an approximation,
and allow the PSF to vary appropriately with wavelength.
The final extraction is applied to the scattered light subtracted flat-field
image allowing for 2 free paramters per fiber per row and
5 background parameters per row.

The final flat-field spectra are stored as
detected counts per fiber per pixel with wavelengths of each pixel
given by the associated solution of the arc-lamp frame.
We model the flat-field spectra as the product:

\begin{equation}
{\rm Flat Model}_{ij} = A * f_{avg}(\lambda) \, {\rm fflat_i} (\lambda)
\end{equation}

where $A$ is a overall normalization in counts,
$f_{avg}$ is the average response per constant logarithmic wavelength
interval, $fflat_i$ is the fiber-to-fiber response as a function of wavelength.
This model of the extracted flat-field spectra provides a transformation to
compare detected counts from one fiber to another.

This should remove the differential response due to the individual fiber
throughput, as well as the small relative differences in the size of the
spectral pixels at a constant wavelength.  ??Why do we correct for pixel
sizes later on if the differential wavelength dispersion is included in fflat??

The common normalized response function, $f_{avg}$, is specified as a B-spline
function with breakpoints spaced approximately every native pixels.
An example of normalized individual fiber spectra
and the resulting B-spline fit are shown in Figure ?.  The individual fiber
flat vectors are fits to the ratio of the extracted spectra to the superflat
(define above).  The individual vector fits are also B-splines with breakpoints
spaced approximately every 5 native pixels.  The final set of flat vectors are
stored as an image with dimensions Nfiber x Npixels.

\subsection{Object Extraction}

With the extracted calibration frames for a given spectroscopic sequence
reduced, we proceed to extract the remaining science frames.
%To minimize the differences between individual science frames
We first select a set of arc-lamp and flat-field frames as the common
choice of initial calibrations for all science frame extractions in a given
observing sequence.  We loop through the science exposures, processing the
raw images with bias and pixel-to-pixel flat images (see section ??).
We reject a science exposure outright if 1) more than 10\% of the pixels
are flagged as bad, 2) more than 100 rows are saturated, 3) the 25th
percentile count level is greater than 1000 counts (the nominal level
is of order 10 counts), 4) any of the flat-field petals are closed, or 5)
any of the calibration lamps are recorded as on.

Inputs to object extraction include the wavelength coefficients derived
from the associated arc-lamp exposure, both the superflat and fiber flat
vectors from the selected flat-field exposure, the profile shape and width
as a function of position on the CCD image.

The first step in object extraction is a simple tophat aperture (boxcar)
extraction centered at the fiber positions determined from the flat-field
and with a full spatial width of 6 CCD pixels.  The median counts per fiber
are passed directly to a test for overly bright fibers. Fiber spectra are
identified as bright (a.k.a. "WHOPPING") if the median counts per pixel in the
boxcar extraction are greater than 10000 counts above the median in the
frame.  In addition, only the brightest fiber in a spatially contiguous set of
bright fibers is labelled "WHOPPING".

A pixelmask vector is created for each fiber spectrum to be extracted.
See Appendix ?? for a description of the mask bits and their use.

We fit for a slight distortion of the stored flat-field fiber traces to
best match the fiber positions of the science image.  Nominal shifts and
distortions are usually less than a native CCD pixel.  The science frame
is now extracted in a series of 6 steps which we detail below.

\begin{enumerate}
\item{Initial extraction including broad wings of bright (WHOPPING) fibers.}
\item{Reconstruct a smooth background light model based on fitted parameters.}
\item{Calculate a scattered halo image using the model of the fiber spectra less
the aforementioned smooth background.}
\item{Re-extract fiber spectra on the scattered halo subtracted image.}
\item{Reconstruct smooth background and subtract.}
\item{Final extraction with no free parameters in the background and
no free parameters in the profile widths.}
\end{enumerate}

The extracted science spectra are first normalized by the fiber flat vectors.
Strong atmospheric emission lines (sky lines) are identified in the the
set of spectra, and the wavelength solution is shifted to match the
identified lines.  Examples of the shift corrections are shown in Figure ??.
The widths of the identified sky lines are also measured with the same method
as the arc-line width measurements.  All spectra are also normalized by
the average flat-field spectrum (the superflat) to remove small scale
features likely attributed to the chromatic response of the dichroic.
The wavelength solution is corrected to both vacuum wavelengths and the
heliocentric velocity frame.

\subsection{Sky Subtraction}

Sky subtraction is performed on a frame by frame basis using the
"flattened" wavelength calibrated extractions.  The goal of sky subtraction
is to estimate the expected background counts contributing to each of
the native 320x2048 pixels in each extracted frame.  A "supersky" model
at a fiducial airmass of 1 is constructed by performing iterative fits to
the extracted spectra associated with blank sky positions (so-called
"sky" fibers).   The following steps are taken in 3 sequential iterations
in order to produce the sky-subtracted spectra:

\begin{enumerate}

\item{Identify the "sky" fibers which have no bits flagged
in the fiber mask array.}

\item{Divide each sky spectrum by the airmass of the fiber position appropriate
for the midpoint of the observation to produce respresentative sky spectra for
an airmass of 1.  The inverse variance is scaled accordingly.}

\item{Group and sort the sky spectra as a function of wavelength.  This step
transforms a 2-dimensional set of $N_{\rm sky}$ x 2048 pixels into a sorted 1-dimensional array.
Each pixel maintains its associated central wavelength and inverse variance. }

\item{Perform a single cubic b-spline fit as a function of wavelength.
The number of breakpoints (number of free parameters is 4 greater) is set
at 2048 on the red side and 1536 on the blue side.  The breakpoint spacing
is set automatically to maintain approximately constant S/N between breakpoint
positions. The b-spline fit itself is iterative, with upper and lower rejection
thresholds set to mask bad or deviant pixels. }

\item{The b-spline fit is evaluated at all 320x2048 wavelengths representing all
spectral pixels in the frame.  The airmass correction is applied for each individual
fiber, and the rescaled super-sky is subtracted from each spectrum.}

\item{Estimate the significance of the residuals in the sky fibers used for the
fit in wavelength bins separated by breakpoints determined above.  for each bin
where inverse the 67th percentile of $\chi^2$ is greater than 1, we rescale
all the inverse variance values down by the 67th percentile value of $\chi^2$.
The rescaling is actually done with a smooth interpolation as a function of
redshift with a constraint that the inverse variances cannot increase. }

\end{enumerate}

%The b-spline routines from the numerical fortran library: {\bf slatec}
%were ported to IDL to be easily incorporated into the pipeline.

The sequence followed in the determination of the sky subtracted spectrum
and re-scaled errors is called 3 times successively.  After the 1st call,
any sky fibers which have a median $\chi^2$ per pixel greater than 2 is
masked as a 'BADSKYFIBER' and the corresponding bit is set in the fibermask
array.  If any fibers are masked, the sky subtraction is iterated a 2nd time.
The sky subtraction routine is invoked for one final iteration, but with extra
freedom allowed in the fit.  The same freedom is allowed in wavelength, by
keeping the same number of breakpoints, but a quadratic polynomial fit is
allowed as a function of wavelength.  This triples the number of free
parameters in the linear least-squares fit, but the values are still
overconstrained due to the ample number of sky fibers.  The extra freedom
in the model can accomodate variation in the PSF of sky features as a function
of position on the CCD.

The sky subtraction method which utilizes the b-spline model takes advantage
of the inherent over-sampling in wavelength due to the large number of
sky fibers assigned per plate, without the requirement of resampling the
pixel value to a fixed linear wavelength scale.  The least squares fit
is carried out for native spectral pixels where the errors are very nearly
uncorrelated and the fit is evaluated for all the native pixels (320x2048)
at the central wavelengths of the single spectral frames.

The accuracy of the SDSS spectral sky subtraction has been tested in recent
scientific analyses using large numbers of background-limited spectra.
The distribution of flux residuals between spectral observations
on separate nights has been shown to be 8\% larger in width than the average expected
from the reported errors (McDonald et al. 2004, Burgess \& Burles 2005).
The spectra of faint, background-limited galaxies observed with SDSS exhibit a
distribution of residuals about the best fit spectral models described by the sum of a
Gaussian and Laplace distribution (Bolton et al. 2004).
The influence of the exponential tail is greatly enhanced in the vicinity of strong sky
emission lines representative of systematic errors in the brightest lines, but the gaussian
width closely is closely represented by the reported variance array.

\end{document}


\section{Introduction to \castro}

\castro\ is a adaptive mesh, radiation hydrodynamics code that is
designed to model astrophysical reacting flows on massively parallel
computers.

The major capabilities:
\begin{itemize}
\item 1-, 2-, and 3-dimensional unsplit, 2nd-order hydrodynamics
\item multigroup flux-limited diffusion radiation hydrodynamics
\item adaptive mesh refinement with subcycling; jumps of 2x and 4x between levels
\item arbitrary equation of state (gamma-law and stellar EOSes are bundled)
\item general nuclear reaction networks
\item explicit thermal diffusion
\item full Poisson gravity (with isolated boundary conditions)
\item rotation (in the co-rotating frame) in 2-d axisymmetric and 3-d.
\item parallelization via MPI + OpenMP
\end{itemize}

\section{Units and Conventions}

\castro\ works in CGS units unless otherwise specified.
Table~\ref{table:units} shows some of the common symbols / names used
throughout the code documentation and papers.

\begin{table}[t]
\renewcommand{\arraystretch}{1.2}
\centering
\begin{tabular}{lll}
name & units & description \\
\hline
$t$    & s       & time \\
$\rho$ & $\gcc$  & mass density \\
$\ub$  & $\cms$  & velocity vector \\
$p$    & $\presunit$ & pressure \\
$\gb$  & $\accelunit$ & gravitational acceleration \\
$\Sb$  & varies       & source term \\
$E$    & $\ergg$      & specific total energy \\
$e$    & $\ergg$      & specific internal energy \\
$T$    & $K$          & temperature \\
$\kth$ & $\mathrm{erg~cm^{-1}~s^{-1}~K~{-1}}$ & thermal conductivity \\
$X_k$  & --           & mass fraction of species $k$ \\
$\omegadot_k$ & $\mathrm{s^{-1}}$  & species creation rate (from reactions) \\
\hline
\end{tabular}
\caption{\label{table:units} Common quantities and units.}
\renewcommand{\arraystretch}{1.0}
\end{table}

Physical constants, again using the CGS system are available
in {\tt Castro/constants/constants\_cgs.f90}


\section{Algorithm}
\label{sec:algorithm}

In this section, we describe the steps of our instance-based
POS-induction algorithm:
\begin{enumerate}
  \item Sample $r$ substitutes for each word instance in the target
    corpus using an n-gram language model.
  \item Construct $r$ tuples for each instance where each tuple
    consists of a sampled substitute, the target word, and the
    morphological and orthographical features of the target word (see
    Table~\ref{tab:sampleswithfeatures}).
  \item Construct Euclidean embeddings of each word and each feature based on
    all tuples following Gleberson et al.\shortcite{globerson2007euclidean}
    and Maron et al.\shortcite{maron2010sphere}.
  \item Construct a vector representation for each instance by
    concatenating the embedding of the target word with the average of
    its substitute embeddings.
  \item Use $k$-means clustering to cluster the instance vectors where
    $k$ is equal to the number of gold tags.
  %% \item Construct a mapping from clusters to tags for evaluation using
  %%   the most frequent tag found in each cluster.
\end{enumerate}

Steps 1 and 2 construct a tuple representation for each instance.
Table~\ref{tab:sampleswithfeatures} gives some example tuples for Sentence (1)
from the previous section.  In this example $r=3$, so three substitutes are
sampled for each instance as contextual features.  The sampling is with
replacement from the substitute word distribution of a context given by the
n-gram language model, so some substitute words may be repeated.  The target
word and its other features are identical for each of the $r$ tuples
representing a single instance.

\begin{table}[t]
  \centering
  \begin{tabular}{|lllll|}
    \hline
    {\bf Word} & {\bf Subst} & {\bf Suf} & {\bf Cap} & {\bf Num} \\
    \hline
    Vinken & Makhlouf & -- & T & F\\
    Vinken & Makhlouf & -- & T & F\\
    Vinken & \unk & -- & T & F\\
    61 & 20 & -- & F & T\\
    61 & 2000 & -- & F & T\\
    61 & eleven & -- & F & T\\
    years & years & -s & F & F\\
    years & years & -s & F & F\\
    years & years & -s & F & F\\
    \hline
  \end{tabular}
  \caption{The tuples constructed for the instances of ``Vinken'',
    ``61'' and ``years'' from Sentence (1).  The elements of each tuple
    are the target word, sampled substitute, suffix, capitalization, and
    number features.}
  \label{tab:sampleswithfeatures}
\end{table}

%% We construct the co-occurrence data as word--features tuples that consist of
%% word, and its contextual (substitutes), orthographic and morphological
%% features.  Contextual features are sampled from the substitute word
%% distribution of the instance context.  If $r$ random substitutes are sample for
%% each instance than there will be $r$ identical tuples except the contextual
%% features.  Table~\ref{tab:sampleswithfeatures} presents the co-occurrence
%% tuples of each instance in a sample sentence when $r$ is equal to 1.

%% \begin{table*}[!t]
%%   \centering
%%   \footnotesize
%% \begin{tabular}{|lllllll|}
%%   \hline
%%   \textbf{Word} & {\bf Contextual} & {\bf Morphology} &
%%   \specialcell{{\bf Initial}\\{\bf Capital}} & {\bf Number} &
%%   \specialcell{{\bf Contains}\\{\bf Hypen}} &
%%   \specialcell{{\bf Initial}\\{\bf Apostrophe}}
%%   \\
%%   \hline
%%   W:Pierre & \textit{C:Adrian} & & {\it F:IC} &&&\\
%%   W:Vinken & \textit{C:Danon} & & {\it F:IC} &&&\\
%%   W:, & \textit{C:\{} & & &&&\\
%%   W:61 & \textit{C:fourteen} & & & {\it F:N}&&\\
%%   W:years & \textit{C:years} & {\it F:s} &&&&\\
%% %%W:old & \textit{C:old} & & &&&\\
%% %%W:join & \textit{C:head} &&&&&\\
%% %%W:the & \textit{C:its} &&&&&\\
%% %%W:board & \textit{C:company} &&&&&\\
%% %%W:as & \textit{C:as} &&&&&\\
%% %%W:a & \textit{C:a} &&&&&\\
%% %%W:nonexecutive & \textit{C:non-executive} &&&&&\\
%% %%W:director & \textit{C:chairman} & {\it F:or}&&&&\\
%% %%W:Nov. & \textit{C:May} &&{\it F:IC}&&&\\
%% %%W:29 & \textit{C:9} &&&{\it F:N}&&\\
%% %%W. & \textit{C:.} & &&&&\\
%%   \hline
%% \end{tabular}
%% \caption{The first five words of the input sentence \textit{``Pierre Vinken, 61
%%   years old, will join the board as a nonexecutive director Nov.~29 .''} is
%%   represented with their contextual, orthographic and morphological features as
%%   tuples.  The leftmost column presents the target word, second column
%%   represents the contextual, third column is the morphological and the rest of
%%   the columns are the orthographic features.  Unobserved features are set to
%%   null.}
%% \label{tab:sampleswithfeatures}
%% \end{table*}

In step 3, we construct Euclidean embeddings for each unique word and
feature value using the multi-variable version of the CODE algorithm
described in \cite{globerson2007euclidean}.  Given two categorical
variables $W$ and $F$, the CODE algorithm constructs Euclidean
embeddings (vectors) for each of their distinct values in the same
space.  The distance between the embedding of a $w$ value, $\phi(w)$,
and the embedding of an $f$ value, $\psi(f)$, is related to their joint
distribution $p(w, f)$ as
follows\footnote{\cite{globerson2007euclidean} describes several ways
  to relate distances to probabilities, the model used here is the
  marginal-marginal (MM) model.}

\[ p(w,f) = \frac{1}{Z} \bar{p}(w) \bar{p}(f) e^{-d^2_{w,f}} \]

\noindent where $\bar{p}$ represents empirical probabilities
(frequencies from the training data), $d_{w,f}$ is the distance
between the embeddings $\phi(w)$ and $\psi(f)$ and $Z=\sum_{w,f}
\bar{p}(w) \bar{p}(f) e^{-d^2_{w,f}}$ is a normalization constant.
Starting with random vectors for each distinct value of $w$ and $f$,
we use stochastic gradient ascent to move the embedding vectors around
to maximize the likelihood given by this model.  Calculating the
normalization constant $Z$ is the most expensive part of this
procedure.  We solve this problem following \cite{maron2010sphere} who
suggest that a constant $Z$ approximation can be used if the embedding
vectors are kept on the unit sphere.

As Table~\ref{tab:sampleswithfeatures} shows, considering the target
word and its contextual, morphological and orthographic features gives
us more than two variables.  Yatbaz et al.
\shortcite{yatbaz-sert-yuret:2012:EMNLP-CoNLL} adopt the two
variable CODE algorithm to this multi-variable case in an ad-hoc
manner by considering the target word as $w$ and all other features as
distinct $f$ values.  We implement the multi-variable extension of
CODE suggested by \cite{globerson2007euclidean} (Section 6.2) which
optimizes the following likelihood function:

\[ \ell(\phi, \psi^{(1)}, \ldots, \psi^{(K)}) =
    \sum_{i=1}^K \sum_{w,f^{(i)}} \bar{p}(w,f^{(i)}) \log p(w,f^{(i)}) \]

\noindent where $w$ are the target words, $\phi$ are the embeddings of
target words, $K$ is the number of different types of
features\footnote{For example the number of features $K=4$ in
  Table~\ref{tab:sampleswithfeatures}: Subst, Suf, Cap, and Num.},
$f^{(i)}$ are the values of the $i$'th feature, and $\psi^{(i)}$ are
the embeddings for the values of the $i$'th feature.  This extension
can be seen as a set of $K$ bivariate CODE models $p(w,f^{(i)})$ that
share the same target word embeddings $\phi(w)$ but build their own
feature embeddings $\psi^{(i)}(f^{(i)})$.

%% To handle co-occurrence tuples we use the modified version of S-CODE that can
%% model more than two variables (see Appendix~\ref{app:multiscode}).  We feed
%% the tuples to the modified S-CODE which places $n$-dimensional embeddings for
%% word types that frequently co-occur with the same features (and features that
%% co-occur with the same words types) close to each other on the sphere.
%% Figure~\ref{fig:scodeexample} illustrates the embeddings of a sample
%% co-occurrence data on a sphere after S-CODE converges.  This modified S-CODE is
%% aware of the feature types which enables us to construct our instance based
%% representation.  In addition, the modified S-CODE can weight the different
%% feature types and this will be the interest of future work.

%% \begin{figure}[h]
%% \centering
%%  \begin{minipage}[c]{0.49\columnwidth}
%%   \footnotesize
%%   \begin{tabular}{l|l}
%%     \textbf{Word} & \textbf{Substitute} \\
%%     \hline
%%     $\hdots$&$\hdots$\\
%%     W:director & S:chairman \\
%%     W:chief & S:chairman \\
%%     $\hdots$&$\hdots$\\
%%     W:Pierre & S:John \\
%%     W:Frank & S:John \\
%%     $\hdots$&$\hdots$\\
%%   \end{tabular}
%%   \end{minipage} \hfill
%%   \begin{minipage}[c]{0.49\columnwidth}
%%     \raisebox{-\height}{
%%       \includegraphics[width=1\columnwidth]{scode-ex.png}
%%     }
%%   \end{minipage}
%%   \caption{The table on the left is a co-occurrence data and  figure on the
%%   right represents the final embeddings of the words and contextual features
%%   after S-CODE converges.  Dashed circles represent the possible groupings of the
%%   word type embeddings on the sphere.}
%%   \label{fig:scodeexample}
%% \end{figure}

%The limitation of representing co-occurrence data as pairs is that S-CODE can
%not distinguish whether the type of the word-feature pair is contextual,
%orthographic or morphological.

Step 4 constructs a vector representation for each word instance with the
concatenation of its word type embedding and the average of its $r$ substitute
embeddings.  If the original embeddings are in $d$ dimensional space, this
results in a $2d$ dimensional vector representing an instance.

Step 5 clusters these $2d$ dimensional instance vectors using a
modified k-means algorithm with smart initialization
\cite{arthur2007k} and assigns each instance to one of $k$ clusters.
%% Step 6 constructs a mapping between the clusters and the gold tags
%% for evaluation.

%% Yatbaz et al.\shortcite{yatbaz-sert-yuret:2012:EMNLP-CoNLL} model co-occurrence
%% pairs using the S-CODE with two variables and cluster the embeddings of word
%% types with weighted k-means algorithm.  The sentences in
%% Figure~\ref{fig:typelimitation} illustrates the limitation of clustering word
%% type embeddings.  The word {\em offer} is a {\em verb} in the first sentence
%% and a {\em noun} in the second one.  S-CODE constructs only one embedding for
%% each unique word type and feature value.  Thus clustering the word type
%% embeddings is actually applying the one-tag-per-word assumption.

%% \begin{figure}[ht]
%%   %  \begin{minipage}[c]{\columnwidth}
%%     \begin{tabular}{ll}
%%       (1) & $\hdots$ it will also {\em offer} buyers the option $\hdots$\\
%%       &{\bf Substitutes:} give, help, attract\\
%%       (2) & The {\em offer} is being launched $\hdots$\\
%%       &{\bf Substitutes:} campaign, project, scheme\\
%%     \end{tabular}
%%    \caption{Ambiguous occurrences of the word {\em offer}.}
%%    \label{fig:typelimitation}
%%    %\end{minipage} \hfill
%%  \end{figure}
%% On the other hand, the substitutes of {\em offer} in both of the sentences can
%% semantically and syntacticly disambiguates the correct category of the
%% corresponding occurrences.

%% The next section presents the results of our system and compares them with the
%% results of the word based state-of-the-art system.
%% To construct the co-occurrence data we pair each word instance with randomly
%% sampled substitutes that can be observed in the context of the corresponding
%% instance and with orthographic and morphological features of the word instance.
%% Random substitutes were sampled (with replacement) from a substitute word
%% distribution for the context calculated based on an n-gram language model.
%%
%% We enriched the word--substitute co-occurrence data by extracting morphological
%% and orthographic features and incorporating them as word--feature pairs.  They
%% fed the co-occurrence data into the S-CODE algorithm.  S-CODE places the
%% embeddings for word types that frequently co-occur with the same substitutes or
%% features (and substitutes or features that co-occur with the same words) close
%% to each other on the $n$-dimensional sphere.  Finally, they apply k-means
%% clustering to group vectors of word types to induce word categories.
%%
%% First, we construct a pairwise co-occurrence
%% representation of words and their substitutes.  Next, we map each word and each
%% substitute in the co-occurrence data to real vectors (embeddings) on an
%% $n$-dimensional sphere using the S-CODE algorithm \cite{maron2010sphere}.
%% S-CODE places the vectors for words that frequently co-occur with the same
%% substitutes (and substitutes that co-occur with the same words) close to each
%% other on the sphere.  We then construct vectors for each word instance by using
%% the embeddings of the word itself and its sampled substitutes in the
%% co-occurrence data.  Finally, we apply k-means clustering to group these
%% vectors to induce word categories.
%%
%% In Section~\ref{sec:cooc} we detail the representation of words and their
%% substitutes as co-occurrence data, in Section~\ref{sec:embedding} we describe
%% the embedding algorithm, and finally Section~\ref{sec:clustering} describes how
%% we represent the word instances using the embeddings calculate in the previous
%% step.
%%
%% \subsection{Context Representation}
%% \label{sec:cooc}
%% % How we represent the context?
%% % How we relate the word and the context?
%%
%% We represent the context of a word with random substitutes that are
%% likely to occupy the same position as the word.  We sample random
%% substitutes (with replacement) from a substitute word distribution for
%% the context calculated based on an n-gram language model.  The sample
%% space of the substitute word distribution is the vocabulary of the
%% language model.
%% %% \footnote{Sampled substitutes might include the unknown
%% %%   word tag \unk\ representing words outside the fixed size
%% %%   vocabulary of the language model.  For example proper nouns
%% %%   typically have \unk\ as a substitute.}
%% In effect, we are using substitute word distributions and the sampled random
%% substitutes as {\em contextual features} that represent properties of a word's
%% position.  Table~\ref{tab:subdist} shows the substitute word distributions for
%% some positions in an example sentence.
%% %% \begin{table*}[t]
%% %%   \footnotesize
%% %%   \centering
%% %%   \caption{The substitute word distributions (with probabilities in
%% %%     parentheses) for some of the positions in the example sentence
%% %%     \textit{``Pierre Vinken, 61 years old, will join the board as a
%% %%     nonexecutive director Nov.~29.''} based on a 4-gram language
%% %%   model.}
%% %%   \label{tab:subdist}
%% %%   \begin{tabular}{|ll|} \hline
%% %%     \textbf{will:} & \textit{will} (0.9985), \textit{would} (0.0007), \textit{to} (0.0006), \textit{also} (0.0001), $\ldots$ \\
%% %%     \textbf{join:} & \textit{join} (0.6528), \textit{leave} (0.2140), \textit{oversee} (0.0559), \textit{head} (0.0262), \textit{rejoin} (0.0074), $\ldots$ \\
%% %%     \textbf{the:}  &\textit{its} (0.9011), \textit{the} (0.0981), \textit{a} (0.0006), $\ldots$ \\
%% %%     \textbf{board:} & \textit{board} (0.4288), \textit{company} (0.2584), \textit{firm} (0.2024), \textit{bank} (0.0731), \textit{strike} (0.0030), $\ldots$ \\
%% %%     \hline
%% %%   \end{tabular}
%% %% \end{table*}
%% %%
%% To capture the relation between each word and its context we construct
%% a co-occurrence representation by pairing the words with randomly
%% sampled substitutes.  Table~\ref{tab:samples} shows random substitutes of each
%% word and their pairwise co-occurrence representation input to S-CODE on an
%% example sentence.  It is possible (and beneficial) to sample more than one
%% substitute and generate multiple pairs for the same word-context pair as seen
%% in Table~\ref{tab:samples}.  In the co-occurrence data, a target word might
%% appear both as a word and a random substitute therefore to clarify this
%% ambiguity we prepend ``W:'' and ``S:'' to words and substitutes, respectively.
%% The calculation of substitute distributions and substitute word sampling are
%% detailed in Appendix~A.
%% %% \begin{table}[h]
%% %%   \footnotesize
%% %%   \caption{The table on the left shows three possible substitutes
%% %%     sampled with replacement for each position in an example sentence
%% %%     based on a 4-gram language model.  The table on the right is the
%% %%     pairwise co-occurrence data fed to the S-CODE algorithm derived
%% %%     from these samples.  The prefixes ``W:'' and ``S:'' are used to
%% %%     distinguish target words and substitutes.  Sampled substitutes
%% %%     might include the unknown word tag ``\unk'' representing words
%% %%     outside the fixed size vocabulary of the language model.}
%% %% \begin{tabular}{|ll|} \hline
%% %% \textbf{Word} & \textbf{Random Substitutes}\\
%% %% \hline
%% %% Pierre & \textit{Mr.}  / \textit{Pierre} /  \textit{John}\\
%% %% Vinken & \textit{\unk} / \textit{Beregovoy} / \textit{Cardin}\\
%% %% %, & \textit{,} / \textit{,} / \textit{,}\\
%% %% %61 & \textit{48} / \textit{52} / \textit{41}\\
%% %% %years & \textit{years} /  \textit{years} /  \textit{years}\\
%% %% %old & \textit{old} /  \textit{old} /  \textit{old}\\
%% %% %, & \textit{,} /  \textit{,} /  \textit{,}\\
%% %% %will & \textit{will} /  \textit{will} /  \textit{will}\\
%% %% $\hdots$&\\
%% %% join & \textit{head} /  \textit{join} /  \textit{leave}\\
%% %% the  & \textit{its} /  \textit{its} /  \textit{the}\\
%% %% %board & \textit{board} /  \textit{company} / \textit{firm}\\
%% %% $\hdots$&\\
%% %% %as & \textit{as} / \textit{as} / \textit{as}\\
%% %% %a & \textit{a} / \textit{a} / \textit{a}\\
%% %% %nonexecutive & \textit{nonexecutive} / \textit{non-executive} / \textit{nonexecutive}\\
%% %% $\hdots$&\\
%% %% director & \textit{chairman} / \textit{chairman} / \textit{director}\\
%% %% $\hdots$&\\
%% %% %Nov. & \textit{April} / \textit{May} / \textit{of}\\
%% %% %29 & \textit{16} /  \textit{29} / \textit{9}\\
%% %% %. & \textit{.}  / \textit{.} / \textit{.}\\
%% %% \hline
%% %% \end{tabular}
%% %% \quad
%% %% \begin{tabular}{|ll|}
%% %% \hline
%% %% \textbf{Word} & \textbf{Substitute}\\
%% %% \hline
%% %% W:Pierre & \textit{S:Mr.}\\
%% %% W:Pierre & \textit{S:Pierre}\\
%% %% W:Pierre & \textit{S:John}\\
%% %% W:Vinken & \textit{S:\unk}\\
%% %% W:Vinken & \textit{S:Beregovoy}\\
%% %% W:Vinken & \textit{S:Cardin}\\
%% %% $\hdots$&\\
%% %% W:join & \textit{S:head}\\
%% %% W:join & \textit{S:join}\\
%% %% W:join & \textit{S:leave}\\
%% %% W:the & \textit{S:its}\\
%% %% W:the & \textit{S:its}\\
%% %% W:the & \textit{S:the}\\
%% %% $\hdots$&\\
%% %% W:director & \textit{S:chairman}\\
%% %% W:director & \textit{S:chairman}\\
%% %% W:director & \textit{S:director}\\
%% %% $\hdots$&\\
%% %% \hline
%% %% \end{tabular}
%% %% \label{tab:samples}
%% %% \end{table}
%%
%% The next section describes the S-CODE algorithm which takes the
%% pairwise co-occurrence data as its input and calculates the embeddings
%% of the words and their substitutes on an $n$-dimensional sphere.
%%
%% \subsection{Co-occurrence Embedding}
%% \label{sec:embedding}
%% The S-CODE algorithm maps each unique word and substitute in the
%% co-occurrence data to a real vector (embedding) on an $n$-dimensional
%% sphere as detailed in Appendix~B.  The basic idea of the mapping is
%% that words and substitutes that are frequently observed as pairs in
%% the co-occurrence data will have close embeddings while pairs
%% not observed together will have embeddings that are far apart from each
%% other.
%%
%% %%   \begin{minipage}[c]{0.28\columnwidth}
%% %%     \footnotesize
%% %%     \begin{tabular}{l|l}
%% %%       \textbf{Word} & \textbf{Substitute} \\
%% %%       \hline
%% %%       $\hdots$&$\hdots$\\
%% %%       W:offer & S:give\\
%% %%       W:offer & S:help\\
%% %%       W:offer & S:attract\\
%% %%       W:offer & S:campaign\\
%% %%       W:offer & S:project\\
%% %%       W:offer & S:scheme\\
%% %%       $\hdots$&$\hdots$\\
%% %%     \end{tabular}
%% %%   \end{minipage} \hfill
%% %%
%% %%  \begin{minipage}[c]{\columnwidth}
%% %%     \raisebox{-\height}{
%% %%       \includegraphics[width=0.5\columnwidth]{sphere.png}
%% %%     }
%% %%   \end{minipage}
%% %%   \caption{The figure on the left presents the input sentences and the randomly
%% %%     sampled substitutes of the word {\em offer} in each sentences.   The right
%% %%   one presents the final embeddings on a representative sphere after S-CODE
%% %%   converges.}
%% %%   \label{fig:scodeexample}
%% %% \end{figure}
%%
%% The co-occurrence data in Figure~\ref{fig:scodeexample} consists of
%% pairs such as (\textit{W:director}, \textit{S:chairman}) and
%% (\textit{W:chief}, \textit{S:chairman}) therefore S-CODE forces the
%% embeddings of \textit{W:director} and \textit{W:chief} to be close to
%% the embedding of \textit{S:chairman}.  Similarly the embeddings of
%% \textit{W:Pierre} and \textit{W:Frank} will be close to the embedding
%% of \textit{S:John} because they are frequently co-occurring pairs.  As
%% a result the final embeddings of \textit{W:director} and
%% \textit{W:chief} will be close to each other due to the common
%% substitute \textit{S:chairman} and will be apart from
%% \textit{W:Pierre} and \textit{W:Frank} due to the lack of common
%% substitutes (similarly the embeddings of \textit{W:Pierre} and
%% \textit{W:Frank} will be close to each other due to \textit{S:John}).
%%
%% The coordinates of the embeddings for each unique word and substitute
%% constitute the input to the clustering stage as described in the next
%% subsection.
%%
%% % How we relate final embeddings and the input pairs?
%% %% S-CODE constructs embeddings on an $n$-dimensional sphere for each word
%% %% type and substitute.  Each pair in the co-occurrence data can be
%% %% represented in three different ways by using the output of S-CODE: (1)
%% %% word embedding (${\bf W}$) which represents the word type information,
%% %% (2) substitute embedding (${\bf C}$) which represents the context
%% %% information, and (3) concatenation of word and substitute embeddings
%% %% (${\bf W}\oplus{\bf C}$).  In the next section we apply k-means
%% %% clustering to these three representation and analyze the
%% %% characteristic of final clusters.
%%
%% \subsection{Clustering}
%% \label{sec:clustering}
%% %% In Section~\ref{sec:cooc} we describe the transformation of an input
%% %% sentence to a co-occurrence data and we represent each target word
%% %% with the word--substitute pair(s).  In the previous section we
%% %% construct embeddings for each value observed in the co-occurrence data
%% %% using the S-CODE algorithm.
%%
%% At this stage, each unique word in the text and each unique substitute
%% sampled to represent their contexts is mapped to a real vector
%% embedding on an $n$ dimensional sphere\footnote{In fact many words
%%   that appear in the text also appear as substitutes and thus get two
%%   embeddings.}.  We apply the instance weighted k-means clustering
%% algorithm to three different representations derived from these
%% embeddings, each with its own advantages and disadvantages:
%%
%% \paragraph{Type Based:}
%% In this clustering, each target word {\em type} has a single embedding, and gets
%% assigned to a single cluster.  Clustering word embeddings was previously
%% explored in \cite{yatbaz-sert-yuret:2012:EMNLP-CoNLL}, which achieved the best
%% results to date (80\% \mto) for English.  Sections~\ref{sec:typevsinstance}
%% summarize these experiments for completeness.
%% %% \paragraph{Clustering substitute embeddings (${\bf S}$)}
%% %% In a second set of experiments, we ignore target word embeddings and
%% %% apply clustering only to substitute embeddings, associating each
%% %% substitute with a unique cluster.  We then categorize target word {\em
%% %%   tokens} based on what cluster the majority of their substitutes
%% %% belong.  It is important to note that in this setting we are ignoring
%% %% the identity and features of the target words and in effect clustering
%% %% word contexts (substitutes are determined by the context and are
%% %% conditionally independent of the target word).
%% %%
%% %% For example, the target word {\it W:board} in Table~\ref{tab:samples}
%% %% will be represented with the embeddings of {\it S:board}, {\it
%% %%   S:company} and {\it S:firm} while another occurrence of the word
%% %% {\it W:board} in a different context might be represented with
%% %% embeddings of different substitutes such as {\it S:embark} or {\it
%% %%   S:enter}.  Each occurrence of the target word ``board'' is assigned
%% %% to the cluster in which the majority of its substitute embeddings are
%% %% present\footnote{Ties are broken randomly.}.  This approach generally
%% %% results in higher accuracy for highly ambiguous words like {\em offer}
%% %% where clustering substitute embeddings achieves .82 \mto\ compared
%% %% to the one-tag-per-word upper bound of .74.
%% %% Section~\ref{sec:clustering-s} presents the results of experiments
%% %% clustering substitute embeddings.
%% %%
%% %% Unfortunately such highly ambiguous words do not constitute a
%% %% significant portion of the corpus and the overall accuracy suffers
%% %% (.64 compared to .80 \mto\ for word clustering).  We also observed
%% %% similar results in our preliminary experiments without S-CODE trying
%% %% to cluster contexts directly (using the Kullback-Leibler divergence
%% %% between their substitute distributions).  Many common words that occur
%% %% in similar contexts and that have similar substitutes, e.g. {\em his}
%% %% and {\em the}, belong to different parts of speech.  In addition,
%% %% words that are generally not substitutable like ``do'' and ``put'' are
%% %% placed in the same category by the PTB.  This suggests that the
%% %% identity and features of the target word are indispensable and that a
%% %% purely substitutability based linguistic definition is insufficient
%% %% for inducing parts of speech as tagged in the PTB.
%%
%% \paragraph{Instance Based:}
%% In this clustering, we represent each word instance by concatenating the type
%% embedding ($n$ dimensional) with the average of substitutes of that particular
%% instance ($n$ dimensional).  We then apply k-means to the resulting
%% $2n$-dimensional vectors and categorize each instance of a type separately.
%% For instance, the target word ``Pierre'' in Table~\ref{tab:samples} will be
%% represented by concatenating the embedding of {\it W:Pierre} with the average
%% of the embeddings of {\it S:Mr.}, {\it S:Pierre} and {\it S:John}.  This model
%% do not employ the one-tag-per-word assumption and clusters word instances
%% therefore it handles ambiguity.  Clusters that are constructed according to
%% this representation tend to assign fewer categories to each word type than
%% substitute clustering due to the concatenation of ${\bf W}$.  The advantage in
%% highly ambiguous words is still retained (e.g. the \mto\ for {\em offer} is
%% .XX) and the overall result is comparable compared to clustering of word
%% embeddings.  Section~\ref{sec:instance} presents results of the instance based
%% clustering.
%%
%% \paragraph{Summary} The first clustering applies the one-tag-per-word
%% assumption from the beginning and clusters word types instead of instances.
%% %The second setting clusters word contexts (as represented by
%% %substitutes) and is able to categorize individual word tokens.
%% %However it ignores the identity of the target word.
%% The second one clusters word instances by representing each instance with the
%% concatenation of the word type and average of corresponding substitute
%% embeddings.  The target word is represented without enforcing the
%% one-tag-per-word assumption improves the results on highly ambiguous words
%% while achieving close results with the state-of-the-art system.
%% Section~\ref{sec:exp} compares the performance of these two clustering on the
%% part of speech induction problem, as well as
%% experiments with different features and languages.


%  American Nuclear Society Transaction template
%  by Diego Mandelli (INL)
%  Most of the template has been built by Seth R. Johnson
%  based on the ANS transaction guidelines

\documentclass{anstrans}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{amsmath}
% \usepackage{fmtcount}

\usepackage[none]{hyphenat}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{PERFORMING PROBABILISTIC RISK ASSESSMENT THROUGH RAVEN}
\author{A. Alfonsi \and  C. Rabiti \and D. Mandelli \and J.J. Cogliati \and R.A. Kinoshita}

\institute{
Idaho National Laboratory
}

\email{ \{andrea.alfonsi, cristian.rabiti, diego.mandelli, joshua.cogliati, robert.kinoshita\}@inl.gov }

%%%% packages and definitions (optional)
\usepackage{graphicx} % allows inclusion of graphics
\usepackage{booktabs} % nice rules (thick lines) for tables
\usepackage{microtype} % improves typography for PDF
\usepackage{dblfloatfix} % fix two-column floats to allow bottom placement

\newcommand{\SN}{S$_N$}
\renewcommand{\vec}[1]{\bm{#1}} %vector is bold italic
\newcommand{\vd}{\bm{\cdot}} % slightly bold vector dot
\newcommand{\grad}{\vec{\nabla}} % gradient
\newcommand{\ud}{\mathop{}\!\mathrm{d}} % upright derivative symbol

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \twocolumn[
    \begin{@twocolumnfalse}
        \maketitle
    \end{@twocolumnfalse}
  ]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RAVEN (\textbf{R}eactor \textbf{A}nalysis and \textbf{V}irtual control \textbf{EN}viroment)~\cite{ravenFY12,mandelliANS2012} is a software framework that acts as the control logic driver for the Thermal-Hydraulic code RELAP-7, a newly developed software at Idaho National Laboratory. This paper provide an overview of the RAVEN software structure and its utilization in conjunction with RELAP-7/MOOSE~\cite{MOOSE,relap7FY12}. RAVEN is a multi-purpose Probabilistic Risk Assessment (PRA) code that allows dispatching different functionalities.
It is designed to derive and actuate the control logic required to simulate both plant control system and operator actions (guided procedures) and to perform both Monte-Carlo sampling of random distributed events and dynamic event tree based analysis~\cite{ADAPTHakobyan}.
In order to assist the user in the input/output handling, a Graphical User Interface (GUI) and a post-processing data mining module, based on dimensionality and cardinality reduction~\cite{mandelliEsrel2011}, are available.
This paper focuses on the link between the software layout and the mathematical framework from which its structure is derived. In order to show the code capabilities, a demo of a Station Black Out (SBO) analysis of a simplified Pressurized Water Reactor (PWR) model is presented.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{MATHEMATICAL FRAMEWORK}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\label{sec:mathFramework}
Let be $\bar{\theta}(t)$ a vector describing the plant status in the phase space; the dynamic of the plant, including the control system, can be summarized by the following equation:
\begin{equation}
\frac{\partial \bar{\theta}}{\partial t} = \bar{H}(\theta(t),t)
\label{eq:SystemDynamics}
\end{equation}
In the above equation it is assumed the time differentiability in the phase space. Performing an arbitrary decomposition of the phase space, the following statement is obtained:
\begin{equation}
\bar{\theta}=\binom{\bar{x}}{\bar{v}}
\label{eq:firstDecomposition}
\end{equation}

The decomposition is made in such a way that $\bar{x}$ represents the unknowns solved by RELAP-7, while $\bar{v}$ are the variables directly controlled by the control system (i.e., RAVEN). Equation~\ref{eq:SystemDynamics} can now be rewritten as follows:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v},t) \\
\end{cases}
\label{eq:generalSystemEquation}
\end{equation}
It is possible to note that the function $\bar{V}(\bar{x},\bar{v},t)$ representing the control system, does not depend on the knowledge of the complete status of the system but on a restricted subset (i.e. control variables) $\bar{C}$:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v},t) \\
\bar{C} = \bar{G}(\bar{x},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v},t)
\end{cases}
\label{eq:generalSystemEquationwithControl}
\end{equation}

The system of equations in Eq.~\ref{eq:generalSystemEquationwithControl} is fully coupled and has commonly been solved by an operator splitting approach. The reasons for this choice are several:
\begin{itemize}
\item Control system reacts with an intrinsic delay
\item The reaction of the control system might move the system between two different discrete states and
therefore numerical errors will be always of first order unless the discontinuity is treated explicitly.
\end{itemize}
\begin{figure}
\centering
\includegraphics[width=0.35\textwidth]{figures/ControlSystemSoftwareLayout.pdf}
\caption{Control System Software Layout.}
\label{fig:ControlSoftwareLayout}
\end{figure}
Thus, RAVEN is using this approach (Fig.~\ref{fig:ControlSoftwareLayout}) to solve Eq.~\ref{eq:generalSystemEquationwithControl} which becomes:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\bar{C} = \bar{G}(\bar{x},t) & t_{i-1}\leq t\leq t_{i} = t_{i-1} + \Delta t_{i}\\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\end{cases}
\label{eq:generalSystemEquationwithControlSplitting}
\end{equation}
Even if all information needed is contained in $\bar{x}$ and $\bar{v}$, it is not a practical and efficient way to implement the control system. Hence, a system of auxiliary variables has been introduced.
The auxiliary variables are those that in statistical analysis are artificially added, when possible, to non-Markovian systems into the space phase to obtain a Markovian behavior back, so that only the information of the previous time step is needed to determine the future status of the system.
Thus, the introduction of the auxiliary system into the mathematical framework leads to the following formulation of the Eq.~\ref{eq:generalSystemEquationwithControlSplitting}:
\begin{equation}
\begin{cases}
\dfrac{\partial \bar{x}}{\partial t} = \bar{F}(\bar{x},\bar{v}_{t_{i-1}},t) \\
\bar{C} = \bar{G}(\bar{x},t) & t_{i-1}\leq t\leq t_{i} = t_{i-1} + \Delta t_{i}\\
\dfrac{\partial \bar{a}}{\partial t} = \bar{A}(\bar{x},\bar{C},\bar{a}_{t_{i-1}},\bar{v}_{t_{i-1}},t) \\
\dfrac{\partial \bar{v}}{\partial t} = \bar{V}(\bar{x},\bar{v}_{t_{i-1}},\bar{a},t)
\end{cases}
\label{eq:generalSystemEquationwithControlSplittingAndAux}
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{SOFTWARE STRUCTURE}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RAVEN, is plugged with the software environment MOOSE~\cite{MOOSE}. MOOSE is a computer simulation framework,  developed at Idaho National Laboratory (INL), that simplifies the process for predicting the behavior of complex systems and developing non-linear, multi-physics simulation tools. Other than providing the algorithms for the solution of the differential equation, MOOSE also provides all the manipulation tools for the \verb!C++! classes containing the solution vector. This framework has been used to construct and develop the Thermal-Hydraulic code RELAP-7, giving an enormous flexibility in the coupling procedure with RAVEN.

RELAP-7 is the next generation nuclear reactor system safety analysis. It will become the main reactor systems simulation toolkit for RISMC (\textbf{R}isk \textbf{I}nformed \textbf{S}afety \textbf{M}argin \textbf{C}haracterization)~\cite{mandelliANS_RISMC} project and the next generation tool in the RELAP reactor safety/systems analysis application series.
RAVEN has been developed in a high modular and pluggable way in order to enable easy integration of different programming languages (i.e., \verb!C++!, \verb!Python!) and coupling with other applications including the ones based on MOOSE. The code consists of four main modules:
\begin{itemize}
\item RAVEN/RELAP-7 interface
\item \verb!Python! Control Logic
\item \verb!Python! Calculation Driver
\item Graphical User Interface
\end{itemize}

The RAVEN/RELAP-7 interface, coded in \verb!C++!, is the container of all the tools needed to interact with RELAP-7/MOOSE. It has been designed in order to be general and pluggable with different solvers simultaneously in order to allow an easier and faster development of the control logic/PRA capabilities for multi-physics applications.
%(to properly generate the monitored quantities and accordingly modify the controlled
% parameters in the raven/relap7 simulation)
The interface provieds all the capabilities to generate the monitored quantities and accordingly modify the controlled parameters in the RELAP-7/MOOSE calculation.
%The interface provides all the capabilities to control, monitor, and process the %parameters/quantities in order to drive the RELAP-7/MOOSE calculation.
In addition, it contains the tools to communicate to the MOOSE input parser which information, i.e. input syntax, must be provided in order to run a RAVEN  calculation.\\The control logic module is used to drive a RAVEN/RELAP-7 calculation. Up to now it is implemented by the user via \verb!Python! scripting. The reason of this choice is to try to preserve generality of the approach in the initial phases of the project so that further specialization is possible and  inexpensive. The implementation of the control logic via \verb!Python! is rather convenient and flexible. The user only needs to know few \verb!Python! syntax rules in order to build an input. Although this extreme simplicity, it will be part of the GUI task to automatize the construction of the control logic scripting in order to minimize user effort.

The core of PRA analysis is contained in the module called "Raven Runner". It consists of a \verb!Python! driver in which Monte-Carlo based algorithm has been implemented. It calls RAVEN multiple times, changes initial conditions and seeds the random generator for the distributions.
The multiple calculations, required by the employment of these algorithms, can be run in parallel, using queues/sub-process/\verb!Python! systems. The analysis of dynamic stochastic systems through Monte-Carlo algorithm can be summarized as follows:
\begin{enumerate}
\item Initial Sampling of:
       \begin{enumerate}
       \item Physical parameters
       \item Initial conditions
       \item Transition conditions, i.e. time instant in which transition events occur (e.g., time in which a reactor scram occurs, etc.)
    \end{enumerate}
\item Run the system simulator using the values previously sampled and eventually applying a random noise to some parameters at each time step
\item Repeat 1 and 2 for a large number of calculations (user input)
\end{enumerate}
The "runner" basically performs a different seeding of the random number generator and interact, through RAVEN, with the \verb!Python! control logic input in order to sample the variables specified by the user.

As previously mentioned, a Graphical User Interface (GUI) is not required to run RAVEN, but it represents an added value to the whole code. The GUI is compatible with all the capabilities actually present in RAVEN (control logic, Monte-Carlo, etc.).  Its development is performed using QtPy, which is a \verb!Python! interface for a \verb!C++! based library (\verb!C++!) for GUI implementation. The GUI is based on a software named Peacock, which is a GUI interface for MOOSE based application and, in its base implementation, is only able to assist the user in the creation of the input.  In order to make it fit all the RAVEN needs, the GUI has been specialized and is in continuous evolution.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{DEMO FOR A PWR PRA ANALYSIS}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In order to show the capabilities of RAVEN coupled with RELAP-7/MOOSE, a PRA analysis on a simplified PWR model (Fig.~\ref{fig:PWRmodel}) has been employed.
\begin{figure}
   \centering
    \includegraphics[width=0.4\textwidth]{figures/PWR_TMI_SCHEME.PNG}
    \caption{PWR model scheme.}
    \label{fig:PWRmodel}
\end{figure}
\\Since RELAP-7 still has limitations for the component controllable parameters and models, it has been necessary to act on unconventional factors (i.e. inlet/outlet friction factors in order to simulate a realistic pump coast-down).
\begin{figure} [H]
\centering
  \centering
  \includegraphics[width=0.35\textwidth]{figures/PRA_dist2.png}
  \label{fig:pdf_temp}
   \caption{Comparison between max reached clad temperature and clad failure temperature distributions: Probability distribution functions.}
\label{fig:distributionResults}
\end{figure}

The Probabilistic Risk Assessment analysis has been performed simulating a Station Black Out accident, running Monte-Carlo samplings (400 simulations) on the recovery time of the diesel generators $t_{1}$ (Normal distribution, mu = 120 s, sigma = 20 s) and the clad failure temperature $TC{f}$(Triangular distribution, xPeak = 1477.59 K, xMin~ =~1255.37 K, xMax = 1699.82 K). Since the scope of this demo is to show the functionalities contained in RAVEN and RELAP-7 is not yet optimized for long simulation times, the transient has been accelerated in order to simulate a maximum of 300 seconds.
Figure~\ref{fig:distributionResults} shows the distribution of the maximum temperature reached by the clad in the core channels (blue histogram) and compares it with the distribution of clad failure temperature (red histogram).
As already mentioned, the transient has been accelerated, since the scope of the analysis was just to show RAVEN capabilities to perform stochastic analysis of relatively complex systems. %That can explain the large overlapping of the two distributions, which indicates a high failure %probability of the system considered.

Figure~\ref{fig:limit_surface_rng_temp_and_dg} shows the limit surface, i.e. the boundaries between system failure (red points) and system success (green points), obtained by the 400 Monte-Carlo simulations. Since only two uncertain parameters have been considered (i.e., DG recovery time and clad fail temperature), this boundary lies in a 2-dimensional space.
The slope of the limit surface pictured in Fig.~\ref{fig:limit_surface_rng_temp_and_dg} also shows, in this particular demo, how the DG recovery time has a greater impact on the system dynamics then the clad failure temperature.
\begin{figure}
   \centering
    \includegraphics[width=0.45\textwidth]{figures/PRA_limitSurface.png}
    \caption{Limit Surface for the SBO analysis of a simplified PWR model}
    \label{fig:limit_surface_rng_temp_and_dg}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{CONCLUSIONS}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In this paper it has been presented RAVEN as a tool to perform dynamic PRA through Monte-Carlo sampling. In particular, the software structure and all the components that are involved in the computation have been presented, including system simulator (i.e., RELAP-7) and the control logic, characterized by a monitoring system and on-line control of selected parameters.
An example of PRA analysis has been also presented for a SBO-like case for a simplified PWR loop.
The description of the implementation for such case demonstrates how the flexibility of the software framework provides the basic tools to perform Dynamic PRA, uncertainty quantification and plant control.
Next capabilities, to be implemented to RAVEN and that are currently under development, include dynamic event tree generation~\cite{ADAPTHakobyan}, adaptive sampling~\cite{mandelliSVMANS} and more advanced data mining algorithms~\cite{mandelliEsrel2011}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{ENDNOTES}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This work is supported by the U.S. Department of Energy, under DOE Idaho Operations Office Contract DE-AC07-05ID14517. Accordingly, the U.S. Government retains a nonexclusive, royalty-free license to publish or reproduce the published form of this contribution, or allow others to do so, for U.S. Government purposes.

\bibliographystyle{ans}
\bibliography{bibl}
\end{document}