\documentclass[11pt]{article}
\usepackage{setspace}
\usepackage{pxfonts}
\usepackage{graphicx}
\usepackage{geometry}

\geometry{letterpaper,left=.5in,right=.5in,top=0in,bottom=.75in,headsep=5pt,footskip=20pt}

\title{Problem Set 2 -- Introduction to computational modeling}
\author{Computational Neuroscience Summer Program}
\date{June, 2011}

\begin{document}
\maketitle

In this problem set you will be exploring the relation between several fundamental neuronal properties.  For all problems, you should assume a specific membrane capacitance of $c_m = 10$ nF/mm\textsuperscript{2}, a specific membrane resistance of $r_m = 1$ M$\Omega\cdot$mm\textsuperscript{2}, and a resting membrane potential of $E = -70$ mV.  You should perform all calculations for a variety of cell surface areas (use realistic values -- between 0.01 and 0.1 mm\textsuperscript{2}).  Write up your results in a text editor of your choosing.  Include any relevant figures.  Each question can be answered in 1-2 sentences.  Include a printout of your Matlab code as well as any calculations that aren't in the code.  You may work individually or in groups, but each student should hand in their own report.

\subsection*{Equations}

\begin{center}
\begin{tabular}{ll}
$C_m = A \cdot c_m$ & $R_m = \frac{r_m}{A}$\tabularnewline
$\tau_m = c_m \cdot r_m$ & $V_\infty = E + R_mI_{ext}$\tabularnewline
$V(t) = V_\infty + (V(0) - V_\infty)e^\frac{-t}{\tau_m}$ & \tabularnewline
\end{tabular}
\end{center}

\subsection*{Problems}

\paragraph{1.}  Plot (seperately) total membrane capacitance ($C_m$) and total membrane resistance ($R_m$) as a function of cell surface area ($A$).  Your graph should include appropriate units.  Briefly describe the relation between $C_m$, $R_m$, and $A$.

\paragraph{2.}  Compute the membrane time constant $\tau_m$.  What does $\tau_m$ mean in terms of the neuron?

\paragraph{3.}  How much external electrode current would be required to hold the neuron at the membrane potentials below?
\[
V_\infty \in \{-80, -75, -70, -65, -60, -55, -50\}~\mathrm{mV}
\]
For each cell surface area (see above) plot the $I_{ext}$ required to hold the neuron at each of the membrane potentials listed.  Use a different color for each surface area, and include a legend in your plot.  In your own words, describe the relation between cell surface area and $I_{ext}$.

\paragraph{4.  Challenge problem.}  Assume an external current of $I_{ext} = 8$ nA.  How much time would it take to reach the membrane potentials below?
\[
V_m \in \{-70, -65, -60, -55, -50\}~\mathrm{mV}
\]
Repeat your calculations for several cell surface areas (see above).  In your own words, describe the relation between cell surface area and time to reach target voltage.

%\paragraph{5.}  Assume a reset potential of $V_{reset} = -80$ mV and an action potential threshold of $V_{threshold} = -55$ mV.  Plot the expected firing rate $r_{isi}$ as a function of the amount of injected external current $I_{ext}$ (use 5 $I_{ext}$ between 1 and 10 nA).  Plot a seperate curve, in a different color, for for each surface area (see above).  Describe in your own words the relation between surface area, $I_{ext}$, and $r_{isi}$.

\end{document}


%#!pdflatex Naruse_Esurf_2020.tex

\section{Forward model description}

Here we describe the formulation of the forward model used for producing training datasets for the inverse model (Fig. \ref{fig:model_explanation}). This model is based on the model developed by \citet{kostic2006response}, which predicts the behavior of surge-type turbidity currents, but we modified it to consider sediment transport and deposition of multiple grain-size classes. The initial setting of the flows was set to be the lock-exchange condition, which assumes that the collapse of a rectangular-shaped cloud of sediment suspension produces a turbidity current.

In a turbidity current flowing over hundreds of kilometers, \citep{Luchi2018} suggested that the upper layer of the current is predicted to be continuously diluted while the lower layer remains highly concentrated, thus maintaining the current over long distances. Existing one-layer shallow water equation models are insufficient to reproduce such phenomena. The forward model of this study is not an exception.

However, the focus of this study is on rapidly decelerating sedimentary turbidity currents. Normally graded turbidites are considered to be deposited from such decaying flows. In this study, the distribution of turbidites is assumed to be limited to about several tens km at most, and the separation of the lower and upper layers that occurs in sustained turbidity currents after flowing tens of kilometers does not need to be considered when calculating such relatively small-scale turbidity currents. In fact, Kostic and Parker (2006), on which the forward model of this study is based, has been verified to reproduce turbidity currents at experimental and small natural scales (e.g., Fildani et al., 2006). This suggests that the inverse model in this study is well suited to analyze a single bed of turbidites that generally exhibit normal grading in strata.

\begin{figure*}[t]
  \includegraphics[width=12cm]{fig02.eps}
  \caption{Explanation of model parameters. The turbidity current exchanges suspended sediment with the active layer ($L_{a}$ in thickness) on the top of the deposit ($\eta_T$ in thickness) by settling and entrainment. The volumetric rate of settling of the $i$th grain-size class of sediment is calculated from the basal sediment concentration $r_{0} C_i$ multiplied by the sediment settling velocity $w_{s}{i}$. The sediment entrainment rate from the active layer is $w_{si} F_i e_{si}$, where $F_i$ is the volumetric fraction of the $i$th grain-size class in the active layer and $E_{si}$ is the unit dimensionless rate of sediment entrainment. The time variation of grain-size distribution in the active layer is computed in this model.}
  \label{fig:model_explanation}
\end{figure*}

\subsection{Layer-averaged equations}

Let $t$ and $x$ be the time and bed-attached streamwise coordinates, respectively. Parameters $U$ and $h$ denote the layer-averaged flow velocity and the depth, respectively. The total sediment concentration is $C_T$. Here, we apply the following layer averaged conservation equations of fluid mass, momentum and suspended sediment mass of a turbidity current \citep{parker1986self,kostic2006response}:

\begin{eqnarray}
  \frac{\partial h}{\partial t} + \frac{\partial Uh}{\partial x} & = & e_wU \label{eq:conserv_fluidmass} \\
  \frac{\partial Uh}{\partial t} + \frac{\partial U^2h}{\partial x} & = & R g C_T h S - \frac{Rg}{2}\frac{\partial C_T h^2}{\partial x} - C_f U^{2} \label{eq:conserv_momentum} \\
\frac{\partial C_i h}{\partial t} + \frac{\partial U C_i h}{\partial x} & = & w_{si} (F_i e_{si} - r_0 C_i) \label{eq:conserv_suspensionmass}
\end{eqnarray}

\noindent where $R(=\rho_s/\rho_f - 1)$ is the submerged specific density of the sediment ($\rho_s$ and $\rho_f$ are the densities of the sediment and the fluid), and $g$ is the gravity acceleration. $S$ is the slope, and $C_f$ denotes the friction coefficient. The right-hand side of the fluid mass conservation (Equation \ref{eq:conserv_fluidmass}) considers the entrainment of ambient fluid to the flow, in which the empirical entrainment coefficient $e_w$ is applied. Equation \ref{eq:conserv_suspensionmass} describes the mass conservation of the suspended sediment in the flow, which varies depending on the balance between settling and entrainment of the sediment from and to the active layer. In this model, the grain-size distribution of sediment is discretized to $N$ classes. The parameter $C_i$ denotes the suspended sediment concentration of the $i$th class. The model applies the active layer assumption, in which the grain-size distribution is vertically uniform in the bed surface layer (active layer) that exchanges sediment with suspended load \citep{Hirano1971}. $F_i$ indicates the fraction of the $i$th grain-size class in the active layer. The parameter $w_{si}$ denotes the settling velocity of the sediment particles in the $i$th class, and $r_0$ denotes the ratio of near-bed concentration to the layer-averaged concentration of the suspended sediment.

The mass conservation of the sediment in the active layer and the deposit (historical layer), respectively, takes respectively the form

\begin{eqnarray}
  \frac{\partial \eta_i}{\partial t} & = & \frac{w_{si}}{1-\lambda_p}(r_0 C_i - e_{si} F_i) \label{eq:conserv_bed} \\
\frac{\partial \eta_T}{\partial t} &=& \sum \frac{\partial \eta_i}{\partial t}.
\label{eq:total_exner_equation} \\
\frac{\partial F_i}{\partial t} + \frac{F_i}{L_a}\frac{\partial \eta_T}{\partial t} & = & \frac{w_{si}}{L_a (1 - \lambda_p)}(r_0 C_i - F_i e_{si} ). \label{eq:conserv_activelayer}
\end{eqnarray}

\noindent where $\eta_i$ denotes the volume per unit area of the $i$th grain size class, and $\eta_T$ is the total thickness of the deposit. $L_a$ denotes the thickness of the active layer, which is assumed to be constant, for simplicity. The parameter $\lambda_p$ denotes porosity of the active layer and the deposit (0.4 in this study), and $e_{si}$ is an empirical coefficient for sediment entrainment of the $i$th class from the active layer. Equation \ref{eq:conserv_bed} describes the mass conservation of the $i$th class sediment in the bed, and rate of the bed aggradation is obtained by summation of accumulation rates of all grain-size classes (Equation \ref{eq:total_exner_equation}). Equation \ref{eq:conserv_activelayer} considers the temporal development of the grain size distribution in the active layer, where the time development of the total bed thickness $\eta_T$ is obtained by summation of the right-hand side of Equation \ref{eq:conserv_bed} for all grain-size classes.

To solve the Equations \ref{eq:conserv_fluidmass}--\ref{eq:conserv_activelayer}, empirical relations are required for the parameters: $w_{si}$, $r_0$, $C_f$, $L_a$, $e_w$, and $e_{si}$. Here we applied the formulation of \citet{dietrich1982settling} for obtaining the settling velocity $w_{si}$. The ratio of near-bed to layer-averaged concentrations $r_0$ and the bed friction coefficient $C_f$ are fixed to be 2.0 and 0.004, for simplicity \citep{Garcia1990}. The active layer thickness $L_a$ is assumed to be constant (0.003 m). Regarding the entrainment coefficients of ambient water and basal sediment $e_w$ and $e_{si}$, we applied formulations proposed by \citet{parker1987experiments} and \citet{garcia1991entrainment} respectively.

For computational efficiency and numerical stability, a deformed grid approach was adopted to solve Equations \ref{eq:conserv_fluidmass}--\ref{eq:conserv_suspensionmass}. In this transformed coordinate, the propagating flow head was fixed at the downstream boundary using a Landau transformation \citep{Crank1984}. The tail of the flow was also fixed at the upstream end of the calculation domain, and thus the grid spacing in the dimensional coordinate space was continuously stretched during calculation, whereas that in dimensionless space remained constant. This scheme was based on \citet{kostic2006response}, and more details regarding the numerical implementation were given by \citet{Nakao2017}.

\subsection{Model input parameters and topographic settings}
In this study, a turbidity current was assumed to occur from a cloud of suspended sediment (height: $H_0$, length $l_0$). The initial flow velocity was set to 0, and the sediment of the $i$th grain-size class was considered to be initially homogeneously distributed in the suspension cloud at the concentration $C_i$ (Fig. \ref{fig:model_input_parameters}). The suspended sediment cloud was located at the upstream end of the calculation domain, where the slope gradient was 0.1. This steep slope extended for 5.0 km and transited to a gently sloping basin plain (gradient is $S_l$) in the downstream region. Total length of calculation domain was 100 km. In summary, the number of initial conditions required for the forward model calculation was three ($H_0$, $l_0$ and $S_l$) plus number of grain-size classes ($C_i$).

\begin{figure}[t]
  \includegraphics[width=8.3cm]{fig03.eps}
  \caption{Model input parameters. The initial conditions of turbidity current is assumed to be the suspended sediment cloud that is $H_0$ and $l_0$ in height and length, respectively. The initial sediment concentrations $C_1$ to $C_4$ and the basin slope $S_l$ are to be specified for calculation. These seven input parameters are subject to be reconstructed by inverse analysis.}
  \label{fig:model_input_parameters}
\end{figure}


\section{Hardware Support}
\label{hardwaresupport}

Both AMD and INTEL have introduced instructions to perform
word-wise (16-, 32-, and 64-bit) Boolean functions,
including population count {\tt popcnt} ({\apl \qplus\qslash\qomega}),
left-zero count {\tt lzcnt} ({\apl \qomega\qiota\01}),
and trailing-zero count {\tt tzcnt}
({\apl \qlpar\qrotate\qomega\qrpar\qiota\01}).~\cite{INTEL:avx,AMD:instructions}


%\documentclass[slides]{beamer} %switch "slides" to "handout" for printing out
\documentclass[handout]{beamer}

\include{preamble}

%presentation preamble
\usetheme{progressbar}
\usecolortheme{progressbar}
\usefonttheme{progressbar}
\useoutertheme{progressbar}
\useinnertheme{progressbar}

\title[Lec 1]{Predictive Analytics Lecture 2}
\institute[Wharton, Statistics]{Stat 422/722\\ at The Wharton School of the University of Pennsylvania}
\date{January 17 \& 18, 2017}

\author{Adam Kapelner}

\begin{document}

%immediately create a title page
\frame{\titlepage}

\section{LM Inference, Corr. $\not \Rightarrow$ Causation \& Mult. Testing}

\begin{frame}\frametitle{No Inference Possible as of Now}

We haven't spoken about $t$ or $F$ tests. Why is that? \\~\\ \pause

In order to have inference, we need to make explicit random variable model assumptions

\beqn
Y \sim g( \beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p, \sigsq, \ldots)
\eeqn

must be assumed to be something like

\beqn
Y \sim \normnot{\beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p}{\sigsq}
\eeqn

Is this a reasonable thing to do?

\end{frame}

\begin{frame}\frametitle{Back to Modeling}

We said before that our model for $Y$ was

\beqn
Y = f(x_1, \ldots, x_p) + \errorrv
\eeqn

assuming we can know the model, there still is $\errorrv$. Where does it come from? According to determinism a la Laplace, if one knew all the causal information, there would be no error

\beqn
y = t(z_1, z_2, \ldots)
\eeqn

i.e $t$ is the deterministic true mathematical model. %Consider the cigarette example .%where the response is completely explained by the \emph{causal} variables $c_1, c_2, \ldots$. Causal is usually defined as a variable that affects the response variable that one can \qu{manipulate}.

\end{frame}

\begin{frame}\frametitle{}

\begin{figure}
\centering
\includegraphics[width=3.5in]{laplace.png}
\end{figure}

\end{frame}

\begin{frame}\frametitle{Example Lung Cancer Causal Model}

\begin{figure}
\centering
\includegraphics[width=3.8in]{cigarettes}
\end{figure}

\small
Arrows represent causal directions and diamond boxes represent \qu{manipulable} variables (more on this soon). \pause  What functions for the response would be deterministic?

\beqn
y = t(\pause d_1, d_2, s_1), y = t(d_1, d_2, s_2, \pause c_1, c_2, c_3, c_4), y = t(d_1, d_2, c_1, c_2, c_3, c_4, \pause c_5) \\
\eeqn
%%http://www.webmd.com/lung-cancer/guide/lung-cancer-causes#3
\end{frame}

\begin{frame}\frametitle{The Root Cause of Randomness}

\small
But let's say we only have information about $c_1$ (a contributory cause, one among many co-occurrent causes). Since we don't have all the inputs (nor the information of the states of the co-occurent causes), we cannot be sure of $y$. Hence we'll employ a statistical model,

\beqn
Y \sim \pause \bernoulli{f(c_1)}
\eeqn

where we saw before that $f(c_1 = 1) = 16\%$ and $f(c_1 = 0) = 0.4\%$ (probabilistic causation). Thus, the response is stochastic only because we lack information. For regression,\\~\\

\beqn
Y = f(x_1, \ldots, x_p) + \underbrace{t(z_1, z_2, \ldots) - f(x_1, \ldots, x_p)}_{\substack{\pause \errorrv \\ \pause \text{(i.e. the \qu{noise} is due to ignorance)}}}
\eeqn

\footnotesize
Note... some believe that there is still intrinsic randomness in the universe even with all relevant information known. But we are punting on the actual philosophy...

\end{frame}

\begin{frame}\frametitle{$t$ is Difficult to Model}

In order to get $t$, you'll need to know all these functions explicitly:

\beqn
y &=& t_y(\pause d_1, d_2, s_1) \\
s_1 &=& t_{s_1}(c_1, c_2, c_3,c_4,s_2) \\
s_2 &=& f_{s_2}(c_5, s_1)
\eeqn

which means that even if you know all the values of variables, you may not be able to properly model the response since you do not know the functional forms $t_y$, $t_{s_1}$ and $t_{s_2}$.

\end{frame}

\begin{frame}\frametitle{A \qu{Nice} Type of Ignorance}

\begin{figure}
\centering
\includegraphics[width=2.5in]{nice_ignorance}
\end{figure}

\small
In the situation where the true model is

\beqn
y = g(x) + h_1(u_1) + h_2(u_2) + \ldots + h_m(u_m)
\eeqn

and $x$ is observed but $u_1, \ldots, u_m$ are the \qu{unknowns}.

\beqn
h_1(u_1) + h_2(u_2) + \ldots + h_m(u_m) \convd \normnot{\sum_{k=1}^m \mu_k}{\sum_{k=1}^m \sigsq_k}
\eeqn

as the number of unseen variables increase (central limit theorem).

\end{frame}

\begin{frame}\frametitle{The Normal Homoskedastic Error Model}

Let $c = \sum_{k=1}^m \mu_k$ and $\sigsq = \sum_{k=1}^m \sigsq_k$, then

\beqn
y = \underbrace{g(x) + c}_{f(x)} + \errorrv, \quad \text{s.t.} \quad \errorrv =  \sum_{k=1}^m h_k(u_k) - c \sim \normnot{0}{\sigsq}
\eeqn

\begin{figure}
\centering
\includegraphics[width=1.5in]{nice_ignorance}
\end{figure}

Also, since $x$ does not affect the other variables in any way, it cannot have an influence on their spread, hence $\sigsq$ is not a function of $x$. Thus the error spread is the same everywhere across the range of $x$ (homoskedasticity).

\end{frame}

\begin{frame}\frametitle{Parametric Worldview}

We are back to the fundamental statistical problem, $Y = f(x) + \errorrv$ where now we are more \qu{okay} with the noise being normal and homoskedastic for all $x$.\\~\\

We now invoke the parametric worldview. Within that parametric worldview, we will buy into the linear model. Thus,

\beqn
Y \sim \normnot{\beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p}{\sigsq}
\eeqn

But there is one more assumption...

\end{frame}

\begin{frame}\frametitle{Independence}

We now assume that each response is independent of every other response. \footnotesize Second person:

\begin{minipage}{0.55\textwidth}

\begin{figure}
\centering
\includegraphics[width=2.1in]{cigarettes}
\end{figure}
First person:
\begin{figure}
\centering
\includegraphics[width=2.1in]{cigarettes}
\end{figure}
\end{minipage}
\begin{minipage}{0.35\textwidth}
\normalsize
No effect of first person's $y_1$ (nor any of the unobserved variables which generate the $\errorrv_1$) on the second person's $y$ (or $\errorrv_2$). \\~\\ \pause

If there are, we need to observe them and rotate them into our estimate of $f(x)$. Examples for this cigarette case?
\end{minipage}

\end{frame}

\begin{frame}\frametitle{The Classic OLS Assumptions}

Preassuming

\begin{itemize}
\item linearity (the parametric assumption)
\end{itemize}

we then	further assume

\begin{itemize}
\item independence (most important)
\item homoskedasticity (less important)
\item normality of $\errorrv$ (least important if $n$ is large)
\end{itemize}

in order to get inference.

\end{frame}

\begin{frame}\frametitle{A Different Means of Estimation}

\small
Last time, we were working on creating a fit $\fhat$ that means we need estimates of all the parameters:

\beqn
\fhat(x_1, x_2, \ldots, x_p) = \betahat_0 + \betahat_1 x_1 + \ldots + \betahat_p x_p
\eeqn

where the unknown parameters were $\beta_0, \beta_1, \ldots, \beta_p$. Our strategy last time was to minimize SSE via a calculus to obtain $\braces{\betahat_0, \betahat_1,  \ldots, \betahat_p}$. \pause Why was this arbitrary? \\~\\

Given the three new assumptions (that it's not too much of a stretch to buy into usually), we now have a completely specified joint probability distribution for our observed data,

\beqn
\cprob{Y_1 = y_1, Y_2 = y_2, \ldots, Y_n = y_n}{\X_1 = \x_1, \X_2 = \x_2, \ldots, \X_n = \x_n}
\eeqn

where $\x_i := \bracks{x_{i1}, x_{i2}, \ldots, x_{ip}}$ i.e. the vector of all known measurements / covariates.

\end{frame}

\begin{frame}\frametitle{What's a probability? What's a likelihood? }

\small
In general, a parametric density function / mass function of a r.v. looks like the following:

\beqn
\prob{x; \theta} = \ldots
\eeqn

where $\theta$ are the tuning knobs on the model. We ask the question \qu{what's the probability of this realization $x$ (the data) assuming the density was parameterized at $\theta$}? Now we ask the inverse question:

\beqn
\lik{\theta; x}= \ldots
\eeqn

that is \qu{what's the likelihood of these parameters assuming we saw $x$ (the data) come out the way it did}? The $\lik{}$ denotes the \emph{likelihood function}. Of course, probability and likelihood are exactly the same numerically,

\beqn
\prob{x; \theta} = \lik{\theta; x}= \ldots
\eeqn

but conceptually they couldn't be further apart!

\end{frame}

\begin{frame}\frametitle{Maximum Likelihood Estimation (MLE)}

\small
Why not just ask the very common-sense question, what $\theta$ maximizes the probability of seeing what we observe? That would be a good guess as to what $\theta$ is.\pause

\beqn
\thetahat := \argmax_{\theta \in \Theta} \braces{\lik{\theta; x}}
\eeqn

where $\Theta$ represents the space the parameter lives in. In our situation, $\Theta$ represents \pause all real numbers in $p$ dimensions. Let's do this in our example. The first step:

\beqn
&&\cprob{Y_1 = y_1, Y_2 = y_2, \ldots, Y_n = y_n}{\X_1 = \x_1, \X_2 = \x_2, \ldots, \X_n = \x_n} \\
&=& \prod_{i=1}^n \cprob{Y_i = y_i}{\X_1 = \x_i}
\eeqn

How so? \pause Each observation is independent of every other. Recall $\prob{ABC} = \prob{A}\prob{B}\prob{C}$ if $A$, $B$ and $C$ are independent.

\end{frame}

\begin{frame}\frametitle{MLE of the Linear Model Parameters}

\small
We can continue,

\beqn
&=& \prod_{i=1}^n \cprob{Y_i = y_i}{\X_1 = \x_i} \\
&=& \prod_{i=1}^n \oneoversqrt{2\pi \sigsq} \exp{-\oneover{2\sigsq} \squared{y - \cexpe{Y_i}{\X_i}}}
\eeqn

How? \pause Normality and homoskedasticity of $\errorrv$.

\beqn
&=& \prod_{i=1}^n \oneoversqrt{2\pi \sigsq} \exp{-\oneover{2\sigsq} \squared{y - (\beta_0 + \beta_1 x_{i1}+ \ldots + \beta_p x_{ip})}} \\ \pause
\eeqn

How? \pause Linearity of $\cexpe{Y_i}{\X_i}$. Now we wish to maximize the above over all possible $\beta_0, \beta_1, \ldots, \beta_p$.

\end{frame}

\begin{frame}\frametitle{MLE of the Linear Model Parameters}

\small
Then, by some precalc tricks,

\beqn
&=& \prod_{i=1}^n \oneoversqrt{2\pi \sigsq} \exp{-\oneover{2\sigsq} \errorrv_i^2} \\ \pause
&=& \tothepow{\oneoversqrt{2\pi \sigsq}}{n} \exp{\sum_{i=1}^n -\oneover{2\sigsq} \errorrv_i^2} \\ \pause
&=& \tothepow{\oneoversqrt{2\pi \sigsq}}{n} \exp{-\oneover{2\sigsq} \sum_{i=1}^n \errorrv_i^2}
\eeqn

Pick $\braces{\betahat_0, \betahat_1,  \ldots, \betahat_p, \sigsqhat}$ such that the above is minimized. The solutions are called the \qu{maximum likelihood estimates (MLE's)}.

\end{frame}

\begin{frame}\frametitle{Amazing coincidence}

Using calculus, the solution to $\braces{\betahat_0, \betahat_1,  \ldots, \betahat_p}$ is equivalent to minimizing SSE... What a coincidence!! \\~\\

\small
Note: $\sigsqhat = \oneover{n} SSE$

\end{frame}

\begin{frame}\frametitle{The Likelihood Ratio (LR)}

%\small
Imagine two models: (a) the \qu{full} model where $\theta \in \Theta$ and (b) a reduced model where $\theta \in \Theta_R \subset \Theta$. The reduced space has $q$ less degrees of freedom for $\theta$ to operate. Consider the ratio of the likelihoods

\beqn
LR :=
%
\displaystyle \max_{\theta \in \Theta} \lik{\theta; x}
%
/
%
\displaystyle \max_{\theta \in \Theta_R}  \lik{\theta; x}
%
\eeqn

representing how much more probable the full model is over the restricted model. But is this is this increase in probability \emph{statistically significant}? It turns out as $n$ gets large and under pretty forgiving conditions,

\beqn
Q := 2 \natlog{LR} \convd \chisq{q}
\eeqn

\end{frame}

\begin{frame}\frametitle{Testing the Simple Reduced Model}

Let's test our \qu{naive model} from Lecture 1 (always predicting $\yhat = \ybar$) versus having a model having many predictors in a linear model.

\beqn
LR &=& \frac{
\displaystyle \max_{\beta_0, \beta_1, \ldots, \beta_p, \sigsq}
\lik{\beta_0, \beta_1, \ldots, \beta_p; y_1, \ldots, y_n, \x_1, \ldots, \x_n}
}{
\displaystyle \max_{\beta_0, \sigsq}
\lik{\beta_0, \beta_1 = 0, \ldots, \beta_p = 0; y_1, \ldots, y_n, \x_1, \ldots, \x_n}
} \\
&=& \frac{
\tothepow{\oneoversqrt{2\pi \sigsqhat}}{n} \exp{-\oneover{2\sigsqhat} SSE}
}{
\tothepow{\oneoversqrt{2\pi \sigsqhat_0}}{n} \exp{-\oneover{2\sigsqhat_0} SSE_0}
} \\
&=& \tothepow{\frac{SSE_0}{SSE}}{n/2}
\frac{
\exp{-\frac{n}{2 SSE} SSE}
}{
\exp{-\frac{n}{2 SSE_0} SSE_0}
} \\
\eeqn

\end{frame}

\begin{frame}\frametitle{Testing the Simple Reduced Model}

Now we build the Q statistic:

\beqn
Q = 2\natlog{\tothepow{\frac{SSE_0}{SSE}}{n/2}} = n\natlog{\frac{SSE_0}{SSE}} \convd \chisq{p}
\eeqn

This can be used to test

\beqn
&& H_0: \beta_1 = 0, \beta_2 = 0, \ldots, \beta_p = 0 \\
&& H_a: \text{at least one is non-zero}
\eeqn

There is another test for this you've learned about?
\end{frame}

\begin{frame}\frametitle{Omnibus F-test}

\beqn
F = \frac{\frac{SSE_0 - SSE}{p}}{\frac{SSE}{n-p}} = \frac{SSE_0 - SSE}{SSE} \frac{n-p}{p} = \parens{\frac{SSE_0}{SSE} - 1} \frac{n-p}{p} \sim F_{p, n-p}
\eeqn

Both tests use the same test statistic, namely $SSE_0 / SSE$ (up to constants and a monotonic transformation). It is a harder proof to demonstrate they have the same power for the same $n$ and $\alpha$ (but they do). \\~\\

Some points

\begin{itemize}
\item The likelihood ratio test / F test can also test any subset of the predictors (even one).
\item Thus, we now have inference for every predictor or subset of predictors i.e.
\begin{itemize}
\item Hypothesis testing
\item Confidence intervals
\end{itemize}
\end{itemize}

\end{frame}

\begin{frame}\frametitle{What does inference buy you?}

Previously,

\beqn
Y \sim g(\beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p, \sigsq, \ldots)
\eeqn

Do not assume OLS assumptions. We picked L2 loss and minimized to get $\braces{\betahat_0, \betahat_1,  \ldots, \betahat_p}$. What do these numbers means? \pause

\beqn
Y \inddist \normnot{\beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p}{\sigsq}
\eeqn

Assume OLS assumptions. Using MLE, we wind up minimizing L2 loss and get the same $\braces{\betahat_0, \betahat_1,  \ldots, \betahat_p}$. What do these numbers means? \pause Same thing, except now ... \pause we can \qu{test} each value and provide confidence intervals for each value. You know their stability.

\end{frame}

\begin{frame}\frametitle{What you want to say about $\betahat_j$}

[Interpret stolen bases in baseball dataset in JMP].\\~\\

A change in $x_j$ of $+1$ causes / induces a $\beta_j$ difference in its mean response $y$.\\~\\

\end{frame}

\begin{frame}\frametitle{Umbrella Sales and Car Accidents}

Consider a simple example. $x:$ umbrella sales and $y:$ car accidents. What would the relationship look like? \pause

\begin{figure}
\centering
\includegraphics[width=2.5in]{umbrellas_car_accidents.png}
\end{figure}

Does 100 more umbrellas sold \textit{cause} $15.3$ more car accidents (on average)? \pause No... only an association (assessed by a linear correlation).

\end{frame}

\begin{frame}\frametitle{Correlation Does Not Imply Causation}

What can correlation mean?

\begin{itemize}
\item It is a coincidence. How can this be?
\item They are consequence from of a common cause (the \emph{lurking} or \emph{counfounding} variable). How can this be?
\item There is causation \pause
\begin{itemize}
\item x causes y (possibly with intermediates)
\item y causes x (possibly with intermediates)
\item x and y cause each other (cyclic)
\end{itemize}
(recall time-boundedness property)
\end{itemize}

\end{frame}

\begin{frame}\frametitle{Controlling for the Confounder}

The confounding variable is likely $z = $ rainfall.

\begin{figure}
\centering
\includegraphics[width=1.5in]{confounder}
\end{figure}

The illustration shows that if you change $x$ obviously $y$ doesn't change whatsoever (causes always precede their dependent effects an assumption known as temporal boundedness) \\~\\

[Show regression in R]

\end{frame}

\begin{frame}\frametitle{A Proper Interpretation of $\betahat_j$}

$\betahat_j$ estimates $\beta_j$. Imagine $n$ is large and the confidence interval is really small. So basically, $\betahat_j = \beta_j \neq 0$. Interpretation? \\~\\ \pause

Another object naturally observed with exactly the same features except that $x_j$ is increased by $1$ unit will have a $\beta_j$ difference in its mean response $y$.\\~\\ \pause

Another one: $\betahat_j$ estimates $\beta_j$. Imagine $n$ is not so large and the confidence interval is not small but we are still convinced $\beta_j \neq 0$.  Interpretation? \\~\\

Another object naturally observed with exactly the same features except that $x_j$ is increased by $1$ unit will have a $\betahat_j \pm \se{\betahat_j}$ difference in its mean response $y$. (Not much difference except accounting for parameter estimation error).\\~\\

\end{frame}

\begin{frame}\frametitle{When can you say \qu{causes}?}

\small

When can the interpretation be as follows? \sout{Another object naturally observed with exactly the same features except for a change} \emph{If this object in front of us has its} \pause $x_j$ changed by $+1$, it will \sout{have} \emph{cause} a $\betahat_j \pm \se{\betahat_j}$ difference in its mean response $y$.

\begin{enumerate}
\item If we can just assume the model looks as follows:

\vspace{-0.3cm}

\begin{figure}
\centering
\includegraphics[width=3.5in]{get_causality}
\end{figure}

(for all $p$ features ... how can the illustration be updated for one variable?)

\item \pause If we've run a randomized experiment manipulating $x_j$ among the objects AND assuming an linear additive effect of $x_j$ on $y$.
\end{enumerate}

\end{frame}

\begin{frame}\frametitle{Consider a Realistic Model}

\begin{figure}
\centering
\includegraphics[width=4.5in]{realistic_model}
\end{figure}

\end{frame}

\begin{frame}\frametitle{Consider Realistic Predictors}

\begin{figure}
\centering
\includegraphics[width=4.1in]{realistic_predictors}
\end{figure}

Grey variables and known to be dependent but the values are unknown and the $u_k$'s are the \qu{unknown unknowns}.

\end{frame}

\begin{frame}\frametitle{Consider Realistic Predictors}

Observations from the previous illustration

\begin{itemize}
\item Maybe some of the predictors $x_1, \ldots, x_p$ are causal, but most are likely not.
\item Of the ones that are not causal due to a confounder, you may have an idea of the lurking variables but it is unlikely you can measure them. Think college GPA vs SAT with confounder true IQ / ability.
\item If some variables are causal, it is unlikely they have an additive causal effect; their effect is likely moderated by many other interacting variables possibly in non-linear ways.
\item A linear model for $y$ on $x_1, \ldots, x_p$ is likely far from the truth (not related to our discussion on causality).
\end{itemize}

\end{frame}

\begin{frame}\frametitle{Inference and Causality}

\begin{figure}
\centering
\includegraphics[width=4.5in]{inference_possible}
\end{figure}

\end{frame}

\begin{frame}\frametitle{Sidebar: Theories are Hard...}
\begin{figure}
\centering
\includegraphics[width=3.5in]{theories_are_impossible}
\end{figure}

\footnotesize
Maybe we know the predictors, but don't know the causal dependencies. How many theories are possible? \pause 23 variables, 4 configurations between each pair, 23 possible dependences to the the response ... $4^{\binom{23}{2}} \times 2^{23} = 1.757 \times 10^{159}$. And that's not even counting the unknown unknowns... many have said \qu{science is impossible}.

\end{frame}

\begin{frame}\frametitle{More on OLS Coefficient Interpretation}

\small
The linear regression coefficient interpretation again: another object \emph{naturally observed} with exactly the same features except that $x_j$ is increased by $1$ unit will have a $\betahat_j \pm \se{\betahat_j}$ difference in its mean response $y$.\\~\\

What do we mean by naturally observed? \pause This other object is realized from the same joint distribution as all other observations. This means that whatever \textit{multicollinearity} / \textit{covariance structure} exists between the predictors, $\braces{\cov{X_j}{X_k}}$, will give rise to the predictor values in the other object.

\begin{figure}
\centering
\includegraphics[width=2.8in]{predictor_covariance_structure}
\end{figure}

\end{frame}

\begin{frame}\frametitle{The Hidden \qu{Fifth} OLS Assumption}

So this language \qu{... exactly the same features except that $x_j$ is increased by ...} is \pause kind of absurd in the context of a strong covariance structure as ... \pause i.e. it will be very rare to observe an observation with $x_j$ different without any other predictor values different. Example from baseball dataset? \\~\\ \pause

There is room to argue that to have these interpretations be at all realistic, we must assume there is not a strong multicollinearity structure between $x_j$ and the other predictors.

\end{frame}

\begin{frame}\frametitle{But Real Correlations Still Rock}

We've been beating up on correlations and their interpretations e.g. the following:

\begin{figure}
\centering
\includegraphics[width=2.5in]{umbrellas_car_accidents.png}
\end{figure}
\pause

But even though higher umbrella sales do not \qu{cause} accidents, can they still predict them? \pause Yes, $R^2$ is totally agnostic to (a) if your model is true and \pause (b) if your variables are causal or not. Predictors \textit{truly} correlated (a causal link exists) to the response contain information about the value of the response and it doesn't matter through what channel it provides that information. \pause

\end{frame}

\begin{frame}\frametitle{Fake / Spurious Correlations}
%%from http://io9.gizmodo.com/our-new-favorite-website-spurious-correlations-1574464459

\footnotesize
$x$ is margarine consumption per capita in America measured yearly for 10 years from 2000-2009, $y$ is the divorce rate in Maine per 1000 people measured yearly for 10 years from 2000-2009

\vspace{-0.2cm}
\begin{figure}
\centering
\includegraphics[width=2.2in]{margarine_divorce_time.png}
\end{figure}

\vspace{-0.3cm}
Are they linearly predictive of one another? \pause

\vspace{-0.2cm}
\begin{figure}
\centering
\includegraphics[width=2.2in]{margarine_divorce.png}
\end{figure}
\pause

\vspace{-0.3cm}
$R^2 \approx 99\%$, $F$ test $\pval \approx 1 \times 10^{-8}$. [R demo] \pause Be careful about featurization... try to at least have some inkling of an idea for a causal dependency for the response on the predictors... Data dredging / mining is dangerous.

\end{frame}

\begin{frame}\frametitle{Testing Multiple Predictors at Once}

[JMP Baseball data]

\end{frame}

\section{Extrapolation \& Design}

\begin{frame}\frametitle{Dataframe Design}

We spoke a lot about featurization i.e. selecting the columns in the dataframe (these are the predictors to measure). Once we did this, we can then go out and sample observations and then measure each for their predictor values. \\

But we didn't speak at all about selecting the observations themselves!

\end{frame}

\section{Logistic Regression \& Binary Prediction}

\begin{frame}\frametitle{Modeling Categorical Responses}

Previously the response $y$ was continuous and via the OLS assumptions we obtained the statistical model,

\beqn
Y \inddist \normnot{\beta_0 + \beta_1 x_1 + \ldots + \beta_p x_p}{\sigsq}
\eeqn

If the response $y$ is categorical, can we still use this? No... the only elements in the support of the r.v. $Y$ are the levels only. \\~\\

First, assume $Y$ is binary i.e. zero or one. We spoke about this statistical model before,

\beqn
Y \sim \bernoulli{f(x_1, \ldots, x_p)}
\eeqn

since $\cexpe{Y}{x_1, \ldots, x_p} = f(x_1, \ldots, x_p)$, then $f$ is still the conditional expectation function like before except now it varies only within \pause $\zeroonecl$ and it is the same as $\cprob{Y = 1}{x_1, \ldots, x_p}$.

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\end{document}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

\begin{frame}\frametitle{}

\end{frame}

%\begin{frame}\frametitle{$R^2$ vs. $F$ test}
%
%In this case $R^2$ will be related to $F$, the omnibus test statistic for whether the model has any signal whatsoever.
%
%\beqn
%R^2 = \frac{SSE_0 - SSE}{SSE_0} = \ldots = 1 - \inverse{1 + F \frac{p-1}{n-p}}
%\eeqn
%
%\beqn
%F &=& \frac{\frac{SSE_0 - SSE}{p - 1}}{\frac{SSE}{n-p}} = \frac{SSE_0 - SSE}{SSE} \frac{n-p}{p-1} = \ldots \\
%&=& \underbrace{\frac{R^2}{1-R^2}}_{
%%
%\substack{
%\text{ratio of variance} \\
%\text{explained to} \\
%\text{unexplained}
%}}
%%
%\underbrace{\frac{n-p}{p-1}}_{\substack{
%\text{penalty for} \\
%\text{too many features}
%}}
%\eeqn


\section{Backtracking Algorithm}

\subsection{Syntax}

\begin{figure}[ht]
    \begin{gather*}
    \begin{aligned}
        \text{Existential variables}\quad&\al, \bt\\
        \text{Types}\quad&A, B, C &::=&\quad 1 \mid \top \mid \bot \mid a \mid \all A \mid A\to B \mid \al\\
        \text{Algorithmic judgment chain}\quad&\jg &::=&\quad A \le B \mid e\Lto A \mid e\To_{a} \jg \mid \appInfAlg{A}{e}\\
        \text{Algorithmic worklist}\quad&\Gm &::=&\quad \cdot \mid \Gm, a \mid \Gm, \al \mid \Gm \Vdash \jg
    \end{aligned}
    \end{gather*}
\Description{Algorithmic Syntax}
\caption{Algorithmic Syntax}\label{fig:top_alg_syntax}
\end{figure}

The algorithmic syntax is shown in Figure~\ref{fig:top_alg_syntax}.
Compared with the declarative system, existential variables $\al, \bt$ are used
as placeholders for unsolved mono-types.
The judgment chain $\jg$ and worklist context $\Gm$ are defined in the same way as that of Chapter~\ref{chap:ICFP}.

The well-formedness definition for worklist context remains
the same as that of Chapter~\ref{chap:ICFP}.
The hole notation is also inherited.

\paragraph{The Solve Notation}
We define a set of auxiliary substitution functions in the form $\{\al := \tau_A\}$
to improve readability of our algorithmic definitions.
Basically it refers to a global substitution when solving an existential variable.

A detailed definition of the notation is shown as follows:
\begin{gather*}
    \begin{aligned}
        \{\al := \tau\}~(\Gm_L, \al, \Gm_R) &= \Gm_L, [\tau/\al]\Gm_R & \tau = 1, \top, \bot \text{ or }a\\
        \{\al := \bt\}~(\Gm_L, \al, \Gm_R) &= \Gm_L, [\bt/\al]\Gm_R & \bt \in \Gm_L\\
        \{\al := \al[1] \to \al[2]\}~(\Gm_L, \al, \Gm_R) &= \Gm_L, \al[1], \al[2], [\al[1] \to \al[2]/\al]\Gm_R\\
    \end{aligned}
\end{gather*}

\subsection{Algorithmic Subtyping}

\begin{figure}[!ht]
    \noindent\framebox{$\Gm\rto \Gm'$} $\Gm$ reduces to $\Gm'$.
    \begin{gather*}
    \begin{aligned}
    \Gm, a &\algrule \Gm\\
    \Gm, \al &\algrule \Gm\\
    \Gm, x:A &\algrule \Gm\\
    % \\
    % \pmb{
    % (\Gm, L \le \al \le U)} &\algrule \Gm \Vdash l_1 \le u_1 \Vdash \ldots \Vdash l_n \le u_m
    % 	\quad \color{blue} \text{Add $nm$ judgments}\\
    \\
    \Gm \Vdash 1\le 1 &\algrule \Gm\\
    \Gm \Vdash a\le a &\algrule \Gm\\
    \Gm \Vdash A_1\to A_2 \le B_1\to B_2 &\algrule \Gm \Vdash A_2 \le B_2 \Vdash B_1\le A_1\\
    \Gm \Vdash \forall a. A\le B &\algrule \Gm, \al \Vdash [\al/a]A\le B\\
    \Gm \Vdash A\le \forall b. B &\algrule \Gm,b \Vdash A\le B\\
    \Gm \Vdash A\le \top &\algrule \Gm\\
    \Gm \Vdash \bot \le B &\algrule \Gm\\
    \\
    \Gm[\al] \Vdash \al\le \al &\algrule \Gm\\
    \\
    % \multispan2{\text{\jimmy{These 2 rules introduce non-determinicity}}}\\
    \Gm[\al] \Vdash A \le \al &\algrule \{\al := \top\}~\Gm[\al]\\
    \Gm[\al] \Vdash \al \le A &\algrule \{\al := \bot\}~\Gm[\al]\\
    \\
    \Gm[\al] \Vdash \al \le A\to B &\algrule
    \{\al := \al[1] \to \al[2]\}~(\Gm[\al] \Vdash \al \le A\to B)\\
    &\qquad\qquad \text{when } \al\notin FV(A \to B)\\
    \Gm[\al] \Vdash A\to B \le \al &\algrule
    \{\al := \al[1] \to \al[2]\}~(\Gm[\al] \Vdash A\to B \le \al)\\
    %\Gm[\al[1], \al[2], L \cup \{\al[1] \to \al[2]\} \le \al \le U] \Vdash A \to B \le \al[1] \to \al[2]\\
    &\qquad\qquad \text{when } \al\notin  FV(A \to B)\\
    \\
    \Gm[a][\bt] \Vdash a \le \bt &\algrule \{\bt := a\}~\Gm[a][\bt]\\
    \Gm[a][\bt] \Vdash \bt \le a &\algrule \{\bt := a\}~\Gm[a][\bt]\\
    \Gm[\bt] \Vdash 1 \le \bt &\algrule \{\bt := 1\}~\Gm[\bt]\\
    \Gm[\bt] \Vdash \bt \le 1 &\algrule \{\bt := 1\}~\Gm[\bt]\\
    \\
    \Gm[\al][\bt] \Vdash \al \le \bt &\algrule \{\bt := \al\}~\Gm[\al][\bt]\\
    \Gm[\al][\bt] \Vdash \bt \le \al &\algrule \{\bt := \al\}~\Gm[\al][\bt]\\
    \end{aligned}
    \end{gather*}
\Description{Algorithmic Garbage Collection and Subtyping}
\caption{Algorithmic Garbage Collection and Subtyping}\label{fig:top_alg_subtyping}
\end{figure}

Figure~\ref{fig:top_alg_subtyping} describes the algorithmic rules for subtyping.
The relation is stated in a small-step ``reduction'' form, i.e. in each step,
the worklist is analysed from the right-hand-side and reduced according to the top judgment.
The overall procedure succeeds iff the worklist eventually reduces to $\cdot$ (the empty worklist).

We categorize them into 7 groups according to their behavior:
\begin{enumerate}
    \item Rules 1-3 are basic garbage collection rules.
        Given that the worklist $\Gm$ is well-formed,
        no reference of a variable should occur before its declaration.
        Therefore removing the declaration in the top position does not break well-formedness.

        An existential variable that is unsolved in the top position indicates
        that it is not constrained,
        thus picking any well-formed mono-type as its solution is acceptable.
        In our algorithmic formalization, we simply drop the existential variable.

    \item Rules 4-10 directly correspond to the declarative subtyping rules.
        With no top-level existential variables,
        there is nothing to guess immediately,
        and thus the algorithm behaves just like the declarative system.

    \item Rule 11 is a base case in the algorithmic system.
        The declarative reflexivity property suggests that any solution is acceptable,
        thus the judgment holds without any constraint.

    \item Rules 12-13 are important rules that require backtracking techniques
        for implementation.
        These rules \emph{overlap} with all the remaining rules when solving
        an existential variable.
        In other words, they simply try if $\top$ or $\bot$ satisfies the constraints
        in parallel with other possibilities.

    \item Rules 14-15 compares an existential variable $\al$ with a function type,
        resulting in solving the $\al$ by $\al[1] \to \al[2]$.
        The freshness condition rules out the possibility
        when there is a cyclic dependency.
        For example, the judgment
        \[\al \le 1 \to \al\]
        is satisfied with either of these solutions to $\al$:
        \[ \bot, 1 \to \bot, \top \to \bot, 1 \to 1 \to \bot, \ldots \]
        However, we argue that comparing $\al$ with a function type
        that contains $\al$ itself is hardly useful in practice,
        and most of the solutions are meaningless.
        It would be nice if we may develop a complete algorithm or
        weaken the specification to reject such cases,
        but in this work, we choose to simply propose an incomplete algorithm,
        where in this example, only the $\bot$ solution is considered with Rule 13.
        The condition of Rule 14 rejects the judgment for further analysis
        and thus does not produce more solutions.
        This is one source of incompleteness of our algorithm with respect to the declarative specification.

    \item Rules 16-19 solve existential variables against a type variable or the unit type.
        For instance, the judgment
        \[\al \le 1\]
        only has two solutions: $\al = 1$ or $\al = \bot$.
        In similar cases, one of the solutions is produced by Rule 12 or 13,
        and the other one is given by one of the rules in this group.
        Additional well-formedness checks are performed when type variables are encountered;
        a solution to an existential variable must be well-formed in the context
        before the existential variable is defined.

    \item Rules 20-21 deal with subtyping judgments
        that compare two different existential variables.
        The only difference between them is the variable order.
        Similar to the type variable case in the previous group,
        existential variables must solve to another one defined earlier.
        With Rules 12, 13, 20 and 21, a judgment like
        \[\al \le \bt\]
        could possibly give any of the following solutions:
        \[ \al = \bt ~(\text{or } \bt = \al)
            \text{ or } \al = \bot \text{ or } \bt = \top \]
        Those are good attempts, but unfortunately,
        they do not cover the complete set of possibilities.
        The following example worklist
        \[ \al, \bt \Vdash \bt \le 1 \to 1 \Vdash \al \le \bt \]
        has a solution $\al = 1 \to \top, \bt = 1 \to 1$ missed by our algorithm.
        Similar situations happen when the judgments are specifically ordered;
        if $\bt \le 1 \to 1$ is the top-most judgment,
        the algorithm will not miss this solution.

        Although such treatment for existential variable solving is incomplete in theory,
        the algorithm completely handles practical programs
        where unification is simply equality.
        For other programs that exploit complex guessing involving subtyping,
        the programmer may put type annotations when the type inference algorithm
        does not find the optimal solution.
\end{enumerate}

\subsection{Algorithmic Typing}

\begin{figure}[!ht]
\noindent\framebox{$\Gm\rto \Gm'$} $\Gm$ reduces to $\Gm'$ (continued).
\begin{gather*}
\begin{aligned}
    \Gm \Vdash e \Lto B &\algrule \Gm \Vdash e\To_a a\le B \quad
    \text{when } e \neq \lam e' \text{ and } B \neq \all B'\\
    \Gm \Vdash e\Lto \all A &\algrule \Gm,a \Vdash e\Lto A\\
    \Gm \Vdash \lam e \Lto A\to B &\algrule \Gm, x:A  \Vdash e \Lto B\\
    \Gm[\al] \Vdash \lam e \Lto \al &\algrule \{\al := \al[1]\to \al[2]\}~\Gm, x:\al[1] \Vdash e \Lto \al[2]\\
    \Gm \Vdash e \Lto \top &\algrule \Gm\\
    \Gm[\al] \Vdash e \Lto \al &\algrule \{\al := \top\}~\Gm[\al]
    % \quad\text{\jimmy{Additional}}
    \\[3mm]
    \Gm \Vdash x\To_a \jg &\algrule \Gm \Vdash [A/a] \jg \quad \text{when } (x:A)\in \Gm\\
    \Gm \Vdash (e:A)\To_a \jg &\algrule \Gm \Vdash [A/a]\jg \Vdash e \Lto A\\
    \Gm \Vdash ()\To_a \jg &\algrule \Gm \Vdash [1/a]\jg\\
    \Gm \Vdash \lam e \To_a \jg &\algrule
    \Gm,\al,\bt \Vdash [\al\to\bt/a]\jg, x:\al \Vdash e\Lto \bt\\
    \Gm \Vdash e_1\ e_2 \To_a \jg &\algrule \Gm \Vdash e_1\To_b (\appInfAlg{b}{e_2})
    \\[3mm]
    \Gm \Vdash \appInfAlg{\all A}{e} &\algrule \Gm,\al \Vdash \appInfAlg{[\al/a]A}{e}\\
    \Gm \Vdash \appInfAlg{A\to C}{e} &\algrule \Gm \Vdash [C/a]\jg \Vdash e \Lto A\\
    \Gm \Vdash \appInfAlg{\bot}{e} &\algrule \Gm \Vdash [\bot/a]\jg\\
    \Gm[\al] \Vdash \appInfAlg{\al}{e} &\algrule
        \{\al := \al[1]\to \al[2]\}~\Gm \Vdash \appInfAlg{\al[1]\to\al[2]}{e}\\
    \Gm[\al] \Vdash \appInfAlg{\al}{e} &\algrule
        \{\al := \bot\}~\Gm[\al] \Vdash [\bot/a]\jg
\end{aligned}
\end{gather*}
\Description{Algorithmic Typing}
\caption{Algorithmic Typing}\label{fig:top_alg_typing}
\end{figure}

The algorithmic typing rules are split into three groups,
according to the category of the top-most judgment.

\begin{enumerate}
    \item Checking mode. Rules 22-27 reduce top-level checking judgments.
            Rules 22, 23, 24 and 26 directly reflect how the declarative system behaves.
            Rule 25 splits $\al$ into $\al[1] \to \al[2]$ to mimic the same logic as Rule 24,
            since a lambda expression must be of a function type.
            Rule 27 is another backtracking rule, which overlaps with all other checking rules.
            Solving $\al$ to $\top$ in such case reflects
            the declarative rule $\mathtt{Decl{\top}}$ when the unknown type is $\top$.
            Furthermore, we eliminate the algorithmic counterpart of declarative rule
            $\mathtt{Decl1I}$, because a combination of Rules 22 and 30 already
            accepts the judgment $() \Lto 1$.

    \item Inference mode. Rules 28-32 reduce inference judgments.
            Like the work presented in Chapter~\ref{chap:ICFP}, the encoding of the return type is by
            an explicit substitution on the binder of a judgment chain.
            Rules 28, 29, 30 and 32 correspond to the declarative system straightforwardly.
            Rule 31 guesses an unannotated lambda with a mono function type $\al \to \bt$.
            Writing in a slightly different way may help improve readability:
            \[ \Gm \Vdash \lam e \To_a \jg \rrule{31'}
                \Gm, \al, \bt \Vdash [\al \to \bt / a]\jg \Vdash \lam e \Lto \al \to \bt \]
            Rule 32 illustrates how the judgment chain works, with a continuation-passing-style
            encoding of the type inference task.

    \item Application inference mode. Rules 33-37 reduce application inference judgments.
            Each of these judgments accepts an input function type and an argument expression
            and produces the expected return type.
            Rules 33, 34 and 35 are direct translations from the declarative rules.
            Rule 33, specifically, enables implicit parametric polymorphism via
            existential variable solving.
            Rules 36 and 37 deal with cases where a single existential variable
            $\al$ behaves as a function type.
            Rule 36 splits $\al$ into a function unknown type $\al[1] \to \al[2]$.
            Rule 37 tries the solution $\al = \bot$ and returns the $\bot$ type.
            % Both of the rules are not so useful in reality,
            % since it is derived from a parametric function type like $\all a$,
            % which behaves like the the $\bot$ type.

\end{enumerate}


\subsection{gammapy.astro}
\label{ssec:gammapy-astro}
\todo{Atreyee}

The gammapy.astro sub-package contains utility functions for studying physical scenarios in high energy astrophysics.
The dark matter module computes the so called J-factors and the gamma-ray spectra expected from annihilation of dark matter in different channels according to the recipe described in \cite{2011JCAP...03..051C}. In the source sub-module, dedicated classes exist for modeling galactic sources according to some come physical models, eg: SNR evolution models \citep{1950RSPSA.201..159T, 1999ApJS..120..299T}, evolution of PWN during the free expansion phase \citep{2006ARA&A..44...17G} or computation of physical parameters in a pulsar assumed to be a simple dipole. There are also dedicated tools for simulating synthetic populations based on physical models derived from observational or theoretical considerations for different classes of Galactic VHE gamma-ray emitters: PWNe, SNRs \cite{1998ApJ...504..761C}, pulsars \cite{2006ApJ...643..332F, 2006MNRAS.372..777L, 2004A&A...422..545Y} and gamma-ray binaries. While the present list of use cases is rather preliminary, this can be enriched with time with by users and/or developers according to future needs.


%!TEX root = morusAC.tex

\section{Conclusion}
\label{sec/Conclusion}

This work provides a comprehensive analysis of the components of
\MORUS.  In particular, we show that \MORUS[1280]'s keystream exhibits a correlation of $2^{-76}$ between certain ciphertext bits. This enables a plaintext recovery
attack in the broadcast setting, using about $2^{152}$ blocks of data.
While the amount of data required is impractical, this seems to
violate the security claims of \MORUS[1280] because the attack works
even if the key is refreshed regularly.  Moreover, the broadcast
setting is practically relevant, as was shown with attacks against RC4
as used in TLS~\cite{DBLP:conf/uss/AlFardanBPPS13}.

We have shared an earlier version of this paper with the authors of
\MORUS and they agree with the technical details of the keystream
bias.  However they consider that it is not a significant weakness in
practice because it requires more than $2^{64}$ ciphertexts bits.  In
the context of the CAESAR competition, we believe that certificational
attacks such as this one should be taken into account, in order to
select a portfolio of candidates that reflects the state of the art in
terms of cryptographic design.

\ifanonymous
\else
\subsubsection{Acknowledgments.}

The results presented here were originally found during the Flexible
Symmetric Cryptography workshop held at the Lorentz Center in Leiden,
Netherlands.  The authors would like to thank Meltem Sonmez Turan, who
participated in the initial discussion.
The second author was supported by the European Union's H2020 grant 644052 (HECTOR).
The fourth and sixth authors
are partially supported by the French Agence Nationale de la Recherche
through the BRUTUS project under Contract ANR-14-CE28-0015.
The fifth author was supported by EPSRC Grant EP/M013472/1.

\fi

\FloatBarrier

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


\section{Collision.\-h File Reference}
\label{_collision_8h}\index{Collision.\-h@{Collision.\-h}}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item
void {\bf collision} ({\bf Circle} \&circle1, {\bf Circle} \&circle2)
\end{DoxyCompactItemize}

\subsection{Function Documentation}
\index{Collision.\-h@{Collision.\-h}!collision@{collision}}
\index{collision@{collision}!Collision.h@{Collision.\-h}}
\subsubsection[{collision}]{\setlength{\rightskip}{0pt plus 5cm}void collision (
\begin{DoxyParamCaption}
\item[{{\bf Circle} \&}]{circle1, }
\item[{{\bf Circle} \&}]{circle2}
\end{DoxyParamCaption}
)}\label{_collision_8h_a6961b2ca0f31dc15b2c370439971dfdf}
Collision Detection
\begin{DoxyParams}{Parameters}
{\em circle1} & \-: one of the circles on which collision detection is done \\
\hline
{\em cirlce2} & \-: another circle on which collision detection is done determines whether collsion occurs between given 2 circles and if so, changes their velocoties accordingly \\
\hline
\end{DoxyParams}
condition to check whether a collision occurs between the circles

velocity of approach must be less than 0 for the collision to happen

calculating new normal velocities after collision

calculating the final velocity vectors

updating the velocities of the circles

Definition at line 13 of file Collision.\-h.


\documentclass{beamer}
\usepackage{color}
\usepackage{hyperref}
% \usepackage{pgf, pgfarrows, pgfnodes}
\usepackage{mathtools}
\usetheme{AnnArbor}
\title[https://github.com/cheraaqee/popSR]{Perceptually-Optimized Loss Function for Image Super-Resolution}
\author[ICSPIS2021]{\small Amirhossein Arezoomand \inst{1} \and Pooryaa Cheraaqee \inst{1} \and Azadeh Mansouri \inst{1}}
\institute[]{\inst{1} \textbf{Department of\\ Electrical and Computer Engineering,\\ Kharazmi University}}
% \date{\today}
\begin{document}
%%%%
\begin{frame}
\frametitle{ICSPIS 2021}
\titlepage
\end{frame}
%%%%
\section*{Outline}
\begin{frame}
\frametitle{Outline}
\tableofcontents[pausesections]
\end{frame}
%%%
\section{Problem Definition}
\subsection{Image Super-Resolution}
\begin{frame}
\frametitle{What is \emph{Super-Resolution}?}
\begin{itemize}
\visible<1->{
\item increasing the dimension}
\begin{itemize}
\visible<2,3>{
\item $\text{input (}X_{M\times N}) \xrightarrow{\text{upsampling by a factor of 2 (i.e. }2\uparrow)} \text{output (}Y_{2M\times 2N})$}
\visible<3>{
\item BiLinear, BiCubic, etc.}
\end{itemize}
\visible<4->{
\item
\textcolor{red}{\textbf{!! Preserving the quality !!}}}
\end{itemize}
\visible<5->{
\begin{center}
\includegraphics[height=4cm]{sr_sample}
\end{center}
}
\end{frame}
\subsection{Loss Function}
\begin{frame}
\frametitle{CNNs and Loss Functions}
\begin{itemize}
\visible<1->{
\item Super-Resolver CNNs
\vskip 0.5cm
	\only<2-5>{
		\includegraphics[trim={4.7cm, 25.5cm, 14.5cm, 2cm}, clip, width=1cm]{figure_slide}}
	\only<3-5>{
		\includegraphics[trim={5.7cm, 25.5cm, 7.3cm, 1.3cm}, clip,width=5cm]{figure_Cnn}}
	\only<4-5>{
		\includegraphics[trim={6.55cm, 24.3cm, 8.2cm, 1.2cm}, clip, width=3cm]{figure_output}}

	\only<5>{
		\hskip 6.5cm \includegraphics[trim={6.55cm, 23.3cm, 8.5cm, 1.2cm}, clip, width=3cm]{figure_gt}}
}
% \visible<6->{
% \includegraphics[trim={4.7cm, 25.5cm, 14.5cm, 2cm}, clip, width=1cm]{figure_slide}\includegraphics[trim={6.55cm, 24.3cm, 8.2cm, 1.2cm}, clip, width=3cm]{figure_output}
% \includegraphics[trim={6.55cm, 23.3cm, 8.5cm, 1.2cm}, clip, width=3cm]{figure_gt}
% }
\visible<7->{
\item The Loss Function

	\only<8-14>{$X\rightarrow \text{Network's input}$}

		\only<9-14>{$\hat{Y}\rightarrow \text{Network's output}$}

		\only<10-14>{$Y\rightarrow \text{The correct answer}$}

		\only<11-14>{$W\rightarrow \text{Current network's weight}$}

		\only<12-14>{$Y=F(X, W)$}

		\only<13-14>{\small{The amount of update that must be applied to} $W~(i.e. \Delta W) = E(Y, \hat{Y})$; where $E\in[0,1]$}

		\only<14>{\small{The updated network's weights} $(i.e. W\prime) = W+\Delta W$}

		\onslide<15>{\textbf{How to define $E(Y, \hat{Y})$}?}
}
\end{itemize}
\end{frame}
%%%
\section{Previous Attempts}
\begin{frame}
	\frametitle{Ways to Define a Loss Function}
	\begin{itemize}
	\visible<2->{\item Visible Error}

		\visible<3->{
			$\displaystyle E(Y, \hat{Y})=\frac{1}{M\times N}\sum_{i=1}^M{\sum_{j=1}^N{(Y(i, j)-\hat{Y}(i, j))^2}}$
			}
		\visible<4->{\item Quality Metrics}

		\visible<5->{
			$E(Y, \hat{Y})=SSIM(Y, \hat{Y})$[1]
			}

		\visible<6->{
			\begin{center}
				\includegraphics[width=8cm]{ssim_vs_mse}
			\end{center}
			}
	\end{itemize}
\end{frame}
%%%
\section{The Taken Approach}
\begin{frame}
\frametitle{Our Method}
\begin{itemize}
\visible<2->{
\item DCT
\begin{itemize}
\visible<3->{
\item Expressive
\only<4-5>{

\includegraphics[width=3cm]{figure_dct_kernels}
}
\only<5>{
\includegraphics[width=5cm]{figure_dct_examples}
}
}
\visible<6->{
\item Fast!
}
\end{itemize}
}
\visible<7->{
\item Weighting the Important Components

	\visible<8->{
		Empirically determined compression quantization
		}

	\visible<9->{
		\includegraphics[width=3cm]{figure_JPEG_q}
		}

}
\end{itemize}

\end{frame}
%%%%
\begin{frame}
\frametitle{The Proposed Loss Function}
\only<1-4, 9>{
${Y, \hat{Y}}\rightarrow [0, 1]$
}
\vskip 0.5cm

	\only<2-4>{\textcolor[rgb]{0,0,1}{$\xrightarrow{(1)}$ compute $DCT(Y)$ and $DCT(\hat{Y})$}}

	\only<3-8>{\textcolor[rgb]{0,0.33,0.63}{$\xrightarrow{(2)}$ quantize $DCT(Y)$ and $DCT(\hat{Y})$}}

	\only<4>{\textcolor[rgb]{0,0.63,0.33}{$\xrightarrow{(3)}$ compute the visible error between the quantized coefficients}}
	\vskip 0.5cm

	\only<6-8>{\includegraphics[width=2cm]{figure_JPEG_q}}\hskip 0.5cm \only<7-8>{$\xrightarrow{upsample}$ \includegraphics[width=4cm]{figure_JPEG_q_i}}

	\only<8>{$Q_l = \alpha \cdot \uparrow(Q)$}

	\only<9>{\fbox{\textcolor{blue}{\textbf{$\displaystyle popSR(Y, \hat{Y})=\frac{1}{21\times21}\sum_{i=1}^{21}\sum_{j=1}^{21}\left(\frac{DCT\left(Y\right)(i, j)}{Q_l(i, j)}-\frac{DCT\left(\hat{Y}\right)(i, j)}{Q_l(i, j)}\right)^2$}}}}
\end{frame}
%%%
\section{Results}
%%%%
\begin{frame}
\frametitle{Experimental Setup}
	\begin{itemize}
		\item train SRCNN [2] with MSE
		\item train SRCNN with popSR
		\item Timofte et. al [3] for train
		\item Set5 [4] Set14 [5] for test on various scales
	\end{itemize}
\end{frame}
\subsection{Qualitative}
\begin{frame}
	\frametitle{Sample Outputs}
	\only<1-3>{\includegraphics[height=6cm]{figure_sample}}
\only<2-3>{\includegraphics[height=6cm]{figure_sample_2}}
\only<3>{\includegraphics[height=6cm]{figure_sample_2}}
\end{frame}
%%%%
\subsection{Quantitative}
\begin{frame}
\frametitle{Objective Evaluation}
	\only<1>{
		\begin{itemize}
			\item Three metrics:
				\begin{itemize}
					\item PSNR
					\item SSIM
					\item GMSD [6]
				\end{itemize}
			\item Two datasets:
				\begin{itemize}
					\item set5
					\item set14
				\end{itemize}
			\item 3 scaling factors
				\begin{itemize}
					\item $2\uparrow$
					\item $3\uparrow$
					\item $4\uparrow$
				\end{itemize}
		\end{itemize}
		}
		\only<2>{set5 \& $2\uparrow$}

		\only<2>{\includegraphics[width=5cm]{table_set5_2}}

		\only<3>{set5 \& $3\uparrow$}

		\only<3>{\includegraphics[width=5cm]{table_set5_3}}

		\only<4>{set5 \& $4\uparrow$}

		\only<4>{\includegraphics[width=5cm]{table_set5_4}}

		\only<5>{set14 \& $2\uparrow$}

		\only<5>{\includegraphics[width=5cm]{table_set14_2}}

		\only<6>{set14 \& $3\uparrow$}

		\only<6>{\includegraphics[width=5cm]{table_set14_3}}

		\only<7>{set14 \& $4\uparrow$}

		\only<7>{\includegraphics[width=5cm]{table_set14_4}}

\end{frame}
%%%%
\section{Conclusion\& Future Works}
%%%
\begin{frame}
	\frametitle{Conclusions}
	\begin{itemize}
		\item<1-> Perceptual
		\item<2-> Portable
		\item<3-> Efficient
		\item<4-> Faster Convergence
		\item<5-> Incorporating Color

	\end{itemize}
\end{frame}
\section*{References}
\begin{frame}
	\frametitle{Bibliography}
	\tiny{
	\begin{enumerate}
		\item Wang, Zhou, Alan C. Bovik, Hamid R. Sheikh, and Eero P. Simoncelli. "Image quality assessment: from error visibility to structural similarity." IEEE transactions on image processing 13, no. 4 (2004): 600-612.
                \item Dong, Chao, Chen Change Loy, Kaiming He, and Xiaoou Tang. "Learning a deep convolutional network for image super-resolution." In European conference on computer vision, pp. 184-199. Springer, Cham, 2014.
		\item Timofte, Radu, Vincent De Smet, and Luc Van Gool. "Anchored neighborhood regression for fast example-based super-resolution." In Proceedings of the IEEE international conference on computer vision, pp. 1920-1927. 2013.
		\item Bevilacqua, Marco, Aline Roumy, Christine Guillemot, and Marie Line Alberi-Morel. "Low-complexity single-image super-resolution based on nonnegative neighbor embedding." (2012): 135-1.
		\item Zeyde, Roman, Michael Elad, and Matan Protter. "On single image scale-up using sparse-representations." In International conference on curves and surfaces, pp. 711-730. Springer, Berlin, Heidelberg, 2010.
		\item Xue, Wufeng, Lei Zhang, Xuanqin Mou, and Alan C. Bovik. "Gradient magnitude similarity deviation: A highly efficient perceptual image quality index." IEEE Transactions on Image Processing 23, no. 2 (2013): 684-695.
	\end{enumerate}
	}
\end{frame}
\end{document}


\section{Standard Libraries}

Since Fl is a very young language, there are no extensive
standard libraries%
\index{standard libraries}%
{} and thus this section is very tentative and is likely
to be modified significantly in future releases.
All standard libraries reside in the vosslib%
\index{vosslib}%
{} directory.
The easiest way to make sure this directory is in the search path
for fl is to create a file called {\em .vossrc} in your home directory
that contains a line
\begin{hol}
VOSS-LIBRARY-DIRECTORY = /path/where/voss/is/installed/vosslib
\end{hol}

\subsection{defaults.fl}
\index{defaults.fl}

This is a basic library that contains many useful general functions.

\newcommand{\FLfun}[2]{\parbox[t]{2in}{#1}  \parbox[t]{4.5in}{#2}}
\begin{tabbing}
excitation             \=         \kill
\FLfun{length l}{Returns the length of the list l.}\\
\FLfun{append l1 l2}{Appends lists l1 and l2. Note '@' and 'and' are infix aliases to append.}\\
\FLfun{el i l}{Select element i in list l. List elements are numbered from 1.}\\
\FLfun{last l}{Return the last element in list l.}\\
\FLfun{butlast l }{Return the list l with the last element removed.}\\
\FLfun{replicate x n }{Return a list with n copies of x as elements.}\\
\FLfun{map fn l }{Apply the function fn to each element of the list l and return the resulting list.}\\
\FLfun{itlist f l x }{Combine all the elements in l with the function f, i.e., f (hd l) (f (el 2 l) (f (el 3 l) (... (f (last l) x)))...).}\\
\FLfun{rev\_itlist f l x }{As itlist, but do it in reverse.}\\
\FLfun{find p l }{Return the first element in the list that makes the predicate p true.}\\
\FLfun{exists p l }{Determine whether an element exists in the list l that satisfies the predicate p.}\\
\FLfun{forall p l }{Determine whether all elements in in the list l satisfies the predicate p.}\\
\FLfun{mem x l }{Determines whether there is an element in l equal to x.}\\
\FLfun{assoc x al }{Return the second component of a pair in the list l whose first component is equal to x.}\\
\FLfun{rev\_assoc x l }{Same as assoc but exchange meaning of fst and snd.}\\
\FLfun{rev xl }{Reverse list xl.}\\
\FLfun{filter p l }{Returns the list obtained by removing from l every element that does not satisfy p. }\\
\FLfun{flat ll }{Takes a list of lists and return the list obtained by merging all the lists.}\\
\FLfun{interleave ll }{Takes a list of lists and returns a single list that is the interleaving of each list.}\\
\FLfun{combine l r }{Takes lists l and r and creates a list of pairs whose first components are drawn from l and whose second components are drawn from r.}\\
\FLfun{split pl }{Takes a list of pairs and returns a pair of lists. The first list are all first components of the pairs and the second list contain all second components of the pairs.}\\
\FLfun{s1 intersect s2 }{Return the list of elements common to both s1 and s2.}\\
\FLfun{s1 subtract s2 }{Return the list of elements that are in s1 but not in s2.}\\
\FLfun{s1 union s2 }{Return the union (no duplicates) of s1 and s2.}\\
\FLfun{distinct l }{Determines whether there are any duplicates in the list l. If so, returns false; otherwise returns true.}\\
\FLfun{setify l }{Take a list and make it into a set (no duplicates).}\\
\FLfun{s1 set\_equal s2 }{Determines whether the two sets s1 and s2 are equal.}\\
\FLfun{declare vl }{Takes a list of Boolean variables and forces them to be evaluated in the order they appear in the list. Useful in declaring Boolean variables for the OBDD ordering.}\\
\FLfun{num2str n }{Converts a number (positive) to a string.}\\
\FLfun{lg n }{Computes the number of bits requires to represent n as an unsigned binary number.}\\
\FLfun{bdd\_profile expr\_list }{Takes a list of Boolean expressions and prints out a histogram over the width of the combined OBDD forest.}\\
\FLfun{excitation ckt nd }{Computes the next state function for node nd in circuit ckt. {\em NOTE:} this function only works correctly when using the UNIT-DELAY model.}\\
\FLfun{node\_profile ckt node\_list }{Prints out a bdd profile for all the current values on the nodes in node\_list. Mostly useful in conjunction with the '-m n' option to STE (i.e., abort the simulation at a suitable time and check the size\\
and profile of the OBDDs on the selected nodes.}
\end{tabbing}

\subsection{verification.fl}
\index{verification.fl}

This is the basic verification library that contains useful functions
to make writing verification
conditions much more convenient. It should be noted that this is an
abstract data type so not all
functions defined in the library are exported. In order to shorten
the typing information, we use
the following shorthand: voss\_tuple = (bool, (string, (bool, (int, int)))).
All these functions, with the exception of node\_vector, variable\_vector,
verify and nverify returns lists of five-tuples, of the form described in
the description of STE.
Briefly, the functions are as follows:
\begin{tabbing}
excitation             \=         \kill
\FLfun{UNC}{Unconstrained. Useful as padding when writing functions generating verification conditions.}\\
\FLfun{n is v}{Node n is asserted/checked to have the value v with guard true.}\\
\FLfun{nv isv vv}{Node list nv is asserted/checked to have the values in the value list vv with guard true.}\\
\FLfun{node\_vector s n}{Create a list of strings of the form s catenated with the string representing integer i, where i goes from (n-1) to 0.}\\
\FLfun{variable\_vector s n}{Create a list of Boolean variables of the form s catenated with the string representing integer i, where i goes from (n-1) to 0. Note that these variables are not declared until they are forced to be evaluated. See declare in defaults.fl for a function to do so.}\\
\FLfun{vl when e}{Imposes the domain constraint denoted by the Boolean expression e on all the five-tuples in vl.}\\
\FLfun{vl from t}{Set all the starting times in the five-tuples in vl to t.}\\
\FLfun{vl to t}{Set all the ending times in the five-tuples in vl to t.}\\
\FLfun{during f t vl}{Set all the starting and ending times in the five-tuples in vl to f and t respectively.}\\
\FLfun{vl1 then vl2}{Merge the lists together, but adjust the durations for the five-tuples in vl2 so that the ``time 0'' for vl2 is equal to the maximum time of any five-tuple in vl1}\\
\FLfun{vl for t}{Same as 'to' above.}\\
\FLfun{verify fsm l ant cons trl}{An old shorthand for (declare l) seq (STE "" fsm [] ant cons trl. Probably should be removed.}\\
\FLfun{nverify fsm l ant cons trl}{Same as verify but the first argument is the option string to STE. Again, should be viewed as obsolete.} \\
\FLfun{SymbIndex nl addr fn}{Symbolic indexing function. Will apply the function fn to every element $i$ in nl and then apply a when condition to each result that requires addr to be equal to $i$.}
\end{tabbing}

\subsection{arithm.fl}
\index{arithm.fl}

This is a library of bitvector%
\index{bitvector}%
{} functions. A bitvector is represented
as a list of Booleans and is viewed as a big-endian vector%
\index{big-endian vector}%
{}, i.e, the
head of the list is the most significant bit.
\begin{tabbing}
excitation             \=         \kill
\FLfun{num2bv sz n}{Convert the integer n to a bitvector of size sz.}\\
\FLfun{bv2num bv}{If the bitvector bv does not contain any Boolean variables, view it as an unsigned binary number and convert it to a number.}\\
\FLfun{prefix n av}{Return the n first elements of av.}\\
\FLfun{suffix n av}{Return the n last elements of av}\\
\FLfun{av add bv}{Add the two bitvectors together.}\\
\FLfun{increment av}{Add one to the bitvector av.}\\
\FLfun{ones\_complement av}{Return the 1's complement of the bitvector av.}\\
\FLfun{twos\_complement av}{Return the 2's complement of the bitvector av.}\\
\FLfun{av subtract bv}{Subtract bitvector bv from bitvector av.}\\
\FLfun{av greater bv}{Compute the Boolean expression for the number denoted by av is greater than the number denoted by bv. Both bitvectors are viewed as unsigned integers.}\\
\FLfun{av equal bv}{As for greater, but for equality.}\\
\FLfun{av geq bv}{As for greater, but for greater than or equal to.}\\
\FLfun{av less bv}{As for greater, but for less than.}\\
\FLfun{av leq bv}{As for greater, but for less than or equal to.}\\
\FLfun{av bvAND bv}{Bit-wise AND.}\\
\FLfun{av bvOR bv}{Bit-wise OR.}\\
\FLfun{av bvXOR bv}{Bit-wise XOR.}\\
\FLfun{bvNOT av}{Bit-wise NOT.}
\end{tabbing}

\subsection{HighLowEx.fl}
\index{HighLowEx.fl}

This library defines only two funcitons: Hexpl%
\index{Hexpl}%
{} and Lexpl%
\index{Lexpl}%
{}.
The basic task of both is to take a Boolean function and
return an assignments to some set of variables that would make
the Boolean function evaluate to true.
The two functions differ only in that Hexpl tries to find an
assignment with as many $1$'s as possible, whereas Lexpl tries to
assign as many $0$'s as possible.
In order to make the output more readable, both functions take as
first argument a list of pairs.
The first element in the pair is a string and the second argument
is a list of Boolean variables.
The string will be used as a header for the assignemnts to the list of
variables.
For example, is $i$, $Aa$, $Ab$, $a$, $b$, $d$, and $q$ denote lists of
Booelan variables, and $f$ denote some Boolean expression over
these (and possibly other) variables, then we may get:
\begin{hol}
: Lexpl [("I",i),("Aa",Aa),("Ab",Ab),("a",a),("b",b),("d",d),("q",q)] f;
"
I = 001011000
Aa = 0000
Ab = 0001
a = 1111
b = 0000
d = 0000
q = ----

"
\end{hol}
where $0$'s and $1$'s denote assignemnt to the corresponding variables to
make $f$ evaluate to $1$, whereas $-$ denote don't care conditions.


\section{Overview}

FlexibleSUSY provides Mathematica and C++ code to create spectrum
generators for non-minimal supersymmetric models.

\subsection{Design goals}

FlexibleSUSY is designed with the following points in mind:

\paragraph{Speed}
Exploring the parameter space of supersymmetric models with a high
number of free parameters is quite time consuming.  Therefore
FlexibleSUSY aims to produce spectrum generators with a short run-time.

The two most time consuming parts of a spectrum generator are the
calculation of the beta functions and the pole masses for mixed
particles.

The reason is the following: The RG solving algorithms usually need
$O(10)$ iterations to calculate a particle spectrum with $0.1\%$
precision.  During each iteration the Runge--Kutta algorithm needs to
calculate all beta functions $O(50)$ times.  Most two-loop beta
functions involve $O(50)$ matrix multiplications and additions.  All
together one arrives at $O(2.5\cdot 10^4)$ matrix multiplications.  To
optimize these matrix multiplications FlexibleSUSY uses the fast
linear algebra package \href{Eigen}{http://eigen.tuxfamily.org}, which
exploits C++ expression templates to make the matrix multiplications
easy to write and optimize.

The second most time consuming part is the precise calculation of the
pole masses for mixed particles.  For each particle $\psi_i$ the full
self-energy matrix $\Sigma^\psi_{ij}(p=m^\text{tree}_{\psi_i})$ has to
be evaluated.  Each self-energy matrix entry again involves the
evaluation of $O(50)$ Feynman diagrams, which involves the calculation
of vertices and loop functions.  All in all, one arrives at $O(500)$
Feynman diagram or $O(3\cdot 10^4)$ loop function evaluations.  To
speed up the calculation of the pole masses FlexibleSUSY makes use of
multi-threading, where each pole mass is calculated in a separate
thread.  By this technique one can gain a speed-up of $20$--$30\%$.

\paragraph{Modularity}
The large variety of supersymmetric models makes it likely that the
user needs to modify the generated spectrum generator source code.
FlexibleSUSY uses object orientation with C++ to modularize the source
code to make it easy for the user to modify and extend the spectrum
generator.  An important application here are the constraints: The RG
solvers provide a constraint interface,
\figurename~\ref{fig:schematic-two-scale-constraint-interface},
%
\begin{figure}
  \centering
  \tikzumlset{fill class=white}
  \begin{tikzpicture}
    \umlclass[x=0, y=0]{RGFlow$<$Two\_scale$>$}{}{
      + solve()
    }
    \umlclass[x=6, y=0, type=abstract]{Constraint$<$Two\_scale$>$}{}{
      + \umlvirt{apply()}\\
      + \umlvirt{get\_scale() : double}
    }
    \umlclass[x=6, y=-3]{MyConstraint}{}{
      + apply()\\
      + get\_scale() : double
    }
    \umldep{RGFlow$<$Two\_scale$>$}{Constraint$<$Two\_scale$>$}
    \umlinherit{MyConstraint}{Constraint$<$Two\_scale$>$}
  \end{tikzpicture}
  \caption{Schematic two-scale constraint interface}
  \label{fig:schematic-two-scale-constraint-interface}
\end{figure}
%
which can be implemented to create the custom constraint
\code{MyConstraint}.  In the \code{apply()} function the constraint
application takes place and the \code{get_scale()} function specifies
the scale at which the constraint is to be applied.

\subsection{Requirements}

\begin{itemize}
\item Mathematica, version 7 or higher
\item SARAH, version 4.0.4 or higher \url{http://sarah.hepforge.org}
\item C++11 compatible compiler (g++ 4.4.7 or higher, clang++ 3.1 or
  higher)
\item Fortran compiler (gfortran, ifort etc.)
\item Eigen library, version 3.1 \url{http://eigen.tuxfamily.org}
\item Boost library, version 1.36.0 or higher
  \url{http://www.boost.org}
\item GNU scientific library \url{http://www.gnu.org/software/gsl/}
\item lapack (needed for the Lattice algorithm only)
  \url{http://www.netlib.org/lapack/}
\end{itemize}
%
Optional:
%
\begin{itemize}
\item Looptools, version 2.8 or higher
  \url{http://www.feynarts.de/looptools/}
\end{itemize}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage[noend]{algpseudocode}
\usepackage{url}
\usepackage{listings}

\newlength\tindent
\setlength{\tindent}{\parindent}
\setlength{\parindent}{0pt}
\renewcommand{\indent}{\hspace*{\tindent}}

\title{COMP 312 Assignment 7}
\author{Daniel Braithwaite}

\begin{document}
	\pagenumbering{gobble}
	\maketitle
	\newpage
  	\pagenumbering{arabic}

  	\section{Python}
  		\subsection{Program A}
			\subsubsection{Code}
				\lstinputlisting[language=Python]{Programs/01.py}
			\subsubsection{Output}
				Estimate of W: 1.20972369916\\
				Conf int of W: (1.2029828999724295, 1.2164644983404909)\\

Estimate of Balk: 0.214441575607\\
Conf int of Balk: (0.21298878230402357, 0.21589436890972064)\\

Estimate of Reject: 0.008358\\
Conf int of Reject: (0.0079898917534854726, 0.0087261082465145256)\\

  		\subsection{Program B}
  			\subsubsection{Code}
				\lstinputlisting[language=Python]{Programs/02.py}
			\subsubsection{Output}

1 Tug Boats\\
\\
Estimate of W: 1.5617122988\\
Conf int of W: (1.5568093809484571, 1.5666152166434895)\\
\\
Estimate of U: 0.994934336555\\
Conf int of U: (0.99485610117267298, 0.99501257193779857)\\
\\
2 Tug Boats\\
\\
Estimate of W: 1.55240355925
Conf int of W: (1.547537739331946, 1.5572693791732504)\\
\\
Estimate of U: 1.0\\
Conf int of U: (1.0, 1.0)\\
\\
1 Tug Boats\\
\\
Estimate of W: 1.5617122988\\
Conf int of W: (1.5568093809484571, 1.5666152166434895)\\

Estimate of U: 0.994934336555\\
Conf int of U: (0.99485610117267298, 0.99501257193779857)\\
\\
2 Tug Boats\\
\\
Estimate of W: 1.55240355925\\
Conf int of W: (1.547537739331946, 1.5572693791732504)\\
\\
Estimate of U: 1.0\\
Conf int of U: (1.0, 1.0)\\

\end{document}


%! Author = Michelangelo Prisciano
%! Date = 30/11/2021

\documentclass{article}

% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}

% Set page size and margins
% Replace `letterpaper' with`a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}

\title{Monte Carlo Simulation for Influence Models of Information Diffusion in Social Networks}
\author{Michelangelo Prisciano}

\begin{document}
\maketitle

\section{Introduction}

This project aims to follow up from the paper "Markov Chain Model Representation of Information Diffusion in Social Networks"
(\cite{monte_carlo_sim}) by exploring how information flows in a social network specifically with a threshold model.
This is based on the idea that an agent is most likely to adopt an idea when the number of its connection crosses a fixed threshold value.

\subsection{Keys and Objectives}
The goal of this project is to model the flow of information in a network through Markov Chains and a Monte Carlo simulation. The model adopted
initially is a combination of a threshold and probabilistic model, while other will be investigated at a later stage.

\section{Algorithm}
Starting with n infected seed nodes, we will follow how the infection progress through a combination of threshold and probabilistic
model. Every node that has a number of infected connections that crosses a set threshold will be infected with a probability p.
Suppose n is the total number of neighbour nodes of a particular node, k is the number of neighbour infected nodes. Then,
\[
    p = \frac{n-k}{n}
\]

In this scenario it is crucial to be able to access the number of infected connections of every node in a short amount of time,
preferably constant. An interesting way of keeping track of the number of infected connections of every node is through an array
of length n where n is the number of nodes in the graph. Initially the array is initialised in a way that every node has 0 infected
connections. As seed nodes are chosen and more nodes get infected, the array is updated in a "cascade" way. \newpage

For the sake of simplicity a pure threshold model is considered in this example. The complete graph \emph{g} has 6 nodes,
labelled from 0 to 5. Node 0 is chosen to be a seed infected node and the threshold \emph{t} is set to 1. \\ \\

\emph{Starting point}
\begin{tikzpicture}[main/.style = {draw, circle}]
\node[main] (0) [fill=red]{$0$};
\node[main] (1) [above right of=0] {$1$};
\node[main] (2) [below right of=0] {$2$};
\node[main] (3) [above right of=2] {$3$};
\node[main] (4) [above right of=3] {$4$};
\node[main] (5) [below right of=3] {$5$};
\draw (0) -- (1);
\draw (0) -- (3);
\draw (3) -- (2);
\draw (3) -- (4);
\draw (3) -- (5);
\end{tikzpicture} \\

\begin{gather*}
[0\qquad1\qquad0\qquad1\qquad0\qquad0]\\
0\qquad1\qquad2\qquad3\qquad4\qquad5\\
\end{gather*}
Nodes 1 and 3 both have 1 infected connection, therefore \underline{the next nodes to be infected will be 1 and 3.} \\

\emph{Loop N1}
\begin{tikzpicture}[main/.style = {draw, circle}]
\node[main] (0) [fill=red]{$0$};
\node[main] (1) [above right of=0, fill=red] {$1$};
\node[main] (2) [below right of=0] {$2$};
\node[main] (3) [above right of=2, fill=red] {$3$};
\node[main] (4) [above right of=3] {$4$};
\node[main] (5) [below right of=3] {$5$};
\draw (0) -- (1);
\draw (0) -- (3);
\draw (3) -- (2);
\draw (3) -- (4);
\draw (3) -- (5);
\end{tikzpicture} \\

\begin{gather*}
    [2\qquad1\qquad1\qquad1\qquad1\qquad1]\\
    0\qquad1\qquad2\qquad3\qquad4\qquad5\\
\end{gather*}

Therefore, \underline{the next nodes to be infected will be 2, 4 and 5.} \\

\emph{Loop N2}
\begin{tikzpicture}[main/.style = {draw, circle}]
\node[main] (0) [fill=red]{$0$};
\node[main] (1) [above right of=0, fill=red] {$1$};
\node[main] (2) [below right of=0, fill=red] {$2$};
\node[main] (3) [above right of=2, fill=red] {$3$};
\node[main] (4) [above right of=3, fill=red] {$4$};
\node[main] (5) [below right of=3, fill=red] {$5$};
\draw (0) -- (1);
\draw (0) -- (3);
\draw (3) -- (2);
\draw (3) -- (4);
\draw (3) -- (5);
\end{tikzpicture} \\
\begin{gather*}
    [2\qquad1\qquad1\qquad4\qquad1\qquad1]\\
    0\qquad1\qquad2\qquad3\qquad4\qquad5\\
\end{gather*}

There are two more possible approaches to model the infection, merely a pure threshold and a pure probabilistic model. The former is
not that interesting due to the deterministic nature of the approach which is not versatile enough to model real world situations,
despite being a good starting point. The latter, on the other hand, is an approach which will be investigated at a later stage. The difference
is that there would be no threshold of infected connections to cross, every neighbour of an infected node will be infected with the probability
p mentioned earlier.
\section{Observations}

\bibliographystyle{alpha}
\bibliography{sample}

\end{document}


\hypertarget{graphics}{%
\section{Graphics}\label{graphics}}

The \texttt{graphics} module provides a number of classes to provide
simple visualization capabilities. To use it, you first need to import
the module:

\begin{lstlisting}
import graphics
\end{lstlisting}

The \texttt{Graphics} class acts as an abstract container for graphical
information; to actually launch the display see the \texttt{Show} class.
You can create an empty scene like this,

\begin{lstlisting}
var g = Graphics()
\end{lstlisting}

Additional elements can be added using the \texttt{display} method.

\begin{lstlisting}
g.display(element)
\end{lstlisting}

Morpho provides the following fundamental Graphical element classes:

\begin{lstlisting}
TriangleComplex
\end{lstlisting}

You can also use functions like \texttt{Arrow}, \texttt{Tube} and
\texttt{Cylinder} to create these elements conveniently.

To combine graphics objects, use the add operator:

\begin{lstlisting}
var g1 = Graphics(), g2 = Graphics()
// ...
Show(g1+g2)
\end{lstlisting}

\hypertarget{show}{%
\section{Show}\label{show}}

\texttt{Show} is used to launch an interactive graphical display using
the external \texttt{morphoview} application. \texttt{Show} takes a
\texttt{Graphics} object as an argument:

\begin{lstlisting}
var g = Graphics()
Show(g)
\end{lstlisting}

\hypertarget{trianglecomplex}{%
\section{TriangleComplex}\label{trianglecomplex}}

A \texttt{TriangleComplex} is a graphical element that can be used as
part of a graphical display. It consists of a list of vertices and a
connectivity matrix that selects which vertices are used in each
triangle.

To create one, call the constructor with the following arguments:

\begin{lstlisting}
TriangleComplex(position, normals, colors, connectivity)
\end{lstlisting}

\begin{itemize}

\item
  \texttt{position} is a \texttt{Matrix} containing vertex positions as
  \emph{columns}.
\item
  \texttt{normals} is a \texttt{Matrix} with a normal for each vertex.
\item
  \texttt{colors} is the color of the object.
\item
  \texttt{connectivity} is a \texttt{Sparse} matrix where each column
  represents a triangle and rows correspond to vertices.
\end{itemize}

Add to a \texttt{Graphics} object using the \texttt{display} method.

\hypertarget{arrow}{%
\section{Arrow}\label{arrow}}

The \texttt{Arrow} function creates an arrow. It takes two arguments:

\begin{lstlisting}
arrow(start, end)
\end{lstlisting}

\begin{itemize}

\item
  \texttt{start} and \texttt{end} are the two vertices. The arrow points
  \texttt{start} -\textgreater{} \texttt{end}.
\end{itemize}

You can also provide optional arguments:

\begin{itemize}

\item
  \texttt{aspectratio} controls the width of the arrow relative to its
  length
\item
  \texttt{n} is an integer that controls the quality of the display.
  Higher \texttt{n} leads to a rounder arrow.
\item
  \texttt{color} is the color of the arrow. This can be a list of RGB
  values or a \texttt{Color} object
\end{itemize}

Display an arrow:

\begin{lstlisting}
var g = Graphics([])
g.display(Arrow([-1/2,-1/2,-1/2], [1/2,1/2,1/2], aspectratio=0.05, n=10))
Show(g)
\end{lstlisting}

\hypertarget{cylinder}{%
\section{Cylinder}\label{cylinder}}

The \texttt{Cylinder} function creates a cylinder. It takes two required
arguments:

\begin{lstlisting}
cylinder(start, end)
\end{lstlisting}

\begin{itemize}

\item
  \texttt{start} and \texttt{end} are the two vertices.
\end{itemize}

You can also provide optional arguments:

\begin{itemize}

\item
  \texttt{aspectratio} controls the width of the cylinder relative to
  its length.
\item
  \texttt{n} is an integer that controls the quality of the display.
  Higher \texttt{n} leads to a rounder cylinder.
\item
  \texttt{color} is the color of the cylinder. This can be a list of RGB
  values or a \texttt{Color} object.
\end{itemize}

Display an cylinder:

\begin{lstlisting}
var g = Graphics()
g.display(Cylinder([-1/2,-1/2,-1/2], [1/2,1/2,1/2], aspectratio=0.1, n=10))
Show(g)
\end{lstlisting}

\hypertarget{tube}{%
\section{Tube}\label{tube}}

The \texttt{Tube} function connects a sequence of points to form a tube.

\begin{lstlisting}
Tube(points, radius)
\end{lstlisting}

\begin{itemize}

\item
  \texttt{points} is a list of points; this can be a list of lists or a
  \texttt{Matrix} with the positions as columns.
\item
  \texttt{radius} is the radius of the tube.
\end{itemize}

You can also provide optional arguments:

\begin{itemize}

\item
  \texttt{n} is an integer that controls the quality of the display.
  Higher \texttt{n} leads to a rounder tube.
\item
  \texttt{color} is the color of the tube. This can be a list of RGB
  values or a \texttt{Color} object.
\item
  \texttt{closed} is a \texttt{bool} that indicates whether the tube
  should be closed to form a loop.
\end{itemize}

Draw a square:

\begin{lstlisting}
var a = Tube([[-1/2,-1/2,0],[1/2,-1/2,0],[1/2,1/2,0],[-1/2,1/2,0]], 0.1, closed=true)
var g = Graphics()
g.display(a)
\end{lstlisting}

\hypertarget{sphere}{%
\section{Sphere}\label{sphere}}

The \texttt{Sphere} function creates a sphere.

\begin{lstlisting}
Sphere(center, radius)
\end{lstlisting}

\begin{itemize}

\item
  \texttt{center} is the position of the center of the sphere; this can
  be a list or column \texttt{Matrix}.
\item
  \texttt{radius} is the radius of the sphere
\end{itemize}

You can also provide an optional argument:

\begin{itemize}

\item
  \texttt{color} is the color of the sphere. This can be a list of RGB
  values or a \texttt{Color} object.
\end{itemize}

Draw some randomly sized spheres:

\begin{lstlisting}
var g = Graphics()
for (i in 0...10) {
  g.display(Sphere([random()-1/2, random()-1/2, random()-1/2], 0.1*(1+random()),       color=Gray(random())))
}
Show(g)
\end{lstlisting}


\setupbodyfont[xits]

\starttext

\section{Introduction}

XITS is Times-like font for scientific publishing with support for mathematical
typesetting. It has wide coverage of Latin, Greek and Cyrillic scripts, as
well as extensive coverage of Unicode symbols used in mathematics and other
fields of science. XITS supports also proper mathematical typesetting and can
be used to typeset complex mathematical equations in modern \TEX\ engines,
namely \LUATEX\ and \XETEX, as well as Microsoft Office starting from 2007
version.

XITS is available as an OpenType font, in four styles; regular, bold, italic
and bold italics, besides the maths font.

\section{Font features}

XITS supports the following OpenType features:

\starttable[|lT|l|]
\HL
\NC feature\NC Description \NC\SR
\HL
\NC \Use{2}[I]{All fonts} \MR
\NC kern \NC Kerning \NC\FR
\NC liga \NC Ligatures \NC\MR
\NC onum \NC Oldstyle numbers \NC\MR
\NC frac \NC Diagonal fractions \NC\MR
\NC \Use{2}[I]{The maths font, spports additional features} \MR
\NC ss01 \NC Mathematical Calligraphic Alphabet \NC\MR
\NC ss02 \NC Mathematical Greek Sans Serif Alphabet \NC\MR
\NC ss03 \NC Mathematical Italic Sans Serif Digits \NC\MR
\NC ss04 \NC Mathematical Bold Monospace Digits \NC\MR
\NC ss05 \NC Mathematical Bold Double-Struck Alphabet \NC\MR
\NC ss06 \NC Mathematical Italic Double-Struck Alphabet \NC\MR
\NC ss07 \NC Mathematical Bold Italic Double-Struck Alphabet \NC\MR
\NC ss08 \NC Upright Integrals \NC\LR
\NC ss09 \NC Negated Symbols With Vertical Stroke \NC\MR
\HL
\stoptable

\section{Installation}

\subsection{\CONTEXT}
\CONTEXT\ MkIV are needed for using the math font, text fonts can be used with
either MkIV or MkII with \XETEX\ engine, MkII with \PDFTEX\ is not supported.

Recent versions of \CONTEXT\ already have typescripts for XITS, so just
installing the fonts into TEXMF tree is enough.

\subsection{\LATEX}
A modern \TEX\ engine with Unicode and OpenType support is needed, namely
\LUATEX\ or \XETEX. In addition to {\ss fontspec} package, {\ss unicode-math}
is needed for using XITS fonts in math mode.

If you are using \LUATEX\ then you can either install the fonts OS wide or in
TEXMF tree. If you are using \XeTeX\ then you need to either install fonts OS
wide, or adapt your {\ss fontconfig} configuration to look for for fonts
installed under TEXMF tree, otherwise you will not be able to access fonts by
font name.

\subsection{MS Office}
MS Office 2007 or newer is required, the fonts can be installed the regular
way.

\section{Usage}

\subsection{\LATEX}

\subsubsection{Examples}
\startTEX
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}

\begin{document}
Text $x+y=\sqrt{z}$
\end{document}
\stopTEX

\subsection{\CONTEXT}

\subsubsection{Examples}

\startTEX
\setupbodyfont[xits]

\starttext
Text $x+y=\sqrt{z}$
\stoptext
\stopTEX

\stoptext