%!TEX root = ../../dissertation.tex

\section{Properties of the exchange economy}
\label{sec:properties}

We compute an accurate global solution to the scaled Pareto problem
by methods described in Appendix \ref{app:computation_BCFL}.
We  describe its properties here.
We start with the Pareto weight, then go on to explore
the dynamics of the Pareto weight,
the connection between consumption and the real exchange rate,
and the responses of consumption and other variables to changes in various state variables.

{\textit The Pareto frontier.\/}
One of the outputs of the numerical solution is the value function $J$, a function of
promised utility $U$ and the exogenous state variables.
Given values for the exogenous state variables, this gives us the Pareto frontier:
the highest utility of agent 1 ($J$) consistent with a given level of utility
for agent 2 ($U$) and the productive capacity of the economy.

We describe the Pareto frontier in Figure \ref{fig:pareto-frontier}
with state variables $z_{1t} = z_{2t} = \wh{z}_t = 1$ and $v_t = v$.
The outer curve in the figure is the consumption frontier,
which echoes Figure \ref{fig:consumption-frontier}.
The inner curve is the Pareto frontier.
We see that it has much the same shape.
It's inside the consumption frontier largely because of risk:
utility is below consumption because risk reduces utility.
If we increase risk aversion to 50 ($\alpha = -49$, not shown),
it shifts in further.

Changes in the state variables change both frontiers.
Movements in productivity and output shift the frontiers --- both of them ---
in and out ($\bar{z}_t$, which affects the two intermediate goods proportionately)
or twist them ($\wh{z}_t$, which affects the two goods differently).
Changes in risk twist the Pareto frontier, since risk affects the two goods differently,
but not the consumption frontier, since it has no effect on quantities of intermediate goods.

{\textit Dynamics of the Pareto weight.\/}
We see the impact of recursive preferences in Figure \ref{fig:exchange-pareto-weight-two},
where we graph $\log \lambda^*_t $ against time for a (very long) simulation of the model.
The flat horizontal line refers to the additive case ($\alpha = \rho = -1$).
As we know, the Pareto weight doesn't change in this case.
The other line refers to the recursive case, and we see clear variation in the Pareto weight.
We also see that the variation is both large and very persistent.
%Persistence is important, as we'll see, in producing persistent movements in
%the real exchange rate.

This touches on a question that's been discussed extensively:
Is the Pareto weight stable, or does one agent eventually consume everything?
\citet{Anderson2005-of} and \citet{Borovicka2016-rr} document some of the difficulties
of establishing stability in similar one-good settings.
\citet{Colacito2011-zp} prove stability in a two-good
world with elasticities of substitution between goods and over time equal to one.
\citet{Colacito2013-yq}, \citet{Kollmann2015-sy}, and \citet{Tretvoll2011-lo,Tretvoll2015-lo,Tretvoll2018-dj}
solve similar models numerically and report that the solutions are stable.
We also find that they're stable, but extremely persistent.

We get a sense of how stability works in Figure \ref{fig:change-pareto-weight-ra},
where we plot the expected change in the log Pareto weight against its level.
The exogenous state variables here have been set equal to their means.
In the additive case, the expected (and actual) change is zero.
The log Pareto weight is a martingale with no variance.
With greater risk aversion, mean reversion becomes evident.
If the Pareto weight is below its steady state value of one ($\log \lambda_t^* = 0$),
it's expected to increase.
If above, it's expected to decrease.
The effect is stronger when we increase risk aversion to 50.
There is also an evident nonlinearity in the solution,
as there is in \citet[Figure 5]{Colacito2011-zp},
but most of it occurs in regions of the state space we rarely reach.

The elasticity of substitution between foreign and domestic intermediate goods
also plays a role in persistence.
See Figure \ref{fig:change-pareto-weight-arm}.
With smaller values, mean reversion is slower.
And with larger values, it's faster.
As the elasticity increases, the line flattens out and we approach
the one-good world with a constant Pareto weight.

The intertemporal elasticity of substitution also has an effect,
but with the numbers we've chosen the effect is smaller.
See Figure \ref{fig:change-pareto-weight-ies}.
Evidently smaller values of $\rho$, and larger values of the IES [$1/(1-\rho)$],
lead to flatter lines.

{\textit Consumption and exchange rate.\/}
We noted earlier that the relation between the log consumption ratio [$\log (c_{2t}/c_{1t})$]
and the log of the real exchange rate [$ \log e_t = \log (p_{2t}/p_{1t}) $]
is mediated by the log Pareto weight ($\log \lambda^*_t$).
See equation (\ref{eq:cons-rer}).
In the additive case, the Pareto weight is constant and we have a
perfect linear relationship between the two variables.
We see exactly this in the line in Figure \ref{fig:exchange-cons-rer-two}.

The scatter of points in the same figure represents the recursive case,
where the Pareto weight acts like a wedge from the perspective of the additive model.
With our numbers, the variation in the Pareto weight is enough to change
a negative correlation of minus one between the consumption ratio and exchange rate
to a slight positive correlation.
\citet{Colacito2013-yq}, \citet{Kollmann2015-sy}, and \citet{Tretvoll2011-lo} show the same.
If we increase risk aversion $1-\alpha$ to 50,
the correlation becomes strongly positive.
In the recursive model,
we can produce any correlation we like by varying the risk aversion
parameter.

Recursive preferences also have an impact on exchange rate dynamics
as the persistence in the Pareto weight is reflected in the real exchange rate.
We see in Figure \ref{fig:rer-acfs} that the additive model is much less persistent:
The half-life (where the autocorrelation function equals one-half) is about a year.
By five years, the autocorrelation is essentially zero.
Exchange rate dynamics reflect, in this case, the modest persistence of relative productivity $\wh{z}_t$.
With recursive preferences, the exchange rate is much more persistent.
In fact with these parameter values, it's virtually a martingale.
We can reproduce any level of persistence we like by varying risk aversion
between the two cases.
There's a range of opinion, summarized nicely by \citet{Crucini2008-mi},
about how much persistence we need for the model to be realistic.
The larger point is that recursive preferences are a device that can deliver
persistence in real exchange rates and macroeconomic variables in general.
It's what an older literature would call a propagation mechanism.

{\textit Responses to productivity and volatility shocks.\/}
We get another perspective on the model's dynamics from impulse responses.
Starting at the steady state, we increase one of the exogenous state variables
by one standard deviation at date one, simulate the model for several periods,
and compute the mean dynamics of all the variables in the model.
This goes somewhat beyond traditional impulse responses in linear models in
which the subsequent innovations are turned off.

In Figure \ref{fig:irf-zhat}
we describe responses to an increase in (the log of) relative productivity $\wh{z}_t$.
The effect on future values of $\log \wh{z}_t$ declines at a constant rate
as described by equation (\ref{eq:lom-zhat}).
Neither average productivity $\bar{z}_t$ nor volatility $v_t$ change,
so this implies an increase in $\log z_{1t}$ and an equal decrease in $\log z_{2t}$.
The quantity of apples goes up, and the quantity of bananas goes down.
Because of home bias, consumption goes up in country 1 (the apple eaters)
and down in country 2 (banana eaters).
The exchange rate rises as scarce bananas become more expensive.

All of this would be true in the additive case as well.
What's different is the response of the Pareto weight.
It goes up as we compensate the agent in country 2 with promises of higher future consumption.
This effect eventually wears off, but it does so very slowly.

In Figure \ref{fig:irf-v}
we describe the responses to an increase in volatility $v_t$.
Here there's no change in the quantities of intermediate goods.
In the additive case, there would be virtually no effect.
In the recursive case, utility falls, but it falls more for country 1 because
of its home bias in favor of the good whose supply has become riskier.
The social planner responds by decreasing the Pareto weight
on agent 2.
Consumption therefore rises in country 1 and falls in country 2.
The real exchange rate falls.
This is entirely a demand-side effect.
By increasing the weight on agent 1, the demand for apples goes up
and the demand for bananas goes down.
The magnitudes are small, but it's an interesting effect that we would like to explore
further in a production economy, where supply can respond to
changes in market conditions.


\chapter{Darwin Library}
\label{sec:darwin_lib}

Darwin is a simple library written in Python for BN modeling and inference.
The main purpose of the library is teaching BNs and quick prototyping or testing small networks.
In order to achieve these goals, the library has a simplistic approach of implementation, using native Python data structure and light usage of object oriented programming.
The structure of Darwin is basically divided into two categories: potentials and graph manipulations.
The features are also split into two main categories: inference and modeling tools.
Later, in this section, we also present a guide for getting started using Darwin.

\section{Structure}
\label{sec:system:sec1}

In order to work with BNs, Darwin has two main set of implementations: potential and graph manipulations.
These two categories form individually or together the tree structure of the library as presented in Figure \ref{fig:tree_darwin}.

\begin{figure}[hbt]
    \begin{center}
        \includegraphics[width=\textwidth]{img/structure_darwin}
    \end{center}
    \caption{Three structure of Darwin.}
    \label{fig:tree_darwin}
\end{figure}

At the root, the class \emph{Potential} is a data structure for modeling a probability table.
The \emph{NetworkX} \cite{hagberg-2008-exploring} is set of data structures for graph manipulation and is also included at the root of the library.
Similarly, \emph{GraphWithPotential} is a class which basically maps nodes in a graph with a set of potentials, besides providing manipulations on the graph and the potentials on it.
\emph{BayesianNetwork} is a class that inherits from \emph{GraphWithPotential} but maps only one potential per node.
This data structure is used for modeling a BN.
In the same way, the class \emph{MarkovNetwork} entirely inherits the behaviour and properties of \emph{GraphWithPotential}, therefore it can be used for MN modeling.

The \emph{Utils} branch is formed by a set of standalone functions which implement core procedures for the other classes.
Mainly, these functions are defined by numerical operations on lists of probabilities.
One advantage of having those implementations as standalone functions is that future optimized code can be included or modified without disturbing the other classes, since the other classes only makes a function call to those utilities functions.
Basically, there are three main utilities: \emph{BnUtils}, \emph{MnUtils}, and \emph{PotentialUtils}.
The BnUtils has a set of functions for BN manipulations and operations, such as moralization, triangulization, join tree construction, among others.
In MnUtils, we have utilities for MN propagation such as finding an optimal path for propagating in a tree.
Lastly, PotentialUtils is formed by a set of procedures for numerical operations such as multiplication, division and marginalization of tables.
All potential manipulations in PotentialUtils is implemented according to the efficient implementation proposed in \cite{koll09}.

In the \emph{Modeling} brach, there is an implementation of d-Separation as proposed in Algorithm 3.1 of \cite{koll09}.
While in the branch \emph{Inference} there are few data structures useful for exact inference in BNs.
The \emph{Barren} function is used for identifying barren potentials in factorizations.
\emph{SumOut} is a function which systematically removes a set of variables from a factorization by multiplying potentials with the variables and them marginalizing the variables out.
The class \emph{VariableElimination} implements the exact inference algorithm VE as originally proposed by \cite{zhan94}.
Finally, the \emph{Test} branch has a set of unit tests which assure the correct functioning of core functions in the whole library.

\section{Features}
\label{sec:system:sec2}

Here, we highlight some feature of the library.
In general, the features are tools to facilitate the use of Darwin in teaching and prototyping of small system.
The library is not intended for fast inference, neither high accuracy.
Therefore, all numerical operations are implemented using native Python code, instead of high performance libraries such as \emph{numpy} \cite{van2011numpy}.
The graph manipulations are done by an external library called \emph{NetworkX}, a robust and well known library with high performance and large set of tools.

For modeling, Darwin has the testing of d-Separation implemented using a reachability algorithm.
Also, the library has built in tools for converting a BN into a MN, including the join tree construction by moralization, triangulization and the assignment of potentials.
The triangulization step, specifically, has implemented 4 different heuristics, the same as implemented in \emph{PgmPy} \footnote{http://pgmpy.org}.

For inference, the library provides a basic function for eliminating variables in a factorization, called \emph{SumOut}.
But for faster inference, it is recommended to use the VE implementation which absorb evidence, removes barren and independent by evidence potentials, perform inference by summing out non relevant variables and, finally, normalize the final result.

\section{Usage}
\label{sec:system:sec3}

In order to get started with Darwin, we now present a quick overview of the most common classes and functions.
The main classes are \emph{Potential}, \emph{GraphWithPotential}, \emph{BayesianNetwork}, and \emph{MarkovNetwork}.

The Potential class is defined by the given arguments: \emph{variables} which is a list with strings, \emph{cardinalities} corresponding to the variables which is a list with integers in the same order than the variables, probabilities \emph{values} in a list with floating numbers, \emph{left hand side} which is a list with the variables in the LHS of the potential, and similarly the \emph{right hand side} is defined.
For example, considering a CPT $P(a|b)$ with binary variables and probability values 0.4, 0.5, 0.6, 0.5, we can use Darwin to represent this potential as:
\begin{verbatim}
    Potential(["a", "b"], [2, 2], [0.4, 0.5, 0.6, 0.5], ["b"], ["a"])
\end{verbatim}

The GraphWithPotential class contains basically a list with potentials, a graph defined using NetworkX, and a dictionary mapping nodes in the graph to a list of potentials.
After declaring a GraphWithPotential, the user can add potentials to a node using the \emph{add\_potential} method.
For example, the following code creates a graph with two nodes $\{a\}$ and $\{a,b\}$ and assign $P(a)$ to $\{a\}$ and $P(b|a)$ to $\{a,b\}$ in a GraphWithPotential.
\begin{verbatim}
    p1 = Potential(["a"], [2], [0.2, 0.8], ["a"], [])
    p2 = Potential(["a", "b"], [2, 2], [0.4, 0.5, 0.6, 0.5], ["b"], ["a"])

    G = networkx.Graph()
    G.add_nodes(["a", "ab"])

    GwP = GraphWithPotential()
    GwP.add_potential("a", p1)
    GwP.add_potential("ab", p2)
\end{verbatim}

The MarkovNetwork inherits from GraphWithPotential, therefore modeling a MN is simply using the GraphWithPotential like in the code above.
In the same way, modeling a BN uses the BayesianNetwork class which also inherits from GraphWithPotential.
The difference for a BN is that only one potential is assigned at one node and the graph used is a DAG.
For instance, the code above can be used to declare a BN with two nodes $a \rightarrow ab$ just by changing the definition of $G$ to the below code, which is a directed graph.
\begin{verbatim}
    G = networkx.DiGraph()
    G.add_edge("a", "ab")
\end{verbatim}


\end{multicols}
\chapter{Results}

\noindent Below, our results are presented.  See the appendix for graphed
visualizations of the predictions. All predictions are made on \textsc{forex}
market data for the \textsc{eur}/\textsc{usd} currency pair from February 9th,
2017---the day following the fourteen consecutive trading days of data that the
models were trained on.

\section{Measurements}

\begin{center}
  \begin{tabular}{l S[table-format=3.4] S[table-format=3.4] S[table-format=3.4] S[table-format=3.4]}
             & \multicolumn{2}{c}{06.00--07.00} & \multicolumn{2}{c}{07.00--08.00}                 \\ \hline\hline
             & \textsc{\quad lstm} & \textsc{\quad rnn} & \textsc{\quad lstm} & \textsc{\quad rnn} \\ \hline
    ${MAPE}$ & \ubold 51.0738\%    & 135.0695\%         & 253.9935\%          & \ubold 237.0991\%  \\
    ${RMSE}$ & \ubold 0.0261       & 0.2096             & \ubold 0.0455       & 0.0981
  \end{tabular}
\end{center}
\begin{center}
  \begin{tabular}{l S[table-format=3.4] S[table-format=3.4] S[table-format=3.4] S[table-format=3.4]}
             & \multicolumn{2}{c}{08.00--09.00} & \multicolumn{2}{c}{09.00--10.00}                 \\ \hline\hline
             & \textsc{\quad lstm} & \textsc{\quad rnn} & \textsc{\quad lstm} & \textsc{\quad rnn} \\ \hline
    ${MAPE}$ & \ubold 147.7115\%   & 154.5905\%         & 131.6576\%          & \ubold 120.2149\%  \\
    ${RMSE}$ & \ubold 0.0592       & 0.1735             & 0.1857              & \ubold 0.1843
  \end{tabular}
\end{center}
\begin{center}
  \begin{tabular}{l S[table-format=3.4] S[table-format=3.4] S[table-format=3.4] S[table-format=3.4]}
             & \multicolumn{2}{c}{10.00--11.00} & \multicolumn{2}{c}{11.00--12.00}                 \\ \hline\hline
             & \textsc{\quad lstm} & \textsc{\quad rnn} & \textsc{\quad lstm} & \textsc{\quad rnn} \\ \hline
    ${MAPE}$ & \ubold 109.234\%    & 377.7257\%         & \ubold 250.9250\%   & 348.9639\%         \\
    ${RMSE}$ & 0.3678              & \ubold 0.1159      & \ubold 0.1083       & 0.1265
  \end{tabular}
\end{center}
\begin{center}
  \begin{tabular}{l S[table-format=3.4] S[table-format=3.4] S[table-format=3.4] S[table-format=3.4]}
             & \multicolumn{2}{c}{12.00--13.00} & \multicolumn{2}{c}{13.00--14.00}                 \\ \hline\hline
             & \textsc{\quad lstm} & \textsc{\quad rnn} & \textsc{\quad lstm} & \textsc{\quad rnn} \\ \hline
    ${MAPE}$ & \ubold 152.8492\%   & 217.5117\%         & \ubold 170.5649\%   & 225.3889\%         \\
    ${RMSE}$ & \ubold 0.1166       & 0.1689             & \ubold 0.1001       & 0.1468
  \end{tabular}
\end{center}
\begin{center}
  \begin{tabular}{l S[table-format=3.4] S[table-format=3.4] S[table-format=3.4] S[table-format=3.4]}
             & \multicolumn{2}{c}{14.00--15.00} & \multicolumn{2}{c}{15.00--16.00}                 \\ \hline\hline
             & \textsc{\quad lstm} & \textsc{\quad rnn} & \textsc{\quad lstm} & \textsc{\quad rnn} \\ \hline
    ${MAPE}$ & \ubold 159.9678\%   & 168.4376\%         & \ubold 166.1331\%   & 255.8209\%         \\
    ${RMSE}$ & \ubold 0.1472       & 0.1836             & \ubold 0.2515       & 0.2559
  \end{tabular}
  \captionof{table}{Measurement results over a day of trading.  The better
    result is denoted with \textbf{bold} numbers.}
\label{tbl:results}
\end{center}

\begin{multicols}{2}

\vfill\null
\columnbreak


\documentclass{article}
\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % For .eps inclusion
%\usepackage{indentfirst} % Controls indentation
\usepackage[compact]{titlesec} % For regulating spacing before section titles
\usepackage{adjustbox} % For vertically-aligned side-by-side minipages
\usepackage{array, mathrsfs, mhchem, amsmath} % For centering of tabulars with text-wrapping columns
\usepackage{hyper ref}
\usepackage[autolinebreaks,framed,numbered]{mcode}
\pagenumbering{gobble}
\setlength\parindent{0 cm}
\begin{document}
\large

\section*{Recap of \textit{Synechococcus} post-translational oscillator}

\begin{figure}
\begin{center}
\includegraphics[width=0.5\textwidth]{pto.png}
\caption{Model for the post-translational oscillator, from Rust 2007.}
\end{center}
\end{figure}

\begin{itemize}
\item Recall that the post-translational oscillator at the heart of the cyanobacterial clock cycles through four states characterized by peaks in four phosphorylation states of the protein KaiC:
\begin{enumerate}
\item U-KaiC: no phosphorylation (``dawn")
\item T-KaiC: threonine phosphorylated (``noon")
\item D-KaiC: both phosphorylated (``dusk")
\item S-KaiC: serine phosphorylated (``midnight")
\end{enumerate}
\item KaiA promotes KaiC's kinase activity. The accumulation of S-KaiC (in conjunction with KaiB) inhibits KaiA.
\item A general model for this clock is described by:

\begin{eqnarray*}
\frac{dT}{dt} & = & k_{UT} U + k_{DT} D -\left(  k_{TD} + k_{TU} \right) T\\
\frac{dD}{dt} & = & k_{TD} T + k_{SD} S - \left(k_{DT} + k_{DS} \right) D\\
\frac{dS}{dt} & = &k_{DS} D +  k_{US} U - \left( k_{SU} + k_{SD} \right) S\\
k_{xy} & = & k_{xy}^0 + \frac{k_{xy}^A A(S)}{K + A(S)}\\
A(S) & = & \max \left(0, \left[ \textrm{KaiA} \right] - 2 S \right)
\end{eqnarray*}

This includes every forward and backward reaction along the loop (though some rate constants are measured to be very low). First-order kinetics are assumed for all phosphorylation and dephosphorylation reactions.

\item A few features seen here that are very common in oscillators:
\begin{itemize}
\item A process driving forward progression.
\item A negative feedback loop that kicks in after a delay (either explicity temporal or resulting from nonlinearity)
\end{itemize}
\item The model presented does not include a positive feedback loop. Notice that most oscillations are relatively sinusoidal, like a harmonic oscillator. Later in this lecture, we will argue that oscillators which contain both positive and feedback loops behave like relaxation oscillators, with strikingly fast transitions.
\end{itemize}

\section*{Entrainment}

\begin{figure}
\begin{center}
\includegraphics[width=\textwidth]{adp_falling.png}
\caption{Change in ATP:ADP ratio upon a dark pulse, from Rust 2011.}
\end{center}
\end{figure}

\begin{itemize}
\item Unexpected periods of darkness during the subjective day lead to decreases in the ATP:ADP ratio. Typically, ATP makes up 90\% of the combined pool of these two molecules; after an eight-hour pulse of darkness, the ratio falls to about 40\%.

\item Since ATP serves as the phosphate group donor for KaiC's phosphorylation reactions, this increases the tendency for KaiC to be in an unphosphorylated state.

\item The dependence on the ATP:ADP ratio is easily studied in vitro, where more ADP can be spiked in (or ATP can be regenerated by adding pyruvate kinase). The phase of the clock is reset to a lower overall phosphorylation (primarily U-KaiC and S-KaiC) after a period when the ATP:ADP ratio is low. This is sensible because that phosphorylation pattern corresponds to the period between midnight and dawn.

\end{itemize}
\begin{figure}
\begin{center}
\includegraphics[width=0.5\textwidth]{adp_feedback.png}
\caption{Model for the effect of ATP:ADP ratio on the PTO, from Rust 2011.}
\end{center}
\end{figure}
\begin{itemize}

\item The model described above was modified to account for the entrainment system as follows:

\[k_{phos} = k_{phos}^A \left( \frac{A(S)}{K + A(S)} \right) \left( \frac{[\textrm{ATP}]}{[\textrm{ATP] + $K_{rel}$[ADP}]} \right) \]

The dephosphorylation reactions do not appear to depend on the ATP:ADP ratio when observed experimentally, so they remain dependent only on $A(S)$.

\item This model follows a limit cycle that maintains the appropriate period for various steady-state daylight ATP:ADP ratios, but shifts phase in response to sudden changes in the ratio.

\item If the dark pulse is delivered around subjective dusk, the phase is modestly advanced; if delivered around subjective dawn, the phase lags. The magnitude of the phase shift is largest around mid-day, when kinase activity would otherwise have peaked: this results in a large phase advance.
\end{itemize}

\section*{Phase response curve (PRC)}

\begin{itemize}
\item One way to quantify the phase shift due to perturbation is with a \textit{phase response curve}. The change in phase (positive if advanced, negative if retarded) is plotted against the timing of the perturbation. These plots are rather popular because they can be made even if nothing mechanistic is understood about the system.

\item Example for circadian rhythm and ``light therapy" illumination common for seasonal affective disorder. Effect on the cycle shifts sharply overnight (exposure in the evening retards the cycle, and exposure in the early morning advances it; little effect during the day).

\item This example emphasizes that the ideal phase response curve is not necessarily flat at zero; entrainment requires the ability to shift phase and a PRC can be more or less well-suited to adjusting the phase in response to stimuli.

\end{itemize}

\section*{\textit{Synechococcus elongatus} transcriptional-translational feedback loop}

\begin{itemize}
\item The mechanism for entrainment described above provides a means for response to natural fluctuations in the ATP:ADP ratio presumably caused by increased availability of ATP during photosynthetic periods.
\item Others have also proposed that the clock could entrain on temperature (another environmental cue that reflects recent lighting conditions). The cyanobacterial clock period is fairly robust to changes in temperature ($\pm 5$ degrees Celsius, a wider range than most marine varieties encounter during the circadian cycle; \textit{Synechococcus elongatus} is a freshwater cyanobacterium, however); the phase, however, can be shifted by abrupt temperature changes of the same range.
\item When temperature and light-dark cycling are offset in phase by 12 hours, the cyanobacterial clock syncs to the light-dark cycling, suggesting that illumination (via ATP:ADP ratios?) is the physiologically-predominant form of entrainment.
\item Unfortunately, the cyanobacterial clock can also be phase-shifted by means which are presumed to be unintentional. For example, overexpression of KaiC for a few hours can reset the phase to subjective dawn. Indeed the in vitro post-translational oscillator can be broken by varying the stoichiometry of the components.
\item KaiA and KaiBC are transcribed from two different operons. KaiA's rate of translation is effectively constant; however, KaiBC transcription and translation vary with the circadian cycle. The problem of keeping ratios constant is therefore exacerbated by the variation in cyanobacterial growth rate with media conditions (e.g. division times ranging from 14-34 hours in common media).
\item A response regulator, RpaA, is activated through phosphorylation by a histidine kinase (SasA) downstream of the PTO. It then binds at hundreds of genes throughout the genome to drive expression of its targets, including \textit{kaiBC}.
\item In $\Delta$rpaA strains, \textit{kaiBC} expression is four-fold lower than normal, breaking the PTO.
\end{itemize}

\begin{figure}
\begin{center}
\includegraphics[width=\textwidth]{rpa.png}
\caption{Role of RpaA in regulation of kaiBC and other targets, from Markson 2013.}
\end{center}
\end{figure}

\begin{itemize}
\item The RpaA loop helps to maintain stoichiometry because RpaA is activated through phosphorylation just before the majority of KaiC is double-phosphorylated, a condition that occurs around dusk normally, but could also reflect an aberrantly high KaiA:KaiC ratio. Under this condition RpaA would help restore the normal stoichiometry by causing more KaiBC to be expressed.
\item In an upcoming discussion paper (after the break), you'll find that in addition to keeping the clock operational, the transcriptional feedback loop helps prevent phase drift of the PTO.

\end{itemize}

\section*{Simple harmonic oscillator}

\begin{itemize}
\item We now return to the notion that there are two general categories of oscillators driving biological clocks. The first characterizes oscillators that lack a positive feedback loop and show oscillatory patterns similar to harmonic oscillators.

\item Some oscillators have greater stability in amplitude, phase, and/or frequency against likely perturbations than others.

\item Consider the harmonic oscillator system:

\[  \frac{d^2 x}{dt^2} + a \frac{dx}{dt} + bx = 0 \]

\item In order to apply stability analysis techniques we already know, we could e.g. convert this into a linear system by substitutition:

\begin{eqnarray*}
\frac{dx}{dt}  & = & y\\
\frac{dy}{dt} + a y + b x & = & 0\\
\frac{dy}{dt} & = & -b x - a y\\
\frac{d}{dt} \begin{pmatrix} x \\ y \end{pmatrix} & = & \begin{pmatrix} 0 & 1  \\ -b & -a \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}
\end{eqnarray*}

\item If $a=0$, we have stable oscillations. Arbitrarily choosing $b=1$ and initial conditions of $x(0)=0$ and $y(0)=1$ gives a pair of sinusoidal functions with a phase offset of 90 degrees, e.g.
\[ x(t) = \sin t \hspace{3 cm} y(t) = \cos(t) \]

\item Consider what happens when we perturb $x$, say, by decreasing its magnitude soon after $x$ reaches its nadir. This will cause the slope of $y$ to decrease prematurely, and though the system will continue to oscillate at the same frequency, its magnitude will be permanently decreased and its phase will be shifted.

\item Even worse, a non-zero value of $a$ would cause these oscillations to either grow or decay.
\end{itemize}

\section*{van der Pol oscillator}
\begin{itemize}
\item Not all oscillators suffer from these problems. Consider the van der Pol oscillator with $\mu \gg 1$:

\[ \frac{d^2 x}{dt^2} + \mu \left( x^2 -1 \right)\frac{dx}{dt} + x = 0 \]

\item Notice that

\[ \frac{d^2 x}{dt^2} + \mu \left( x^2 -1 \right)\frac{dx}{dt} = \frac{d}{dt} \left[ \frac{dx}{dt} + \mu \left( \frac{x^3}{3} - x \right) \right] \]

\item To simplify this system, we substitute\footnote{Following Strogatz example 7.5.1}:

\begin{eqnarray*}
&F(x) = \frac{x^3}{3} - x \hspace{3 cm} w = \frac{dx}{dt} + \mu F(x)&\\
&\frac{dx}{dt} = \mu F(x) - w&\\
& \frac{dw}{dt} =  \frac{d^2 x}{dt^2} + \mu \left( x^2 -1 \right)\frac{dx}{dt} = -x&
\end{eqnarray*}

\item Finally, substituting $y=w/\mu$:
\begin{eqnarray*}
\frac{dx}{dt} & = & \mu \left(F(x) - y \right)\\
 \frac{dy}{dt} & = & -\frac{x}{\mu}
\end{eqnarray*}

\item By plotting we can see that the system will spend the majority of its time along the cubic nullcline $y=F(x)$, where it moves slowly, then zap quickly to the other half of the plane. This builds intuition that the oscillator functions on two distinct time scales, which indeed we can see from a simulation of the time evolution of the system.

\item It is possible to show that perturbations do not change the amplitude (or frequency) of the oscillations, unlike the simple harmonic oscillator studied above.

\item Perturbations of $x$ will still cause a phase shift. Intuitively, however, we predict that the impact on phase will be small unless the sign of $x$ changes during the perturbation. (Otherwise the oscillator will quickly snap back to a similar position along the nullcline.)

\item Conceptually-similar biological models include the Fitzhugh-Nagumo simplification of Hodgkin and Huxley's action potential model.

\item In general, oscillators based on a fast positive feedback and slow negative feedback loop will behave like relaxation oscillators, while oscillators based on negative feedback loops with a long delay are more smoother (``sinusoidal").

\end{itemize}

\begin{figure}
\begin{center}
\includegraphics[width=0.7\textwidth]{gonze.png}
\caption{Image taken directly from the \href{http://homepages.ulb.ac.be/~dgonze/TEACHING/osc_design.pdf}{lecture notes} of Didier Gonze.}
\end{center}
\end{figure}

\begin{itemize}

\item Another interesting feature of the vdPo and oscillators that combine positive and negative feedback loops is that their frequencies can be tuned while maintaining constant amplitude (Tsai et al., 2008).
\end{itemize}

\section*{Isochrons}
\begin{itemize}
\item To explore the notion that perturbations will have less impact on phase for van der Pol oscillators, we introduce the concept of \textit{isochrons} (some authors call them isochrones).

\item Consider a point $x_0$ which does not lie on the limit cycle, but whose trajectory will approach the limit cycle as $t \to \infty$. Since $x_0$ is not on the limit cycle, its trajectory is not periodic, formally speaking.

\item However. there is some corresponding point $y_0$ on the limit cycle whose trajectory will be indistinguishable from that of $x_0$ as $t \to \infty$. We could define $x_0$ to have the ``same phase" as $y_0$.

\item Using this definition, we can define the \textit{isochrons} of $y_0$ as the set of all points that have the same phase as $y_0$. Finding isochrons analytically is a daunting task, but MATLAB is pleased to oblige us.

\item What we see for the van der Pol oscillator is that in most parts of the cycle, the isochrons are almost horizontal. (The more so as $\mu$ increases.) This suggests that perturbations of $x$ will not greatly change the phase of the oscillator unless the $y$-axis is crossed, or the perturbations come at one of the few points in the cycle where the isochrons are nearly vertical.

\end{itemize}

\section*{Coupled oscillators and phase stabilization}

\begin{itemize}
\item Christiaan Huygens is credited with performing the first analysis of coupled oscillators in 1665. He discovered that two pendulums mounted on the same support beam would synchronzie, evidently through vibrations of the beam.
\item Synchronization is an effective means to overcome error in frequency and phase of otherwise-independent oscillators. If you are a former MA 19a student, you have likely seen examples, including synchronization of firefly flashing.
\item One rather humorous example are male Japanese tree frogs, which ribbit periodically.When two frogs are close to one another, they coordinate their calls to be approximately 180 degrees out of phase from one another. Adding a third frog results in one of two stable patterns: two frogs calling at the same time, or all three frogs calling at phases offset by 120 degrees.
\item We'll model the change in phases over time with $\omega$ as the innate frequency and phase differences $\phi = \theta_1 - \theta_2$ and $\psi = \theta_2 - \theta_3$.
\begin{eqnarray*}
\frac{d\theta_1}{dt} & = & \omega + H(- \phi) + H(- \phi - \psi) = \omega - H(\phi) - H(\phi + \psi)\\
\frac{d\theta_2}{dt} & = & \omega + H(\phi) + H(-\psi) =  \omega + H(\phi) - H(\psi)\\
\frac{d\theta_3}{dt} & = & \omega + H(\phi + \psi) + H(\psi)\\
\frac{d\phi}{dt} & = & -2 H(\phi) - H(\phi + \psi) + H(\phi)\\
\frac{d\psi}{dt} & = & H(\phi) - H(\phi + \psi)  - 2 H(\phi)\\
\end{eqnarray*}
where $H(\theta)$ describes the change of phase due to a phase difference, which is assumed to be $2\pi$ periodic and odd (so that the phase changes go in opposite direction if the phase difference changes sign).

\item  $H(\theta)= a \sin x + b \sin 2x$ fulfills our requirements for $H$: if we plot the trajectories for this system, we'll see that the frogs can be made to ribbit at equal intervals (either thirds or halfs, depending on the initial conditions.
\end{itemize}

\begin{lstlisting}
function [] = frogs()
    initial_phases = [0.1, 0.2];
    time_interval = [0, 20];
    global a b
    a = -1;
    b = -0.1;
    [timepoints, concentrations] = ode45(@chain1ddt, ...
        time_interval, initial_phases);
    plot(timepoints, concentrations(:,1), '-b', 'LineWidth', 3); hold on;
    plot(timepoints, concentrations(:,2), '-r', 'LineWidth', 3);
    title(sprintf('phi_0=%0.2f, psi=%0.2f',initial_phases(1),initial_phases(2)));
    xlabel('Time');
    ylabel('Phase differences');
    h = legend('\phi','\psi','Location','SouthEast');
    set(gca, 'FontSize', 24);
    set(h, 'FontSize', 24);
end

function changes_in_values = chain1ddt(time, current_values)
    phi = current_values(1);
    psi = current_values(2);
    change_in_phi = - 2*H(phi) + H(psi) - H(phi+psi);
    change_in_psi = - 2*H(psi) + H(phi) - H(phi+psi);
    changes_in_values = [change_in_phi; change_in_psi];
end

function returned_value = H(phase_difference)
    global a b
    returned_value = a * sin(phase_difference) + b * sin(2*phase_difference);
end
\end{lstlisting}

\begin{figure}
\begin{center}
\includegraphics[width=0.7\textwidth]{frogs.pdf}
\caption{Timecourse of $\phi=\theta_2 - \theta_1$ and $\psi = \theta_3 - \theta_2$ for $a=-1$, $b=-1$ and (left) $\phi(0) = 0$ and $\psi(0) = 1.7$ or (right) $\phi(0)=0.1$ and $\psi(0) = 0.2$.}
\end{center}
\end{figure}
\begin{itemize}
\item If we perturb the phase of one frog, the system will tend to restore its relative phase (unless the perturbation is so large that the system approaches the other stable solution).
\item Similar models can also explain synchronization between coupled oscillators with slightly different frequencies. Some fireflies, for example, can sync to artificial light pulses with $\pm$15\% differences in period. (Fireflies of one species can even tune their baseline frequency for improved long-term matching.)
\item In this case the coupling was negative (driving the frog's timing apart), but for positive coupling we'd expect synchronization and stabilization of phase.
\end{itemize}

\section*{\textit{Dictyostelium discoideum} aggregation}

\begin{itemize}

\item Another example of a system of coupled oscillators is a cellular slime mold community coordinating aggregation. While the phase of this clock does not appear to be linked to an external environmental cue, individual cells can entrain on the extracellular products of already-oscillating neighbors, establishing synchrony between cells in the population.
\item \textit{Dictyostelium} normally live as individual amoebae, but when they begin to run out of food, these amoeba aggregate together to form a motile slug that can travel much faster than any cell alone. The goal of this movement is for the cells to reach a position from which their spores could be disbursed, hopefully to germinate in more favorable conditions. The slug is capable of traveling a few millimeters upward through the leaf litter, where it forms an upright stalk, at the tip of which will form a ball of spores.
\item One issue with this life strategy is that it requires cells to signal to one another that they are starving, identify the center of their community, and move toward that point to form an aggregate.
\item The major chemical player in communication between cells in this system is cAMP. The external concentration of cAMP is found to oscillate in aggregating populations, and with each peak, cells exhibit contractions toward the center of the group.
\item After each peak, both intracellular and extracellular cAMP are hydrolyzed. Inside the cell, this process is carried out by the phosphodiesterase REG A.
\item When cAMP is added exogenously at the incorrect phase of the cycle, the phase is shifted; when it is continuously kept high, the cycle is eliminated entirely.
\item Cells detect cAMP through a high affinity receptor called CAR1. There are two main effects of signalling through CAR1: activation of ACA, an adenylyl cyclase, and activation of ERK2, which inhibits REG A.
\end{itemize}
\begin{figure}
\begin{center}
\includegraphics[width=0.5\textwidth]{maeda.png}
\caption{cAMP-based oscillator in \textit{Dictyostelium}, from Maeda 2004.}
\end{center}
\end{figure}
\begin{itemize}
\item What I have described so far is a positive feedback loop that would tend to increase intra- and extracellular cAMP indefinitely. The negative feedback loop in this case is that cAMP activates a protein called protein kinase A (PKA), which represses both ERK2 and ACA.
\item The following set of differential equations, modified from Laub and Loomis (1998) by Maeda et al. (2004), produce an oscillating system for an appropriate choice of parameter values:

\begin{eqnarray*}
\frac{d [\textrm{ACA}]}{dt} & = & k_1  [\textrm{CAR1}] - k_2 [\textrm{PKA}]  [\textrm{ACA}]\\
\frac{d [\textrm{PKA}]}{dt} & = & k_3  [\textrm{cAMPint}] - k_4 [\textrm{PKA}] \\
\frac{d[ \textrm{ERK2}]}{dt} & = & k_5  [\textrm{CAR1}] - k_6 [\textrm{PKA}]  [\textrm{ERK2}]\\
\frac{d [\textrm{REG A}]}{dt} & = & k_7  - k_8 [\textrm{REG A}]  [\textrm{ERK2}]\\
\frac{d [\textrm{cAMPint}]}{dt} & = & k_9  [\textrm{ACA}] - k_{10} [\textrm{REG A}] [\textrm{cAMPint}]\\
\frac{d[ \textrm{cAMPext}]}{dt} & = & k_{11}  [\textrm{ACA}] - k_{12}  [\textrm{cAMPext}]\\
\frac{d [\textrm{CAR1}]}{dt} & = & k_{13}  [\textrm{cAMPext}]  - k_{14} [\textrm{CAR1}] \\
\end{eqnarray*}

\end{itemize}

\begin{center}
\includegraphics[width=0.7\textwidth]{slime.pdf}
\end{center}

\begin{itemize}

\item Although neighboring cells can phase-lock, on the larger scale of the population, moving fronts of external cAMP appear, ultimately forming spirals. Cells within the field of one spiral will ultimately form a slug together.
\item External cAMP also binds to a different G protein receptor to ultimately activate phospholipase C, which will produce IP$_3$, causing calcium oscillations that lead to directional pseudopod extension.
\end{itemize}

\section*{Summary}

\begin{itemize}
\item When we return after break, we'll continue our discussion of clocks and oscillations, launching into natural clocks whose oscillators depend on transcriptional feedback loops.
\item A majority of synthetic clocks rely on such feedback loops, which have been easier to construct than protein-protein interactions.
\item However, you will see that coupling has also been used to synchronize synthetic clocks such as the one developed in Jeff Hasty's group at UCSD.
\end{itemize}

\end{document}

lectures/Lecture 19 - Smooth, Relaxation, and Coupled Oscillators/lecture notes/lecture 19 notes.tex


% README file for moduleDocumentationTemplate TeX template.
% This template should be used to document all Basilisk modules.
% Updated 20170711 - S. Carnahan
%
%-Copy the contents of this folder to your own _Documentation folder
%
%-Rename the Basilisk-moduleDocumentationTemplate.tex appropriately
%
% All edits should be made in one of:
% sec_modelAssumptionsLimitations.tex
% sec_modelDescription.tex
% sec_modelFunctions.tex
% sec_revisionTable.tex
% sec_testDescription.tex
% sec_testParameters.tex
% sec_testResults.tex
% sec_user_guide.tex
%
%-Some rules about referencing within the document:
%1. If writing the suer guide, assume the module description is present
%2. If writing the validation section, assume the module features section is present
%3. Make no other assumptions about any sections being present. This allow for sections of the document to be used elsewhere without breaking.

%In order to import some of these sections into a document in a different directory:
%\usepackage{import}
%Then, the sections are called with \subimport{relative path}{file} in order to \input{file} using the right relative path.
%\import{full path}{file} can also be used if absolute paths are preferred over relative paths.

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

\documentclass[]{BasiliskReportMemo}

\usepackage{cite}
\usepackage{AVS}
\usepackage{float} %use [H] to keep tables where you put them
\usepackage{array} %easy control of text in tables
\usepackage{graphicx}
\bibliographystyle{plain}

\newcommand{\submiterInstitute}{Autonomous Vehicle Simulation (AVS) Laboratory,\\ University of Colorado}

\newcommand{\ModuleName}{CSSWlsEst}
\newcommand{\subject}{Weight Least-Squares Minimum-Norm Coarse Sun Heading Estimator}
\newcommand{\status}{Released}
\newcommand{\preparer}{S. Piggott}
\newcommand{\summary}{This is a report documenting the results of the unit test performed for the
   coarse sun sensor sun point vector estimation algorithm.  A weighted least-squares minimum-norm algorithm is used to estimate the body-relative sun heading using a cluster of coarse sun sensors.  Using two successive sun heading evaluation the module also computes the inertial angular velocity vector.  As rotations about the sun-heading vector are not observable, this angular velocity vector only contains body rates orthogonal to this sun heading vector.  }

\begin{document}

\makeCover

%
%	enter the revision documentation here
%	to add more lines, copy the table entry and the \hline, and paste after the current entry.
%
\pagestyle{empty}
{\renewcommand{\arraystretch}{2}
\noindent
\begin{longtable}{|p{0.5in}|p{3.5in}|p{1.07in}|p{0.9in}|}
\hline
{\bfseries Rev} & {\bfseries Change Description} & {\bfseries By}& {\bfseries Date} \\
\hline
1.0 & Initial Documentation & S. Piggott & 2016-10-01\\
\hline
1.1 & Modified Format to BSK documentation & H. Schaub & 2018-04-29\\
\hline
1.2 & Added User Guide Section & H. Schaub & 2018-04-29\\
\hline
1.3 & Added discussion on the inertial angular velocity vector evaluation & H. Schaub & 2018-05-26\\
\hline

\end{longtable}
}

\newpage
\setcounter{page}{1}
\pagestyle{fancy}

\tableofcontents %Autogenerate the table of contents
~\\ \hrule ~\\ %Makes the line under table of contents

\section{Introduction}
When in safe mode, the spacecraft uses its coarse sun sensors (CSSs) in order to
point the vehicle's solar arrays at the Sun.  This is done in order to ensure
that the vehicle gets to a power-positive state with a minimum set of sensors
in order to recover from whatever event triggered the transition to safe mode.
The nominal vehicle considered in this report has 8 coarse sun sensor (CSS) sensors available to it
which allows it to resolve the exact sun direction in almost all body axes as
long as all sensors are functional.  With these cosine CSS a minimum of 3 sensor must provide a signal to determine a unique answer.

\subsection{Sun Heading Evaluation}
If more than 3 CSS detect a sun signal, the algorithm needs to be able to obtain
the sun pointing vector that best fits the current outputs from all of the CSSs.
This is done by a least squares estimation process that provides the sun vector
that best fits from a weighted least squares perspective.  The weights are
simply set based on the current output of each sensor which ensures that the
sensors that have the best measurements are trusted the most.  If 3 CCS see the sun, then a unique heading is computed.  If 1-2 CSS see the sun then a minimum norm solution is evaluated.  If no CSS sees the sun then a zero vector is returned.
The details of
this algorithm are available in Steve O'Keefe's PhD dissertation.
\footnote{\href{http://gradworks.umi.com/3704787.pdf}
   {O'Keefe Public Dissertation Link}}

The algorithm stores its internal variables in the CSSWLSConfig data structure
with the input message provides the CSS sensor values.  The output is a {\tt NavAttIntMsg} message that contains the estimated sun-heading vector in body frame components.  This
sun-heading estimation algorithm does not use any information stored from previous frames so it is a
fresh computation every time it is called.  It can therefore be called at any
rate needed by the system.

\subsection{Partial Angular Velocity Evaluation}
Using two successive sun-heading vector evaluations it is possible to evaluate a partial solution of the spacecraft inertial angular velocity vector.  Note that rate about the sun heading vector are not obsdervable, but rates about the other two axes can be obtained.

Let $\bm d_{n}$ be current sun heading vector from the above sun heading algorithm.  The prior estimate is denoted as $\bm d_{n-1}$, while $\Delta t$ is the time step between the two measurements.  The angular velocity vector is then evaluated using
\begin{equation}
	\label{eq:cssEst1}
	\bm\omega_{B/N} = \frac{\bm d_{n} \times \bm d_{n-1}}{|\bm d_{n} \times \bm d_{n-1}|}
	\arccos\left(
		\frac{\bm d_{n} \cdot \bm d_{n-1}}{|\bm d_{n}| |\bm d_{n-1}|}
	\right) \frac{1}{\Delta t}
\end{equation}
These vector evaluations are performed using $\mathcal{B}$ frame vector components.

Note that iff both $\bm d_{n}$ and $\bm d_{n-1}$ are nearly collinear a zero body rate vector is returned.  Further, during start-up and reset operations it is possible that $\Delta t$ might be zero for a single evaluation.  In this case also a zero rate vector is returned.

\section{Test Design}
The unit test for the cssWlsEst module is located in:\\

\noindent
{\tt fswAlgorithms/attDetermination/CSSEst/\_UnitTest/CSSWlsEstUnitTest.py} \\
\\

Please see the python script for information on test setup and initial
conditions.  \\

\noindent This unit test is designed to functionally test the algorithm
outputs as well as get complete code path coverage.  The test design is broken
up into four main parts:\\
\begin{enumerate}
\item{Main Body Axis Estimates: The principal body axes (b1, b2, b3) are tested
   with both positive and negative values to ensure that all axes are correctly
   estimated.}
\item{Double Coverage Test: There are small regions of pointing where only two
   sun sensors provide "good" values, which results in a case where only the
   minimum norm solution can be used instead of a full least squares solution.
   One of these regions is tested here.}
\item{Single Coverage Test: One of the sensors used for the double coverage test
   is zeroed in order to simulate a sensor failure and hit the single coverage
   code.  The accuracy of this estimate is severely compromised.}
\item{Zero Coverage Case: The case where no sensors provide an above-threshold
   value is tested here.}
\end{enumerate}

\section{Test Results}

The values obtained in the test over time are best visualized in
Figure~\ref{fig:point_fig}.  That shows a comparison between the Sun pointing
vector input to the test and the estimate provided by the algorithm.
\begin{figure}[htb]
        \centerline{
        \includegraphics[scale=0.5]{Figures/sunEstAccuracy}
        }
        \caption{Truth and Estimated Sun Pointing Vector}
        \label{fig:point_fig}
\end{figure}

As this plot shows, the algorithm is very accurate up until 6.0 seconds,
so both directions of the three primary body axes are estimated precisely.
Then the double coverage case is reasonably accurate, but no longer precise as
there isn't sufficient information available to get a good pointing direction.
The single coverage test is not accurate at all (~45 degrees of error), but that
is simply the best that the algorithm can do with that limited information.

Figure ~\ref{fig:num_fig} shows the number of CSSs used by the algorithm to
estimate the sun pointing vector over the duration of the test.  It continues
for longer than Figure~\ref{fig:point_fig} because the algorithm stops setting
its output message once it gets to the zero valid sensors case as there is no
good information to provide.
\begin{figure}[htb]
        \centerline{
        \includegraphics[scale=0.5]{Figures/numGoodCSS}
        }
        \caption{Number of CSSs Used in Estimate}
        \label{fig:num_fig}
\end{figure}

\begin{enumerate}
\item{Main Body Axis Estimates: The sun pointing estimation algorithm is not
   required to provide a precise estimate of the Sun direction.  This algorithm
   is only intended to be used in safe mode where the arrays only need to be
   approximately pointed at the Sun.  For this reason, a pointing vector
   was flagged as successful when it provided the Sun direction within 17.5
   degrees which corresponds to a cosine loss of approximately 5\%.  All body
   axes met this criteria with large margins.  A check was also performed that
   verified that the predicted number of CSSs matched up with what the
   algorithm used and this check was also 100\% successful.  The UseWeights flag
   was initially set to False, and then was changed to True after two cases to
   ensure that the algorithm works correctly in both cases.
    \textcolor{ForestGreen}{Test successful.}}
\item{Double Coverage Test: The same accuracy criteria was used for this test.
   This is mostly a function of CSS geometry and it is also the main driving
   case for the success criteria used.  It was correct to within 14 degrees.
   The predicted number of CSSs used (2) also matched the algorithm's selection.
    \textcolor{ForestGreen}{Test successful.}}
\item{Single Coverage Test: The single coverage case did not have its accuracy
   tested as there are no accuracy requirements for this case.  It simply must
   provide an estimate and exit.  The predicted number of CSSs used (1) did
   match the algorithm's selection.  \textcolor{ForestGreen}{Test successful.}}
\item{Zero Coverage Test: The zero coverage test is only provided here to
   demonstrate that the algorithm passivates its outputs without hitting any
   unacceptable event.  It does correctly flag that no valid CSSs were found
   during the test. \textcolor{ForestGreen}{Test successful.}}

   \item{Angular Velocity Test:  The same 8 unit CSS configuration is used as in the earlier tests, but the true sun heading is set equal to $\hat{\bm b}_{1}$.  A BSK sample time of 0.5 seconds is setup, and the simulation is run 3 times to reach a simulation time of 1.0 seconds.  It takes 2 steps for the module to evaluate the update rate $\D t$, thus the expected rate estimate is a zero vector for these steps.  As the sun heading is being evaluated in the 2nd step, with the 3rd step there is a non-zero $\D t$ value, but the old and new sun-heading vectors are the same.  The expected rate output is again a zero vector.  Next the true sun heading is changed to be $\hat{\bm b}_{2}$, corresponding to a 90$\deg$ heading change about $\hat{\bm b}_{3}$.  The simulation is run for two more steps. The expected inertial body rate with step 4 would be $-\pi$ rad/sec about $\hat{\bm b}_{3}$.  The 5th step must yield again a zero rate vector as the sun heading has not changed.  Next, a reset function is called and a single simulation step is called.  The expected output is the zero rate vector again.  Finally, the true sun heading vector is changed back to $\hat{\bm b}_{1}$ and another simulation step is performed to show a $+\pi$ rad/sec rotation about $\hat{\bm b}_{3}$.
   The test results status is: \input{AutoTeX/passFailRate.tex}}
\end{enumerate}

\section{Test Coverage}
The method coverage for all of the methods included in the cssWlsEst
module are tabulated in Table~\ref{tab:cov_met}

\begin{table}[htbp]
    \caption{ADCS Coarse Sun Sensor Estimation Coverage Results}
   \label{tab:cov_met}
        \centering \fontsize{10}{10}\selectfont
   \begin{tabular}{c | r | r | r} % Column formatting,
      \hline
      Method Name    & Unit Test Coverage (\%) & Runtime Self (\%) & Runtime Children (\%) \\
      \hline
      SelfInit\_cssWlsEst& 100.0 & 0.0 & 0.0 \\
      CrossInit\_cssWlsEst & 100.0 & 0.0 & 0.0 \\
      computeWlsmn & 100.0 & 0.01 & 0.64 \\
      Update\_cssWlsEst & 100.0 & 0.04 & 0.88 \\
      \hline
   \end{tabular}
\end{table}

For all of the code this test was designed for, the coverage percentage is
100\%.  For Safe Mode, we do expect this algorithm to be the highest usage
element from an ADCS perspective, so the CPU usage is almost certainly fine as
is.  The main penalty comes from the use of matrix multiply in the computeWlsmn
function.  The only issue of note here is that the matrix multiply algorithm(s)
use in the FSW should be optimized as much as possible as they are major sources
of CPU spin.

\section{Conclusions}
The safe mode sun vector estimator described in this document is functionally
ready from a PDR perspective.  It has no noted failure cases, all code is tested
for statement coverage, and it successfully meets its test criteria for all
cases.  The only area where there might be a question is the desired behavior
for zero-coverage cases.  We may wish to change the outputs to something more
obviously in-error instead of just having the algorithm go silent.

%
%\input{secModuleDescription.tex} %This section includes mathematical models, code description, etc.
%
%\input{secModuleFunctions.tex} %This includes a concise list of what the module does. It also includes model assumptions and limitations
%
%\input{secTest.tex} % This includes test description, test parameters, and test results
%

\input{secUserGuide.tex} % Contains a discussion of how to setup and configure  the BSK module

\bibliography{bibliography} %This includes references used and mentioned.

\end{document}


\section{Integrals}


% Like most advanced LaTeX files, this one begins with a lot of
% boilerplate. You don't need to understand (or even read) most of it.
% All you need to do is fill in your name, UMN ID, email address,
% and the number of the pset. (Search for "METADATA" to find the place
% for this.) Then, you can go straight to the "EXERCISE 1"
% section and start writing your solutions.
% The "VARIOUS USEFUL COMMANDS" section is probably worth taking a
% look at at some point.

%----------------------------------------------------------------------------------------
%	PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[paper=a4, fontsize=12pt]{scrartcl} % A4 paper and 12pt font size
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm,amssymb} % Math packages
\usepackage{mathrsfs}    % More math packages
\usepackage{sectsty}  % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all section titles centered, the default font and small caps %remove this to left align section tites
\usepackage{hyperref} % Turns cross-references into hyperlinks,
                      % and defines \url and \href commands.
\usepackage{graphicx} % For embedding graphics files.
\usepackage{framed}   % For the "leftbar" environment used below.
\usepackage{ifthen}   % Used for the \powset command below.
\usepackage{lastpage} % for counting the number of pages
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[height=10in,a4paper,hmargin={1in,0.8in}]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}     % This is a powerful tool to draw vector
                      % graphics inside LaTeX. In particular, you can
                      % use it to draw graphs.
\usepackage{verbatim} % For the "verbatim" environment, in which
                      % special symbols can be used freely without
                      % confusing the compiler. (And it's typeset in
                      % a constant-width font.)
                      % Useful, e.g., for quoting code (or ASCII art).

%\numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)

\setlength\parindent{20pt} % Makes indentation for paragraphs longer.
                           % This makes paragraphs stand out more.

%----------------------------------------------------------------------------------------
%	VARIOUS USEFUL COMMANDS
%----------------------------------------------------------------------------------------
% The commands below might be convenient. For example, you probably
% prefer to write $\powset[2]{V}$ for the set of $2$-element subsets
% of $V$, rather than writing $\mathcal{P}_2(V)$.
% Notice that you can easily define your own commands like this.
% Caveat: Some of these commands need to be properly "guarded" when
% they occur in subscripts or superscripts. So you should not write
% $K_\CC$, but rather $K_{\CC}$.
\newcommand{\CC}{\mathbb{C}} % complex numbers
\newcommand{\RR}{\mathbb{R}} % real numbers
\newcommand{\QQ}{\mathbb{Q}} % rational numbers
\newcommand{\NN}{\mathbb{N}} % nonnegative integers
\newcommand{\PP}{\mathbb{P}} % positive integers
\newcommand{\Z}[1]{\mathbb{Z}/#1\mathbb{Z}} % integers modulo k
                                            % (syntax: "\Z{k}")
\newcommand{\ZZ}{\mathbb{Z}} % integers
\newcommand{\id}{\operatorname{id}} % identity map
\newcommand{\lcm}{\operatorname{lcm}}
% Lowest common multiple. For historical reasons, LaTeX has a \gcd
% command built in, but not an \lcm command. The preceding line
% rectifies that.
\newcommand{\set}[1]{\left\{ #1 \right\}}
% $\set{...}$ compiles to {...} (set-brackets).
\newcommand{\abs}[1]{\left| #1 \right|}
% $\abs{...}$ compiles to |...| (absolute value, or size of a set).
\newcommand{\tup}[1]{\left( #1 \right)}
% $\tup{...}$ compiles to (...) (parentheses, or tuple-brackets).
\newcommand{\ive}[1]{\left[ #1 \right]}
% $\ive{...}$ compiles to [...] (Iverson bracket, aka truth value; also, set of first n integers).
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
% $\floor{...}$ compiles to |_..._| (floor function).
\newcommand{\underbrack}[2]{\underbrace{#1}_{\substack{#2}}}
% $\underbrack{...1}{...2}$ yields
% $\underbrace{...1}_{\substack{...2}}$. This is useful for doing
% local rewriting transformations on mathematical expressions with
% justifications. For example, try this out:
% $ \underbrack{(a+b)^2}{= a^2 + 2ab + b^2 \\ \text{(by the binomial formula)}} $
\newcommand{\powset}[2][]{\ifthenelse{\equal{#2}{}}{\mathcal{P}\left(#1\right)}{\mathcal{P}_{#1}\left(#2\right)}}
% $\powset[k]{S}$ stands for the set of all $k$-element subsets of
% $S$. The argument $k$ is optional, and if not provided, the result
% is the whole powerset of $S$.
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height
\newcommand{\nnn}{\nonumber\\} % Don't number this line in an "align" environment, and move on to the next line.

%----------------------------------------------------------------------------------------
%	MAKING SUMMATION SIGNS ALWAYS PUT THEIR BOUNDS ABOVE AND BELOW
%	THE SIGN
%----------------------------------------------------------------------------------------
% The following are hacks to ensure that sums (such as
% $\sum_{k=1}^n k$) always put their bounds (i.e., the $k=1$ and the
% $n$) underneath and above the sign, as opposed to on its right.
% Same for products (\prod), set unions (\bigcup) and set
% intersections (\bigcap). Remove the 8 lines below if you do not want
% this behavior.
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}

%----------------------------------------------------------------------------------------
%	ENVIRONMENTS
%----------------------------------------------------------------------------------------
% The incantations below define how theorem environments
% (\begin{theorem} ... \end{theorem}) and their likes will look like.
\newtheoremstyle{plainsl}% <name>
  {8pt plus 2pt minus 4pt}% <Space above>
  {8pt plus 2pt minus 4pt}% <Space below>
  {\slshape}% <Body font>
  {0pt}% <Indent amount>
  {\bfseries}% <Theorem head font>
  {.}% <Punctuation after theorem head>
  {5pt plus 1pt minus 1pt}% <Space after theorem headi>
  {}% <Theorem head spec (can be left empty, meaning `normal')>

% Environments which make the text inside them slanted:
\theoremstyle{plainsl}
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{proposition}[theorem]{Proposition}
  \newtheorem{lemma}[theorem]{Lemma}
  \newtheorem{corollary}[theorem]{Corollary}
  \newtheorem{conjecture}[theorem]{Conjecture}
% Environments that don't:
\theoremstyle{definition}
  \newtheorem{definition}[theorem]{Definition}
  \newtheorem{example}[theorem]{Example}
  \newtheorem{exercise}[theorem]{Exercise}
  \newtheorem{examples}[theorem]{Examples}
  \newtheorem{algorithm}[theorem]{Algorithm}
  \newtheorem{question}[theorem]{Question}
 \theoremstyle{remark}
  \newtheorem{remark}[theorem]{Remark}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}

%----------------------------------------------------------------------------------------
%	METADATA
%----------------------------------------------------------------------------------------
\newcommand{\myname}{Darij Grinberg} % ENTER YOUR NAME HERE
\newcommand{\myid}{00000000} % ENTER YOUR UMN ID HERE
\newcommand{\mymail}{dgrinber@umn.edu} % ENTER YOUR EMAIL HERE
\newcommand{\psetnumber}{1} % ENTER THE NUMBER OF THIS PSET HERE

%----------------------------------------------------------------------------------------
%	HEADER AND FOOTER
%----------------------------------------------------------------------------------------
\ihead{Solutions to homework set \#\psetnumber} % Page header left
\ohead{page \thepage\ of \pageref{LastPage}} % Page header right
\ifoot{\myname, \myid} % left footer
\ofoot{\mymail} % right footer

%----------------------------------------------------------------------------------------
%	TITLE SECTION
%----------------------------------------------------------------------------------------
\title{
\normalfont \normalsize
\textsc{University of Minnesota, School of Mathematics} \\ [25pt] % Your university, school and/or department name(s)
\horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
\huge Math 4281: Introduction to Modern Algebra, \\
Spring 2019:
Homework \psetnumber\\% The assignment title
\horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
}
\author{\myname}

\begin{document}

\maketitle % Print the title

\begin{center} % Delete this if you want to save space!
{\large due date: \textbf{Friday, 8 February 2019} at the beginning of class, \\
or before that by email or canvas.

Please solve \textbf{at most 4 of the 6 exercises}!}
\end{center}

%----------------------------------------------------------------------------------------
%	EXERCISE 1
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 1: Mutual divisibility is rare}

\subsection{Problem}

Let $a$ and $b$ be two integers such that $a \mid b$ and
$b \mid a$.
Prove that $\abs{a} = \abs{b}$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 2
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 2: Congruence means equal remainders}

\subsection{Problem}

Let $n$ be a positive integer.
Let $u$ and $v$ be two integers.
Prove that $u \equiv v \mod n$
        % While it's called "congruent", the LaTeX command for
        % the symbol is "\equiv".
if and only if $u \% n = v \% n$.
        % To get the "%" sign, you need to type "\%".
        % Just typing "%" starts a comment.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 2
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 3: Even and odd}

\subsection{Problem}

Let $u$ be an integer.

\begin{enumerate}

\item[\textbf{(a)}]
Prove that $u$ is even if and only if $u \% 2 = 0$.

\item[\textbf{(b)}]
Prove that $u$ is odd if and only if $u \% 2 = 1$.

\item[\textbf{(c)}]
Prove that $u$ is even if and only if $u \equiv 0 \mod 2$.

\item[\textbf{(d)}]
Prove that $u$ is odd if and only if $u \equiv 1 \mod 2$.

\item[\textbf{(e)}]
Prove that $u$ is odd if and only if $u + 1$ is even.

\item[\textbf{(f)}]
Prove that exactly one of the two numbers $u$ and $u + 1$ is even.

\item[\textbf{(g)}]
Prove that $u \tup{u+1} \equiv 0 \mod 2$.

\item[\textbf{(h)}]
Prove that $u^2 \equiv -u \equiv u \mod 2$.

\end{enumerate}

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 4
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 4: Factorials 102}

\subsection{Problem}

\begin{enumerate}

\item[\textbf{(a)}]
Prove that
\[
\dfrac{1! \cdot 2! \cdot \cdots \cdot \tup{2n}!}{n!}
= 2^n \cdot \prod_{i=1}^n \tup{\tup{2i-1}!}^2
\qquad \text{for each } n \in \NN .
\]

\item[\textbf{(b)}]
Prove that
\[
\sum_{k=0}^n \dfrac{1}{k! \cdot \tup{k+2}}
= 1 - \dfrac{1}{\tup{n+2}!}
\qquad \text{for each } n \in \NN .
\]

\end{enumerate}

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 5
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 5: Binomial coefficients 102}

\subsection{Problem}

Prove that
\[
\dfrac{\tup{ab}!}{a! \tup{b!}^a}
= \prod_{k=1}^a \dbinom{kb-1}{b-1}
\]
for all $a \in \NN$ and all positive integers $b$.

\subsection{Solution}

[...]

%----------------------------------------------------------------------------------------
%	EXERCISE 6
%----------------------------------------------------------------------------------------
\horrule{0.3pt} \\[0.4cm]

\section{Exercise 6: Binomial coefficients and coprimality}

\subsection{Problem}

It is well-known (see, e.g., \cite[Proposition 3.20]{detnotes})
that $\dbinom{n}{k} \in \ZZ$ for all $n \in \ZZ$ and $k \in \NN$.
(This is not at all clear from the definition of $\dbinom{n}{k}$;
it is saying that the product of any $k$ consecutive integers
is divisible by $k!$.
The case of $k = 2$ is the statement of Exercise 3 \textbf{(g)}.)
Thus, we can study the divisibility of binomial coefficients
by various integers.
There are hundreds of theorems about this; this exercise is
about one of them.

Let $a$ and $b$ be two coprime positive integers.

\begin{enumerate}

\item[\textbf{(a)}]
Prove that $\dfrac{a}{a+b} \dbinom{a+b}{a} = \dbinom{a+b-1}{a-1}$
and $\dfrac{b}{a+b} \dbinom{a+b}{a} = \dbinom{a+b-1}{b-1}$.

\item[\textbf{(b)}]
Prove that if $h \in \QQ$ satisfies $ah \in \ZZ$ and $bh \in \ZZ$,
then $h \in \ZZ$.
(This is where the coprimality of $a$ and $b$ comes into play.)

\item[\textbf{(c)}]
Prove that $a+b \mid \dbinom{a+b}{a}$.

\item[\textbf{(d)}]
Find a counterexample to the claim of part \textbf{(c)} if
$a$ and $b$ are allowed to not be coprime.

\end{enumerate}

\subsection{Solution}

[...]

\begin{thebibliography}{99999999}                                                                                %

% Feel free to add your sources -- or copy some from the source code
% of the class notes ( http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.tex ).

% This is the bibliography: The list of papers/books/articles/blogs/...
% cited. The syntax is: "\bibitem[name]{tag}Reference",
% where "name" is the name that will appear in the compiled
% bibliography, and "tag" is the tag by which you will refer to
% the source in the TeX file. For example, the following source
% has name "GrKnPa94" (so you will see it referenced as
% "[GrKnPa94]" in the compiled PDF) and tag "GKP" (so you
% can cite it by writing "\cite{GKP}").

\bibitem[GrKnPa94]{GKP}Ronald L. Graham, Donald E. Knuth, Oren Patashnik,
\textit{Concrete Mathematics, Second Edition}, Addison-Wesley 1994.\\
See \url{https://www-cs-faculty.stanford.edu/~knuth/gkp.html} for errata.

\bibitem[Grinbe19]{detnotes}Darij Grinberg,
\textit{Notes on the combinatorial fundamentals of algebra},
10 January 2019. \\
\url{http://www.cip.ifi.lmu.de/~grinberg/primes2015/sols.pdf}
\\
The numbering of theorems and formulas in this link might shift
when the project gets updated; for a ``frozen'' version whose
numbering is guaranteed to match that in the citations above, see
\url{https://github.com/darijgr/detnotes/releases/tag/2019-01-10} .

\end{thebibliography}

\end{document}


%\documentclass{emulateapj}
%\documentclass[letterpaper,12pt,preprint]{aastex}
\documentclass[usenatbib]{mn2e}
\bibliographystyle{mn2e}

% packages
\usepackage{amssymb,amsmath,amsbsy}
\usepackage{booktabs}
\usepackage[caption=false]{subfig}
\usepackage{color}

% commands
\newcommand{\given}{\,|\,}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\transpose}[1]{{#1}^{\mathsf{T}}}
\newcommand{\inverse}[1]{{#1}^{-1}}
\newcommand{\msun}{\mathrm{M}_\odot}

\newcommand{\project}[1]{\textsl{#1}}
\newcommand{\superfreq}{\project{SuperFreq}}

% TO DO
\usepackage{graphicx}
\newcommand{\apwtodo}[1]{{\color{red} APW: (\MakeUppercase{#1})}}
\newcommand{\djdtodo}[1]{{\color{green} DJD: (\MakeUppercase{#1})}}

%Dan's Math Definitions
\newcommand{\scripty}[1]{\ensuremath{\mathcalligra{#1}}}
\def\sr{\scripty{r}}
\def\Mach{\mathcal{M}}
\def\bin{\rm{bin}}
\def\Mdot{\dot{M}}
\def\Msun{ M_{ \rm{\odot} } }

\def\xb{\bar{x}}
\def\yb{\bar{y}}

\begin{document}

\title{Cavity search: a parameter study of the importance of chaos for feeding black hole binaries}
\author[D. J. D'Orazio, Adrian M. Price-Whelan]{Daniel J. D'Orazio$^1$, Adrian M. Price-Whelan$^1$
    \thanks{dorazio@astro.columbia.edu; adrn@astro.columbia.edu}\\
     $^1$Department of Astronomy, Columbia University, 550 West 120th Street, New York, NY 10027
}

%\author{
%Daniel J. D'Orazio\altaffilmark{\colum},
%Adrian M. Price-Whelan\altaffilmark{\colum}
%}

% Affiliations
%\newcommand{\colum}{1}
% \newcommand{\adrn}{2}

%\altaffiltext{\colum}{Department of Astronomy,
   %                   Columbia University,
      %                550 W 120th St.,
         %             New York, NY 10027, USA}
% \altaffiltext{\adrn}{To whom correspondence should be addressed: adrn@astro.columbia.edu}

\maketitle

\begin{abstract}
%Danny boy
% Context
The interaction of a binary and a thin gasesous disk lies at the heart
of a number of important astrophysical phenomena. These include the
formation of planetary systems and the fate of massive black hole
binaries at the centers of galactic nuclei.
%The masses and orbital distributions of planetary systems are
%dictated by the interaction of a planet-star binary with a
%proto-planetery disk. The
%merger rates and electromagnetic signatures of massive black hole
%binares are influenced by gas which is torqued to the centers of
%galactic nuclei upon merger. Their fate is tied to the level
%of orbital evolution and mass feeding influenced by the coupled nature
%of binary+disk evolution.
The salient features of binary+disk interactions are captured largley
by the gravitaitonal dynamics of a disk of particles in the plane of
the binary.
%Aims
Here we gain insight into binary+disk dynamics by studying orbits of
test particles in the binary plane via the restricted three body
problem.
%Methods
We investigate the resonant structure of orbits over a range of binary
mass ratios and orbital eccentricities relvant to astrophysical
systems.
% Results
We find some cool chaos crap related to Dan's other paper on CBD
transitions and also some dynamics stuff related to Adrian's work.
% Conclusions

\end{abstract}

%\keywords{
%stuff
%}

\section{Introduction}\label{sec:introduction}

\section{Methods}\label{sec:methods}

\subsection{Equations of Motions}
%\section{Equations of Motions}
The equations of motion for a test particle in the plane of an
eccentric binary are described by the elliptical, restricted three
body problem (ER3Bp). We write the ER3Bp as two coupled second order
ODE's in the non-uniformly rotating, isotropically pulsating, frame of
the eccentric binary ($\bar{x}$, $\bar{y}$),
\begin{equation}
\begin{array}{c}
\ddot{\xb} - 2\dot{\yb} = \frac{\partial{U}}{\partial{\xb}}  \left( 1 + e \cos{f} \right)^{-1} \nonumber \\ \nonumber \\
\ddot{\yb} + 2\dot{\xb} = \frac{\partial{U}}{\partial{\yb}}  \left( 1 + e \cos{f} \right)^{-1}
\label{Eqmotion}
\end{array}
\end{equation}
for binary with true anomaly $f$, eccentricity $e$, mean motion $\equiv 1$,
and $ \ \dot{} \ \equiv d/df$. Because the independent variable is
$f$, there is no need to solve for $f$ in terms of the time $t$ unless
converting the solution back to the non-rotating frame.

The ($\bar{x}$, $\bar{y}$) are dimensionless coordinates of the
massless third particle which are constructed by dividing the
dimensional coordinates by the time changing binary separation
\begin{equation}
\begin{array}{c}
\xb = \xb^* \frac{1 + e \cos{f}}{a ( 1-e^2) } \nonumber \\ \nonumber \\
\yb = \yb^* \frac{1 + e \cos{f}}{a ( 1-e^2) }
\end{array}
\end{equation}
where $*$ denotes the dimensional variable.

The position of the primaries is found from dividing the dimensional
position over time by the binary position and is always fixed at the
same values as in the circular R3B, \textit{i.e.}
\begin{equation} \nonumber
\xb_2 = \xb^*_2 \frac{1+e \cos{f}}{a (1-e^2)} =   \frac{a}{1+q} \frac{(1-e^2)}{1+e \cos{f}}  \frac{1+e \cos{f}}{a (1-e^2)}  = \frac{1}{1+q}
\end{equation}
where $q = M_2/M_1$, $M_2 < M_1$.Similarly $\xb_p = -q/(1+q)$.

There is no longer a conserved quantity in the ER3B, but there is an
analogue to the Jacobi constant which is time dependent,
\begin{equation}
C_{eJ} = \frac{2 U}{1 + e \cos{f}} - \left( \dot{\xb}^2 + \dot{\yb}^2 \right) - 2 e \int^f_{f_0}{\frac{ U \sin{f} }{(1 + e \cos{f})^2 } \ df}
\end{equation}
and can be used to check the accuracy of the integrator (not yet
implemented).

\subsection{Set-up}
To set up initial velocity profiles recall that the independent
variable is no longer the time, but the true anomaly $f$. This can be
taken into account most simply by using the Virial theorem with the
pseudo potential of Eq. \ref{Eqmotion}. Assuming only azimuthal
initial velocities,
\begin{equation}
\begin{array}{c}
\bar{v_x} = -v_{\phi} \frac{\yb_0}{R} \quad \bar{v_x} = v_{\phi} \frac{\xb_0}{R} \\ \nonumber \\ \nonumber
v_{\phi} =   \left[ \sqrt{ \frac{\mu_1}{\bar{r}_1}  +  \frac{\mu_2}{\bar{r}_2} }  \right] \left( 1 + e \frac{\xb}{R} \right)^{-1}  - R\\ \nonumber \\ \nonumber
\bar{r}^2_1 =  (\xb + \mu_2)^2 + \yb^2  \qquad \bar{r}^2_2 =  (\xb - \mu_1)^2 + \yb^2  \\ \nonumber \\ \nonumber
R^2 = \xb^2 + \yb^2 \\ \nonumber \\ \nonumber
\mu_1 = \frac{1}{1+q} = 1-\mu_2  \qquad \mu_2 = \frac{q}{1+q}
\end{array}
\end{equation}
where we subtract the speed of the rotating frame from the azimuthal
velocity. Since the angular frequency of the rotating frame is unity
in our coordinates we need only subtract the particle specific
velocity $R$.

%If we were going to convert back into the time coordinate, we would need to use
%\begin{equation}
%df  = n \sqrt{1-e^2} \left( \frac{a}{r}\right)^2 dt = \frac{n (1 + e \cos{f})^2}{(1-e^2)^{3/2}}  dt
%\end{equation}
%where the last line substitutes the time dependent binary separation $r$.

To convert back to time t, and unscaled distances we multiply the
coordinates by the time dependent binary separation and solve for
$t(f)$ in the usual manner.

Describe potential and things varied (mass ratio, viscosity,
eccentricity, what else?)\\ Lets start with mass ratio - look for
Linblad resonances, and see what happens when linear stability is
lost.

Orbits are integrated with ...

\subsection{Numerical determination of the fundamental frequencies}\label{sec:freqs}

Regular orbits in Hamiltonian systems may be represented in a special set of coordinates known as angle-action variables \citep[e.g.,][]{goldstein80}: in these coordinates, the position variables---the angles---increase linearly with time with rates set by a set of fundamental frequencies, and the momentum variables---the actions---are integrals of motion. More specifically, for a regular orbit represented in coordinates $(x_n, v_n)$, there exists a transformation $(x_n, v_n)\rightarrow(\theta_n, J_n)$ such that
\begin{align}
	\theta_n(t) &= \theta_n(0) + \Omega_n\,t\\
	J_n &= {\rm const.}
\end{align}
The $\Omega_n$ are known as the fundamental frequencies and there are $N$ such frequencies for non-resonant orbits in systems with $N$ degrees of freedom.

\apwtodo{Need to use a different symbol here for integer vector}
A resonant orbit is an orbit for which there exists at least one relation such that\footnote{The repeated indices imply summation.} $n_n\,\Omega_n = 0$ where $n_n$ is a vector of integers. \apwtodo{More theory-speakery here methinks...}

[How to numerically determine the frequencies using:]
\begin{equation}
	x(t) = \sum a_k\,e^{i \, \omega_k \, t}
\end{equation}

[How to detect chaos with this shite and measure rate of frequency diffusion]

\section{Conclusions}\label{sec:conclusions}

%\acknowledgements
\section{Acknowledgments}
APW is supported by a National Science Foundation Graduate Research Fellowship under Grant No.\ 11-44155. DJD is supported by a National Science Foundation Graduate Research Fellowship under Grant No. DGE1144155
This work was supported in part by the National Science Foundation under Grant No. PHYS-1066293.
This research made use of Astropy, a community-developed core Python package for Astronomy \citep{astropy13}.
This work additionally relied on Columbia University's \emph{Hotfoot} and \emph{Yeti} compute clusters, and we acknowledge the Columbia HPC support staff for assistance, especially Mr. Alex Bergier.

%\bibliographystyle{apj}
%\bibliography{refs}

\end{document}