\hiddenappendixsection{Correctness Proof}
In this appendix, we reason about an \SLCO model~$m = \it{mn}\ \it{class^*}\ \it{obj^*}\ \it{chan^*}$ and a unidirectional, synchronous channel~$\it{chan} = \it{chn}()\ \textbf{sync from}\ \it{on_1}.\it{pn_1}\ \textbf{to}\ \it{on_2}.\it{pn_2}\ \in \ \it{chan^*}$.
As discussed in Chapter~\ref{chap:reusable-correct-transformations}, transformation~\TSim is considered to be correct if~$\it{LTS}(m)$ and~$\rho(\it{LTS}(\TSim(m, \it{chn})))$ are branching bisimilar~\cite{GlabWeijBisim96} for some appropriate label-renaming function~$\rho$,
where $\it{LTS}(m)$ refers to the labeled transition system~(LTS) of model~$\it{m}$ as defined by the operational semantics described in Appendix~\ref{ap:sos-slco}.
First, we discuss the label-renaming function~$\rho$ that corresponds to transformation~\TSim.
Second, we list the conditions for model~$\it{m}$ that must hold to ensure that~$\it{LTS}(m)$ and~$\rho(\it{LTS}(\TSim(m, \it{chn})))$ are branching bisimilar.
Finally, we show that a branching bisimulation between~$\it{LTS}(m)$ and~$\rho(\it{LTS}(\TSim(m, \it{chn})))$ exists by defining a relation~$R$ and showing that~$R$ is a branching bisimulation according to the definition given in Section~\ref{subsec:reusable-correct-transformations:correctness_of_simple}.

\subsection{Label-Renaming Function}
The definition of transformation~\TSim given in Appendix~\ref{sec:transformations-slco:simple} defines that all transitions in model~$\it{m}$ that send or receive signals over channel~$\it{chan}$ are replaced by transitions that send or receive signals with a modified name.
Let $\it{Sgn} \subseteq \SignalNames$ be the set of all signal names that are passed over channel~$\it{chan}$ in model~$\it{m}$.
Without loss of generality, we assume that all other channels in model~$\it{m}$ are used to pass signals with names not in~$\it{Sgn}$.
If this is not the case, the signals passed over these other channels can be renamed.
After applying transformation~\TSim to model~$\it{m}$, the set of names of signals that are passed over the modified channel~$\it{chan'}$ is~$\it{Sgn'} \cup \it{Sgn''}$, where~$\it{Sgn'} = \{``s\_" + \it{sgn} \mid \it{sgn} \in \it{Sgn}\}$ and~$\it{Sgn''} = \{``a\_" + \it{sgn} \mid \it{sgn} \in \it{Sgn}\}$.
The label-renaming function~$\rho$ that corresponds to transformation~\TSim is defined as follows, for every~$\it{sgn'} \equiv ``s\_" + \it{sgn}$ and~$\it{sgn''} \equiv ``a\_" + \it{sgn}$ such that~$\it{sgn}\in \it{Sgn}$.
%
\begin{itemize*}
\item $\rho(\textbf{send}~\it{sgn'()}) = \tau$
\item $\rho(\textbf{receive}~\it{sgn'()}) = \it{sgn()}$
\item $\rho(\textbf{send}~\it{sgn''()}) = \tau$
\item $\rho(\textbf{receive}~\it{sgn''()}) = \tau$
\end{itemize*}

\noindent
Renaming~$\rho$ is straightforwardly extended on LTSs.
By renaming the labels~$\textbf{receive}~\it{sgn'()}$ to $\it{sgn()}$, for every~$\it{sgn'} \equiv ``s\_" + \it{sgn}$ such that~$\it{sgn}\in \it{Sgn}$, we indicate that these labels represent successful communication.
The other labels are renamed to $\tau$ because they represent the implicit synchronization in the source model and should result in unobservable behavior of the target model.

\subsection{Applicability Conditions}
To ensure that~$\it{LTS}(m)$ and~$\rho(\it{LTS}(\TSim(m, \it{chn})))$ are branching bisimilar, a number of conditions must hold for model~$\it{m}$.
As mentioned above, the synchronous channel~$\it{chan}$ connects two objects~$\it{obj_1}$ and~$\it{obj_2}$.
Each object~$\it{obj_i}$ is named~$\it{on_i}$ and is an instance of class~$\it{class_i}$ with name~$\it{cn_i}$, for $i = 1,2$.
We require that the following conditions hold for~$\it{m}$.
\begin{enumerate}
\item Channel~$\it{chan}$ is unidirectional, as mentioned above.
\item At most one state machine~$\it{sm_1}$ of object~$\it{obj_1}$ sends signals over channel~$\it{chan}$.
\item At most one state machine~$\it{sm_2}$ of object~$\it{obj_2}$ receives signals over channel~$\it{chan}$.
\item Object~$\it{obj_1}$ is the only instance of class~$\it{class_1}$.
\item Object~$\it{obj_2}$ is the only instance of class~$\it{class_2}$.
\end{enumerate}
A model can be adapted with the model transformations described in Section~\ref{sec:slco:endogenous} if these conditions are not met.
If the first condition does not hold, transformation~\Transformation{uni} can be applied to replace a bidirectional channel with two unidirectional channels.
Furthermore, transformation~\Transformation{ex} can be applied if the second or third condition is not met.
It ensures that each pair of state machines communicates over a channel that is used by these two state machines only.
Finally, the transformation that clones classes can be applied if the last two conditions are not met.

Since only the behavior of the instances of classes~$\it{class_1}$ and~$\it{class_2}$ are affected by transformation~\TSim and objects~$\it{obj_1}$ and~$\it{obj_2}$ are the only instances of these classes, the behavior of all other objects is unchanged.
Furthermore, because state machines~$\it{sm_1}$ and~$\it{sm_2}$ are the only state machines that communicate over channel~$\it{chan}$, the behavior of all other state machines is also unchanged.
Finally, because channel~$\it{chan}$ is unidirectional, state machine~$\it{sm_1}$ can only send signals over this channel, and state machine~$\it{sm_2}$ can only receive signals over this channel.

\subsection{Bisimulation Relation}
We use~$\it{cf} = \langle m, \sobjs, \vglob, \vloc, \buf \rangle$ to represent a configuration of~$\it{LTS}(m)$ and~$\it{cf'} = \langle \TSim(m), \sobjs', \vglob', \vloc', \buf' \rangle$ to represent a configuration of~$\rho(LTS(\TSim(m, \it{chn})))$.
According to the definition of branching bisimilarity, $\it{LTS}(m)$ and $\rho(LTS(\TSim(m, \it{chn})))$ are branching bisimilar if their initial configurations are branching bisimilar.
For each configuration~$\it{cf} = \langle m, \sobjs, \vglob, \vloc, \buf \rangle$, including the initial configuration, a counterpart~$\it{cf'} = \langle \TSim(m), \sobjs', \vglob', \vloc', \buf' \rangle$ exists such that~$\sobjs = \sobjs'$, $\vglob = \vglob'$, $\vloc = \vloc'$, $\buf'(\langle \it{chn}, \it{on_1}, \it{on_2} \rangle) = \nil$, $\buf'(\langle \it{chn}, \it{on_2}, \it{on_1} \rangle) = \nil$, and~$\buf = \buf'$ otherwise.
Transformation~\TSim does not modify the initial states and the variables of a model.
It does, however, replace a unidirectional, synchronous channel with a bidirectional, asynchronous channel.
Therefore, according to the definitions concerning initialization provided in Section~\ref{sec:sos-slco:initialization}, the initial configuration~$\it{cf'_i}$ of $\rho(LTS(\TSim(m, \it{chn})))$ is the counterpart of the initial configuration~$\it{cf_i}$ of $\it{LTS}(m)$ as discussed above.
Thus, if we prove that a branching bisimulation exists between each configuration~$\it{cf}$ and its counterpart~$\it{cf'}$, we prove that $\it{LTS}(m)$ and $\rho(LTS(\TSim(m, \it{chn})))$ are branching bisimilar.

For each~$\it{sgn} \in \it{Sgn}$,
transformation~\TSim modifies state machine~$\it{sm_1}$ by replacing each transition
%
\[
\it{trans^s_{sgn}} = \it{tn}\ \textbf{from}\ \it{sn^s_1}\ \textbf{to}\ \it{sn^s_2}\ \textbf{send}\ \it{sgn}()\ \textbf{to}\ \it{pn}
\]
%
with two transitions
%
\begin{align*}
& \it{tn_1}\ \textbf{from}\ \it{sn^s_1}\ \textbf{to}\ \it{sn^s_{sgn}}\ \textbf{send}\ \it{sgn_1}()\ \textbf{to}\ \it{pn}\ \text{and}\\
& \it{tn_2}\ \textbf{from}\ \it{sn^s_{sgn}}\ \textbf{to}\ \it{sn^s_2}\ \textbf{receive}\ \it{sgn_2}()\ \textbf{from}\ \it{pn},
\end{align*}
%
where~$\it{tn_1}$ and~$\it{tn_2}$ are fresh transition names, $\it{sn^s_{sgn}}$ is a fresh state name, $\it{sgn_1} \equiv ``s\_" + \it{sgn}$, and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
Similarly, for each~$\it{sgn} \in \it{Sgn}$,
each transition
%
\[
\it{trans^r_{sgn}} = \it{tn}\ \textbf{from}\ \it{sn^r_1}\ \textbf{to}\ \it{sn^r_2}\ \textbf{receive}\ \it{sgn}()\ \textbf{from}\ \it{pn}
\]
%
of state machine~$\it{sm_2}$ is replaced with two transitions
%
\[
\begin{array}{l}
\it{tn_1}\ \textbf{from}\ \it{sn^r_1}\ \textbf{to}\ \it{sn^r_{sgn}}\ \textbf{receive}\ \it{sgn_1}()\ \textbf{from}\ \it{pn}\ \text{and}\\
\it{tn_2}\ \textbf{from}\ \it{sn^r_{sgn}}\ \textbf{to}\ \it{sn^r_2}\ \textbf{send}\ \it{sgn_2}()\ \textbf{to}\ \it{pn},
\end{array}
\]
%
where~$\it{tn_1}$ and~$\it{tn_2}$ are fresh transition names, $\it{sn^r_{sgn}}$ is a fresh state name, $\it{sgn_1} \equiv ``s\_" + \it{sgn}$, and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.

We define a relation~$R$ between configurations as follows: $(\it{cf}, \it{cf'})\in R$ if and only if $\vglob = \vglob'$, $\vloc = \vloc'$, and one of the following four conditions holds.
%
\begin{enumerate}
\item
  \begin{enumerate}
    \item
      $\sobjs = \sobjs'$,
    \item
      $\buf'(\langle \it{chn}, \it{on_1}, \it{on_2} \rangle) = \nil$,
      $\buf'(\langle \it{chn}, \it{on_2}, \it{on_1} \rangle) = \nil$,
      and $\buf' = \buf$ otherwise;
  \end{enumerate}

\item
  \begin{enumerate}
    \item
      $\sobjs(\it{on_1})(\it{smn_1}) = \it{sn^s_1}$,
      $\sobjs'(\it{on_1})(\it{smn_1}) = \it{sn^s_{sgn}}$,
      $\sobjs = \sobjs'$ otherwise,
    \item
      $\buf'(\langle \it{chn}, \it{on_1}, \it{on_2}\rangle) = (\it{sgn_1}, \varepsilon)$,
      $\buf'(\langle \it{chn}, \it{on_2}, \it{on_1}\rangle) = \nil$,
      and $\buf' = \buf$ otherwise,
  \end{enumerate}
  if there is a transition~$\it{trans^s_{sgn}}$ from state~$\it{sn^s_1}$ and~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$;

\item
  \begin{enumerate}
    \item
      $\sobjs(\it{on_1})(\it{smn_1}) = \it{sn^s_2}$,
      $\sobjs(\it{on_2})(\it{smn_2}) = \it{sn^r_2}$,
      $\sobjs'(\it{on_1})(\it{smn_1}) = \it{sn^s_{sgn}}$,
      $\sobjs'(\it{on_2})(\it{smn_2}) = \it{sn^r_{sgn}}$,
      $\sobjs = \sobjs'$ otherwise,
    \item
      $\buf'(\langle \it{chn}, \it{on_1}, \it{on_2}\rangle) = \nil$,
      $\buf'(\langle \it{chn}, \it{on_2}, \it{on_1}\rangle) = \nil$,
      and $\buf' = \buf$ otherwise,
  \end{enumerate}
  if there is a transition~$\it{trans^s_{sgn}}$ to state~$\it{sn^s_2}$ and a transition~$\it{trans^r_{sgn}}$ to state~$\it{sn^r_2}$;

\item
  \begin{enumerate}
    \item
      $\sobjs(\it{on_1})(\it{smn_1}) = \it{sn^s_2}$,
      $\sobjs'(\it{on_1})(\it{smn_1}) = \it{sn^s_{sgn}}$,
      $\sobjs = \sobjs'$ otherwise,
    \item
      $\buf'(\langle \it{chn}, \it{on_1}, \it{on_2}\rangle) = \nil$,
      $\buf'(\langle \it{chn}, \it{on_2}, \it{on_1}\rangle) = (\it{sgn_2}, \varepsilon)$,
      and $\buf' = \buf$ otherwise,
  \end{enumerate}
  if there is a transition~$\it{trans^s_{sgn}}$ to state~$\it{sn^s_2}$ and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
\end{enumerate}
%
We prove that $R$ is a branching bisimulation by distinguishing two cases.
First, we consider the case in which $(\it{cf_1}, \it{cf_1'})\in R$ and $\it{cf_1} \TextModelRelation{l} \it{cf_2}$.
We distinguish four cases.
\begin{enumerate}
\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the first condition stated above and distinguish between the cases~$l \not \equiv \it{sgn}()$ and~$l \equiv \it{sgn}()$, for any~$\it{sgn} \in \it{Sgn}$.
\begin{itemize}
\item
In the first case, the transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ cannot be the result of synchronous communication between state machines~$\it{sm_1}$ and~$\it{sm_2}$.
Thus, the transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ is the result of some of the transitions of these two state machines that are unaffected by the transformation or one or more transitions of some of the other state machines in the model, which are also unaffected by the transformation.
Because transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ is the result of behavior that is unaffected by the transformation, a transition~$\it{cf'_1} \TextModelRelation{l} \it{cf'_2}$ can also be made from configuration~$\it{cf'_1}$, and~$(\it{cf_2}, \it{cf_2'})\in R$ according to the first condition.
\item
In the second case, the transition~$\it{cf_1} \TextModelRelation{\it{sgn}()} \it{cf_2}$ is the result of synchronous communication between state machines~$\it{sm_1}$ and~$\it{sm_2}$.
According to the SOS rule for synchronous communication, state machine~$\it{sm_1}$ has to be in a state~$\it{sn^s_1}$ with an outgoing transition~$\it{trans^s_{sgn}}$, and state machine~$\it{sm_2}$ has to be in a state~$\it{sn^r_1}$ with an outgoing transition~$\it{trans^r_{sgn}}$.
After transformation, according to the SOS rules for asynchronous communication, state machine~$\it{sm_1}$ can make a transition from such a state~$\it{sn^s_1}$ to a state~$\it{sn^s_{sgn}}$ and send a signal over channel~$\it{chan'}$.
This results in a transition~$\it{cf'_1} \TextModelRelation{\tau} \it{cf'_2}$,
where the label~$\tau$ is the result of renaming the label~$\textbf{send}\ \it{sgn_1}()$, and~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$.
Furthermore, $(\it{cf_1}, \it{cf'_2})\in R$ according to the second condition.
Next, state machine~$\it{sm_2}$ can make a transition to a state~$\it{sn^r_{sgn}}$ and receive the signal sent by state machine~$\it{sm_1}$.
This results in a transition~$\it{cf'_2} \TextModelRelation{\it{sgn}()} \it{cf'_3}$,
where the label~$\it{sgn}()$ is the result of renaming the label~$\textbf{receive}\ \it{sgn_1}()$, and~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$.
In configuration~$\it{cf'_3}$, state machine~$\it{sm_1}$ is in state~$\it{sn^s_{sgn}}$ and state machine~$\it{sm_2}$ is in state~$\it{sn^r_{sgn}}$.
Thus, $(\it{cf_2}, \it{cf_3'})\in R$ according to the third condition.
\end{itemize}

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the second condition stated above and distinguish between the cases~$l \not \equiv \it{sgn}()$ and~$l \equiv \it{sgn}()$, for any~$\it{sgn} \in \it{Sgn}$.
\begin{itemize}
\item
In the first case, the transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ cannot result from behavior of state machine~$\it{sm_1}$, because this state machine can only send a signal over the synchronous channel~$\it{chan}$ in a state~$\it{sn^s_1}$ with an outgoing transition~$\it{trans^s_{sgn}}$.
Thus, the transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ must result from behavior of one or more other state machines.
If the transition is the result of behavior of state machine~$\it{sm_2}$, then it must be the result of one of the transitions of this state machine that are unaffected by the transformation, because the affected transitions can only lead to synchronous communication.
Furthermore, all other state machines are unaffected by the transformation.
Thus, the same behavior can be performed in the transformed model, leading to a transition~$\it{cf'_1} \TextModelRelation{l} \it{cf'_2}$.
Furthermore, since the values of~$\sobjs(\it{on_1})(\it{smn_1})$ and~$\sobjs'(\it{on_1})(\it{smn_1})$ remain the same, $(\it{cf_2}, \it{cf_2'})\in R$.
\item
In the second case, according to the SOS rule for synchronous communication, state machine~$\it{sm_2}$ has to be in a state~$\it{sn^r_1}$ with an outgoing transition~$\it{trans^r_{sgn}}$.
After transformation, according to the SOS rules for asynchronous communication, state machine~$\it{sm_2}$ is able to receive the signal in the buffer that corresponds to channel~$\it{chan'}$.
This leads to a transition~$\it{cf'_1} \TextModelRelation{\it{sgn}()} \it{cf'_2}$,
where the label~$\it{sgn}()$ is the result of renaming the label~$\textbf{receive}\ \it{sgn_1}()$, and~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$.
In configuration~$\it{cf_2}$, state machine~$\it{sm_1}$ is in state~$\it{sn^s_2}$ and state machine~$\it{sm_2}$ is in state~$\it{sn^r_2}$.
Furthermore, in configuration~$\it{cf'_2}$, state machine~$\it{sm_1}$ is in state~$\it{sn^s_{sgn}}$ and state machine~$\it{sm_2}$ is in state~$\it{sn^r_{sgn}}$.
Thus, $(\it{cf_2}, \it{cf_2'})\in R$ according to the third condition.
\end{itemize}

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the third condition stated above.
If transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ is the result of behavior of state machines that are unaffected by the transformation, then $\it{cf'_1} \TextModelRelation{l} \it{cf'_2}$ and~$(\it{cf_2}, \it{cf_2'})\in R$.
Otherwise, according to the SOS rules for asynchronous communication,
state machine~$\it{sm_2}$ can make a transition from a state~$\it{sn^r_{sgn}}$ to a state~$\it{sn^r_2}$ and send a signal over channel~$\it{chan'}$, resulting in a transition~$\it{cf'_1} \TextModelRelation{\tau} \it{cf'_2}$,
where the label~$\tau$ is the result of renaming the label~$\textbf{send}\ \it{sgn_2}()$, and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
Furthermore, $(\it{cf_1}, \it{cf_2'})\in R$ according to the fourth condition.
Next, state machine~$\it{sm_1}$ can make a transition from a state~$\it{sn^s_{sgn}}$ to a state~$\it{sn^s_2}$ and receive the signal sent over channel~$\it{chan'}$, resulting in a transition~$\it{cf'_2} \TextModelRelation{\tau} \it{cf'_3}$,
where the label~$\tau$ is the result of renaming the label~$\textbf{receive}\ \it{sgn_2}()$, and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
According to the first condition, $(\it{cf_1}, \it{cf_3'})\in R$.
Following the reasoning for the first case, each transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ either corresponds to a transition~$\it{cf_3'} \TextModelRelation{l} \it{cf_4'}$ with~$(\it{cf_2}, \it{cf_4'})\in R$ or two transitions~$\it{cf_3'} \TextModelRelation{\tau} \it{cf_4'}$ and~$\it{cf_4'} \TextModelRelation{l} \it{cf_5'}$ with~$(\it{cf_1}, \it{cf_4'}) \in R$ and~$(\it{cf_2}, \it{cf_5'}) \in R$.

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the fourth condition stated above.
If transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ is the result of behavior of state machine~$\it{sm_2}$ or state machines that are unaffected by the transformation, then $\it{cf'_1} \TextModelRelation{l} \it{cf'_2}$ and~$(\it{cf_2}, \it{cf_2'})\in R$.
Otherwise, according to the SOS rules for asynchronous communication,
state machine~$\it{sm_1}$ can make a transition from a state~$\it{sn^s_{sgn}}$ to a state~$\it{sn^s_2}$ and receive the signal sent over channel~$\it{chan'}$, resulting in a transition~$\it{cf'_1} \TextModelRelation{\tau} \it{cf'_2}$,
where the label~$\tau$ is the result of renaming the label~$\textbf{receive}\ \it{sgn_2}()$, and~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
According to the first condition, $(\it{cf_1}, \it{cf_2'})\in R$.
Following a similar reasoning as in the case discussed above, transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ can be mimicked from configuration~$\it{cf'_2}$.
\end{enumerate}

\noindent
Second, we consider the case in which $(\it{cf_1}, \it{cf_1'})\in R$ and $\it{cf_1'} \TextModelRelation{l} \it{cf_2'}$.
We distinguish four cases.
\begin{enumerate}
\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the first condition stated above.
If~$\it{cf_1'} \TextModelRelation{\tau} \it{cf_2'}$, then this transition must be the result of a transition of state machine~$\it{sm_1}$ from a state~$\it{sn^s_1}$ to a state~$\it{sn^s_{sgn}}$, and the label~$\tau$ must be the result of renaming the label~$\textbf{send}\ \it{sgn_1}$, where~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$.
In that case, $(\it{cf_1}, \it{cf_2'})\in R$ according to the second condition.
Otherwise, the transition~$\it{cf_1'} \TextModelRelation{\it{l}} \it{cf_2'}$ is the result of behavior of state machine~$\it{sm_2}$ or one of the state machines that are unaffected by the transformation.
In that case, the corresponding transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ must also exist for the original model, and~$(\it{cf_2}, \it{cf_2'})\in R$ holds according to the first condition.

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the second condition stated above.
If~$\it{cf_1'} \TextModelRelation{\it{sgn}()} \it{cf_2'}$, then this transition must be the result of a transition of state machine~$\it{sm_2}$ from a state~$\it{sn^r_1}$ to a state~$\it{sn^r_{sgn}}$, and the label~$\it{sgn}()$ must be the result of renaming the label~$\textbf{receive}\ \it{sgn_1}$, where~$\it{sgn_1} \equiv ``s\_" + \it{sgn}$.
In that case, $\it{cf_1'} \TextModelRelation{\it{sgn}()} \it{cf_2'}$ and~$(\it{cf_2}, \it{cf_2'})\in R$ according to the third condition.
If this is not the case, then the transition~$\it{cf_1'} \TextModelRelation{\it{l}} \it{cf_2'}$ is the result of behavior of state machine~$\it{sm_2}$ that is unaffected by the transformation or behavior of one of the state machines that are unaffected by the transformation.
In that case, the corresponding transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ must also exist for the original model, and~$(\it{cf_2}, \it{cf_2'})\in R$ holds according to the second condition.

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the third condition stated above.
If~$\it{cf_1'} \TextModelRelation{\tau} \it{cf_2'}$, then this transition must be the result of a transition of state machine~$\it{sm_2}$ from a state~$\it{sn^r_{sgn}}$ to a state~$\it{sn^r_2}$, and the label~$\tau$ must be the result of renaming the label~$\textbf{send}\ \it{sgn_2}$, where~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
In that case, $(\it{cf_1}, \it{cf_2'})\in R$ according to the fourth condition.
Otherwise, the transition~$\it{cf_1'} \TextModelRelation{\it{l}} \it{cf_2'}$ is the result of behavior one of the state machines that are unaffected by the transformation.
In that case, the corresponding transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ must also exist for the original model, and~$(\it{cf_2}, \it{cf_2'})\in R$ holds according to the third condition.

\item
We assume that $(\it{cf_1}, \it{cf_1'})\in R$ according to the fourth condition stated above.
If~$\it{cf_1'} \TextModelRelation{\tau} \it{cf_2'}$, then this transition must be the result of a transition of state machine~$\it{sm_1}$ from a state~$\it{sn^s_{sgn}}$ to a state~$\it{sn^s_2}$, and the label~$\tau$ must be the result of renaming the label~$\textbf{receive}\ \it{sgn_2}$, where~$\it{sgn_2} \equiv ``a\_" + \it{sgn}$.
In that case, $(\it{cf_1}, \it{cf_2'})\in R$ according to the first condition.
Otherwise, the transition~$\it{cf_1'} \TextModelRelation{\it{l}} \it{cf_2'}$ is the result of behavior of state machine~$\it{sm_2}$ that is unaffected by the transformation or behavior of one of the state machines that are unaffected by the transformation.
In that case, the corresponding transition~$\it{cf_1} \TextModelRelation{l} \it{cf_2}$ must also exist for the original model, and~$(\it{cf_2}, \it{cf_2'})\in R$ holds according to the fourth condition.

\end{enumerate}


\section{\toolname}\label{sec:liquidhaskell}
\begin{figure}[t!]
\centering
\captionsetup{justification=centering}
\noindent\makebox[\textwidth]{\includegraphics[width=\textwidth]{text/realworldhaskell/liquidHaskell}}
\caption{\toolname Workflow.}
	\label{fig:internals}
\end{figure}
%
% link for workflow
% https://www.draw.io/#G0Bwp_mIorSVqJb2RENnNVWVlQTmc
%
We start with a short description of the \toolname workflow,
summarized in Figure~\ref{fig:internals} and continue with an
example driven overview of how properties are specified
and verified using the tool.

% \mypara{Usage}
\mypara{Source}
\toolname can be run from the command-line\footnote{\url{https://hackage.haskell.org/package/liquidhaskell}}
or within a web-browser\footnote{\url{http://goto.ucsd.edu/liquid/haskell/demo/}}.
It takes as \emph{input}:
%
(1)~a single Haskell \emph{source} file with code and refinement
    type specifications including refined datatype definitions,
    measures (\S~\ref{sec:tool:measures}), predicate and type
    aliases, and function signatures;
%
(2)~a set of directories containing \emph{imported modules}
    (including the \verb+Prelude+) which may themselves
    contain specifications for exported types and functions; and
%
(3)~a set of predicate fragments called \emph{qualifiers},
    which are used to infer refinement types. This set is
    typically empty as the default set of qualifiers extracted
    from the type specifications suffices for inference.

\mypara{Core}
\toolname uses GHC to reduce the source to the Core IL~\cite{SulzmannCJD07}
and, to facilitate source-level error reporting, creates a map from Core
expressions to locations in the Haskell source.

\mypara{Constraints}
Then, it uses the abstract interpretation framework of Liquid Typing~\cite{LiquidPLDI08},
modified to ensure soundness under lazy evaluation~\ref{chapter:refinedhaskell}
and extended with Abstract~\ref{chapter:abstractrefinements}
and Bounded~\ref{boundedrefinements} Refinement Types
and Refinement Reflection~\ref{refinementrflection},
to generate logical constraints from the Core IL.

\mypara{Solution}
Next, it uses a fixpoint algorithm (from~\citep{LiquidPLDI08})
combined with an SMT solver to solve the constraints, and hence
infers a valid refinement typing for the program.
%
\toolname can use any solver that implements the SMT-LIB2
standard~\cite{SMTLIB2}, including Z3~\citep{z3}, CVC4~\citep{CVC4}, and
MathSat~\citep{MathSat}.

\mypara{Types \& Errors}
% \NV{satisfiability and validity refer to different things here,
% which is confusing...}
If the set of constraints is satisfiable, then \toolname outputs
\textsc{Safe}, meaning the program is verified.
If instead, the set of constraints is not satisfiable, then \toolname
outputs \textsc{Unsafe}, and uses the invalid constraints to
report refinement type errors at the \emph{source positions}
that created the invalid constraints, using the location
information to map the invalid constraints to source positions.
%
In either case, \toolname produces as output a source map
containing the \emph{inferred} types for each program
expression, which, in our experience, is crucial for
debugging the code and the specifications.

%\mypara{Optional Typing}
%
\toolname is best thought of as an \emph{optional} type checker
for Haskell. By optional we mean that the refinements have \emph{no}
influence on the dynamic semantics, which makes it easy to apply
\toolname to \emph{existing} libraries.
%
To emphasize the optional nature of refinements and preserve
compatibility with existing compilers, all specifications
appear within comments of the form \verb|{-@ ... @-}|,
which we omit below for brevity.

\subsection{Specifications}

A refinement type is a Haskell type where each component
of the type is decorated with a predicate from a (decidable)
refinement logic. We use the quantifier-free logic of equality,
uninterpreted functions and linear arithmetic (QF-EUFLIA)~\cite{Nelson81}.
For example,
%
\begin{code}
   {v:Int | 0 <= v && v < 100}
\end{code}
%
describes @Int@ values between @0@ and @100@.

\mypara{Type Aliases} For brevity and readability, it is often convenient
to define abbreviations for particular refinement predicates and types.
For example, we can define an alias for the above predicate
%
\begin{code}
  predicate Btwn Lo N Hi = Lo <= N && N < Hi
\end{code}
%
and use it to define a \emph{type alias}
%
\begin{code}
  type Rng Lo Hi = {v:Int | Btwn Lo v Hi}
\end{code}
%
We can now describe the above integers as @(Rng 0 100)@.

\mypara{Contracts}
To describe the desired properties of a function, we need
simply refine the input and output types with predicates
that respectively capture suitable pre- and post-conditions.
For example,
%
\begin{code}
  range :: lo:Int -> hi:{Int | lo <= hi} -> [(Rng lo hi)]
\end{code}
%
states that @range@ is a function that takes two @Int@s
respectively named @lo@ and @hi@ and returns a list of @Int@s
between @lo@ and @hi@. There are three things worth
noting.
%
First, we have binders to name the function's \emph{inputs}
(\eg @lo@ and @hi@) and can use the binders inside the
function's \emph{output}.
%
Second, the refinement in the \emph{input} type describes the
\emph{pre-condition} that the second parameter @hi@ cannot
be smaller than the first @lo@.
%
Third, the refinement in the \emph{output} type describes the
\emph{post-condition} that all returned elements are between
the bounds of @lo@ and @hi@.

\subsection{Verification}\label{sec:tool:verification}

Next, consider the following implementation for @range@:
%
\begin{code}
  range lo hi
    | lo <= hi  = lo : range (lo + 1) hi
    | otherwise = []
\end{code}
%
When we run \toolname on the above code, it reports an
error at the definition of @range@. This is unpleasant!
One way to debug the error is to determine what type has
been \emph{inferred} for @range@, \eg by hovering the
mouse over the identifier in the web interface.
In this case, we see that the output type is essentially:
%
\begin{code}
  [{v:Int | lo <= v && v <= hi}]
\end{code}
%
which indicates the problem. There is an \emph{off-by-one}
error due to the problematic guard. If we replace the second @<=@
with a @<@ and re-run the checker, the function is verified.

\mypara{Holes} It is often cumbersome to specify the Haskell
types, as those can be gleaned from the regular type signatures
or via GHC's inference. Thus, \toolname allows the user to leave
holes in the specifications. Suppose @rangeFind@ has type
%
\begin{code}
  (Int -> Bool) -> Int -> Int -> Maybe Int
\end{code}
%
where the second and third parameters define a range.
We can give @rangeFind@ a refined specification:
%
\begin{code}
  _ -> lo:_ -> hi:{Int | lo <= hi} -> Maybe (Rng lo hi)
\end{code}
%
where the @_@ is the unrefined Haskell type for the
corresponding position in the type.

\mypara{Inference} Next, consider the implementation
%
\begin{code}
  rangeFind f lo hi = find f $ range lo hi
\end{code}
%$
where @find@ from @Data.List@ has the (unrefined) type
%
\begin{code}
  find :: (a -> Bool) -> [a] -> Maybe a
\end{code}
%
\toolname uses the abstract interpretation framework of
Liquid Typing~\cite{LiquidPLDI08} to infer that the type
parameter @a@ of @find@ can be instantiated with @(Rng lo hi)@
thereby enabling the automatic verification of @rangeFind@.

Inference is crucial for automatically synthesizing types
for polymorphic instantiation sites -- note there is another
instantiation required at the use of the apply operator
@dollar@ --  and to relieve the programmer of the tedium of %$
specifying signatures for all functions.
%
Of course, for functions exported by the module,
we must write signatures to specify preconditions -- otherwise,
the system defaults to using the trivial (unrefined) Haskell
type as the signature \ie, checks the implementation assuming
arbitrary inputs.

\subsection{Measures}\label{sec:tool:measures}
So far, the specifications have been limited to comparisons and
arithmetic operations on primitive values.
We use \emph{measure functions}, or just measures, to
specify \emph{inductive properties} of algebraic data types.
%
For example, we define a measure @len@ to write properties about the number
of elements in a list.
%
\begin{code}
  measure len :: [a] -> Int
  len []      = 0
  len (x:xs)  = 1 + (len xs)
\end{code}
%
Measure definitions are \emph{not} arbitrary Haskell code but a very
restricted subset~\ref{sec:measures}.
Each measure has a single equation per constructor that defines the
value of the measure for that constructor. The right-hand side of the
equation is a term in the restricted refinement logic. Measures are
interpreted by generating refinement types for the corresponding
data constructors.
%
For example, from the above, \toolname derives the
following types for the list data constructors:
%
\begin{code}
  []  :: {v:[a]| len v = 0}
  (:) :: _ -> xs:_ -> {v:[a]| len v = 1 + len xs}
\end{code}
%
Here, @len@ is an \emph{uninterpreted function} in the refinement logic.
We can define multiple measures for a type; \toolname simply conjoins
the individual refinements arising from each measure to obtain a single
refined signature for each data constructor.

\mypara{Using Measures}
We use measures to write specifications about algebraic types.
For example, we can specify and verify that:
%
\begin{code}
  append :: xs:[a] -> ys:[a]
         -> {v:[a]| len v = len xs + len ys}

  map    :: (a -> b) -> xs:[a]
         -> {v:[b]| len v = len xs}

  filter :: (a -> Bool) -> xs:[a]
         -> {v:[a]| len v <= len xs}
\end{code}

\mypara{Propositions}
%%In addition to allowing the specification of structural features like
%%lengths, heights and so on,
Measures can be used to encode sophisticated
invariants about algebraic data types.
%
To this end, the user can write a measure whose output has a special type
@Prop@ denoting propositions in the refinement logic. For instance, we can
describe a list that contains a @0@ as:
%
\begin{code}
  measure hasZero :: [Int] -> Prop
  hasZero []      = false
  hasZero (x:xs)  = x == 0 || hasZero xs
\end{code}
%
We can then define lists containing a @0@ as:
%
\begin{code}
  type HasZero = {v : [Int] | hasZero v }
\end{code}
%
Using the above, \toolname will accept
%
\begin{code}
  xs0 :: HasZero
  xs0 = [2,1,0,-1,-2]
\end{code}
%
but will reject
%
\begin{code}
  xs' :: HasZero
  xs' = [3,2,1]
\end{code}

\subsection{Refined Data Types}

Often, we require that \emph{every} instance of a type satisfies some invariants.
For example, consider a @CSV@ data type, that represents tables:
%
\begin{code}
  data CSV a = CSV { cols :: [String]
                   , rows :: [[a]]    }
\end{code}
%
% With \toolname we can enforce the invariant that for every @CSV@ table,
% with a number of columns given by @dim@,
% each row has @dim@ elements,
% with the below refined data type definition
%%With \toolname we can enforce the invariant that every @CSV@ table
%%has the number of columns given by @dim@, and that each row has
%%@dim@ elements with a refined data type definition, such as:
With \toolname we can enforce the invariant that every row in a @CSV@ table
should have the same number of columns as there are in the header
%
\begin{code}
  data CSV a = CSV { cols :: [String]
                   , rows :: [ListL a cols] }
\end{code}
%
using the alias
%
\begin{code}
  type ListL a X = {v:[a]| len v = len X}
\end{code}
%
A refined data definition is \emph{global} in that \toolname
will reject any @CSV@-typed expression that does not respect
the refined definition. For example, both of the below
%
\begin{code}
  goodCSV = CSV [  "Month", "Days"]
                [ ["Jan"  , "31"]
                , ["Feb   , "28"]
                , ["Mar"  , "31"] ]

  badCSV  = CSV [  "Month", "Days"]
                [ ["Jan"  , "31"]
                , ["Feb   , "28"]
                , ["Mar"        ] ]
\end{code}
%
are well-typed Haskell, but the latter is rejected by \toolname.
%
Like measures, the global invariants are enforced by refining
the constructors' types.

\subsection{Refined Type Classes}\label{sec:type-classes}

Next, let us see how \toolname allows verification of
programs that use ad-hoc polymorphism via type classes.
%
While the implementation of each typeclass instance is
different, there is often a common interface that
all instances should satisfy.

\mypara{Class Measures}
As an example, consider the class definition
%
\begin{code}
  class Indexable f where
    size :: f a -> Int
    at   :: f a -> Int -> a
\end{code}
%
For safe access, we might require that @at@'s second
parameter is bounded by the @size@ of the container.
To this end, we define a \emph{type-indexed}
measure, using the @class measure@ keyword
%
\begin{code}
  class measure sz :: a -> Nat
\end{code}
%
Now, we can specify the safe-access precondition
independent of the particular instances of @Indexable@:
%
\begin{code}
  class Indexable f where
    size :: xs:_ -> {v:Nat | v = sz xs}
    at   :: xs:_ -> {v:Nat | v < sz xs} -> a
\end{code}

\mypara{Instance Measures}
For each concrete type that instantiates a class, we require
a corresponding definition for the measure.
For example, to define lists as an instance of @Indexable@,
we require the definition of the @sz@ instance for lists:
%
\begin{code}
  instance measure sz :: [a] -> Nat
    sz []     = 0
    sz (x:xs) = 1 + (sz xs)
\end{code}
%
Class measures work just like regular measures in that the above
definition is used to refine the types of the list data constructors.
After defining the measure, we can define the type instance as:
%
\begin{code}
  instance Indexable [] where
    size []        = 0
    size (x:xs)    = 1 + size xs

    (x:xs) `at` 0  = x
    (x:xs) `at` i  = index xs (i-1)
\end{code}
%
\toolname uses the definition of @sz@ for lists to check that @size@
and @at@ satisfy the refined class specifications.
% NV the dictionary relevant this were removed
% , and hence, that
% the above creates a valid instance dictionary for @Indexable@.

\mypara{Client Verification}
At the clients of a type-class we use the refined
types of class methods. Consider a client of @Indexable@s:
%
\begin{code}
  sum :: (Indexable f) => f Int -> Int
  sum xs = go 0
    where
      go i | i < size xs = xs `at` i + go (i+1)
           | otherwise   = 0
\end{code}
%
\toolname proves that each call to @at@ is safe, by using the refined
class specifications of @Indexable@.
Specifically, each call to @at@ is guarded by a check @i < size xs@
and @i@ is  increasing
from 0, so \toolname proves that @xs `at` i@ will always be safe.

\begin{comment}
\subsection{Abstracting Refinements}

So far, all the specifications have used \emph{concrete} refinements. Often it is
useful to be able to \emph{abstract} the refinements that appear in a
specification. For example, consider a monomorphic variant of @max@
%
\begin{code}
  max     :: Int -> Int -> Int
  max x y = if x > y then x else y
\end{code}
%
We would like to give @max@ a specification that lets us verify:
%
\begin{code}
  xPos  :: {v: _ | v > 0}
  xPos  = max 10 13

  xNeg  :: {v: _ | v < 0}
  xNeg  = max (-5) (-8)

  xEven :: {v: _ | v mod 2 == 0}
  xEven = max 4 (-6)
\end{code}
%
To this end, \toolname allows the user to \emph{abstract refinements} over
types~\cite{vazou13}, for example by typing @max@ as:
%
\begin{code}
 max :: forall <p :: Int -> Prop>.
          Int<p> -> Int<p> -> Int<p>
\end{code}
%
The above signature states that for any refinement @p@, if the two
inputs of @max@ satisfy @p@ then so does the output. \toolname uses
Liquid Typing to automatically instantiate @p@ with suitable concrete
refinements, thereby checking @xPos@, @xNeg@, and @xEven@.

\mypara{Dependent Composition}
Abstract refinements turn out to be a surprisingly expressive and
useful specification mechanism. For example, consider the function
composition operator:
%
\begin{code}
  (.) :: (b -> c) -> (a -> b) -> a -> c
  (.) f g x = f (g x)
\end{code}
%
Previously, it was not possible to check, \eg that:
%
\begin{code}
  plus3 :: x:_ -> {v:_ | v = x + 3}
  plus3 = (+ 1) . (+ 2)
\end{code}
%
as the above required tracking the dependency between @a@, @b@ and @c@,
which is crucial for analyzing idiomatic Haskell.
With abstract refinements, we can give the @(.)@ operator the type:
%
\begin{code}
  (.) :: forall < p :: b -> c -> Prop
                , q :: a -> b -> Prop>.
           f:(x:b -> c<p x>)
        -> g:(x:a -> b<q x>)
        -> y:a
        -> exists[z:b<q y>].c<p z>
\end{code}
%
which gets automatically instantiated at usage sites, allowing \toolname
to precisely track invariants through the use of the ubiquitous
higher-order operator.

\mypara{Dependent Pairs}
Similarly, we can abstract refinements over the definition of datatypes.
% Similarly, we can abstract refinements over the definition of datatypes.
For example, we can express dependent pairs in \toolname by refining the
definition of tuples as:
%
\begin{code}
  data Pair a b <p :: a -> b -> Prop>
    = Pair { fst :: a, snd :: b<p fst>}
\end{code}
%
That is, the refinement @p@ relates the @snd@ element with the @fst@.
Now we can define increasing and decreasing pairs
%
\begin{code}
  type IncP = Pair <{\x y -> x < y}> Int Int
  type DecP = Pair <{\x y -> x > y}> Int Int
\end{code}
%
and then verify that:
%
\begin{code}
  up :: IncP
  up = Pair 2 5

  dn :: DecP
  dn = Pair 5 2
\end{code}
%
Now that we have a bird's eye view of the various specification mechanisms
supported by \toolname, let us see how we can profitably apply them to
statically check a variety of correctness properties in real-world codes.
\end{comment}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


%!TEX root = morusAC.tex

%\pagebreak[4]

\section{Discussion}
\label{sec/Discussion}

%This is just a sketch for now...

We now discuss the impact of these attacks on the security of \MORUS.

\subsubsection{Keystream correlation.}

We emphasize that the correlation we uncover between plaintext and ciphertext bits is
\emph{absolute}, in the sense that it does not depend on the encryption
key, or on the nonce.  This is the same situation as the keystream correlations
in AEGIS~\cite{sacryptMinaud14}.  As such, they can be leveraged to
mount an attack in the broadcast setting, where the same message is
encrypted multiple times with different IVs and potentially different
keys~\cite{DBLP:conf/fse/MantinS01}.  In particular, the broadcast setting appears
in practice in man-in-the-browser attacks against HTTPS connections
following the BEAST model~\cite{duong2011here}.  In this scenario, an
attacker uses Javascript code running in the victim's browser (by
tricking the victim to visit a malicious website) to generate a large
number of request to a secure website.  Because of details of the HTTP
protocol, each request includes an authentication token to identify the
user, and the attacker can target this token as a repeated plaintext.
Concretely, correlations in the RC4 keystream have been exploited in this
setting, leading to the recovery of authentication cookies in
practice~\cite{DBLP:conf/uss/AlFardanBPPS13}.

\subsubsection{Data complexity.}

The design document of \cipher{MORUS} imposes a limit of $2^{64}$
encrypted blocks for a given key. However, since our attack is
independent of the encryption key, and hence immune to rekeying, this
limitation does not apply: all that matters for our attack is that the
same plaintext be encrypted enough times.

With the trail presented in this work, the data complexity is clearly
out of reach in practice, since exploiting the correlation would require
$2^{152}$ encrypted blocks for \cipher{MORUS1280}, and $2^{146}$
encrypted blocks for \cipher{MORUS640}. The data complexity could be
slightly lowered by leveraging multilinear cryptanalysis; indeed, the
trail holds for any bit shift, and if we assume independence, we could
run $w$ copies of the trail in parallel on the same encrypted blocks
(recall that $w$ is the word size, and the trail is invariant by
rotation by $w$ bits). This would save a factor $2^5$ on the data
complexity for \cipher{MORUS640}, and $2^6$ for \cipher{MORUS1280}; but
the resulting complexity is still out of reach.

However, \cipher{MORUS1280} with a 256-bit key claims a security level
of 256 bits for confidentiality, and an attack with complexity $2^{152}$
violates this claim, even if it is not practical.

\subsubsection{Design considerations.}
The existence of this trail does hint at some weakness in the
design of \cipher{MORUS}. Indeed, a notable feature of the trail is that
the values of rotation constants are mostly irrelevant: a similar trail
would exist for most choices of the constants. That it is possible to
build a trail that ignores rotation constants may be surprising. This
would have been prevented by adding a word-wise rotation to one of the
state registers at the input of the ciphertext equation.

%%% Local Variables:
%%% TeX-master: "morusAC"
%%% End:


\section{Machine learning approach}
ML techniques in SHM were heavily utilised by researchers for damage detection~\cite{Doebling1998, alvandi2006assessment, fan2011vibration, raghavan2008effects, su2009identification, Mitra2016}.
Moreover, machine learning techniques attempt to map the patterns of the input data acquired by sensors to output targets for a damage estimation at different levels ~\cite{rytter1993vibrational}.
Accordingly, ML techniques demands high domain knowledge of the examiner to perform hand-crafted damage-sensitive feature extraction on the raw data acquired by sensors before being fed into a suitable ML model.
Generally, the process of damage-sensitive features extraction (hand-crafted) in the field of SHM emerged due to the enormous development in the physics-based SHM techniques such as modal strain energy (MSE)~\cite{Kim}, modal curvature (MC)~\cite{Wahab}, modal assurance criterion (MAC), and Coordinate (MAC)~\cite{Allemang2003}, modal flexibility (MF)~\cite{Jaishi}, damage locating vector (DLV)~\cite{Bernal2002}, wavelet transform~\cite{Staszewski,Kima} and probabilistic reconstruction algorithm (PRA)~\cite{Hay2006} among others.

In this section, we are going to describe several feature extraction techniques and classification models used with machine learning utilised for structural damage detection.
These algorithms are suitable for scenarios where the sensitive damage features obtained from the structural responses are affected by the changes that occur due to the operational and environmental variability and the changes made by the damage.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Feature extraction techniques}
\subsubsection{Principal component analysis}
PCA is a popular method used for damage identification in SHM.
Further, PCA shows a solid and efficient performance in feature extraction, and structural damage detection~\cite{liu2014research, wang2014principal, nguyen2010fault}.
Besides, PCA proves to be an effective tool to improve the training efficiency and enhance the classification accuracy for other ML algorithms, such as unsupervised learning methods~\cite{liu2019rapid, datteo2017statistical, torres2014data}.

PCA is dimensionality reduction technique utilised to reduce the dimensionality of large data (input space) into a lower dimension (feature space) through transforming a large set of variables into a smaller one with minimal loss information~\cite{Jolliffe2002}.
Moreover, PCA can be utilised for damage detection by eliminating noise and obtaining sensitive features of damage as eigenvectors.
The PCA technique is illustrated below.
In the beginning, a matrix \(U(t)\) is constructed as shown in Eqn. \ref{U(t)}, which contains all registered data with time histories.
\begin{equation}
	U(t)=
	\begin{bmatrix}
		u_1{(t1)}       & u_2{(t1)} & \dots & u_M{(t1)} \\
		u_1{(t2)}       & u_2{(t2)} & \dots & u_M{(t2)} \\
		\vdots 			& \vdots 	& \ddots & \vdots \\
		u_1{(t_N)}      & u_2{(t_N)} & \dots & u_M{(t_N)}
	\end{bmatrix}\ ,
	\label{U(t)}
\end{equation}
where \(t\) corresponds to the time, \(u_i\ (i = 1, 2, ..., M)\) represents to the response from the \(i-th\) sensor installed in the monitored structure, \(M\) represents the total number of sensors, \(t_j\ (j = 1, 2, ..., N)\) represents the \(j-th\) time step of the data registering and \(N\) is the total time observations during monitoring.
Additionally, each column represents data registration of one sensor.
The next step is to normalise the time series of each sensor data registrations by subtracting the mean value shown in Eqn.~\ref{mean value}:
\begin{equation}
	\bar{u_i} = \frac{1}{N}\sum_{j=1}^{N}u_i(t_j)\ ,
	\label{mean value}
\end{equation}
Equation~\ref{normalised matrix} represents the normalised matrix.
\begin{equation}
	U'(t)=
	\begin{bmatrix}
		u_1{(t1)}-\bar{u_1}       & u_2{(t1)}-\bar{u_2} & \dots  & u_M{(t1)}-\bar{u_M} \\
		u_1{(t2)}-\bar{u_1}       & u_2{(t2)}-\bar{u_2} & \dots  & u_M{(t2)}-\bar{u_M} \\
		\vdots 					  & \vdots 	  			& \ddots & \vdots \\
		u_1{(t_N)}-\bar{u_1}      & u_2{(t_N)}-\bar{u_2}& \dots  & u_M{(t_N)}-\bar{u_M}
	\end{bmatrix}
	\label{normalised matrix}
\end{equation}
After computing the normalised matrix, the covariance matrix is computed as shown in Eqn.~\ref{covariance}:
\begin{equation}
	C = \frac{1}{M}U'^TU' \ ,
	\label{covariance}
\end{equation}
Next, the eigenvalue and the corresponding eigenvector of the covariance matrix are computed through solving the following equation~\ref{eigvalue}:
\begin{equation}
	(C-\lambda_iI)\psi_i =0 \ ,
	\label{eigvalue}
\end{equation}
where \(I\) represents the \(M\times M\) identity matrix, \(\psi_i = [\psi_{i,1},\psi_{i,2}, \hdots, \psi_{i,j}]^T\) in which \(\psi_{i,j}(j=1, 2, \hdots, M)\) is the element related to the \(j-th\) sensor.
Usually, eigenvalues are sorted into decreasing order, particularly \(\lambda_1>\lambda_2>\hdots>\lambda_M\).
Then, the first eigenvector \(\psi_1\) corresponding to \(\lambda_1\) holds the greatest variance and consequently holds the most important information for the original matrix U.
The first few principal components hold most of the variance, whereas the remaining less important components involve the measurement of noise.
Accordingly, the first few eigenvectors are utilised as sensitive features for damage detection and localisation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Mahalanobis squared distance}
MSD is an effective multivariate distance measuring technique in which it measures the distance between a point and a distribution.
Therefore, MSD is utilised with multivariate statistics outlier detection~\cite{Worden2000}.
Assuming \(X\) to be a training set with data acquired when the undamaged structure is under environmental and/or operational variations (EOVs) with multivariate mean vector \(\mu\) and covariance matrix \(\Sigma\)~\cite{Farrar2013}.
Accordingly, the damage index \((DI_i)\) between feature vectors from training set \(X\) and any new feature vector from the test matrix \(Z\) is calculated using Eqn.~\ref{msd}.
\begin{equation}
	DI_i = (z_i-\mu)\Sigma^{-1}(z_i-\mu)^T
	\label{msd}
\end{equation}
where \(z_i\) is a tested feature vector.
The performance of this technique mainly relies on acquiring all likely EOVs in the training set~
\cite{Farrar2013}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Gaussian mixture models}
GMM is a clustering method commonly used with unsupervised learning, in which it aims to find main clusters of points in a dataset that share some common characteristics or features.
Additionally, GMM has also been referred to as Expectation-Maximization (EM) clustering that is based on the optimization strategy.
%%%%%%%%%%
The damage detection is performed based on multiple MSD-based algorithms, in which the covariance matrices and mean vectors are functions of the main components.
%%%%%%%%%%
A GMM is defined as a superposition of K Gaussian distributions as shown in Eqn. \ref{gmm}.

\begin{equation}
	p(x) = \sum_{k=1}^K P(k) \mathcal{N}(x|\mu_k,\Sigma_k)
	\label{gmm}
\end{equation}
where \(x\) represents the training samples in the dataset, and \(P(k)\) corresponds to the mixture proportion (contribution weight) of the \(k-\)th distribution, in which the mixture proportion must satisfy \(0\leq P(x)\leq 1\).
The sum of all mixture proportion satisfies the following Eqn.~\ref{mixture}
\begin{equation}
	\sum_{k=1}^{K}P(x) =1
	\label{mixture}
\end{equation}
\(\mathcal{N}(x|\mu_k,\Sigma_k)\) refers to the conditional probability of the instance \(x\) for the \(k-\)th Gaussian distribution \(\mathcal{N}(\mu_k,\Sigma_k)\) presented in Eqn.~\ref{conditional}, where \(\mu_k\) and \(\Sigma_k\) are the mean and the covariance of that Gaussian distribution respectively.
\begin{equation}
	\mathcal{N}(x|\mu_k,\Sigma_k) = \frac{\exp(-\frac{1}{2}(x-\mu_k)^T\Sigma_k^{-1}(x-\mu_k))}{(2\pi)^{\frac{d}{2}\sqrt{\det(\Sigma_k)}}}
	\label{conditional}
\end{equation}
The complete GMM is parameterized by the mean vectors, covariance matrices and the mixture weights from all component densities \(\{\mu_k,\Sigma_k, P(x)\}_{k=1,\hdots,K}\).

The parameters can be carried out from the training data using the classical maximum likelihood estimator (CMLE) based on the EM algorithm~\cite{Dempster1977}.
Damage can be detected through estimating \(k\) \(DIs\) for each data sample \(x\) as shown in Eqn. \ref{DIs}
\begin{equation}
	DI_q(x) = (x-\mu_k)\Sigma_k^{-1}(x-\mu_k)^T
	\label{DIs}
\end{equation}
where \(\mu_k\) and \(\Sigma_k\) refers to all observations from the \(k\) data component.
For each observation the DI is given by the smallest DI estimated on each component as in Eqn. \ref{DI}
\begin{equation}
	DI(x) = \min[DI_k(x)]
	\label{DI}
\end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Classification models}
\subsubsection{Support vector machine}
Support vector machine (SVM) is a supervised ML model that is utilised as a classification and regression tool.
The idea behind SVM is to find an optimal hyperplane (e.g separate line) in N-dimensional space (N is the number of features) that separates the classes, furthermore, the aim of the hyperplane is to maximize the margin between the points on either side hence so called \enquote{decision line/boundary}.
Furthermore, when we try to separate two classes of data points, we could have many possible hyperplanes, however, our goal is to find the hyperplane that has the maximum margin (maximum distance between data points of both classes).
Figure~\ref{fig:SVM} shows SVM hyperplanes in 2D feature space and 3D feature space.
\begin{figure}[!h]
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=.8\linewidth]{figures/2d_svm.png}
		\caption{Hyperplane 2D feature space }
		\label{fig:2dsvm}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=1.0\linewidth]{figures/3d_svm.png}
		\caption{Hyperplane 3D feature space}
		\label{fig:3dsvm}
	\end{subfigure}
	\caption{SVM for 2D and 3D feature space.}
	\label{fig:SVM}
\end{figure}

\subsubsection{K-Nearest Neighbor}
K-Nearest Neighbor (KNN) is a supervised ML technique utilized to perform classification tasks.
KNN does not have a specialized training phase.
It saves all the training data and uses the entire training set for classifying a new data point, which adds time complexity at the testing time.
Moreover, KNN is a non-parametric learning algorithm, which means it does not have any assumptions regarding the input data, which is useful considering the real-world data does not obey the typical theoretical assumptions such as linear separability, uniform distribution among others.

In the KNN technique, at the first, the distance between the new data point and the whole other data points is calculated.
Furthermore, any distance method can be applied e.g. Euclidean, Manhattan, etc.
Accordingly, it picks the K-nearest points, where K is an integer number (number of neighbors) that can be chosen in such a way the model will be able to predict new unseen data accurately.
Then, it assigns the new data point to the class to which the majority of the K data points belong.
In Fig.~\ref{fig:datapoints} shows initial data points (training set) before classification, and Fig.~\ref{fig:KNN_K_5} shows the result of applying KNN techniques on the data points (3 classes) assuming \(K=6\).
\begin{figure}[!h]
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=1\linewidth]{figures/KNN_datapoints.png}
		\caption{Data points }
		\label{fig:datapoints}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.49\textwidth}
		\centering
		\includegraphics[width=1.0\linewidth]{figures/KNN_K_6.png}
		\caption{3-Classes with \(K=6\)}
		\label{fig:KNN_K_5}
	\end{subfigure}
	\caption{KNN algorithm: data classification with \(K=6\) .}
	\label{fig:KNN}
\end{figure}

\subsubsection{Decision tree}
Decision trees are supervised ML that is used in applications for classification and regression.
Additionally, decision trees are considered the bases for many other ML techniques such as random forests, bagging and boosted decision trees.
The idea of a decision tree is to represent the whole data as a tree where each internal node represents a test on an attribute (a decision rule) and each branch represents an outcome of the test, and finally each leaf node (terminal node) holds the label of the class.

Decision tree can be divided into two categories:
\begin{enumerate}
	\item Categorical variable decision trees: which includes categorical target variables that are divided into categories. A category means that the decision falls into one of the categories and there is no in-between such as (Yes/No category).
	\item Continuous variable decision trees: which has a continuous target variable that can be predicted based on available information (e.g. crack length).
\end{enumerate}
Figure~\ref{fig:Decision_tree} presents a typical decision tree.
Any decision tree has a root node where data input is carried through.
Furthermore, the root node is split into sets of decision rules that result either in a leaf node which is a non-splitting node, or into another decision rule, creating what so-called a branch or sub-tree.
In case there are decision rules that can be eliminated from the tree, a process called \enquote{pruning} is applied to minimize the complexity of the algorithm.
\begin{figure}[!h]
	\begin{center}
		\includegraphics[width=1.0\linewidth]{figures/decision_tree.png}
	\end{center}
	\caption{Decision tree.}
	\label{fig:Decision_tree}
\end{figure}


\section{Introduction}
Community detection is an important topic in graph mining. By learning node community labels on the graph, we are able to detect node hidden attributes as well as explore the closeness between nodes \cite{fortunato2010community}. Conventional methods are mostly user-independent to detect communities solely relying on graph topological structure \cite{fortunato2016community}, generate semi-supervised communities with node constraints \cite{jin2019graph}, or select top-K sub graphs as user-centric communities \cite{li2015influential}. These approaches are no longer enough to satisfy users with a pursuit of personalization, which makes involving user need into community detection to become an inevitable task.

First, user-independent approaches solely consider graph topological structure without user need. Second, semi-supervised approaches detect communities restricted by pre-selected seed nodes. As different user needs refer to different seeds, each individual user requires a separate process to run the whole model completely to get personalized communities, which is inapplicable in real cases. Third, sub-graph selection approaches only generate communities from the partial graph instead of the whole one.

To detect personalized communities on the whole graph, I propose a \textbf{g}enetic \textbf{P}ersonalized \textbf{C}ommunity \textbf{D}etection (gPCD) model with an offline and an online step. Specifically, in the offline step, I convert the user-independent graph community to a binary community tree which is encoded with binary code. Subsequently, a deep learning method is utilized to learn low-dimensional embedding representations for both user need and nodes on the binary community tree. In the online step, I propose a genetic tree-pruning approach on the tree to detect personalized communities by maximizing user need and minimizing user searching cost simultaneously. The whole genetic approach runs in an iterative manner to simulate an evolutionary process and generate a number of partition candidates which are regarded as ``chromosomes'' in each genetic generation. Through the selection, cross-over and mutation process, successive chromosomes are bred as better personalized community partitions to meet with user need.


\documentclass[]{article}
\usepackage[margin=1.0in]{geometry}
\usepackage{amssymb}

%title material
\title{Astronomy 400B Homework \#5}
\author{Please Show Your Work for Full Credit}
\date{Due April 30, 2015 by 9:35am}

%include latex definitions
\input{astro400B_definitions.tex}

%begin the document
\begin{document}

%make the title, goes after document begins
\maketitle

\section{Sparke \& Gallagher Problem 8.7}

The quantity $\ave{\Delta_k^2}^{1/2}$ gives the expected fractional deviation
$|\delta(\vx)|$ from the mean density in an overdense of diffuse region of
size $1/k$.  Write $\delta(\vx)$ and $\Phi(\vx)$ as Fourier transforms and
use Poisson's equation
\begin{equation}
\nabla^2 \Phi(\vx) = 4\pi G \rho(\vx)
\end{equation}
\noindent
to show that these lumps and voids cause fluctuations $\Delta\Phi_k$ in the
gravitational potential, where $k^2|\Delta\Phi_k|\sim4\pi G\bar{\rho}\ave{\Delta_k^2}^{1/2}$.
Show that, when $P(k)\propto k$, the {\it Harrison-Zel'dovich} spectrum, $|\Delta\Phi_k|$ does
not depend on $k$: the potential is equally `rippled' on all spatial scales.

\section{Sparke \& Gallagher Problem 8.9}

By substituting into the equation
\begin{equation}
\ddot{R}(t) = -\frac{4\pi G}{3} R(t)\left[ \rho(t) + \frac{3p(t)}{c^2}\right]
\end{equation}
\noindent
show that, when vacuum energy dominates the expansion, we have $R(t) \propto \exp(t\sqrt{\Lambda/3})$.

\section{Sparke \& Gallagher Problem 8.11}

Blackbody radiation and relativistic particles provide most of the
energy density at $t\ll t_{eq}$. Show that the equation
\begin{equation}
H^2(t) = H_0^2[\Omega_r(1+z)^4 + \Omega_m(1+z)^3 + (1 -\Omega_{tot})(1+z)^2 + \Omega_{\Lambda}]
\end{equation}
\noindent
then implies that $H(t)=1/(2t)$. Early on, the leftmost term of the
equation
\begin{equation}
\frac{kc^2}{R^2(t_0)} = H_0^2(1-\Omega_{tot}) = a^2(t)\left[H^2(t) - \frac{8\pi G}{3} \rho(t)\right]
\end{equation}
\noindent
is tiny, so $H^2(t)\approx8\pi G\rho(t)/3$: show that the temperature $T(t)$ is
given by
\begin{equation}
T = \left(\frac{3c^2}{32 \pi G a_B t^2}\right)^{1/4},
\end{equation}
where $a_B = 7.56\times 10^{-16}~\mathrm{J}~\mathrm{m}^{-3}~\K^{-4}$ is the blackbody constant.

\section{Sparke \& Gallagher Problem 8.13}

Show that, when cool matter accounts for most of the energy density, and the universe
is flat with $k=0$, we have
\begin{equation}
\dot{a}\propto a^{-1/2},~\mathrm{and}~a(t)\propto t^{2/3}.
\end{equation}
\end{document}


% declare document class and geometry
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage[margin=1in]{geometry} % handle page geometry

\input{../header.tex}

\title{Phys 220A -- Classical Mechanics -- Lec03}
\author{UCLA, Fall 2014}
\date{\formatdate{09}{10}{2014}} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed

\begin{document}
\setlength{\unitlength}{1mm}
\maketitle

\section{Lagrangian formalism}

The Lagrangian formalism has some advantages over the Newtonian formulation:
\begin{itemize}
\item Looks the same in all coordinate systems
\item Conservation laws are manifestly evident
\item Constraints are simpler to deal with (normal forces, string tensions, etc.)
\item Lagrange equations can be derived from an action principle. This is great because all fundamental laws of physics can be formulated this way (general relativity, Maxwell theory, standard model).
\item Lagrangians and actions are the starting point for the path integral formulation of quantum mechanics.
\item Leads us to Hamiltonian formulation!
\end{itemize}

\subsection{Action principle}

What is the action principle (or Hamilton's principle, the principle of least action)? Start with a system of generalized coordinates $q_i(t)$ and generalized velocities $\dot{q}_i(t)$, $i = 1, \dots N$. The Lagrangian is assumed to be a function $L(q_i, \dot{q}_i, t)$. Then the action is defined as a functional
\begin{equation}
S[q_i(t)] = \int_{t_1}^{t_2} dt L(q_i, \dot{q}_i, t)
\end{equation}
taking for its argument the path $q_i(t)$ with fixed boundary conditions $q_i(t) = q_i^\text{initial}$ and $q_i(t_2)^\text{final}$. (Recall that a functional $F[q(t)]$ maps a function to a real number.)

The action principle (the ``principle of least action'') says that the physical path is given by an extremum of the action:
\begin{equation}
\text{Euler-Lagrange:}	\qquad	\frac{\delta S[q]}{\delta q_i(t)} = 0, \quad i = 1, \dots, N.
\end{equation}
What does this mean? Will need to familiarize ourselves with variational calculus and functional derivatives.

For simplicity let's consider a single coordinate $q(t)$ with initial and final points $q_1, q_2$. Then we have an action
\begin{equation}
S[q(t)] = \int dt L(q, \dot q, t).
\end{equation}
Recall the ordinary derivative is given by
\begin{equation}
\frac{df}{dx} = \lim_{\epsilon \rightarrow 0} \frac{f(x+\epsilon) - f(x)}{\epsilon} = \lim_{\epsilon \rightarrow 0} \frac{\epsilon \delta f + \bigo(\epsilon^2)}{\epsilon} = \delta f
\end{equation}
We consider an infinitesimal variation of $q(t)$,
\begin{equation}
\tilde{q}(t) = q(t) + \delta q(t) = q(t) + \epsilon h(t) + \bigo(\epsilon^2)
\end{equation}
where $h(t)$ is an arbitrary function with $h(t_1) = h(t_2) = 0$ so that initial and final values of $q$ are fixed and the variation vanishes at the end points: $\delta q(t_1) = \delta q(t_2) = 0$.

In the variation of the action we only consider terms to order $\epsilon$,
\begin{align}
\delta S &= S[q+\delta q] - S[q] \\
	&= \int_{t_1}^{t_2} L(q(t) + \epsilon h(t), \dot{q}(t) + \epsilon \dot{h}(t), t) - \int_{t_1}^{t_2} dt L(q(t), \dot{q}(t), t) \\
	&= \epsilon \int_{t_1}^{t_2} dt \left\{ \frac{\pd L}{\pd q} h(t) + \frac{\pd L}{\pd \dot q} \right\} + \bigo(\epsilon^2),
\end{align}
and integrating the second term by parts we find
\begin{equation}
\delta S = \epsilon \int_{t_1}^{t_2} \left\{ \frac{\pd L}{\pd q} h - (\frac{d}{dt} \frac{\pd L}{\pd \dot{q}}) h + \frac{d}{dt} (\frac{\pd L}{\pd \dot{q}} h) \right\} + \bigo(\epsilon^2).
\end{equation}
The third term is a total derivative with vanishing boundary conditions so vanishes when integrated, so we're left with
\begin{equation}
\delta S = \epsilon \int_{t_1}^{t_2} dt \left\{ \frac{\pd L}{\pd q} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}} \right\} h(t) + \bigo(\epsilon^2).
\end{equation}
The action is an extremum if $\delta S = 0$, it's still an integral but the function $h(t)$ is arbitrary. Thus we are left with the Euler-Lagrange equations,
\begin{equation}
\delta S = 0	\qquad \iff \qquad \frac{\pd L}{\pd q} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}} = 0.
\end{equation}
Note that the extremum is not always a minimum of the action (as the name ``least action principle'' implies). For long trajectories we can find paths that are in fact saddle points of the action. However, it will in fact never be a maximum. This is because we can always take a longer path which increases the action.

Some comments:
\begin{enumerate}
\item We can easily generalize to more than one coordinate. Taking variations $\delta q_i = q_i + \epsilon h_i(t)$ we have
\begin{equation}
\delta S = \epsilon \int dt \sum_i \left( \frac{\pd L}{\pd q_i} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}_i} \right) h_i (t) + \bigo(\epsilon^2).
\end{equation}
Since we can just set all $h_j = 0$ for $j \neq i$ we just find the Euler-Lagrange equation applies for each variable,
\begin{equation}
\frac{\pd L}{\pd q_i} - \frac{d}{dt} \frac{\pd L}{\dot{q}_i} = 0, \quad i = 1, \dots, N.
\end{equation}

\item Newton's equation are of course reproduced for conservative forces by choosing $L = T - V$, so for a single particle $L = (1/2)m\dot{x}^2 - V(x)$. Then the Euler-Lagrange equation just reproduces newton's equations
\begin{equation}
-m\ddot{x} - \frac{\pd V}{\pd x} = 0,
\end{equation}
which is 3 dimensions would is $m \ddot{\v{x}} = -\v{\nabla}V(\v{x})$. Similarly for $N$ particles we would have $m_i \ddot{\v{x}}_i = -\v{\nabla}_i V(\v{x})$.

\item One big advantage of the Euler-Lagrange equations is that they take the same form in any coordinate system. To show this, consider a change of coordinates $q_i \rightarrow r_j$ which is a diffeomorphism, in other words a map
\begin{equation}
r_j = r_j(q_1, \dots, q_N, t), \qquad j = 1, \dots, N
\end{equation}
which is differentiable and has a differentiable inverse. (For example, take $q_i$ to be cartesian coordinates $x, y, z$ and $r_j$ to be spherical coordinates $r, \theta, \phi$.) Then we have the Jacobian $J\indices{_j^i} = \frac{\pd r_j}{\pd q_i}$ which has full rank ($\det J \neq 0$). Note that the Lagrangian should of course be independent of coordinates if it is just the difference $T-V$ between kinetic and potential energy. We can write this as
\begin{equation}
L'(r_j, \dot{r}_j, t) = L(q_i(r_j, \dot{r}_j), \dot{q}_i(r_j, \dot{r}_j), t),
\end{equation}
thus we have
\begin{equation}
S = \int dt L(q_i, \dot{q}_i, t) = \int dt L'(r_j, \dot{r}_j, t).
\end{equation}
Therefore the condition that the variation $\delta S$ vanishes is entirely geometric so the Euler-Lagrange equations must take the same form $r_j$ coordinates,
\begin{equation}
\frac{\pd L'}{\pd r_j} - \frac{d}{dt} \frac{\pd L'}{\pd \dot{r}_j} = 0.
\end{equation}

We can check this on the level of the Euler-Lagrange equations themselves. Notice that we have by change of coordinates
\begin{equation}
\frac{\pd L}{\pd q_i} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}_i} = \sum_j \frac{\pd r_j}{\pd q_i} ( \frac{\pd L'}{\pd r_j} - \frac{d}{dt} \frac{\pd L'}{\pd \dot{r}_j} ).
\end{equation}
Writing the term on the right in parentheses as $v_j$ this is just a matrix equation $J\indices{_i^j}v_j = 0$ which since $J$ has full rank implies that $v_j = 0$.

[He works it out in coordinates a bit more but it's unnecessary given the linear algebraic treatment is enough.]
\end{enumerate}

Now, depending on the coordinate the Euler-Lagrange equation might look simpler or more complicated. For example, for a free particle in 3D we have $L = T = (1/2)m \dot{\v{x}}^2$ with EL $\implies \ddot{x}_i = 0$. On the other hand, in spherical coordinates
\begin{equation}
L = \frac{1}{2} m (\dot{r}^2 + r^2 \dot{\theta}^2 + r^2\sin^2\theta \dot{\phi}^2 )
\end{equation}
and the EL equations give us
\begin{align}
0 &= r \dot{\theta}^2 + r\sin^2\theta \dot{\phi}^2 \\
0 &= \frac{d}{dt} (r^2 \sin^2\theta \dot{\phi}^2) \\
0 &= r^2 \sin\theta \cos\theta \dot{\phi}^2 - \frac{d}{dt} (r^2 \dot\theta)
\end{align}
which look much worse to work with. The challenge is to find coordinates which make $L$ as simple as possible!

Note also that the derivation allowed for explicitly time dependent coordinate transformations. This implies that the EL equations also have the same form in non-inertial coordinate systems. Some examples:
\begin{enumerate}
\item \textbf{Constant acceleration}
\begin{align}
x &= x' \\
y &= y' \\
z &= z' + \frac{1}{2} a t^2
\end{align}
for the free particles gives us
\begin{align}
L &= \frac{1}{2} m (\dot{x}^2 + \dot{y}^2 + \dot{z}^2) \\
L' &= \frac{1}{2} m \left[ \dot{x}'^2 + \dot{y}'^2 + (\dot{z}' + at)^2 \right] \\
	&= \frac{1}{2} m (\dot{x}'^2 + \dot{y}'^2 + \dot{z}'^2) + mat \cdot \dot{z}' + \frac{1}{2} mat^2.
\end{align}
That last term does not depend on coordinates. Then EL equations give
\begin{equation}
\ddot{x} = 0, \quad \ddot{y} = 0, \quad \ddot{z} + ma = 0
\end{equation}
which is the same as the equations for a constant gravitational field (this is the equivalence principle).

\item \textbf{Rotating frame}
\begin{align}
x &= x' \cos \omega t + y' \sin \omega t \\
y &= y' \cos \omega t - x' \sin \omega t \\
z &= z',
\end{align}
gives us
\begin{align}
\dot{x} &= \dot{x}' \cos\omega t - \omega x' \sin \omega t + \dot{y}' \sin \omega t + \omega y' \cos \omega t \\
\dot{y} &= \dot{y}' \cos \omega t - y' \omega \sin \omega t - \dot{x}' \sin \omega t - x' \omega \cos \omega t \\
\dot{z} &= \dot{z}'.
\end{align}
Then our Lagrangian is given by
\begin{align}
L &= \frac{1}{2} m (\dot{x}^2 + \dot{y}^2 + \dot{z}^2) \\
	&= \frac{1}{2} m \left[ (\dot{x}' + \omega y')^2 + (\dot{y}' - \omega x')^2 + \dot{z}'^2 \right] \\
	&= \frac{1}{2} m (\dot{\v{x}}' - \v{\omega} \times \v{x}')^2
\end{align}
where $\v{\omega} = (0, 0, \omega)^\top$. We find that the EL equations give us
\begin{equation}
\ddot{\v{x}} - 2 \v{\omega} \times \dot{\v{x}} + \v{\omega} \times \v{\omega} \times \v{x} = 0
\end{equation}
where we recognize the second term as the Coriolis force and the third term as the centrifugal force. We got this from:
\begin{align}
\frac{\pd L}{\pd \v{x}} &= \frac{\pd}{\pd \v{x}} \left( -m \v{x} \cdot (\v{\omega} \times \v{x}) + (m/2) (\v{\omega} \times \v{x})^2 \right) \\
	&= -m \dot{\v{x}} \times \v{\omega} - m (\v{\omega} \times \v{\omega} \times \v{x})
\end{align}
where the first term is obtained by:
\begin{align}
\frac{\pd}{\pd x_m} \dot{\v{x}} \cdot (\v{\omega} \times \v{x}) &= \dot{x}_i \varepsilon_{ijk} \omega_j \delta_{km} \\
	&= \dot{x}_i \omega_j \varepsilon_{ijm} \\
	&= \dot{\v{x}} \times \v{\omega}.
\end{align}

\end{enumerate}

\section{A little more on variational calculus and functional derivatives}

Before, we had  the statement $\delta S / \delta q_i(t) = 0$ as the analog of $df / dx_i = 0$ for extrema. How is this equality defined? For the ordinary derivative we can write $df = f' dx$. For the functional derivative, we have
\begin{align}
\frac{\pd S[q(t) + \epsilon h(t)]}{\pd \epsilon} \Big|_{\epsilon = 0} &= \epsilon \int dt \left( \frac{\pd L}{\pd q} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}} \right) h(t) \\
	&= \epsilon \int dt \frac{\delta S}{\delta q(t)} h(t)
\end{align}
where $\delta q(t) = \epsilon h(t)$. Then we can write
\begin{equation}
\delta S = \int dt \frac{\delta S}{\delta q(t)} \delta q(t).
\end{equation}
Note the integral! This actually looks different than the ordinary derivative.

Most rules for derivatives (product, chain, etc) apply with this definition of the functional derivative. Another quick way to define the functional derivative in general is:
\begin{equation}
\frac{\delta S[q]}{\delta q(t')} = \lim_{\epsilon \rightarrow 0} \frac{S[q(t) + \epsilon \delta(t-t')] - \delta q(t)}{\epsilon}.
\end{equation}
For $S = \int dt L(q, \dot q, t)$ this gives us
\begin{align}
\frac{\delta S[q]}{\delta q} &= \lim_{\epsilon \rightarrow 0} \frac{1}{\epsilon} \int dt \left[ L(q(t) + \epsilon \delta(t-t'), \dot{q}(t) + \epsilon \frac{d}{dt} \delta(t-t'), t) - L(q(t), \dot{q}(t), t) \right] \\
	&= \lim_{\epsilon \rightarrow 0} \frac{1}{\epsilon} \int dt \left[ \cancel{L(q, \dot q, t)} + \epsilon \frac{\pd L}{\pd q} \delta(t-t') + \epsilon \frac{\pd L}{\pd \dot{q}} \frac{d}{dt} \delta(t-t') - \cancel{L(q, \dot q, t)} + \bigo(\epsilon^2) \right] \\
	&= \int dt \left[ \frac{\pd L}{\pd q} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}} \right] \delta(t-t') \\
	&= \frac{\pd L}{\pd q} - \frac{d}{dt} \frac{\pd L}{\pd \dot{q}}.
\end{align}

\end{document}


\chapter{Introduction to Electricity}

What happens when you turn on a flashlight? The battery in the
flashlight acts as an electron pump. The electrons flow through the
wires to the lightbulb (or LED). As the electrons pass through the
lightbulb, they excite the molecules within, which gives off light and
heat. (LEDs also give off light and heat, but they give off a lot less
heat.) Then the electrons return to the battery to be pumped around
again.

When electricity is flowing through a copper wire, the protons and
neutrons of the copper stay put while the electrons jump between the
atoms on their way from the battery to the lightbulb and back again.

In some materials, like copper and iron, electrons are loosely bound
to their nuclei, forming a sea of electrons, which allows enery to flow. These are good \textit{electrical conductors}. In
other materials, like glass and plastic, electrons don't leave their
nuclei easily. Thus, they are terrible electrical conductors -- we call
them \textit{electrical insulators}. For example, the plastic around a
wire is electrical insulation.

\includegraphics[width=0.8\textwidth]{Insulator_vs_Conductor.png}
% KA: https://www.khanacademy.org/science/physics/electric-charge-electric-force-and-voltage/charge-electric-force/v/conductors-and-insulators

\section{Units}

Electrons are very small, so to study them, scientists came up with a
unit that represents \textit{a lot} of electrons. 1 \textit{coulomb}
is about 6,241,509,074,460,762,608 electrons.  When 5 coulombs enter one end of the wire every second (and simultaneously 5 coulombs exit the other end), we say ``This wire is carrying 5 ampere of current.''\index{coulombs}

(Truthfully, we usually shorten ampere to just ``amp''.  This is
sometimes a little awkward because we often shorten the word
``amplifier'' to ``amp''. You should be able to tell which is which
from the context.)\index{amp or ampere}

If you look at the circuit breakers or fuses for your home's
electrical system, you'll see that each one is rated in amps.  For
example, maybe the circuit that supplies power to your kitchen has a 10
amp circuit breaker. If for some reason, more than 10 amps tries to
pass through that wire, the circuit breaker will turn off the whole
circuit.

When it is on, your flashlight pushes about 1 amp of current
through the lightbulb(When it is off, there is no current in the
lightbulb).

\includegraphics[width=0.8\textwidth]{Circuit_OnOff.png}

The lightbulb creates \textit{Resistance} that the current pushes
through.\index{resistance} Think of it like plumbing: The current is the amount of water
passing through a pipe. The resistence is something that tries to stop
the current -- like a ball of hair. The battery is what allows
 the current to push through the resistance; we call that
pressure \textit{voltage}.\index{voltage}

\section{Circuit Diagrams}

Here is a circuit diagram of your flashlight:

\begin{circuitikz}
\draw (0,0) to[battery1,invert,l=$3V$] ++(0,3)
to [switch,i=1A] ++(3,0)
to [lamp=$1\Omega$,bipoles/length=0.9cm] ++(0,-3) -- (0,0);
\end{circuitikz}

The lines are wires.  The symbols that we  will use:

\begin{tabular}{c c c c}
  Battery & Switch & Lamp & Resistor \\
\begin{circuitikz}
\draw (0,0) to[battery1] (2,0);
\end{circuitikz}
&
\begin{circuitikz}
\draw (0,0) to[lamp,bipoles/length=0.9cm,l=$3 \Omega$] (2,0);
\end{circuitikz}
&
\begin{circuitikz}
\draw (0,0) to[switch,/tikz/circuitikz/bipoles/length=1.0cm] (2,0);
\end{circuitikz}
&
\begin{circuitikz}
\draw (0,0) to[R,  l=$3 \Omega$] (2,0);
\end{circuitikz} \\
\end{tabular}

The battery pushes the electrons from one end and pulls them back in at the other, so the circuit must go around in a circle for current to flow. This is why the current stops flowing when the switch breaks the circuit.

You can think of a switch as having zero resistance when it is closed and infinite resistance when it is open.

For our purposes, a lamp is just a resistor that gives off light.
% KA: https://www.khanacademy.org/science/high-school-physics/dc-circuits/electric-power-and-dc-circuits/a/circuit-introduction

\section{Ohm's Law}

Resistance is measured in \textit{ohms}, and we use a Greek capital omega for that: $\Omega$

Voltage is measured in
\textit{volts}.\index{ohms}\index{volts}

\begin{mdframed}[style=important, frametitle={Ohm's Law}]\index{Ohm's law}
  Whenever a voltage $V$ is pushing a current $I$ through a resistance of $I$, the following is true:

  $$V = IR$$

  where $V$ is in volts, $I$ is in amps, and $R$ is in ohms.
\end{mdframed}
% KA: https://www.khanacademy.org/science/physics/circuits-topic/circuits-resistance/v/circuits-part-1

\section{Power and Watts}

\begin{mdframed}[style=important, frametitle={Joule's Law}]\index{Joule's law}

  When a current $I$ is passing through a resistance $R$, the power consumed is

  $$W = I^2 R$$

  where $W$ is in watts, $I$ is in amps, and $R$ is in ohms.
\end{mdframed}

Of course $V = IR$, so we can extend this to:

$$W = I^2 R = I V = \frac{V^2}{R}$$

Your flashlight's batteries provides about 3 volts. How much
battery power is the flashlight using when it is on? The power (in
watts) produced by the battery is the product of the voltage (in
volts) and the current (in amps). So your flashlight giving off $3
volts \times 1 amp = 3 watts$ of power. Some of that power is given
off as light, some as heat.\index{watts}

A watt is 1 joule of energy per second. We say that a watt is a
measure of \textit{power}.

When we talk about how much energy is stored in a battery, we use a
unit like kilowatt-hour. A kilowatt-hour is equivalent to 3.6 million
joules.

\section{Another great use of RMS}

In many electrical problems, the voltage fluctuates a lot.  For
example, the fluctuations in voltage makes the sound that comes out of an
audio speaker.

You can use the root-mean-squared of the voltage to figure out the average power
your speaker is consuming.

Lets say that the RMS of the voltage you are sending to the speaker is $V_{rms}$
and the resistance of the speaker is $R$ ohms, then the power consumed
by the speaker is:

$$P = \frac{V_{rms}^2}{R}$$

Similarly, if you know the RMS of the current you are pushing through
the speaker is $I_{rms}$, then the power consumed by the speaker is:

$$P = I_{rms} R$$

\section{Electricity Dangers}

Large amounts of electricity moving through your body can hurt or even kill
you. You must be careful around electricity.

However, your body is not a very good conductor, so low-voltage
systems (like a flashlight) don't have enough voltage to move succnificant amounts of
current through your body.

However, the  electricity in a power outlet has much more voltage. The voltage
in these outlets is fluctuating between positive and negative, so we
call it \textit{Alternating Current} or AC.
% ADD: Introduce difference between AC and dc

\includegraphics[width=0.8\textwidth]{AC_vs_DC.png}

In most countries, the RMS of the voltage between 110 and 240 V. (The
peak voltage is always $\sqrt{2}$ times the RMS value. In the US, for
example, people say ``Our outlets supply 120 V.'' They mean that the
RMS of the voltage difference between the wire and the earth is 120V.
The peak voltage is almost 170V.)

How much current can a human handle? Not much. You can barely feel 1
mA moving through your body, but at 16 mA, your muscles will clench
and you won't be able to relax them -- many people die from
electrocution because they grab a wire which pushes enough current
through their body to prevent them from letting go of the wire.  At 20
mA, a human's respiratory muscles become paralyzed.

The fuse breaker in a house will often allow 20 A to flow through the
circuit before it shuts off the power: Always, always, always shut off
the power before touching any of the wiring in your house.

While water is actually a mediocre conductor, it can still deliver enough current
to kill you. If you see a wire in a puddle, you should not touch the
puddle. Interestingly, because of the salt, sea water is more than
100 times better at conducting electricity than the water you drink.
% ADD: Sea of electrons makes a good conductor

\includegraphics[width=0.8\textwidth]{Sea_Electrons.png}

If you hold a wire in each hand, how many Ohms of resistance will your
body have? Once it gets past your skin, you will look like a bag of
salt water to the electricity. After the skin, your body will have a
resistance of about 300$\Omega$. However, the skin is a pretty good
insulator. If you have dry, calloused hands, your skin may add a
100,000$\Omega$ to the resistance.

% KA: https://www.khanacademy.org/science/in-in-class10th-physics/in-in-electricity/in-in-electric-power-and-heating-effect-of-current/v/electric-power-energy


\documentclass[11pt]{article}

\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{graphicx}
\usepackage{titling}
\usepackage{float}
\usepackage{bm}
%\usepackage[fleqn]{amsmath}
\usepackage{amssymb,amsmath}
\usepackage{listings}
\usepackage{color}
\usepackage{enumitem}
\usepackage{fancyvrb}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage{tabularx}
\usepackage{diagbox}
\usepackage{pdfpages}
\geometry{letterpaper}
\linespread{1.1}% \geometry{landscape} % rotated page geometry

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}

\lstdefinestyle{mystyle}{
	backgroundcolor=\color{backcolour},
	commentstyle=\color{codegreen},
	keywordstyle=\color{magenta},
	numberstyle=\tiny\color{codegray},
	stringstyle=\color{codepurple},
	basicstyle=\footnotesize,
	breakatwhitespace=false,
	breaklines=true,
	captionpos=b,
	keepspaces=true,
	numbers=left,
	numbersep=5pt,
	showspaces=false,
	showstringspaces=false,
	showtabs=false,
	tabsize=2
}

\lstset{style=mystyle}

\setlength{\droptitle}{-5em}
\title{CE 264 Problem Set 5: Midterm Review}
\date{22 Mar. 2018}
\author{Kun Qian \ \ \ \ \ \ (3033030782)\\ Franklin Zhao \ (3033030808)\\ Yichen Zhong \  (3033030873)}

\begin{document}

	\maketitle
	\renewcommand\theequation{\arabic{equation}}
	\renewcommand{\figurename}{Fig.}
	\renewcommand\thesection{Problem \arabic{section}}
	\renewcommand\thesubsection{(\Alph{subsection})}
	\renewcommand\thesubsubsection{Question (\alph{subsubsection}):}
	\onehalfspacing

\section{}
\noindent The probability to move to North Berkeley is:
\begin{equation}\label{finaleq}
Pr(NB)=\frac{e^{V_{NB}}}{e^{V_{NB}}+e^{V_{SF}}+e^{V_{PO}}}\ \ \text{(since only 3 choices available here)}
\end{equation}
\noindent For the choice-residential model, we have the utility function:
\begin{equation}
U=\beta_{Rent}\times Rent+\beta_{Price}\times Price+\beta_{Size}\times Size+\beta_d\times DummyHouse+\beta_{Log}\times Logsum
\end{equation}
where most values are listed in the problem, but we still need to compute the logsum from the commuter's choice model.
\begin{equation}
LL=log(\prod Pr_{i,j})
\end{equation}
where $i\in\{1,2\}$ represents an individual; $j\in\{1,2,3\}$ represents a residence choice.\\\\
For a nested logit model:
\begin{align}
Pr(Driver)=Pr(Driver|Auto)\times Pr(Auto)\times...\\
Pr(Auto)=\frac{e^{\mu V_A}}{e^{\mu V_A}+e^{\mu V_N}+e^{\mu V_T}}\\ Pr(Driver|Auto)=\frac{e^{\mu_AV_D}}{e^{\mu_AV_D}+e^{\mu_AV_P}}\\
V_A=\frac{1}{\mu_A}log(e^{\mu_AV_D}+e^{\mu_AV_P})\ \ (\text{Similar for }\mu_{NM}\text{ and } \mu_T)
\end{align}
where $\mu_A=1.67$, $\mu_{NM}=1.205$, and $\mu_T=1.784$.
For each individual in each residential choice, the following utility equations are as follows:
\begin{equation}
V_{Drive}=ASC_{Drive}+\beta_{in-veichle}\times T_{Time}+\beta\times Cost
\end{equation}
\begin{equation}
V_{Passgr}=ASC_{ShareRide}+\beta_{in-veichle}\times T_{Time}+\beta\times Cost
\end{equation}
\begin{equation}
V_{Walk}=ASC_{Walk}+\beta_{Walking}\times T_{Time}+\beta\times Cost
\end{equation}
\begin{equation}
V_{Bike}=ASC_{Bike}+\beta_{Bike}\times T_{Time}+\beta\times Cost
\end{equation}
\begin{equation}
V_{W-T}=ASC_{W-T}+\beta_{in-veichle}\times T_{Time}+\beta_{Wait}\times T_{Wait}+\beta_{Transit}\times T_{Transit}+\beta\times Cost
\end{equation}
\begin{equation}
V_{A-T}=ASC_{D-T}+\beta_{in-veichle}\times T_{Time}+\beta_{Wait}\times T_{Wait}+\beta_{Transit}\times T_{Transit}+\beta\times Cost
\end{equation}
The upper level utilites are computed in Table 1.
\begin{center}
Table 1: Upper level utilities
\end{center}
\begin{figure}[H]
\centering
\vspace{-0.6cm}
\includegraphics[width=\linewidth]{tb1.pdf}
\end{figure}
Using these 12 computed upper level utilities, the following results can be derived:
\begin{align}
\tilde{V}_{MD,Auto}=log(e^{-1.562}+e^{-2.268})=-1.161\\
\tilde{V}_{MD,Non}=log(e^{-2.914}+e^{-0.595})=-0.411\\
\tilde{V}_{MD,Tran}=log(e^{0.271}+e^{-0.562})=0.632\\
\tilde{V}_{NB,Auto}=log(e^{-1.925}+e^{-0.300})=-0.121\\
\tilde{V}_{NB,Non}=log(e^{-0.595}+e^{-0.915})=-0.049\\
\tilde{V}_{NB,Tran}=log(e^{-1.306}+e^{0.309})=0.491
\end{align}
\newpage
\begin{align}
\tilde{V}_{PO,Auto}=log(e^{-1.427}+e^{-1.008})=-0.503\\
\tilde{V}_{PO,Non}=log(e^{-0.595}+e^{0.005})=0.443\\
\tilde{V}_{PO,Tran}=log(e^{-1.330}+e^{-1.316})=-0.630
\end{align}
Now, let's compute the logsum for each residential choice:
\begin{align}
\tilde{V}_{MD}=log(e^{-1.161}+e^{-0.411}+e^{0.632})=2.858\\
\tilde{V}_{NB}=log(e^{-0.121}+e^{-0.049}+e^{0.491})=3.472\\
\tilde{V}_{PO}=log(e^{-0.503}+e^{0.443}+e^{-0.630})=2.695
\end{align}
Hence, the utility for each residential choice can be derived:
\begin{align}
V_{MD}=-0.16\times29-0.064\times70+4.400\times0.82-0.782\times0+2.000\times2.858=0.204\\
V_{NB}=-0.16\times28-0.064\times60+4.400\times1.16-0.782\times1+2.00\times3.472=2.946\\
V_{PO}=-0.16\times18-0.064\times82+4.400\times1.26-0.782\times1+2.000\times2.695=2.024
\end{align}
Plug the above equations into Equation~(\ref{finaleq}), and the final result is obtained:
\begin{equation}
Pr(NB)=\frac{e^{2.946}}{e^{0.204}+e^{2.946}+e^{2.024}}=\bf{0.684}
\end{equation}
\section{}
\subsection{}
\begin{align}
Pr(P|G=1)=\frac{e^0}{e^{(0.3+1.8)}+e^1+e^0}=0.084\\
Pr(M|G=1)=\frac{(0.3+1.8)}{e^{(0.3+1.8)}+e^1+e^0}=0.687\\
Pr(T|G=0)=\frac{e^1}{e^{0.3}+e^1+e^0}=0.536\\
Pr(T|G=0)=\frac{e^0.3}{e^{0.3}+e^1+e^0}=0.266
\end{align}
\begin{equation}
LL=log(0.084^2\times0.687^4\times0.536^6\times0.266^2)=-12.8
\end{equation}
Hence, the value of the log-likelihood function at MLE is \textbf{-12.8}.
\subsection{}
\begin{equation}
\rho^2=1-\frac{L(\beta)}{L(0)}=1-\frac{-12.8}{14\times log(\frac{1}{3})}=1-\frac{-12.8}{-15.4}=\bf{0.17}
\end{equation}
\subsection{}
\textbf{Yes,} since now if we check the table of estimated parameters, we noticed given	that $\beta_{3T}=\beta_{3P}=0$, the graduate students' choice will always be $M$, which in fact makes $\beta_S$ not estimable. Hence, changing the availability like this would definitely affect the value of MLE.
\section{}
\subsection{}
\textbf{Yes.} Travel time is a variable across alternatives, so it can be included in all alternatives and four parameters can be estimable. In this example, the parameter values are partially constrained to be the same across motor and nonmotor alternatives.
\subsection{}
\textbf{No.} Because the distance between home and destination for each staff is fixed and does not vary across alternatives. To modify the specification, estimated alternative-specific distance parameters and one base alternative can be used to replace a single beta for all four alternatives.
\subsection{}
\textbf{No.} Because the average price per gallon is a fixed value for all respondents, which means it is perfectly correlated with the car constant. It can be modified to fuel cost per trip based on trip distances to estimate the parameter.
\subsection{}
\textbf{Yes.} Female = 1 – Male. This variable does not vary across alternatives and it is categorical with two categories. So, one utility and one category must be the base and gender can be included in at most 3 alternatives.
\subsection{}
\textbf{No,} at most 2 variables can be included in each utility. So, one of the income categories need to be set as a base and drop from utility.
\section{}
\subsection{}
Because \textit{t-test}$=\frac{\hat{\beta}-0}{\bar{\sigma}}$,
\begin{equation}
\bar\sigma=\frac{\hat{\beta}-0}{\text{\textit{t-test}}}=\frac{0.8}{8.52}=0.094
\end{equation}
Then we let $\alpha$ walk-transit for Transit Nest to de a hypothesis test:
\begin{equation}
\begin{array}{rl}
H_0:&\alpha=1\\
H_1:&\alpha\neq1\\
\text{\textit{t-test}}=&\frac{0.8-1}{0.094}=-2.128<-2.1
\end{array}
\end{equation}
Thus we \textbf{reject} the null hypothesis, and the cross situation is preferred.
\subsection{}
For unrestricted model, we can estimate much more parameters than restricted models. Thus, the likelihood and $\rho^2$ will increase, and we cannot confirm what happens to $\rho^2$.
\end{document}