text:
\documentclass[14pt]{article}
\usepackage{allan}
\setlength{\headheight}{60pt}

\lhead{
    \parbox{5cm}{
        \begin{center}
            Problem Chosen \\[0.2cm]
            \textbf{\Huge{A}}
        \end{center}
    }
}
\chead{
    \parbox{5cm}{
        \textbf{
            \begin{center}
                2022 \\
                MCM \\
                Summary Sheet
            \end{center}
        }
    }
}
\rhead{
    \parbox{5cm}{
        \begin{center}
            Team Control Number \\[0.2cm]
            \textbf{\Huge{0000}}
        \end{center}
    }
}
\cfoot{}

\begin{document}
    \begin{center}
        \textbf{\large Summary}
    \end{center}

    This is the summary.

    % real document begins

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \clearpage
    \pagenumbering{arabic}
    \newpage
    \pagestyle{empty}
    \setlength{\headheight}{12pt}
    \renewcommand{\headrulewidth}{0.5pt}
    % \renewcommand{\headrulewidth}{5cm}
    \renewcommand{\footrulewidth}{0.0pt}
    \pagestyle{fancy}
    \lhead{Team \#2226594}
    \chead{Power Profile of a Cyclist}
    \rhead{Page \thepage\ of \pageref{LastPage}}
    \cfoot{}
    \lfoot{}
    \rfoot{}

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \clearpage
    \thispagestyle{empty}
    \tableofcontents
    \newpage
    \pagestyle{fancy}
    \setcounter{page}{1}

	\newpage
	\section{Introduction}
	\subsection{Background}
	Individual time trial is a common type of bicycle road race and has gained popularity in recent years. In individual time trials, individuals will manage to complete their journey on a fixed trial course all by themselves in the shortest possible time and the one that uses the minimum of time seals the victory.

	In cycling activities, each cyclist has a power curve which indicates the maximum power the rider can maintain in the races. Also, given a rider's power curve, cyclists must find the best way to minimize their power usage and maximize their recovering rate. In addition, there are many kinds of individual riders. Common types are time trial specialists, climbers, sprinters, rouleurs and puncheurs. They will act differently when facing various terrains and difficulties. Time trial specialists are good at solving every kinds of problems. The climbers can easily pass the long slopes while puncheurs perform well when facing cliffy slopes. Rouleurs can make good decisions based on different routes. Sprinters have strong explosive force. We will analyze their actions in the following passage.

	Moreover, the trial course plays a vital role in the game. It will determine how the cyclists spend their energy and control their speed. It has to be mentioned that all the riders will ride a same course. In games, the condition of trials mostly depends on the type of game and what kind of event it is.
	\subsection{Problem Restatement}
	To make sure that the riders can achieve their best score by using the best strategy (including when to get energy supply and recover) according  to their body condition, we need to find out the relationship between these factors. Therefore, our work is divided into 4 parts:
	\begin{itemize}
		\item  Analyze the power profile of two types if riders given their riding type.
		\item  Build a model calculating their power profile and find out the result when it is applied to different trial courses and various weather conditions. Find out how sensitive the model is.
		\item  Give suggestions to riders and their instructors generally on key turning points after determining how sensitive the model is.
		\item  Extend model so that it can be applied to conditions where a team will take part in a time trial.
	\end{itemize}
	\subsection{General Assumptions}
	\begin{enumerate}
		\item  \textbf{All the dynamic coefficient of friction of the road are equal numbers.}

				To help cyclists achieve better grades and prevent them from serious danger, race organizers usually use artificial tracks. Therefore we can assume that the material of tracks is the same, which means the dynamic coefficient of friction of the road is the same.
		\item  \textbf{All the riders know the terrain of the course and can make their decisions.}
		\item  \textbf{Energies produced by breathing can be stored}

				If there is unconsumed energy during the riding process (mainly produced by breathing) , it will be stored. However, it will not exceed the maximum storage amount.
		\item  \textbf{Riders' cycling condition will not change when turning.}

				There are not many sharp turns during the game and riders usually spend little time passing them. Therefore we don't take turns into consideration.
		\item \textbf{Riders won't consume any energy when going downhill.}

				When riding downhill, riders needn't any energy to keep balance, so we won't consider any speed change when a rider goes downhill.
		\item \textbf{Every rider has an expected completing time.}

				According to the second assumption, all the riders know the whole course. Therefore, we can assume that all the cyclists can calculate their expected completing time and their decisions during the game will be affected by this number.

	\end{enumerate}

	\section{Model A}
	\subsection{Model Overview}
	In the first model, we will discuss the power curve of different types of cyclists. We will discuss the energy consumption of riders according their reactions towards different kinds of terrains and their body conditions. Considering basic energy cost such as breathing and processes of metabolism. We will calculate the power curve based on the maximum power a rider can reach in a certain time and how long he can maintain it. Finally, we will discuss the conditions where basic supplement is needed.
	\subsection{Notation}
	\begin{tabular}{|l|l|l|}
		\hline
		$\mathrm{T}_\mathrm{exp}$&expected completing time&$\mathrm{s}$\\
		\hline
		$\mathrm{T}_\mathrm{actual}$&actual completing time&$\mathrm{s}$\\
		\hline
		$t$&the time the game lasts for&$\mathrm{s}$\\
		\hline
		$\mathrm{P}(\mathrm{w})$&power of a cyclist&W\\
		\hline
		$\tau(\mathrm{p})$&time which the rider last for at a constant power ($\mathrm{P}(\mathrm{w})$)&$\mathrm{s}$\\
		\hline
		$\mathrm{M}(\mathrm{T})$&the maximum power in the whole process&$\mathrm{W}$\\
		\hline
		$\mathrm{M}(\mathrm{b})$&the maximum power of human body&$\mathrm{W}$\\
		\hline
		$\sigma$&speed of metabolism&$\mathrm{W}$\\
		\hline
		$\mathrm{E}_\mathrm{B}$&energy stored before the race&$\mathrm{J}$\\
		\hline
		$\mathrm{E}_\mathrm{S}$&energy supplied during the race&$\mathrm{J}$\\
		\hline
		$\tau(\mathrm{E}_\mathrm{S})$&time wasted when recovering&$\mathrm{s}$\\
		\hline
		$\mathrm{k}$&power restriction index&/\\
		\hline
		$\mathrm{m}$&weight of cyclist&$\mathrm{kg}$\\
		\hline
		$f$&air resistance&$\mathrm{N}$\\
		\hline
		$\mathrm{v}$&speed of cyclist&m/s\\
		\hline
		$\mathrm{C}_\mathrm{D}$&air resistance index&/\\
		\hline
		$\rho_\mathrm{air}$&air density&kg/$\mathrm{m}^3$\\
		\hline
		$\mathrm{S}_\mathrm{body}$&cyclists' area exposed to air&$\mathrm{m}^2$\\
		\hline
		$\mathrm{k}_\mathrm{air}$&air condition index&/\\
		\hline
		$D$&distance&m\\
		\hline
		$I$&momentum gathered by wind&$\mathrm{N}$\\
		\hline
		$\mathrm{E}_\mathrm{total}$&the total energy stored before the race&$\mathrm{J}$\\
		\hline
	\end{tabular}
	\subsection{Calculating Energy Consumption}
	First, we need to consider the cyclist's energy source. We divide a rider's energy consumption into several parts. Considering human's basic physiological activities, energy spent by metabolism needs to be calculated. Therefore we use $\sigma$ to describe human body's speed of metabolism, which is a constant of value 41.5. Moreover, the rider's physical fitness determines his total energy before the race which is defined as $\mathrm{E}_\mathrm{total}$. Finally, cyclists can get energy before the race and energy supplied during the race through food consumption (which we define as $\mathrm{E}_\mathrm{B}$ and $\mathrm{E}_\mathrm{S}$).

	We use P(t) to desribe the cyclist's power consumption pattern and E(t) to describe the cyclist's energy condition. First we need to figure out how to describe the distance a cyclist has traveled. When a rider is cycling on a plain, what affect his speed and acceleration speed are his power and air resistance (which will be introduced in the next part). There relationship is shown in the picture below:
	\begin{center}
		\includegraphics[height=2.5cm]{1.png}

		\small \textit{Fig.1 a cyclist's condition on the plain}
	\end{center}
	 Therefore we can get the following formulae:
	$$D=\int^{\mathrm{T}_\mathrm{actual}}_0 \mathrm{v}(\mathrm{t})\cdot \mathrm{dt}$$
	$$\mathrm{m} \cdot \mathrm{a}(\mathrm{t})=\mathrm{m} \cdot \mathrm{v}\dot(\mathrm{t})=\mathrm{F}-f=\dfrac{\mathrm{P}(\mathrm{t})}{\mathrm{v}}-\dfrac{1}{2}\mathrm{k}\mathrm{v}^2$$
	$$\mathrm{v}(0)=0$$
	$$0\leq\mathrm{P}(\mathrm{t})\leq\mathrm{M}_\mathrm{b}$$
	The second step is to describe the cyclist's condition on the slope. We define $k$ as the index which describes the restriction of power. His condition can be shown in the picture below:
	\begin{center}
		\includegraphics[width=7cm]{2.png}

		\small \textit{Fig.2 a cyclist's condition on the slope}
	\end{center}
	Under this circumstance, if $\mathrm{P}(\mathrm{t}) \ge \mathrm{M}$, his power pattern can be calculated through the formulae below:
	$$\mathrm{P}\dot(\mathrm{t})=-\dfrac{1}{\mathrm{k}} \mathrm{P}(\mathrm{t}) \cdot \dfrac{1}{\mathrm{E}(\mathrm{t})}$$
	$$\mathrm{E}\dot(\mathrm{t})=\sigma-\left(f+mg\sin\theta+\mu mg\cos \theta\right)\cdot \mathrm{v}
	(\mathrm{t})$$
	$$\mathrm{E}(0)=\mathrm{E}_\mathrm{total}$$
	$$\mathrm{E}(\mathrm{t})\geq0, \forall 0 \leq \mathrm{t} \leq \mathrm{T}_\mathrm{total}$$
	$$\mathrm{E}(\mathrm{t})=\left[\sigma-\left(f+mg\sin \theta +\mu mg \cos \theta \right)\cdot \mathrm{v}(\mathrm{t})\right]\cdot \mathrm{t}+\mathrm{E}_\mathrm{total}$$
	$$\mathrm{E}(\mathrm{t})=-\dfrac{\mathrm{P}(\mathrm{t})}{\mathrm{k}\cdot \mathrm{P}\dot(\mathrm{t})}=-\dfrac{\mathrm{m}\mathrm{v}\ddot(\mathrm{t})+\dfrac{1}{2}\mathrm{k}{\mathrm{v}(\mathrm{t})}^3}{\mathrm{m}\mathrm{v}\dot(\mathrm{t})\cdot\mathrm{v}(\mathrm{t})+\mathrm{v}\dot(\mathrm{t})^2+\dfrac{3}{2}\mathrm{k}{\mathrm{v}(\mathrm{t})}^2}$$
	By calculating the energy cost, we can also get the relationship between the cyclist's power usage and his speed and his weight,which is:
	$$\mathrm{P}(\mathrm{t})=\mathrm{m}\mathrm{v}\dot(\mathrm{t})\cdot \mathrm{v}(\mathrm{t})+\dfrac{1}{2}\mathrm{k}{\mathrm{v}(\mathrm{t})}^3$$
	$$\mathrm{P}\dot(\mathrm{t})=\mathrm{m}\mathrm{v}\ddot(\mathrm{t})\mathrm{v}(\mathrm{t})+{\mathrm{v}\dot(\mathrm{t})}^2+\dfrac{3}{2}\mathrm{k}{\mathrm{v}(\mathrm{t})}^2$$
	\subsection{Calcucaling Air Resistance}
	Since the cyclists will race against each other in a quick speed, the air resistance ($f$) can't be neglected. We define $f$ as the formulae follow:
	$$f=\dfrac{1}{2} \mathrm{C}_\mathrm{D} \cdot \rho_\mathrm{air} \mathrm{S}_\mathrm{body} v^2$$
	$$\mathrm{k}_\mathrm{air}=\dfrac{1}{2} \mathrm{C}_\mathrm{D} \rho_\mathrm{air}$$
	$$f=\mathrm{k}_\mathrm{air}\cdot \mathrm{v}^2$$
	After searching related data from academic literature, we find out that $\mathrm{C}_\mathrm{D}=0.024$, $\rho_\mathrm{air}=1.293 \mathrm{kg/}\mathrm{m}^3$ and $\mathrm{S}_\mathrm{body}=0.209 \mathrm{m}^2$. Based on these data, we can indicate that $\mathrm{k}_\mathrm{air}\approx0.0032$.
	%\newpage
	\section{Model B}
	\subsection{Model Overview}
	In this model, we will firstly discuss how to descibe rider's basic feature and their power curve in detail. Later, we will also take special factors such as climate ino consideration. Finally, we will apply our model into several distinct trial courses and get out the answer.
	\subsection{Assumptions}
	\begin{enumerate}
		\item	\textbf{Rain is not considered in this model.}

				Many activities have been cancelled or delayed because of rainy days in the past few years. But if the trial's humidity is under the criteria. Roads' dynamic coefficient of friction won't be affected.
	\end{enumerate}
	\subsection{Notation}
	\begin{tabular}{|l|l|l|}
		\hline
		$\mathrm{m}(\mathrm{x})$&weight of cyclist&$\mathrm{kg}$\\
		\hline
		$\mathrm{h}(\mathrm{x})$&height of cyclist&$\mathrm{m}$\\
		\hline
		$\mathrm{BMI}(\mathrm{x})$&body mass index of cyclist&/\\
		\hline
		$\mathrm{E}_\mathrm{total} (\mathrm{x})$&total energy of cyclist&$\mathrm{J}$\\
		\hline
		$\mathrm{S}_\mathrm{body}(\mathrm{x})$&body measure&$\mathrm{m}^2$\\
		\hline
		$\mathrm{T}_\mathrm{min}$&the least time spent to complete the game&$\mathrm{s}$\\
		\hline
		$\mathrm{F}_\mathrm{wind}$&wind force&$\mathrm{N}$\\
		\hline
		$\mathrm{T}$&temperature of the trial&$\circ$\\
		\hline
	\end{tabular}
	\subsection{Calculate Total Energy}
	In this part, we will mainly discuss the cyclist's total power based on his phisycal condition and cycling type.

	First, we need to have a basic understanding of the cyclist's physical condition. Take Tour de France as an example\cite{france}. Among the champions of this race in the past five years, their average height is 1.808$\mathrm{m}$ and their average weight is 68.58$\mathrm{kg}$. Olympic cyclists have an average height og 1.80$\mathrm{m}$ and an average of around 68$\mathrm{kg}$\cite{weight}.

	In our model, we use a series of variables with (x) to describe the cyclist's features. These include $\mathrm{m}(\mathrm{x})$, $\mathrm{h}(\mathrm{x})$, etc. According to the BMI criteria, we can get the formula:
	$$\mathrm{BMI}(\mathrm{x})=\dfrac{\mathrm{x}}{\mathrm{h}^2(\mathrm{x})}$$
	Also, since where our body is exposed to air can be seen as a square, we can find that:
	$$\mathrm{S}_\mathrm{body}(\mathrm{x})\propto\mathrm{h}^2(\mathrm{x})$$
	\subsection{Weather Conditions}
	There are many factors that will affect the speed. They are temperature and wind force.
	\subsubsection{Temperature}
	\subsubsection{Wind force}
	\subsection{Recalculate Speed Function}
	After we have discussed the weather's impact on our model, we need to polish it so that it can be applied to special cases as well. Considering that there is no air resistance but wind force now, we need to recalculate the speed function.

	If the momentum is a constant number (which we define as $\mathrm{F}(\mathrm{t})$), we can get the following formulae:
	$$\mathrm{m}\mathrm{v}\dot(\mathrm{t})=\mathrm{F}(\mathrm{t})-f-\mathrm{F}_{f}-mg\sin \theta=\mathrm{F}(\mathrm{t})-\mathrm{k}_\mathrm{air}{\mathrm{v}(\mathrm{t})}^2-\dfrac{mg\mu}{\mathrm{r}_\mathrm{wheel}}-mg\sin \theta$$
	$$\mathrm{v}(0)=0$$
	$$0\leq\mathrm{F}(\mathrm{t})\leq\mathrm{F}_\mathrm{m}$$
	, and:
	$$\mathrm{E}\dot(\mathrm{t})=\sigma-\mathrm{F}(\mathrm{t})\cdot\mathrm{v}(\mathrm{t})$$
	$$\mathrm{E}(0)=\mathrm{E}_\mathrm{total}$$
	$$\mathrm{E}(\mathrm{t})\geq0$$
	beiyong

	$\mathrm{A}=\mathrm{F}_\mathrm{m}-\dfrac{mg\mu}{\mathrm{r}_\mathrm{wheel}}-mg\sin \theta$

	$\mathrm{v}(\mathrm{t})\\=\\\dfrac{\sqrt{\mathrm{F}_\mathrm{m}-\dfrac{mg\mu}{\mathrm{r}_\mathrm{wheel}}-mg\sin \theta} \tan \mathrm{h} \left(\dfrac{\sqrt{\mathrm{F}_\mathrm{m}-\dfrac{mg\mu}{\mathrm{r}_\mathrm{wheel}}-mg\sin \theta}\ \ \mathrm{C}\sqrt{\mathrm{k}_\mathrm{air}} m+\sqrt{\mathrm{F}_\mathrm{m}-\dfrac{mg\mu}{\mathrm{r}_\mathrm{wheel}}-mg\sin \theta}\ \ \sqrt{\mathrm{k}_\mathrm{air}} x}{\mathrm{m}}\right)}{\sqrt{\mathrm{k}_\mathrm{air}}}$

	$=\dfrac{\sqrt{\mathrm{A}} \tan \mathrm{h}\left[\dfrac{\left(\mathrm{m}\mathrm{C}_1+\mathrm{x}\right)\sqrt{\mathrm{Ak}}}{\mathrm{m}}\right]}{\sqrt{\mathrm{k}}}$

	$\mathrm{v}(0)=\dfrac{\sqrt{\mathrm{A}} \tan h \left(\mathrm{C}_1\sqrt{\mathrm{Ak}}\right)}{\sqrt{\mathrm{k}}}$

	By doing this we can get the result: $\mathrm{C}_1=0$
	\section{Strengths and Weaknesses}
	\subsection*{Strengths}
	\begin{itemize}
		\item
	\end{itemize}
	\subsection*{Weaknesses}
	\begin{itemize}
		\item
	\end{itemize}
	\newpage
	\thispagestyle{empty}
	% \setcounter{page}{\wholepages}
	\renewcommand\refname{References}
	\clearpage
	\addcontentsline{toc}{section}{References}
	\tolerance=500
	\begin{thebibliography}{100}
		\bibitem{114514} Math Modelling, Qiyuan Kang, Jinxing Xie and Jun YeMath Modelling
		\bibitem{UCI}2021 Road World Championships Individual Time Trial (Men Elite), UCI,

		https://www.flanders2021.com/\_media/races/image\_map/1632122636/fit/1650/0/6/men-elite-individual-time-trial.webp
		\bibitem{france}https://www.topendsports.com/sport/cycling/anthropometry-tourdefrance-tables.htm
		\bibitem{weight}Cycling Physique, science4performance,

		https://science4performance.com/2019/09/12/cycling-physique/
		\bibitem{friction}https://zhidao.baidu.com/question/309300297713546924.html
	\end{thebibliography}

\end{document}


text:
% The Potato Processor - Processor Datasheet
% (c) Kristian Klomsten Skordal 2015 <kristian.skordal@wafflemail.net>
% Report bugs and issues on <https://github.com/skordal/potato/issues>

\documentclass[10pt,a4paper]{article}

\usepackage[pdftitle={The Potato Processor Datasheet},
	pdfauthor={Kristian Klomsten Skordal}]{hyperref}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{tabularx}
\usepackage[margin=2.0cm,includefoot,footskip=10pt]{geometry}
\usepackage[british]{babel}

\renewcommand{\familydefault}{\sfdefault}

\titleformat{\section}[block]{}{}{0pt}{\normalfont\large\bfseries}
\pagestyle{empty}

\setlength{\parindent}{0pt}
\setlist[itemize]{leftmargin=*,nosep}

\begin{document}

\begin{minipage}{0.5\textwidth}
\raggedright\huge
\textsf{The Potato Project}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\raggedleft\huge
\textsf{Processor Datasheet}
\end{minipage}

\vspace{0.5em}
\noindent\rule{\linewidth}{1pt}\\

\begin{minipage}[t]{0.48\textwidth}

\section{Architecture}
\includegraphics[width=\textwidth]{diagram.png}

\section{Features}

\begin{itemize}
\item Supports the complete 32-bit RISC-V base integer ISA (RV32I) version 2.0
\item Supports machine mode as defined by the RISC-V supervisor extensions version 1.7
\item Includes a hardware timer with microsecond resolution and compare interrupt
\item 8 IRQ inputs that can be invidually enabled
\item Classic 5-stage RISC pipeline
\item Wishbone interface
\item Automatic test suite
\end{itemize}

\section{Interface}

The processor includes a wishbone interface conforming to the B4 revision of the
wishbone specification.\\

\begin{tabularx}{\textwidth}{|l|X|}
\hline
Interface type & Master \\
Address port width & 32 bits \\
Data port width & 32 bits \\
Data port granularity & 8 bits \\
Maximum operand size & 32 bits \\
Endianess & Little \\
Sequence of data transfer & In-order \\
\hline
\end{tabularx}

\section{Specifications}

\center\includegraphics[width=0.7\textwidth]{riscv.png}
\url{http://riscv.org/specifications/}

\center\includegraphics[width=0.7\textwidth]{opencores.png}
\url{http://opencores.org/opencores,wishbone}

\end{minipage}\hfill
\begin{minipage}[t]{0.48\textwidth}

\section{Example Application}
\includegraphics[width=\textwidth]{example.png}

\section{Signals}

The processor is provided by a VHDL module named \texttt{pp\_potato}. All signals
are active high and the following signals are provided:\\

\begin{tabularx}{\textwidth}{|l|l|X|}
\hline
\textbf{Name} & \textbf{Width} & \textbf{Description} \\
\hline
\texttt{clk} & 1 & Processor clock \\
\texttt{timer\_clk} & 1 & 10~MHz timer clock \\
\texttt{reset} & 1 & Reset signal \\
\hline
\texttt{irq} & 8 & IRQ inputs \\
\hline
\texttt{wb\_adr\_out} & 32 & Wishbone address \\
\texttt{wb\_sel\_out} & 4 & Wishbone byte select \\
\texttt{wb\_cyc\_out} & 1 & Wishbone cycle \\
\texttt{wb\_stb\_out} & 1 & Wishbone strobe \\
\texttt{wb\_we\_out} & 1 & Wishbone write enable \\
\texttt{wb\_dat\_out} & 32 & Wishbone data output \\
\texttt{wb\_dat\_in} & 32 & Wishbone data input \\
\texttt{wb\_ack\_in} & 1 & Wishbone acknowledge \\
\hline
\end{tabularx}\\

Additional signals are used to implement a host-target interface used in the automatic testing
environment. These signals have names starting with \texttt{fromhost} and \texttt{tohost} and
should be left unconnected.\\

\section{Tools and Utilities}

Tools for writing applications for the RISC-V architecture are available from the
RISC-V project, at:\\[1em]
\url{https://github.com/riscv/riscv-tools}\\

\end{minipage}

\vfill
\noindent\rule{\linewidth}{1pt}
{\small
Project page: \url{https://github.com/skordal/potato}\\
Report bugs and issues on \url{https://github.com/skordal/potato/issues}}

\end{document}

ext: tex

max_stars_repo_name: riscveval/Potato

max_issues_repo_name: riscveval/Potato

max_forks_repo_name: riscveval/Potato


text:
\documentclass[12pt]{article}

\input{preamble}

\begin{document}

\begin{flushleft}
\textbf{Propagator BBVI: a flexible framework for rapid design of BBVI
  optimization algorithms} \\
Adam Massmann (akm2203) \\
\today
\end{flushleft}

\textit{Abstract:}

Here I present \texttt{propagator-bbvi}: a BBVI inference approach
built on top of a propagator computing framework. Propagators consist
of stateful cells that accumulate information about a value, and
autonomous machines that add information about a value. In the case of
BBVI, cells are each variational factor, and the autonomous machines
are the computations that calculate gradients from the joint and
update the variational factors. This framework allows us to rapidly
develop and test many novel stochastic gradient update schemes: each
variational factor can use different step size functions and
convergence specifications, the propagator network can optimize
subsets of variational factors based on subsets of the log joint, and
we can mix both re-parameterization and score-based gradient estimates
on portions of the model that are differentiable or not. Additionally,
the propagator based framework has the potential to scale to massively
parallel computation with no changes to model specification.

\section{Introduction}

Box's loop allows us to iteratively refine assumptions about our
data. However, efficient movement around the loop requires that
computationally tractable inference algorithms are easy to derive from
a model encoding our assumptions. Black box variational inference
(BBVI) performs inference on a very broad set of probabilistic models
without difficult model-specific derivations, and is a path towards
quick iterations over Box's loop \citep[e.g.,][]{ranganath-2014,
  kuc-2017}. Here I build a new approach to BBVI using a propagator
computing framework. The \texttt{propagator-bbvi} Haskell library aims
for:

\begin{itemize}
\item A balance between the ease of specification and the flexibility
  of the inference optimization: the probabilistic model should be easy
  to specify on the computer and BBVI inference should follow
  automatically from the specification. However, the library is also
  designed for easy tuning and/or novel development of the optimization
  algorithms underlying the inference methods. So, there is a trade-off
  between automatic inference from the model specification and the
  flexibility to tune the inference algorithm for tractability. Here
  we favor a balance between adding complexity in what the user must
  specify in order to run inference, and granting the user the ability
  to try many different optimization strategies underlying
  inference. Sensible defaults can mitigate some of the added
  complexity of user specification.
\item Extensibility: the library should be easy for users to
  extend. For example, adding new variational distributions or
  optimization algorithms should be simple and additive to code
  (e.g. no need to rewrite or modify existing code).
\item Ability to scale to massive data and models. Through stochastic
  gradient ascent \citep[e.g.,][]{hoffman-2013, ranganath-2014,
    kuc-2017} and parallel execution we hope to build a framework that
  scales. In keeping with the extensibility goal, development of new
  parallel scheduling and data sub-sampling techniques should be
  possible without significant modification of the larger codebase,
  most importantly the machinery for specifying models.
\end{itemize}

As I describe the library design and its novelty for developing new
approaches to BBVI, I will refer back to these three goals:
\textbf{\emph{optimization flexibility}}, \textbf{\emph{extensibility}}, and \textbf{\emph{scalability}}.

\section{Introduction to propagators}

The propagator computing framework \citep{radul-2009} consists of
stateful ``cells'' that accumulate information about a value and
stateless autonomous ``propagators'' that do computations and add
information to cells. In other words, cells do no computation and
propagators store no data. Propagators are attached to
cells to build algorithms, and there are two primary attachment types for propagators:
\texttt{watch} and \texttt{write} attachments. When cells acquire new
information, they trigger any propagators watching them to execute
their computations with the new data, and those propagators will write
the result of their computations to any cells they have a
\texttt{write} attachment to. If any of these writes are new
information for a given cell, then they will trigger their own
watching propagators to fire. In this manner, propagators and cells
form an asynchronous computation network that runs until no cells in
the network can acquire any new information (``quiescence'').

The propagator model is useful in many computational applications,
including functional reactive programming, dependency directed search,
and constraint satisfaction. For a full discussion I recommend
\citet{radul-2009}. However, why propagators for BBVI? In short, they
are a path towards massively parallel computation and flexible
optimization strategies. Because all computation is asynchronous and
there is no global state, the ordering and scheduling of computation
is completely independent of the propagator network. So, once a
problem is coded in terms of propagators, one can alter the scheduling
of the propagator computations to suit their goals without touching
the propagator network. In this way propagators directly lend
themselves to my design goals: (1) \textit{scalability} through
parallel computation, and (2) \textit{extensibility}: computation
scheduling is independent of the algorithm code, so new parallel
schedulers can be developed without modification of any other pieces
of the library.

\section{BBVI with Propagators}

Variational factors are represented as cells: they accumulate
information moving them closer (on average) to the true
posterior. Computations calculating gradients and updating the
variational factors are the propagators. Variational factor cells are
initialized from priors on the latent variables, variational
factor-specific step-size functions, and definitions of convergence
(e.g. maximum number of steps, small change in variational
factor). Gradient propagators are derived from the log joint of the
model. Using the new BBVI algorithm built on propagators consists of
the following specification:

\begin{enumerate}
\item Specify the log joint: $\log p(x, z)$
\item Initialize variational factor cells for each $z$ (defaults
  automate all but prior specification)
\item Transform the log joint to a gradient propagator, using
  existing \texttt{propagator-bbvi} transformation functions or
  developing a new approach with Haskell abstractions.
\item Specify the attachment type of the propagators to the
  variational factors (defaults automate this)
\end{enumerate}

Steps 2-4 may seem opaque now, and I will elaborate on the
consequences and benefits of this algorithmic approach to BBVI.

Additionally, the library is publicly available at:
\url{https://github.com/massma/propagator-bbvi}, and some sparse (but
growing) documentation is available at:
\url{http://www.columbia.edu/~akm2203/propagator-bbvi-0.1.0.0/}.

\subsection{Initializing variational factor cells}

Variational factor cells contain three pieces of information: the
variational factor and its parameterization (e.g. for a Gaussian, the
mean and variance), a \textit{time} integer corresponding to the
number of times the variational factor has been updated, and a
\textit{memory} vector equal in length to the number of parameters of
the variational factor (e.g. in the case of the Gaussian, a vector of
length 2). The \textit{time} and \textit{memory} data are useful for
step size calculations. For example, in \citet{kuc-2017} the step size
parameterization uses both the number of gradient update steps, as
well as a quantity determined by the history of gradient magnitudes.

In addition to the information stored in variational factor cells,
invariant data are also defined for each variational factor. These
include:

\begin{enumerate}
  \item The prior on the variational factor's latent variable,
  \item A step size function. Inputs: the cell's \textit{time} and
    \textit{memory} data; and outputs: a step size and change in the
    \textit{memory} parameter
  \item A count of the total number of factors in the model's log
    joint that contain the variational factor's corresponding latent
    variable.
\end{enumerate}

The use of this count will be elaborated on in Section \ref{gradient},
but it facilitates distributed updates by many propagators
representing subsets of the log joint to a single variational
factor. The count and step size function aid optimization flexibility:
the user can easily specify many different optimization approaches
and parameters to a variational factor independent of those used
for other variational factors.

\subsubsection{Variational factor representation}

A variational factor's parameters can be stored in any form. For
example, in \texttt{propagator-bbvi}'s current version the Dirichlet
distribution's parameters are stored as a vector, while the normal
distribution's parameters are stored in a record datatype. However,
all variational factors must implement the following functions to be a
part of the necessary typeclasses for use in
\texttt{propagator-bbvi}:

\begin{verbatim}
class DistUtil a where
  fromParamVector :: ParamVector -> a
  toParamVector :: a -> ParamVector
  nParams :: a -> Int

class DistUtil a => Dist a c where
  resample :: a -> GenST s -> ST s c
  logProb :: a -> c -> Double
  paramGradOfLogQ ::  a -> c -> ParamVector
\end{verbatim}

The typeclass \texttt{DistUtil}\footnote{a quick rundown on Haskell
  syntax in case you are not familiar: ``::'' means ``has type.'' so
  ``fromParamVector :: ParamVector -> a'' means the function
  ``fromParamVector'' has a type which takes in a parameter vector and
  outputs a distribution of arbitrary type ``a.'' But don't worry too
  much about it; I will explain all code snippits in normal language.}
provides functions that help with the necessary vector arithmetic for
calculating gradients: \texttt{fromParamVector} converts a vector of
parameters to a distribution, \texttt{toParamVector} converts a
distribution to a vector of its parameters, and \texttt{nParams} takes a
distribution and provides the number of parameters it contains. For a
Gaussian example, \texttt{nParams} would return 2, and
\texttt{fromParamVector} would read a vector containing the mean and
variance and return a Gaussian, while \texttt{toParamVector} would
take a Gaussian and return a vector containing the mean and
variance. These functions are generally trivial to implement.

The typeclass \texttt{Dist} provides the necessary functions to
compute score gradients \citep{ranganath-2014}. \texttt{resample}
takes a distribution and a random number generator, and returns a
sample from the distribution. \texttt{lobProb} takes a distribution
and an observation and returns the log of the probability/density of the
observation. \texttt{paramGradOfLogQ} calculates the gradient of the
log probability of an observation under a distribution, with respect to
the parameters of the distribution. The gradient must be in vector
form, and the locations of the gradients within the vector should
match the location of the parameters in \texttt{fromParamVector} and
\texttt{toParamVector}. This typeclass approach to representing
variational factors aids the design goal of extensibility: to add a
new variational factor for use in \texttt{propagator-bbvi}, one need
only define six functions, three of which are trivial.

However, one may also wish to use reparameterization gradient
updates \citep{kuc-2017} for a variational factor. Any distribution
that implements the following four functions can be used with
reparameterization propagators:

\begin{verbatim}
class (Dist a c) => Differentiable a c where
  epsilon ::  a -> GenST s -> ST s c
  transform :: a -> c -> c
  gradTransform :: a -> c -> ParamVector
  sampleGradOfLogQ ::  a -> c -> c
\end{verbatim}

\texttt{epsilon} generates an un-transformed sample: note that while
the function takes a distribution as input, this is only to maintain
correctness with Haskell's type system. \texttt{transform} transforms
a sample generated from \texttt{epsilon} into a sample from the variational
distribution. \texttt{gradTransform} takes the gradient of the
transformation with respect to the variational distribution's parameters, while
\texttt{sampleGradOfLogQ} takes the gradient of the log probability
function with respect to a transformed sample. In the
Gaussian example if \texttt{epsilon} samples from a standard normal,
\texttt{transform} would be $\mu + \sigma \epsilon$,
\texttt{gradTransform} would be $[1.0, \epsilon]$, and
\texttt{sampleGradOfLogQ} would be $-(z - \mu) / \sigma ^ 2$. To
reiterate, defining these functions for a variational factor is not
necessary for using a factor in \texttt{propagator-bbvi}, but they do
allow one to calculate gradients with the reparameterization
gradient. One of the strengths of
\texttt{propagators-bbvi} is that it allows us to easily mix and match
reparameterization updates with score updates on parts of the model
that are or are not differentiable, and on factors for which we can or
cannot implement the functions in the \texttt{Differentiable}
typeclass. This approach lends itself to the goal of optimization
flexibility: we can use reparameterization gradients (with their lower
variance) on factors where possible, and score gradients elsewhere.

\subsection{Transform the log joint to a gradient propagator }
\label{gradient}

A gradient propagator takes as input the information stored in
variational factor cells and observations and outputs gradient updates
for the variational factor cells. \texttt{propagator-bbvi} contains
functions to help build gradient propagators from the log joint, and
in some cases this can currently be automated. In other cases, users
can build their own transformations from a log joint to a gradient
propagator using \texttt{propagator-bbvi} functions stitched together
with Haskell abstractions. Currently, \texttt{propagator-bbvi} only
focuses on score-gradient updates with Rao-Blackwellization
\citep{ranganath-2014}, and reparameterization gradient updates
\citep{kuc-2017}. Rao-Blackwellization requires specification from the
user, but the resulting decrease in the variance of the gradients is
worth the cost. More importantly, Rao-Blackwellization identifies
which factors in the log joint are reliant on which variational
factors, which has benefits in the propagator framework. For example,
with propagators we can split up the gradient calculations from the
log joint into many separate propagators that make gradient updates
based on subsets of the log joint. If we track the number of factors
from the log joint that a propagator uses in its calculations, then we
can rescale the prior and entropy terms to calculate a gradient update
from a subset of the log joint. A specific example: if a propagator
only calculates the gradient based on one factor in the log joint, and
it is writing its update to a variational cell with 10 total factors
in the log joint, then the prior and entropy terms are scaled down by
$1/10$. Haskell's lazy evaluation also helps the user implement
flexible, distributed propagators. The user can specify the necessary
log joint calculations on the full model, and use this same
specification in very local propagators (for example, a gradient
propagator update based on a single factor in the log joint). When the
propagator writes its gradient to the variational cell, lazy
evaluation insures that only the pieces of the full log joint relevant
to the gradient propagation are actually calculated. So, in many cases
one can use the full joint specification in local propagators without
fear that unneeded likelihood computations will be executed. All of
these features allow us to break up the BBVI update computation into
many different propagators, which can all push updates to variational
cells asynchronously. These design decisions aid scalability.

\subsection{Specify the attachment type of gradient propagators}
% discuss rao-blackwellization here?

Current defaults automate specifying the attachment types. However,
small changes to the attachment types can significantly alter the
ordering and characteristics of the optimization, and are a powerful
abstraction tool for testing new optimization techniques. In addition
to the aforementioned \texttt{watch}, we can also attach propagators
using \texttt{with}, which reads content from a cell but is not
triggered to re-compute if the cell is changed. We can also read a
cell with \texttt{content} which waits until an individual cell has
reached quiescence before proceeding with further computation. By
combining these read attachments with selective decisions to
\texttt{write}, we can quickly develop very novel optimization
strategies and test their impact on rate of convergence (e.g. fully
optimizing some factors with others held fixed, or massive
asynchronous optimization where all distributed propagators
continuously update whenever there is a change to any attached cell).

\section{Summary}

\texttt{propagator-bbvi} is a new algorithmic approach to BBVI that is
extensible, scalable, and allows for easy specification of novel
gradient optimizations used in variational inference. To make best use
of space I focused on design decisions in this report, reflecting the
significant time and thought I dedicated to that process. However,
testing along the way suggested that non traditional gradient
optimizations (e.g. fully or partially optimizing some variational
factors with others held fixed) drastically affects convergence rates.

\appendix
\section{Appendix: Informal discussion of future work}

Most of the work so far on the library focused on designing the new
propagator based BBVI-algorithm, creating an extensible framework, and
testing it. In this process, I created only the necessary variational
distributions (normal, Dirichlet) for testing. However, now
\texttt{propagator-bbvi}'s extensible design and framework is
relatively finalized. Much of the motivation of the project was to
create a tool I can use in my future research, and I will continue to
extend the library as I use it. In particular, this will entail adding
more variational distributions and generalizable transformations from
log joints to gradient propagators. Also, currently
\texttt{propagator-bbvi} is built on the \texttt{propagators} library
which has a very simple serial scheduler. While still fast for serial
computations (and useful as a prototype), scaling up
\texttt{propagator-bbvi} as I intend requires a more sophisticated
parallel scheduler. The good news is that developing new underlying
schedulers is completely independent of the \texttt{propagator-bbvi}
code: any execution scheduler can be used without changing the
existing algorithms and framework.

\bibliography{references}

\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

max_stars_repo_name: massma/propagator-bbvi

max_issues_repo_name: massma/propagator-bbvi

max_forks_repo_name: massma/propagator-bbvi


text:
\section{Equations You Need to Know!!!}
\subsection{Thermodynamics}
\begin{align}
\frac{\Delta L}{L}=\alpha\Delta T\\
Q=mc\Delta T\\
Q=mL\\
PV=nRT\\
PV=Nk_bT\\
P=\eta k_BT\\
v_{rms}=\sqrt{\frac{3RT}{M}}=\sqrt{\frac{3k_BT}{M}}\\
K_{avg}=\frac{3}{2}k_BT\\
E_{int}=NK_{avg}\\
\lambda=\frac{1}{\pi d^2 \eta}\\
E_{int}=nC_VT\\
\Delta E_{int} = nC_V\Delta T\\
C_V=\frac{d}{2}R=\left(\frac{3}{2}R\right)_{mon}=\left(\frac{5}{2}R\right)\\
C_P=C_V+R\\
\gamma = \frac{C_P}{C_V}\\
PV^{\gamma}=constant\\
W=\int{PdV}\\
\Delta E_{int}=Q-W\\
\Delta E_{int}=nC_P\Delta T - nR\Delta T\\
\end{align}
\newpage

\subsection{Electricity}
\begin{align}
\vec{F_{12}}=\frac{1}{4\pi\epsilon_0}\frac{q_1q_2}{r_{12}^2}\hat{r}_{12}\\
\vec{E_1}=\frac{1}{4\pi\epsilon_0}\frac{q_1}{r^2}\hat{r}\\
\vec{F_{12}}=q_2\vec{E_1}\\
dQ=\lambda dl\\
dQ=\sigma dA\\
dQ=\rho dV\\
d\vec{E}=\frac{1}{4\pi\epsilon_0}\frac{dQ}{r^2}\hat{r}\\
\Phi_E=\int \vec{E}\cdot d\vec{A}\\
\oint\vec{E}\cdot d\vec{A}=\frac{Q_{enc}}{\epsilon_0}\\
EA=\frac{Q_{enc}}{\epsilon_0}\\
U_{12}=\frac{1}{4\pi\epsilon_0}\frac{q_1q_2}{r_{12}}\\
V_1=\frac{U_{12}}{q_2}\\
V_1=\frac{1}{4\pi\epsilon_0}\frac{q_1}{r}\\
dV=\frac{1}{4\pi\epsilon_0}\frac{dQ}{r}\\
V_f-V_i=-\int_{s_i}^{s_f}\vec{E}\cdot d\vec{s}\\
E_s=-\frac{dV}{ds}
\end{align}
\newpage
\subsubsection{A little note about Volume Integrals}
In Cartesian coordinates, $dV=dxdydz$. In Cylindrical coordinates, you have a z axis, a $\Phi$ axis, and an r axis. A differential amount of radius is dr, a differential amount of z is dz, and a differential amount of $\Phi$ is $d\Phi$. $d\Phi$ is really just a certain amount of arclength that is covered. We can call this arclength, $dl_\Phi$.
\begin{align}
    dV&=drdl_\Phi dz\\
    \shortintertext{So we can sub in arclength for $dl_\Phi$}\\
    &=dr(rd\Phi)dz\\
    dV&=rdrd\Phi dz\\
\end{align}
Now for spherical coordinates, we have 2 angles and a radius. $\theta$ is wrapping around the radius of the circle, where $\Phi$ is going from the north pole to the south pole. The radius is just r.
\begin{align*}
    dV&=drdl_\theta dl_\Phi\\
    &=dr(rd\theta)(rsin\theta d\Phi)\\
    dV&=r^2sin\theta drd\theta d\Phi\\
\end{align*}
\newpage

\subsection{Circuits}
\begin{align}
    V=IR\\
    R_{eq in series}=R_1+R_2+R_3+...\\
    \frac{1}{R_{eq in para}}=\frac{1}{R_1}+\frac{1}{R_2}+\frac{1}{R_3}+...\\
    \shortintertext{Power}\\
    P=V*I\\
    P=R*I^2\\
    P=\frac{V^2}{R}\\
    \shortintertext{Voltage}\\
    V=R*I\\
    V=\frac{P}{I}\\
    V=\sqrt{P*R}\\
    \shortintertext{Resisitance}\\
    R=\frac{V}{I}\\
    R=\frac{V^2}{P}\\
    R=\frac{P}{I^2}\\
    \shortintertext{Current}\\
    I=\frac{V}{R^2}\\
    I=\frac{P}{V}\\
    I=\sqrt{\frac{P}{R}}
\end{align}
\newpage

\subsection{Magnetism}
\begin{align}
    F=q\vec{v}\times\vec{B}\\
    F=I\vec{l}\times\vec{B}\\
    \vec{B}=\frac{\mu_0}{4\pi}\frac{q\vec{v}\times\hat{r}}{r^2}\\
    \oint\vec{B}\cdot d\vec{l}=\mu_0I_{th}\\
    E_{ind}=-\frac{d}{dt}\Phi_B\\
    \oint\vec{E}\cdot d\vec{l}=-\frac{d}{dt}\int\vec{B}\cdot d\vec{a}\\
\end{align}

\subsection{Optics}
\begin{align*}
    E=E_0sin(kx-\omega t +\phi_0)\\
    B=B_0sin(kx-\omega t +\phi_0)\\
    \vec{S}=\frac{1}{\mu_0}\vec{E}\times\vec{B}\\
    c=\frac{1}{\sqrt{\epsilon_0\mu_0}}\\
    c=\lambda f\\
    E=cB\\
    \mathscr{I}=\frac{P}{A}=\frac{\mathscr{E}}{At}\\
    \mathscr{I}=S_{avg}=\frac{1}{\mu_0}E_{rms}B_{rms}\\
    E_{rms}^2=\frac{E_0^2}{2}\\
    B_{rms}=\frac{B_0^2}{2}\\
    \mathscr{P}=\frac{\mathscr{I}}{c}\text{ or }2\frac{\mathscr{I}}{c}\\
    \theta_1=\theta_1'\\
    n_1sin\theta_1=n_2sin\theta_2\\
    \frac{1}{f}=\frac{1}{d_0}+\frac{1}{d_i}\\
    m=\frac{h_i}{h_0}=\frac{-d_i}{d_0}\\
\end{align*}
\newpage

max_stars_repo_name: CameronSWilliamson/GU-MATH

max_issues_repo_name: therealkeyisme/Math-Notes

max_forks_repo_name: therealkeyisme/Math-Notes


text:
At the moment the platform mainly consists of a runtime allowing the Smart Society application to manage the submission of tasks by the user application. The platform provides also some library (against which the application is compiled) to operate with the current components (SmartCom, Orchestration Manager, Peer Manager). The code is in a private repository at \url{https://gitlab.com/smartsociety/appruntime}.%https://gitlab.com/Teudimundo/smartask}.

A Smart Society Application has its own identifier, generated during the registration phase. At the moment the application code is written by a developer directly in Java, in the final version the code will be generated through the programming framework. Each time a task is submitted to the application a new application instance is created, each instance has it's own state.

\subsection{Runtime}

When the runtime is run three endpoints are provided:

\begin{itemize}
\item {\bf POST:/task/:applicationId/} To submit tasks, the runtime will ask the application to create a \textit{instance initializer} that will take care of the setup phase of the task. The application is expected to carry out all the operation that can be performed before interacting with the peers. The posted data is domain--dependent, and it will be serialized and managed by the application at the moment of instance creation. The runtime associated to the instance (hence the task) creates an identifier that is returned as response.

\item {\bf GET:/task/:applicationId/} To retrieve the status of all or part of the tasks of the application, query parameters can be used in the query and they will be managed by the application that might filter which tasks to show based non them. Note that the status format for each task is just required to be a valid json node (either a text or more complex structures), but it will be completely domain--dependent, in fact the SmartSociety application can send whatever information the user application requires.

\item {\bf GET:/task/:applicationId/:taskId} To retrieve the status of a specific task. As for the previous point both query parameters and the response are domain--dependent.

\item {\bf POST:/message/:applicationId/} Used by the peer applications to communicate back with the application. To use this endpoint the application must have previously contacted the peer with a message containing a given conversation identifier. Such identifier is used then by the runtime to dispatch the message to the correct application instance, the content of the message is then handled by the application instance that  changes its state according to the information received.

\end{itemize}

\subsection{Component Library}

The component library allows the application development to be abstracted from the real components, allowing easier testing.
Furthermore the component wrappers will give a simple interface to the component that is integrated with the runtime.

\subsection{Expected evolution}

In the future version of the platform each application and its runtime will be containerized. A service for routing the requests from general endpoints to the right application runtime will be provided.

The way the runtime will evolve, and its interaction with applications, is highly dependent on the outcome of the programming model and programming framework definition efforts currently ongoing within WP7.