% ==============================================================================
%
%                           V E R I F I C A T I O N
%
% ==============================================================================
% ==============================================================================
%
%                               O V E R V I E W
%
% ==============================================================================
\chapter{Verification} % <<< ------------------------------------------------- %
\label{ch:verification}
% ---------------------------------------------------------------------------- %

Designing filters  in Matlab  and running  FPGA simulations  in Vivado  is all
nice  and well,  but  in the  end,  what  counts is  how  the system  performs
in  practice. This chapter  outlines  which sorts  of  measurements have  been
performed, the rationale behind them, and summarizes the results.

All  the metrics  presented in  this  chapter are  based  on the  same set  of
measurements, unless  otherwise mentioned. For  each filter  chain, \num{2000}
measurements have  been made, each  with a size  of \num{8192} samples  in the
time domain at one frequency. Between each of the \num{2000} runs for a single
chain, the signal frequency increases equidistantly from \num{0} to five times
the  filter's  outgoing  sampling frequency. Covering  \num{2000}  frequencies
allows to  cover the  passband ripple  and the  transition band  in sufficient
resolution to detect possible issues.

For the  filter chains  with $R=5$  decimators at their  ends (the  chains for
decimation factors by \num{5}, \num{25},  \num{125} and \num{625}), this means
that the output filter's passband is first traversed, and then its stopband up
until half its incoming sampling rate. This enables us to measure the passband
and  stopband magnitude  response. Furthermore, by  performing an  FFT of  the
filter chain's output at specific frequencies,  we can verify how strongly the
stopband aliases back into the passband. This is the problem illustrated in
Figures~\ref{fig:aliasing:iirCopies},
\ref{fig:cic:freq_responses:passband:aliasing},
and~\ref{fig:stl125:moving_averager}.

For the filter chains with half-band filters as their final stages (\num{1250}
and \num{2500}),  this frequency range is  actually too large, since  we would
only need to measure up to twice  the outgoing sampling rate in order to cover
the final filter's  magnitude response range.  However, there is  no real harm
in going higher (a bit of resolution is lost), and it simplifies the measuring
process, so no particular distinction is made here.

Note that it is generally not necessary to measure at even higher frequencies.
As can be seen in Section~\ref{sec:multi_stage_filter_designs} and some of the
frequency responses  for the filter  cascades which  are being used  (e.g. the
chain for  $R=25$, see page~\pageref{sec:filter_frequency_responses:chain25}),
it  is   the  final  filter  in   a  cascade  which  determines   the  chain's
overall   behavior   in  the   relevant   frequency   regions  (assuming   the
individual   filters  in   the   chains  have   been   sensibly  designed   to
match   each  other's   characteristics,   also  explained   in  the   section
\emph{\nameref{sec:multi_stage_filter_designs}}).    Increasing    the   input
frequency  further simply  moves into  regions  which are  ever more  strongly
attenuated,  so unless  serious issues  are encountered,  the higher  spectral
ranges are not of interest  in verifying the filter chain's functionality. The
measurements for the  \num{1250} and \num{2500} chains, which  do indeed cover
more than the necessary frequency range, confirm this.

All   measurements   are   adjusted   to   have   the   right   scaling   with
Equation~\ref{eqn:verification:transform}  where $x_\mathrm{unsigned}$  is the
measured sample.
\begin{align}
    \label{eqn:verification:transform}
    x_{i,\mathrm{signed}} &= \left(x_{i,\mathrm{unsigned}} - 2^{15}\right) \cdot 2^{-15} \\
    x_{i,\mathrm{V}}      &= x_{i,\mathrm{signed}} \cdot \SI{1.1}{\V}
\end{align}

% >>>
% ==============================================================================
%
%                R M S   F R E Q U E N C Y   R E S P O N S E
%
% ==============================================================================
\section{RMS Frequency Response} % <<< --------------------------------------- %
\label{sec:verification:rms}
% ---------------------------------------------------------------------------- %

To verify  that the  filters perform as  expected, the RMS  of all  samples is
calculated and  plotted against their  respective input frequency, as  seen in
Figure~\ref{fig:verification:rmsAll}.  The RMS looks  good and the passband is
practically flat. Two things stand out as not too positive:
\begin{itemize}\tightlist
    \item
        The passband frequency  response has a slight slope  upwards. It is at
        no  point  higher  than  \SI{20}{\mV},  effectively  having  an  error
        below  \SI{2}{\percent}  in  all  of  the  filter  chains  except  the
        $R=5$  chain.
        This is  mostly in  line with  the case in  the filter  performance as
        predicted  by  Matlab; a  ripple  in  the cascade's  passband  between
        \SI{0.67}{\percent} and \SI{2.8}{\percent} is predicted.
        What is  peculiar is that  the overall  shape of the  passband doesn't
        quite  align  with  Matlab's  designs. No  behavior  occurs  which  we
        consider to be deal-breaking though.
    \item
        The passband of $R=5$ chain looks deformed, on the other hand, and not
        at all what  is expected. Something has gone  horribly wrong here. The
        previous statements do not apply for this case.
\end{itemize}
On the other hand, these results are as expected:
\begin{itemize}
    \item
        The  Passband has  a  slight ripple  of  $\pm\SI{1}{\percent}$ in  all
        filter chains.  This is well within the filter design specification in
        theory.  Matlab predicts a  ripple in the cascade's passband between
        \SI{0.67}{\percent} and \SI{2.8}{\percent}, depending on the chain.
    \item
        The  passband   shows  a   gain  loss. If  the   optimum  case   of  a
        \SI{2}{\bit}  win   were  achieved,   all  of  the   amplitudes  would
        be   at  $\frac{1}{\sqrt{2}}   =  \SI{0.707}{\V}$   (since  input   is
        \SI{2}{V_{\mathrm{PP}}}).    Since   not   all   filter   chains   win
        the   same   amount  of   bits,   this   sadly   is  not   the   case.
        Table~\ref{tab:verification:results} lists  the actual number  of bits
        won, along with  correction factors which need to be  applied to scale
        the output correctly.
\end{itemize}
Overall,  these  results  are  mostly acceptable  in  our  view,  particularly
considering that  this system is  in essence a  first prototype which  has not
gone through any performance tuning  yet. However, there is certainly room for
further investigation and improvement.

\begin{figure}
    \centering
    \input{images/verification/rmsAll.tikz}
    \caption[RMS at Filter Chain Output]{%
        RMS  at   the  output   of  each   filter  chain   over  a   range  of
        frequencies. Input is a sine wave with $\SI{2}{V_{\mathrm{PP}}}$.%
    }
    \label{fig:verification:rmsAll}
\end{figure}

% >>>
% ==============================================================================
%
%                M E A N   F R E Q U E N C Y   R E S P O N S E
%
% ==============================================================================
\section{Mean Frequency Response} % <<< -------------------------------------- %
\label{sec:verification:mean}
% ---------------------------------------------------------------------------- %

Because it  became apparent during tests  that the device has  an offset (even
without filters!), the  mean of each sample has been  calculated too such that
at later stages  the offset can be calibrated out  in the scoping application.
The results are shown in Figure~\ref{fig:verification:meanAll}.

\begin{figure}
    \centering
    \input{images/verification/meanAll.tikz}
    \caption[Mean at Filter Outputs]{%
        The  mean  at  the  output  of  each filter  stage  over  a  range  of
        frequencies.  Since the  input signal is a sine wave  and the function
        generator which provides it has  been verified to have no (meaningful)
        offset, these lines should be located at zero volts.%
    }
    \label{fig:verification:meanAll}
\end{figure}
%>>>
% ==============================================================================
%
%                S N R   F R E Q U E N C Y   R E S P O N S E
%
% ==============================================================================
\clearpage
\section{SNR Frequency Response}% <<< ---------------------------------------- %
\label{sec:verification:snr}
% ---------------------------------------------------------------------------- %

Two  series  of  measurements  are  used  for  SNR: An  automated  one  by  us
which  is  evaluated  with  Matlab's SNR  algorithms. Its  results  are  shown
in  Figure~\ref{fig:verification:snrAll}. SNR for  a signal  is determined  by
separating signal and  noise components, calculating the  respective power and
the ratio of signal power to noise power components\footnote{%
    This is similar to what our scope does.%
}.
This series of measurements  allows us to get a good idea of  the shape of the
system's overall frequency response for the SNR.

However, Matlab's SNR algorithms are  not perfect; the automated separation of
signal from  noise components  is prone  to errors. Consequently,  the results
achieved by  this method are  below the system's true  capabilities. To assess
actual  system performance,  SNR  measurements referenced  against a  measured
noise floor have also been performed  by Mr. Gut. For this, the noise floor is
measured by terminating  the device with a \SI{50}{\ohm}  resistor, instead of
extracting it from  a signal. Afterwards, a signal is put  through the system,
the  power  in  the  signal  is  measured,  and  its  power  compared  to  the
measured noise floor. This  method is more precise than  the automated method,
and  also  happens to  give  better  results. Its findings are  summarized  in
Table~\ref{tab:verification:fifty_ohms}.

When comparing our new system against  the measurements of the STEMlab's stock
configuration by our predecessors\footnote{%
    Those  measurements  are also  referenced  against  a \SI{50}{\ohm}  noise
    floor.%
}, our system achieves an SNR of \SI{84}{\dB} for an input frequency of \SI{3}{\kHz}
at a sampling rate of \SI{50}{\kHz}! The stock configuration needs to downsample
by a factor of \num{65536} (corresponding to a sampling frequency of \SI{1.9}{\kHz}
in order to achieve an SNR of \SI{83.5}{\dB}\footnote{%
    The higher the downsampling ratio, the  better the achievable SNR tends to
    be.%
}.

\begin{figure}
    \centering
    \input{images/verification/snrAll.tikz}
    \caption[SNR at Filter Outputs]{%
        The  SNR  at  the  output  of  each  filter  stage  over  a  range  of
        frequencies.   Note the  downward  spikes in  the passband. These  are
        caused by  Matlab's algorithms during  post-processing and are  not an
        actual system issue.%
    }
    \label{fig:verification:snrAll}
\end{figure}

\begin{table}
    \centering
    \caption[SNR Referenced Against \SI{50}{\ohm}]{%
        SNR  measurements  referenced  against   a  true  \SI{50}{\ohm}  noise
        floor,  measured  by  Mr. Gut. The results  constitute  a  significant
        improvement   over   the   stock  system's   SNR   capabilities   (see
        Table~\ref{tab:stl125:measurements_bucher_kuery}). Only the  chain for
        $f_\mathrm{s}  = \SI{25}{\MHz}$  lies  outside  the expected  pattern;
        this  has already  been seen  in its  magnitude frequency  response in
        Section~\ref{sec:verification:rms}.%
    }
    \label{tab:verification:fifty_ohms}
    \begin{tabular}{SSSSSS}
        \toprule
        {\parbox[t]{10mm}{\raggedleft $f_\mathrm{s}$                       \\(\si{\kHz})}          } &
        {\parbox[t]{10mm}{\raggedleft $f_\mathrm{signal}$                  \\(\si{\kHz})}          } &
        {\parbox[t]{10mm}{\raggedleft $V_\mathrm{sine,RMS}$                \\(\si{\milli\volt})}   } &
        {\parbox[t]{15mm}{\raggedleft $V_\mathrm{noise,RMS}$               \\(\si{\milli\volt})}   } &
        {\parbox[t]{15mm}{\raggedleft $\mathrm{SNR}_\mathrm{\SI{50}{\ohm}}$\\(\si{\dB})}           } &
        {\parbox[t]{10mm}{\raggedleft $\mathrm{SNR}_\mathrm{autom.}$       \\(\si{\dB})}           } \\
        \midrule
           50 &    1 & 707 & 40e-6  & 84   & 71 \\
          100 &   25 & 707 & 55e-6  & 82   & 71 \\
          200 &   50 & 708 & 59e-6  & 81.5 & 69 \\
         1000 &  250 & 708 & 75e-6  & 79.5 & 69 \\
         5000 & 1250 & 707 & 130e-3 & 79.5 & 69 \\
        25000 & 6250 & 707 & 260e-6 & 62   & 69 \\
        \bottomrule
    \end{tabular}
\end{table}

% >>>
% ==============================================================================
%
%                   S T O P B A N D   A T T E N U A T I O N
%
% ==============================================================================
\section{Stopband Attenuation} % <<< ----------------------------------------- %
\label{sec:verification:snr}
% ---------------------------------------------------------------------------- %

Measuring stopband attenuation  is relevant in order to verify  whether or not
the aliasing effect  of the stopband into the passband  during downsampling is
attenuated to the specified degree of \SI{60}{\dB}. See
Figures~\ref{fig:aliasing:iirCopies},
\ref{fig:cic:freq_responses:passband:aliasing}
and~\ref{fig:stl125:moving_averager} for illustrations of the phenomenon.

For this purpose,  the power density spectrum is plotted
properly scaled and adjusted  as seen in Equation~\ref{eqn:verification:power}
through~\ref{eqn:verification:power_density}:
\begin{align}
    x_{i,\mathrm{corrected}} &= x_{i,\mathrm{V}} \cdot \sqrt{\frac{1}{2f_s N}} \label{eqn:verification:power} \\
    X                        &= FFT\left(x_{i,\mathrm{corrected}}\right)       \\
    X_{i,\mathrm{one}}       &= X_i \cdot 2, i < \frac{N}{2}+1                 \\
    X_{i,\mathrm{abs}}       &= |X_{i,\mathrm{one}}|                           \\
    S_{\si{\dB}}             &= 10\log_{10}(X_{i,\mathrm{abs}}^2)              \label{eqn:verification:power_density}
\end{align}

Figures~\ref{fig:verification:fB5}    through    \ref{fig:verification:fB2500}
depict  the results. Each  plot contains  one frequency  which falls  into the
passband, one which falls into the filter's edge, and one which falls into the
stopband.   The passband  and edge  frequency  components are  expected to  be
relatively high (depending on where exactly  in the edge the measurement point
falls). The measurement point in the stopband should be \SI{60}{\dB} below the
passband measurement  point. Most satisfactorily,  this is  the case,  and the
measurement results line up very nicely with the specifications.

\begin{figure}
    \centering
    \input{images/verification/foldingBack5.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=5$]{%
        Attenuation in passband, edge and stopband for $R=5$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB5}
\end{figure}

\begin{figure}
    \centering
    \input{images/verification/foldingBack25.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=25$]{%
        Attenuation in passband, edge and stopband for $R=25$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB25}
\end{figure}

\begin{figure}
    \centering
    \input{images/verification/foldingBack125.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=125$]{%
        Attenuation in passband, edge and stopband for $R=125$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB125}
\end{figure}

\begin{figure}
    \centering
    \input{images/verification/foldingBack625.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=625$]{%
        Attenuation in passband, edge and stopband for $R=625$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB625}
\end{figure}

\begin{figure}
    \centering
    \input{images/verification/foldingBack1250.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=1250$]{%
        Attenuation in passband, edge and stopband for $R=1250$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB1250}
\end{figure}

\begin{figure}
    \centering
    \input{images/verification/foldingBack2500.tikz}
    \caption[Attenuation in Passband, Edge and Stopband for $R=2500$]{%
        Attenuation   in   passband,   edge   and   stopband   for   $R=2500$.
        $f_\mathrm{s}$ is the sampling rate at the chain's output.%
    }
    \label{fig:verification:fB2500}
\end{figure}

% >>>
% ==============================================================================
%
%                                S U M M A R Y
%
% ==============================================================================
\clearpage
\section{Summary} % <<< ------------------------------------------------------ %
\label{sec:verification:summary}
% ---------------------------------------------------------------------------- %

In  conclusion, the  filter  chains  perform their  task  mostly according  to
specifications. The main point  of concern is the stark passband  droop in the
chain for $R=5$ chain. More investigating is  needed to determine the cause of
this behavior. But overall, we consider it to be a success.

Table~\ref{tab:verification:results}  lists  the  resulting  mean  values  for
comparison  against each  other. \emph{SNR  won} is  the theoretical  SNR gain
caused by the bits which are gained  along the processing chain. It is not the
actually achieved  improvement in SNR  as other factors  play a role  as well.
\emph{Correction} is the correction factor which  needs to be applied in order
to achieve the proper gain (\SI{0.707}{\volt} RMS for a \SI{2}{\V_\mathrm{PP}}
signal, see Section~\ref{sec:verification:rms}).

\vfill
\begin{table}[h]
    \centering
    \caption[Mean Metrics for All Filter Chains]{Mean metrics for all filter chains}
    \label{tab:verification:results}
    \begin{tabular}{rrrrrrr}
        \toprule
        {\scshape $R$                 }&
        {\scshape $V_\mathrm{RMS}$ (\si{V})  }&
        {\scshape $V_\mathrm{Mean}$ (\si{V}) }&
        {\scshape $S_\mathrm{SNR}$ (\si{dB}) }&  % TODO: unit correct?
        {\parbox[t]{16mm}{\raggedleft\scshape Corr.\\(\si{1})}}&
        {\parbox[t]{16mm}{\raggedleft\scshape Bits\\won (\si{1})}}&
        {\parbox[t]{16mm}{\raggedleft\scshape SNR\\won (\si{dB})}}\\
        \midrule
        5           & 0.6203   & -0.1800   & 79.0054   & 1.1398   & 1.8113   & 10.9038\\
        25          & 0.6329   & -0.1690   & 76.9049   & 1.1171   & 1.8403   & 11.0784\\
        125         & 0.5643   & -0.0159   & 73.6582   & 1.2529   & 1.6748   & 10.0820\\
        625         & 0.5529   & -0.0155   & 71.8813   & 1.2787   & 1.6453   & 9.9048\\
        1250        & 0.4576   & -0.0130   & 69.7006   & 1.5450   & 1.3724   & 8.2617\\
        2500        & 0.4092   & -0.0127   & 63.5121   & 1.7278   & 1.2111   & 7.2908\\
        \bottomrule
    \end{tabular}
\end{table}
\vfill

% >>>

%^^A vim: foldenable foldcolumn=4 foldmethod=marker foldmarker=<<<,>>>


Motion planning is needed for tensegrity robots to perform complex
tasks, such as goal-directed locomotion over uneven terrains.  Early
methods defined the desired trajectory for the structure's center of
mass \cite{Pinaud2003Path-Planning-f} or for some of its nodes
\cite{Wijdeven:2005dz} in the workspace.  Then, they divided the
trajectory into small segments, and for each of them, a stable
structure configuration was found using optimization.  But collisions
were not considered, which motivated approaches for (self-)collision
avoidance \cite{Xu2013Collision-free-, hernandez2009reconfigurable},
while keeping the structure stable. Recent path planning approaches
take collisions into account, but the control process is assumed slow
enough to eliminate any dynamic effects \cite{Xu2013Collision-free-,
Porta:2015aa}. This quasistatic assumption is often used in
tensegrity-based civil structures \cite{Rhode-Barbarigos:2012fv} but
is not easily justifiable in robotic applications.

\subsection{Efficient Kinodynamic Planning for Tensegrity Robots}

A tensegrity planner should be able to select a reconfiguration that
takes advantage of nonlinear dynamics to emulate behaviors, such as
running, jumping, and climbing, instead of limiting the structure to
slow reconfigurations. At the same time it should deal with the
high-dimensionality of a tensegrity robot's state space. Various
alternatives can be considered, as long as they can deal with
significant dynamics and complex contacts.

Trajectory planning can be formulated as a non-convex constraint
optimization, where a trajectory cost function must be minimized given
constraints arising from collision avoidance and actuator limits.  One
way to solve this problem is sequential convex optimization, where a
convex approximation around a trajectory is computed in an iterative
manner \cite{Schulman:2014aa}. This framework has shown promise in
dynamical systems \cite{Schulman:2014aa} and recently in soft
manipulators \cite{Marchese:2016aa}. At the same time, it does not
provide performance guarantees, as it may get stuck in local minima
where constraints are violated. Approaches, such as {\tt
CHOMP} \cite{Zucker:2013aa}, introduce a Monte Carlo process to
achieve probabilistic completeness. Nevertheless, there are many
implementation aspects that need to be addressed for such methods: a)
simplifications, such as approximating the robot geometry with spheres
may not be appropriate for tensegrities, b) and it may not be easy to
define certain primitives, such as Jacobians, or formulating complex
constraints.

An alternative that provides probabilistic completeness is founded on
sampling-based motion planning~\cite{Kavraki1996Probabilistic-R},
which finds valid robot configurations and connects them with locally
valid paths. Tree-based variants, such as {\tt
RRT}~\cite{LaValle2001}, can deal with significant dynamics as they
only need a forward propagation model, such as a physics engine, to
simulate the progression of a system's state.  Recently the conditions
under which these methods achieve asymptotic optimality have been
identified for kinematic systems
\cite{Karaman:2011aa}. Two recent developments also bring the hope
that sampling-based methods can provide global trajectories for
tensegrity robots in a computationally efficient manner, while
considering complex physical interactions:
\begin{myitem}
  \item[a)] efficient physics-based simulation for tensegrity robots,
    which are verified in hardware, are now available
    \cite{Caluwaerts2013rsif};
  \item[b)] asymptotically optimal and computationally efficient
    sampling-based planners have been developed for highly nonlinear,
    underactuated dynamics \cite{Li2015Sparse-Methods-}.
\end{myitem}

Fig.~\ref{fig:tens_example} illustrates a trajectory computed by such
a method \cite{Li2015Sparse-Methods-} for a simulated SUPERball
robot~\cite{SunSpiralSoftware}. The method provides anytime
properties, i.e., it returns trajectories of increasing quality as
computation time increases. The implementation behind
Fig.~\ref{fig:tens_example} randomly samples controls for the robot
and then optimizes over the resulting trajectories.

While promising, the above implementation is not taking advantage of
morphological computation as the planner reasons about the underlying
robot at its full complexity. One way to improve performance is the
integration of such high-level dynamical planners with lower-level
controllers, such as {\tt CPGs} \cite{Ijspeert2008,
Bliss2013Central-Pattern,MirletzSoftRobotics}. The latter take
advantage of morphological computation and provide identifiable motion
behaviors adaptable to different terrains. In such an integration, the
high-level planner can explore the space by sampling from a library of
maneuvers/behaviors by invoking different low-level controllers. This
can potentially provide a general framework for goal-directed
multi-modal locomotion of tensegrity structures that takes advantage
of morphological computation \cite{Nurzaman:2015aa,
Khazanov:2014aa}. It is useful to consider whether probabilistic
completeness and asymptotic optimality can still be provided for the
integrated framework.

\subsection{Re-Planning in Belief Space with Complex Dynamics}

Despite the progress in tensegrity modeling and even if dynamics are
reasonably taken into account, modeling errors and noise will result
in inaccurate execution of trajectories. One way to deal with this
issue is to represent uncertainty about the robot state as a
probability distribution, and plan in the set of distributions over
states, called the belief space. In this context, the planner aims to
compute the trajectory that maximizes the probability of success in
reaching a desired target. This challenge corresponds to a Partially
Observable Markov Decision Process ({\tt POMDP})
\cite{Kaebling:1998aa}. Planning in the belief space is challenging:
\begin{myitem}
\item[a)] A policy needs to be computed, where an action must be mapped
  to every possible belief distribution, which is a large, continuous
  space.
\item[b)] The resulting belief state dynamics are highly nonlinear
  and underactuated.
\end{myitem}
Nevertheless, recent advances have shown that motion planning in
belief space is becoming practical for many medium size problems by
employing reasonable approximations and efficient algorithmic tools
\cite{Platt:2010aa,Bai:2012aa}, bringing the
hope of potentially addressing more complex problems.

\begin{figure}[h!]
  \vspace{-.1in}
  \centering
\includegraphics[width=.48\textwidth]{figures/belief_replanning.png}
\vspace{-0.3in}
\caption{Replanning in belief space, where the first action of a plan
  is executed and the planner is called again given an updated
  belief. This allows the use of conformant planning, which operates
  in the belief space but does not compute a policy. Instead it
  returns the most robust trajectory.}\vspace{-0.1in}
\label{fig:belief_replanning}
\end{figure}

For instance, one way to reduce the complexity of the first challenge
above is to follow a replanning approach in belief space
\cite{Platt:2010aa}, similar to model predictive control, as
illustrated in Fig.~\ref{fig:belief_replanning}. In this case, only
the first action of the plan is executed and after the belief state is
updated, the planner is called again. This means that the planner does
not need to map actions to every possible belief but instead only
compute the most robust trajectory given the current initial belief,
the probabilistic transition model, and with no online observations.
This type of conformant planning, or a Non-Observable Markov Decision
Process, is easier than computing a general {\tt POMDP} policy.

Even after the consideration of a replanning approach, the second
challenge remains, i.e., the conformant planner needs to optimize the
robustness of trajectories in a highly nonlinear and underactuated
state space. Nevertheless, the recent sampling-based motion planners
for computing asymptotically optimal trajectories for complex
dynamical systems can now address such problems
\cite{Li2015Sparse-Methods-}. Recent work has shown that these methods
can be used for belief space conformant planning, where the objective
is to compute control inputs for high-dimensional, nonlinear and
underactuated systems that safely drive them to a goal region with a
probability above a given threshold \cite{Littlefield:2015aa}.

The representation of the underlying belief plays a critical role. The
high-dimensionality of tensegrities, the multi-modality from the
presence of contacts, and the highly nonlinear nature of the dynamics
pose significant challenges to both parametric representations, such
as Gaussian beliefs, and non-parametric ones, such as particle
filters. The highlighted recent work has followed a particle
representation, which can deal with multi-modality but is
computationally expensive. Figure \ref{fig:particles} shows the
propagation of multiple particles for the SUPERball given the same
control under the presence of noise.  It is interesting to consider
how to achieve effective belief space conformant replanning in the
case of tensegrity robots and focus on the proper modeling and fast
computation of the resulting uncertainty.

\begin{figure}[t]
\centering
\includegraphics[width=.48\textwidth]{figures/particles.png}
\vspace{-0.3in}
\caption{A trajectory for the SUPERBall in belief space, where the
  application of controls can result in different outcomes due to noise.
  For the same control sequence a belief distribution over possible
  future states arises. A particle representation is followed for the
  belief \cite{Littlefield:2015aa}, which is illustrated as
  transparent versions of the robot.}  \vspace{-0.25in}
\label{fig:particles}
\end{figure}

\subsection {Model-based feedback motion planning}

Another avenue for dealing with noise and uncertainty involves the use
of feedback-based controllers, which aim to stabilize the robot at a
target state or trajectory, despite disturbances. For global motion
planning, this requires composing a sequence of low-level feedback
controllers, as shown in Fig.~\ref{fig:funnelcake}.
which \emph{funnel} the system toward a desired target in a way that
local minima are avoided~\cite{Burridge:1999aa, Conner:2006aa}.

One way to implement this principle is through the framework of
whole-body control via an operational space formulation
\cite{Khatib:1987aa,Sentis2005}. This involves the definition of
artificial potential fields for different tasks and their
prioritization, so that lower priority tasks are allowed to influence
the robot given only access to the null-space of higher priority
primitives. Tasks can include the avoidance of self-collisions,
reaching a desired configuration, and maintaining a desired posture.
The formulation of an Elastic Roadmap over operational spaces is done
by tiling the underlying state space with different, locally valid
controllers and specifying the transitions between them, while also
allowing for fast responses to sensory input \cite{Yang2010}. A
challenge for tensegrity robots is defining the artificial potential
fields in a way that they are valid for significant subsets of the
state space. Related to the challenge of defining proper Jacobians for
these systems, defining effective potential fields is not trivial.
Much like trajectory optimization methods, it is typically difficult
to argue about the properties and quality of paths generated from such
feedback controllers.

\begin{wrapfigure}{r}{0.2\textwidth}
  \centering
  \vspace{-.15in}
\includegraphics[width=.2\textwidth]{figures/Funnel.png}
\vspace{-0.2in}

\caption{The basic principle in feedback-based planning. The resulting
  state of a controller should be in the region of attraction of
  another.  The union of these regions should cover the state space so
  that the composition of controllers leads to the goal from any
  initial state.\vspace{-0.1in}}
\label{fig:funnelcake}
\end{wrapfigure}

An alternative methodology aims to provide probabilistic completeness
for feedback-based planning by composing multiple Linearized Quadratic
Regulators ({\tt LQR}), where each regulator stabilizes the system
around an individual trajectory. The composition can result in a
tree-like structure that allows for global planning
\cite{Tedrake2010}, where the {\tt LQR}-trees incrementally cover the
state space with their regions of attraction. A region of attraction
is the subset of the state space where the application of an {\tt LQR}
controller allows the stabilization of the system to a desired
trajectory.  Recent progress has allowed the conservative computation
of such areas for certain systems with dynamics.  A simulation-based
methodology has also been proposed that aims to approximate these
regions given access only to a simulator for the underlying system
\cite{Reist2010}. Applying this line of work on tensegrity robots can
potentially result in feedback solutions that can provide a certificate
of completeness.  It requires the formulation
of locally valid {\tt LQR} controllers for tensegrity robots with
computable regions of attractions, even if approximate. Such
controllers and regions of attractions should be generated quickly
given new sensor data.

The application of effective artificial potential fields or {\tt LQR}
controllers on tensegrity robots may prove difficult due to challenges in modeling
complex dynamic interactions with the environment.  As pointed out in Section
\ref{sec:control}, however, effective low-level and model-free
locomotion controllers have already been defined for tensegrity
structures, such as those based on {\tt
CPG}s \cite{MirletzSoftRobotics, Caluwaerts2013rsif,
Bliss2013Central-Pattern}.  It is interesting to explore the
composition of such controllers in a way that global feedback-based
motion planning can be achieved. This will require exploration of the
conditions under which they work and how transitioning between
different controllers can be achieved, thereby synthesizing
certificates for whether a particular controller can achieve a desired
result. This direction also indicates one way that model-based
planning principles can be integrated with developments in the
model-free low-level controller domain.

\begin{comment}
\komment{

Given the development of effective controllers specifically for
tensegrity structures, such as {\tt CPG}s, one can focus on integrating
these controllers so as to solve more complex planning problems, while
providing feedback solutions with guarantees. This would require that
these controllers are able to provide some form of certificates about
their effectiveness, i.e., the conditions under which they work,
region of attraction, etc..}

\komment{Nice visuals can be generated for many of the principles
for the above set of methods.}
\end{comment}


\subsection{The Taylor rule}


\section{Poisson}

The file of the functions used for this exercise is:

\lstinputlisting{one_a.py}

The result of these functions is given by:

\lstinputlisting{1a.txt}


\section{Updates: 08/13/2020}%
\label{sec:updates_2020_08_13}
\subsection{HMC Results}
%
For a fixed value of \(\beta\), we are interested in finding the values of
\(N_\mathrm{LF}, \varepsilon\) that give the optimal tunneling rate, \(\delta
Q\).
%
% +--------------+
% |   beta = 1   |
% +--------------+
\begin{figure}[htpb]
  \centering
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_b1.png}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}, \varepsilon\) at \(\beta =
    1\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_sin_b1.png}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}, \varepsilon\)
    at \(\beta = 1\)}%
  \end{subfigure}
\end{figure}
%
% +--------------+
% |   beta = 2   |
% +--------------+
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_b2.png}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}, \varepsilon\) at \(\beta =
    2\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_sin_b2.png}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}, \varepsilon\)
    at \(\beta = 2\)}%
  \end{subfigure}
\end{figure}
%
% +--------------+
% |   beta = 3   |
% +--------------+
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_b3.png}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}, \varepsilon\) at \(\beta =
    3\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.40\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/dq_sin_b3.png}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}, \varepsilon\)
    at \(\beta = 3\)}%
  \end{subfigure}
\end{figure}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% +--------------+
% |   beta = 1   |
% +--------------+
\clearpage
% \subsubsection{\(\beta = 1\)}%
% \label{subsubsec:hmc_beta1_lineplots}
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_ns_b1}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 1\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_ns_b1}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 1\)}%
  \end{subfigure}
\end{figure}
%
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_eps_b1}
    \caption{\(\delta Q\) vs. \(\varepsilon\) at \(\beta = 1\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_eps_b1}
    % \caption{\(\delta Q\) vs. \(\varepsilon\) at \(\beta = 1\)}%
    \caption{\(\delta Q_{\sin}\) vs. \(\varepsilon\) at \(\beta = 1\)}%
  \end{subfigure}
\end{figure}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% +--------------+
% |   beta = 2   |
% +--------------+
\clearpage
% \subsubsection{\(\beta = 2\)}%
% \label{subsubsec:hmc_beta2_lineplots}
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_ns_b2}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 2\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_ns_b2}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 2\)}%
  \end{subfigure}
\end{figure}
%
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_eps_b2}
    \caption{\(\delta Q\) vs. \(\varepsilon\) at \(\beta = 2\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_eps_b2}
    \caption{\(\delta Q_{\sin}\) vs. \(\varepsilon\) at \(\beta = 2\)}%
  \end{subfigure}
\end{figure}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% +--------------+
% |   beta = 3   |
% +--------------+
\clearpage
% \subsubsection{\(\beta = 3\)}%
% \label{subsubsec:hmc_beta3_lineplots}
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_ns_b3}
    \caption{\(\delta Q\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 3\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_ns_b3}
    \caption{\(\delta Q_{\sin}\) vs. \(N_{\mathrm{LF}}\) at \(\beta = 3\)}%
  \end{subfigure}
\end{figure}
%
\begin{figure}[h!]
  \centering
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dq_eps_b3}
    \caption{\(\delta Q\) vs. \(\varepsilon\) at \(\beta = 3\)}%
  \end{subfigure}
  \begin{subfigure}[htpb]{0.4725\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/lines/dqs_eps_b3}
    \caption{\(\delta Q_{\sin}\) vs. \(\varepsilon\) at \(\beta = 3\)}%
  \end{subfigure}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage
\subsection{Training results}%
\label{subsec:2020_08_13_training_results}
% +--------------+
% |   beta = 1   |
% +--------------+
\begin{figure}[htpb]
  \centering
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta1/dq_avg.png}
    \caption{\(\langle\delta Q\rangle\) vs training step at \(\beta = 1\)}%
  \end{subfigure}
  \hfill
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta1/dq_sin_avg.png}
    \caption{\(\langle\delta Q_{\sin}\rangle\) vs training step at \(\beta = 1\)}%
  \end{subfigure}
\end{figure}

% +--------------+
% |   beta = 2   |
% +--------------+
\begin{figure}[htpb]
  \centering
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta2/dq_avg.png}
    \caption{\(\langle\delta Q\rangle\) vs training step at \(\beta = 2\)}%
  \end{subfigure}
  \hfill
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta2/dq_sin_avg.png}
    \caption{\(\langle\delta Q_{\sin}\rangle\) vs training step at \(\beta = 2\)}%
  \end{subfigure}
\end{figure}

% +--------------+
% |   beta = 3   |
% +--------------+
\begin{figure}[htpb]
  \centering
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta3/dq_avg.png}
    \caption{\(\langle\delta Q\rangle\) vs training step at \(\beta = 3\)}%
  \end{subfigure}
  \hfill
  \begin{subfigure}[htpb]{0.375\textwidth}
    \includegraphics[width=\textwidth]{updates_2020_08_13/training_lf10_beta3/dq_sin_avg.png}
    \caption{\(\langle\delta Q_{\sin}\rangle\) vs training step at \(\beta = 2\)}%
  \end{subfigure}
\end{figure}


\section{Introduction}

Formal verification is a subject that constantly attracts attention of the research community. Static type systems are considered to be a lightweight verification method but they can be very powerful and precise as well. Dependent type systems in languages like Agda~\cite{Nor07}, Idris~\cite{Bra13} or Coq~\cite{coq} can be successfully applied in practical verification tasks but they are not yet as widely used as they could potentially be. This paper contributes to changing that.

\subsection{Motivation}

Two things have motivated me to write this paper. Firstly, while there are many tutorials on dependently typed programming and basics of verification, I could find little material demonstrating how to put verification to practical use. A must-read introductory paper ``Why Dependent Types Matter'' by Altenkirch, McKinna and McBride \cite{AltMcBMcK05}, which demonstrates how to use dependent types to prove correctness of merge sort algorithm, actually elides many proof details that are required in a real-world application. I want to fill in that missing gap by writing a tutorial that picks up where other tutorials have ended.

My second motivation comes from reading Okasaki's classical ``Purely Functional Data Structures''~\cite{Oka99}. Despite book's title many presented implementations are not purely functional as they make use of impure exceptions to handle corner cases (eg. taking head of an empty list). I realised that using dependent types allows to do better and it is instructive to build a provably correct purely functional data structure on top of Okasaki's presentation.

In the end this paper is both a tutorial and a case study of weight biased leftist heap implemented in dependently typed setting. My goal is to teach the reader how to build complex proofs from simple ones. As a result the reader will be able to verify that operations on a data structure maintain required invariants. Acquired knowledge will allow to understand more advanced verification techniques, eg. equational reasoning provided by Agda's standard library or tactics system found in Idris \cite{Bra13} and Coq \cite{coq}.

\subsection{Companion code}

This tutorial comes with a standalone companion code written in Agda 2.3.4\footnote{\url{http://ics.p.lodz.pl/~stolarek/_media/pl:research:dep-typed-wbl-heaps.tar.gz}}\footnote{NOTE TO THE REVIEWER: Agda 2.3.4 is planned to be released sometime in February or March. Companion code was created using latest development version of Agda. This notice will be removed from final version of the paper.}. I assume the reader is reading companion code along with the paper. Due to space limitations I elide some proofs that are detailed in the code using Notes convention adapted from GHC project~\cite{MarPey12}.

``Living'' version of companion code is available at GitHub\footnote{\url{https://github.com/jstolarek/dep-typed-wbl-heaps}} and it may receive updates after the paper is published.

\subsection{Assumptions}

I assume that reader has basic understanding of Agda, some elementary definitions and proofs. In particular I assume the reader is familiar with definition of natural numbers (\texttt{Nat}s) and their addition (\texttt{+}) as well as proofs of basic properties of addition like associativity, commutativity or 0 as right identity ($a + 0 ≡ a$). Reader should also understand \texttt{refl} with its basic properties (symmetry, congruence, transitivity and substitution), know the concept of ``data as evidence'' and other ideas presented in ``Why Dependent Types Matter'' \cite{AltMcBMcK05} as I will build upon them. All of these are implemented in the \texttt{Basics} module in the companion code. Module \texttt{Basics.Reasoning} reviews in detail the above-mentioned proofs.

\subsection{Notation and conventions}

In the rest of the paper I will denote heaps using \texttt{typewriter font} and their ranks using an \textit{italic type}. The description of merge algorithm will mention heaps \texttt{h1} and \texttt{h2} with ranks \textit{h1} and \textit{h2} respectively, their left children (\texttt{l1} in \texttt{h1} and \texttt{l2} in \texttt{h2}) and right children (\texttt{r1} in \texttt{h1} and \texttt{r2} in \texttt{h2}) with \texttt{p1} and \texttt{p2} as the priorities of root elements in \texttt{h1} and \texttt{h2} respectively. In the text I will use $\oplus$ to denote heap merging operation. So \texttt{h1}$\oplus$\texttt{h2} will be a heap created by merging \texttt{h1} with \texttt{h2}, while \textit{h1}$\oplus$\textit{h2} will be the rank of the merged heap.

I will represent priority using natural numbers with lower number meaning higher priority. This means that 0 will be the highest priority, while the lowest priority will be unbounded. This also means that if \texttt{p1 > p2} holds as a relation on natural numbers then \texttt{p2} is higher priority than \texttt{p1}.

In the text I will use numerals to represent \texttt{Nat}s but the code uses encoding based on \texttt{zero} and \texttt{suc}. Thus 2 in the text will correspond to \texttt{suc (suc zero)} in the source code.

I will use \texttt{\hilight{\{ \}?}} in code listings to represent Agda holes.

Remember that any sequence of Unicode characters is a valid identifier in Agda. Thus \texttt{l≥r} is an identifier, while \texttt{l ≥ r} is application of \texttt{≥} operator to \texttt{l} and \texttt{r} operands.

\subsection{Contributions}

This paper contributes the following:

\begin{itemize}
 \item Section~\ref{sec:no-proofs} presents unverified implementation and the problem of partiality of functions operating on a weight biased leftist heap. While the problem in general is well-known the solution to this particular case can be combined with verification of one of data structure's invariants. This is done in Section~\ref{sec:rank-property}.
 \item Section~\ref{sec:eq-proofs-using-trans} outlines a technique for constructing equality proofs using transitivity of propositional equality. This simple, standalone technique provides ground for understanding verification mechanisms used in Agda's standard library.
 \item Section~\ref{sec:single-pass-merge-proof-by-comp} uses the technique introduced in Section~\ref{sec:eq-proofs-using-trans} to prove code obtained by inlining one function into another. This shows how programs created from small, verified components can be proved correct by composing proofs of these components.
 \item Section~\ref{sec:priority-invariant} contains a case study of how a proof of data structure invariant influences the design of an API. This is demonstrated on the example of priority invariant proof and its influence on designing insertion of a new element into a heap.
\end{itemize}


\documentclass{llncs}
\newcommand{\X}{{\bf X}}
\newcommand{\x}{{\bf x}}
\newcommand{\Y}{{\bf Y}}
\newcommand{\y}{{\bf y}}
\newcommand{\Z}{{\bf Z}}
\newcommand{\z}{{\bf z}}
\newcommand{\bs}{\boldsymbol}
\newcommand{\bSigma}{\boldsymbol \Sigma}
\usepackage{amsmath,amssymb,algorithm,algorithmic}
\usepackage{times}
\usepackage{setspace,verbatim}
\usepackage{epsfig,url,subfigure}

\begin{document}
\title{Partial sparse canonical correlation analysis (PSCCA) for population
  studies in medical imaging}
\author{Anonymous}
\institute{Anonymous}
\maketitle
\begin{abstract}
We propose a new multivariate method, partial sparse canonical
correlation analysis (PSCCA), for computing the statistical
comparisons needed by population studies in medical imaging.  PSCCA is a
multivariate generalization of linear regression that allows one to statistically parameterize imaging studies in terms of
multiple views of the population (e.g., the full collection of
measurements taken from an image set along with batteries of cognitive
or genetic data) while controlling for nuisance variables.  This paper
develops the theory of PSCCA, provides an algorithm and illustrates
PSCCA performance on both simulated and real datasets.  We show, as a
first application and evaluation of this new methodology, that
PSCCA can improve detection power over mass univariate approaches
while retaining the interpretability and biological plausibility of
the estimated effects.  We also discuss the strengths, limitations and
future potential of this methodology.
\end{abstract}
\section{Introduction}
% pubmed references to MRI :
% 2000-2001 --- 25561
% 2001-2002 --- 27053
% 2003-2004 --- 31708
% 2005-2006 --- 38620
% 2008-2009 --- 49288
% 2009-2010 --- 49323
% pubmed references to MRI brain :
% 2000-2001 --- 9938
% 2001-2002 ---
% 2003-2004 --- 12655
% 2005-2006 ---
% 2008-2009 ---
% 2009-2010 --- 19676 ------
% MRI brain statistical parametric mapping 783 results ,
% MRI brain gives
The number of neuroimaging studies published annually has doubled from
9,938 in 2000-2001 to 19,676 in 2009-2010
(\url{http://www.ncbi.nlm.nih.gov/pubmed/}).  This growth has been
accompanied by increasing diversity in the types of data being
collected; Imaging studies now often include not only various
structural and functional modalities but also neurocognitive
batteries, genetics, and environmental measurements.  However, the
statistical methods have changed relatively little over the past
twenty years -- until very recently (e.g., \cite{Tosun2010a}).  The
increasing size of imaging datasets and the concomitant desire for
performing integrative studies across modalities points to the need
for new multivariate statistical methods that elegantly handle large,
multi-view datasets.  These methods should retain or even improve
detection power over traditional mass-univariate (MU) models such as
statistical parametric mapping (SPM) which uses the univariate form of
the general linear model (GLM).  Repeatedly applying the univariate GLM (or
linear regression) at each voxel leads to loss of detection power due
to the well-known multiple comparisons problem.

Canonical Correlation Analysis (CCA)~\cite{hotellingcca} is a
traditional multivariate generalization of standard linear regression
\cite{kshirsagar}.  CCA inherently avoids the multiple-comparisons penalty
associated with MU methods by symmetrically maximizing the correlation
between the full matrices representing two views of the data (here
denoted $\Y$ and $\X$).  The matrix {$\X$} might represent a
tabulation of all demographic data, including genetics, diagnosis,
behavioral measures, age, etc. while $\Y$ may be a matrix of all the
imaging measurements.  In contrast, traditional univariate models only
enable the predicted value to be a vector while the predictors may be
a matrix.  Thus, linear regression is a special case of CCA.  In both
traditional regression and CCA, the number of predictors, $p$, must be
fewer than the number of observations, $n$ (subjects in our
neuroimaging study).  For CCA (or multivariate regression), this
restriction holds for both sets of predictors $p$, $q$, contained in
$\X, \Y$.

Recently, sparse (or penalized) canonical covariance analyses (SCCovA)
~\cite{parkhomenko,witten,lykou} have been proposed as an
approximation to CCA specifically for the high dimensional ($p\gg n$)
setting.\footnote{SCCovA substitutes the identity matrix for
within-view covariance matrices and thus analyze cross-covariance
structure, not correlation structure \cite{cherry}.  Thus, SCCA
(versus SCCovA) does not depend on how the observations are scaled.}
The {\em sparseness} in penalized methods improves interpretability by
including in the model only the most important variables from the
large set of $p$ (and/or $q$) predictors.  From a medical imaging
researcher's perspective, the benefit is that only the most predictive
variables (e.g. parts of the brain) will emerge in the results
provided by a penalized statistical tool.  Hence, brain regions are
highlighted in a way that is similar to SPM.  Furthermore, regions
selected by SCCovA (or similarly sparse canonical correlation analysis
(SCCA)) are treated statistically as a collective (or `network') as
opposed to MU methods which treat each predictor as an independent
variable.

Despite prior studies using SCCovA~\cite{parkhomenko,witten,lykou,Avants2010b}, we are unaware of
previous work that studies factoring (``partialling'') out nuisance
variables within the penalized CCA framework.  While this problem is
addressed in the $p < n$ setting by partial canonical correlation
analysis (PCCA)\cite{timm}, no penalized formulation has yet been
proposed.

This paper contributes the theory of Partial Sparse CCA (PSCCA) along
with a novel and efficient iterative algorithm for PSCCA.  PSCCA (like
CCA) performs a global multivariate test of the association between
two modalities that quantify a study's subjects while accounting for a
third set of nuisance variables.  It generalizes linear regression and
is inherently, sparsely multivariate in multiple views of the data
unlike MU and standard support vector machines (SVM).

The general PSCCA formulation has many applications.  PSCCA may be
applied to almost any statistical scenario in medical imaging studies
traditionally handled by SPM.  PSCCA is able to identify the subset of
the brain most correlated with non-imaging variable(s) of interest
(for instance, a cognitive battery) while factoring out confounding
effects (age, gender).  Alternatively, we may apply PSCCA to the case
where both views of the data are high-dimensional, for instance, to
identify correlations between different imaging modalities
independently from covariates such as scanner, gender, etc.  PSCCA
thus enables complex studies of multiple view data that contains many
more variables than observations.

The rest of the paper is organized as follows: in the next section we
provide a brief review of CCA and Sparse CCA. In Section 3, we present
the theory behind our novel Partial Sparse CCA (PSCCA) framework and
describe the iterative algorithm for performing PSCCA. In Section 4,
we provide experimental results on synthetic and real world
neuroimaging datasets and we conclude with a brief summary in Section
5.

Neuropsychological measures detect high-level cognitive function that
emerges from complex, large-scale neural
networks that include multiple gray matter (GM) regions integrated by
white matter (WM) projections. The clinically-validated Philadelphia
Brief Assessment of Cognition (PBAC) \cite{Libon2007} examines several
cognitive domains, including executive functioning/working memory
(exe), language (lang), visuospatial skills (vs), visual/verbal
episodic memory (mem) and social comportment/behavior (behav). We use
the open-source sparse canonical correlation analysis for neuroimaging
(SCCAN) software to {\bf cross-validate} putative relationships
between the neural substrate and cognition.   We thus relate three quantitative measures: the PBAC, GM density (GMD) derived from T1 MRI, and the fractional anisotropy (FA) of WM derived from DTI.

%What we are doing here ( a few sentences )

%This paper will detail and illustrate our approach to performing
%neuroimaging studies in the style of traditional formulations but
%using a new, powerful multivariate pscca.  We highlight in both
%simulated and real data the advantages and disadvantages of this
%method.

\section{Brief review: CCA and sparse CCA (SCCA)}
\begin{comment}{
Consider a standard neuroimaging population study with both male and
female subjects between 20 and 40 years of age each of which measured
via a series of MRI scans.  Each subject is also designated either
patient or control.  A standard regression analysis will treat the
quantitative imaging measurement as the dependent variable ($\y$) and
age, gender and diagnosis group as covariates $({\X})$ where each test
is performed independently at each voxel.  Detection power is
compromised by the multiple-comparisons problem incurred by the number
of imaging measurements (millions) as well as the confounding
variables (age, gender).   It is compromised because one must perform
additional statistical corrections to the $p$-values output by MU
statistics. If we are using MU models and
want to test the whole brain for effects, then
we can not do much about the first problem.  For the second problem,
we can factor out the effects of these unwanted (confounding)
variables by regressing on the residuals ($\y -\X\beta$).
}
\end{comment}

% CCA~\cite{hotellingcca} is the analog to Principal Component Analysis
% (PCA) for pairs of matrices. PCA computes the directions of maximum
% covariance between elements in a single matrix, whereas CCA computes
% the directions of maximal correlation between a pair of matrices.
% See~\cite{taylor:cca} for a general review of CCA along with some
% representative applications. Unlike PCA, CCA does not depend on how the observations are scaled.

More specifically, given a set of $n$ paired observation vectors
$\{(y_1,x_1),...,(y_n,x_n)\}$--in our case the two matrices are the
quantitative imaging measurement ({\Y}) and age, gender, diagnosis ({\X}) matrices --we would like to simultaneously find the directions
${\bs{\bs\phi_{\Y}}}$ and
${\bs{\bs\phi_{\X}}}$ that maximize the correlation of
the projections of ${\Y}$ onto ${\bs{\bs\phi_{\Y}}}$
with the projections of ${\X}$ onto
${\bs{\bs\phi_{\X}}}$. This is expressed as

\begin{equation}
\label{cca1}
\rho=\max_{{\bs\phi_Y}, {\bs\phi_X}}
\frac{{\bs\phi_{\X}^T\bs\Sigma_{\X\Y}}\bs\phi_{\Y}}{\sqrt{\bs\phi_{\X}^T\bs\Sigma_{\X\X}\bs\phi_{\X}}\sqrt{\bs\phi_{\Y}^T\bs\Sigma_{\Y\Y}\bs\phi_{\Y}}}
\end{equation}
where ${\bs\Sigma_{\X\X}}$, ${\bs\Sigma_{\Y\Y}}$ and ${\bs\Sigma_{\X\Y}}$ are the auto and cross covariance matrices i.e. $\X^T\X$, $\Y^T\Y$ and $\X^T\Y$, respectively. The above objective can also be thought of as maximizing the numerator $\bs\phi_{\X}^T\bs\Sigma_{\X\Y}\bs\phi_{\Y}$ subject to $\bs\phi_{\X}^T\bs\Sigma_{\X\X}\bs\phi_{\X} =1$ and $\bs\phi_{\Y}^T\bs\Sigma_{\Y\Y}\bs\phi_{\Y}=1$

Now, define change of basis as:

\begin{equation}
\label{basisChange}
\bs\psi_{\X} = \bs\Sigma_{\X\X}^{1/2}\bs\phi_{\X}, \;\;\;\;\;\;   \bs\psi_{\Y} = \bs\Sigma_{\Y\Y}^{1/2}\bs\phi_{\Y}
\end{equation}

Then, substituting~(\ref{basisChange}) in~(\ref{cca1}) we get

\begin{equation}
\label{subs}
\rho= \max_{{\bs\psi_{\Y}}, {\bs\psi_{\X}}} \frac{\bs\psi_{\X}^T \bs\Sigma_{\X\X}^{-1/2}\bs\Sigma_{\X\Y}\bs\Sigma_{\Y\Y}^{-1/2}\bs\psi_Y}{\|\bs\psi_{\X}\| \|\bs\psi_{\Y}\|}
\end{equation}

The whitening transform is used to convert covariances to correlations
and also to de-correlate auto-correlation matrices.  In CCA, this
normalizes the data such that the optimization can maximize the
cross-correlation.  The standard whitening transform is defined as
$\X_w= \X\bs\Sigma_{\X\X}^{-1/2}$ and $\Y_w=
\Y\bs\Sigma_{\Y\Y}^{-1/2}$.  Applying the whitening transform
to~(\ref{subs})

\begin{equation}
\label{simplifiedcca}
Corr(\X_w\bs\psi_{\X},\Y_w\bs\psi_{\Y})=\rho=\max_{{\bs\psi_{\Y}}, {\bs\psi_{\X}}} \frac{\bs\psi_{\X}^T \bs\Sigma_{\X_w\Y_w}\bs\psi_Y}{\|\bs\psi_{\X}\| \|\bs\psi_{\Y}\|}
\end{equation}
where $\bs\Sigma_{\X_w\Y_w} = \X_w^T\Y_w$.

As mentioned earlier, CCA results in vectors $\bs\psi_{\X}$,
$\bs\psi_{\Y}$ that are not sparse, and these vectors are not unique
if $p > n$. In most biomedical imaging applications, $p$ is
large and, one needs to find a linear combination of the
variables in $\X_w$ and $\Y_w$ that has large correlation but is also
sparse in the variables that enter the model.

\begin{comment}
Several researchers propose sparse formulations of canonical
covariance analysis: Witten et al.~\cite{witten} use penalized matrix
decomposition to enforce sparsity; Parkhomenko et
al.~\cite{parkhomenko} use soft-max thresholding in an iterative
algorithm.  Both papers assume that within-view covariance matrices
are well-approximated by the identity.  Finally, Lykou and
Whittaker~\cite{lykou} propose a LARS~\cite{lars} style algorithm for
obtaining sparsity in the loadings.
\end{comment}

While several researchers propose sparse formulations of canonical
covariance analysis \cite{parkhomenko,witten,lykou}, none of the these
methods handle confounding variables---a highly desirable modeling
property for many biomedical and neuroimaging applications.  In the
next section, we detail the PSCCA solution to this problem.

\begin{comment}
We formulate a sparse canonical correlation analysis optimization
with an embedded step that factors out the effect of nuisance
variables.  We also provide an efficient power iteration based
algorithm to compute the directions of maximum partial
correlation. Our approach incorporates the normalization constraints
required for correlation (versus covariance) analysis; We call it
Partial Sparse CCA (PSCCA).
\end{comment}

\section{PSCCA (Partial Sparse Canonical Correlation Analysis)}
As described earlier, let $\X$ be the matrix with columns containing voxels from one set of
images of $n$ subjects; $\Y$ is the matrix with columns containing
the second set of measurements from the same $n$ subjects and further
let $\Z$ be the matrix of confounding variables (age, gender, etc.) for
our neuroimaging problem.  The second set of measurements may be
voxels from another imaging modality, scores from a battery of
neuropsychological tests or a much simpler feature such as a binary
diagnosis variable.  Also, let $\lambda_{\X}$ and $\lambda_{\Y}$ ($\in
[0,1]$) (where higher values indicate more sparsity) be the user defined
parameters which control the sparsity for either set of the canonical
variates.  The sparseness parameters can, alternatively, be chosen automatically
from the data so as to maximize the correlation (or likelihood) between the canonical variates.

PCCA~\cite{timm} finds the correlation between $\X$ and $\Y$ after removing (``partialling out'') the linear effect of the confounding variables $\Z$.
We denote the $\X$ and $\Y$ matrices with effect of $\Z$ ``partialled'' out as $\X^{\backslash\Z}$ and $\Y^{\backslash\Z}$. Regressing $\X$ against $\Z$, using standard least squares ($\|\X -\Z\bs\beta\|^2$) gives $\bs\beta=  \bs\Sigma_{\Z\Z}^{-1}\Z^T\X$.
Thus, the residual\footnote{Note that $\X^{\backslash\Z}$ is actually what is called the residual $\X-\Z\bs\beta$ in a least squares regression problem.} can be written as  $\X^{\backslash\Z}=\X - \Z\bs\Sigma_{\Z\Z}^{-1}\Z^T\X$. Applying the whitening transform to $\Z$  as $\Z_w =\Z \Sigma_{\Z\Z}^{-1/2}$, we get $\X^{\backslash\Z}=\X - \Z_w\Z_w^T\X$.
We can write similar equations for the residual when $\Y$ is regressed against $\Z$.

Now, we can write the complete variance-covariance matrix of the residuals as:

\begin{eqnarray}
\label{matrices}
\begin{bmatrix}
 \bs\Sigma_{\X\X}^{\backslash \Z} & \bs\Sigma_{\X\Y}^{\backslash \Z} \\
  \bs\Sigma_{\Y\X}^{\backslash \Z} & \bs\Sigma_{\Y\Y}^{\backslash \Z}
\end{bmatrix}
&=&
\begin{bmatrix}
  \X^T\X -\X^T \Z_w\Z_w^T\X &\;\;\;\;   \X^T\Y -\X^T \Z_w\Z_w^T\Y\\
  \Y^T\X -\Y^T \Z_w\Z_w^T\X &\;\;\;\;   \Y^T\Y -\Y^T \Z_w\Z_w^T\Y
\end{bmatrix}
.
\end{eqnarray}

%The matrices $\bSigma_{X_wX_w\backslash Z_w}$ etc. are the variance-covariance matrices of the residual vectors $\bs r_X$ and $\bs r_Y$ and are defined as:

%\begin{eqnarray}
%\label{matrices}
%\begin{bmatrix}
% \bSigma_{11\backslash 3} & \bSigma_{12\backslash 3} \\
%  \bSigma_{21\backslash 3} & \bSigma_{22\backslash 3}
%\end{bmatrix}
%&=&
%\begin{bmatrix}
% \bSigma_{11} -\bSigma_{13}\bSigma_{33}^{-1}\bSigma_{31} &\;\;\;\; \bSigma_{12} -\bSigma_{13}\bSigma_{33}^{-1}\bSigma_{32}\\
%  \bSigma_{21} -\bSigma_{23}\bSigma_{33}^{-1}\bSigma_{31} &\;\;\;\; \bSigma_{22} -\bSigma_{23}\bSigma_{33}^{-1}\bSigma_{33}
%\end{bmatrix}
%\end{eqnarray}
%where we denote $\X_w \rightarrow 1$, $\Y_w \rightarrow 2$ and $\Z_w \rightarrow 3$ as shorthand.

% Equation~(\ref{matrices}) can easily be extended to handle more than two matrices and also to ``partial'' out the effect of more than one confounding covariate matrices.

The PCCA problem can therefore be written as:

\begin{equation}
\label{pscca}
\rho_{PCCA}=\max_{{\bs\phi_{\Y}}, {\bs\phi_{\X}}} \frac{\bs\phi_{\X}^T \bs\Sigma_{\X\Y}^{\backslash \Z}\bs\phi_Y}{\sqrt{\bs\phi_{\X}^T\bs\Sigma_{\X\X}^{\backslash \Z}\bs\phi_{\X}}\sqrt{\bs\phi_{\Y}^T\bs\Sigma_{\Y\Y}^{\backslash \Z}\bs\phi_{\Y}}}
\end{equation}

Changing the basis as for simple CCA, we get

\begin{equation}
\label{basisChangePSCCA}
\bs\psi_{\X} = (\bs\Sigma_{\X\X}^{\backslash \Z})^{1/2}\bs\phi_{\X}, \;\;\;\;\;\;   \bs\psi_{\Y} = (\bs\Sigma_{\Y\Y}^{\backslash \Z})^{1/2}\bs\phi_{\Y}
\end{equation}

and substituting~(\ref{basisChangePSCCA}) in~(\ref{pscca}) gives

\begin{equation}
\label{subsPSCCA}
\rho_{PCCA}= \max_{{\bs\psi_{\Y}}, {\bs\psi_{\X}}} \frac{\bs\psi_{\X}^T (\bs\Sigma_{\X\X}^{\backslash \Z})^{-1/2}\bs\Sigma_{\X\Y}(\bs\Sigma_{\Y\Y}^{\backslash \Z})^{-1/2}\bs\psi_{\Y}}{\|\bs\psi_{\X}\| \|\bs\psi_{\Y}\|} .
\end{equation}

After some algebraic manipulation we can write the PCCA objective compactly as

\begin{equation}
\label{psccacompact}
\rho_{PCCA}=\max_{{\bs\psi_{\Y}}, {\bs\psi_{\X}}} \frac{\bs\psi_{\X}^T \bs\Sigma_{\X_w\Y_w}^{\backslash \Z}\bs\psi_{\Y}}{\|\bs\psi_{\X}\| \|\bs\psi_{\Y}\|}
\end{equation}
where $\X_w=\X(\bs\Sigma_{\X\X}^{\backslash \Z})^{-1/2}$ and
$\Y_w=\Y(\bs\Sigma_{\Y\Y}^{\backslash \Z})^{-1/2}$. Note the
difference in the whitening transform from the one used in simple CCA;
here we are using the covariance matrix with $\Z$ partialled out
to whiten $\X$ and $\Y$.

Finally, the above objective after incorporating the user specified $\ell_1$ sparsity penalties ($\lambda_{\X}$ and $\lambda_{\Y}$) and under the constraints $\bs\psi_{\X}^T\bs\psi_{\X}=\bs\psi_{\Y}^T\bs\psi_{\Y}=1$ can be written as:

\begin{equation}
\label{psccaSparseConst}
\rho_{PSCCA}=\max_{{\bs\psi_{\Y}}, {\bs\psi_{\X}}} \{ \bs\psi_{\X}^T \bs\Sigma_{\X_w\Y_w}^{\backslash \Z}\bs\psi_{\Y} - \lambda_{\X}\|\bs\psi_{\X}\|_1 - \lambda_{\Y}\|\bs\psi_{\Y}\|_1\}
\end{equation}
Our optimization strategy for (\ref{psccaSparseConst}) combines power
iteration and soft thresholding to compute the canonical vectors while
satisfying  the sparsity constraints.  The approach, described in the next
section, uses an alternating least squares method
\cite{golub} extended to include sparsity constraints
\cite{cichocki}.

%\caption{\baselineskip 12pt \small Cartoons illustrating (a) SCCA ;
%  (b) partial SCCA ; (c) part SCCA.  }
%\label{fig:cartoon}
%\end{figure}

\subsection{PSCCA Algorithm}
Following \cite{golub}, we propose a power iteration based algorithm
for PSCCA for the general problem of finding principal eigenvectors of
the matrices.  This numerical approach does not require one to ever
explicitly form the full $\X_{w}^T \Y_{w}$ matrix and is therefore
appropriate for large datasets where the number of columns in both views may
count in the millions or more.  In all steps below, we employ the
pseudoinverse when needed.  In addition, the function $(x)_+$ is equal to $x$ is $x \geq 0$ and $0$ is $x <0$ and
 \begin{equation}
Sign(x)= \begin{cases} -1, & \mbox{if } x<0 \\0, & \mbox{if } x=0 \\1, & \mbox{if } x>0 \end{cases}
\end{equation}
Note that positivity or negativity constraints on the
$\bs\psi_{\X}, \bs\psi_{\Y}$ may be trivially included with a minor
modification to Algorithm \ref{partial-mic}.
\vspace{-0.1in}
\begin{algorithm}[htdp]
\small \caption{\bf Computing principal eigenvectors for PSCCA}
\label{partial-mic}
\begin{algorithmic}[1]
\STATE Apply the whitening transformation to {\Z} to get $\Z_{w}$.
\STATE Compute $\X^{\backslash \Z}$ and $\Y^{\backslash \Z}$ and the whitened matrices $\X_{w}$ and $\Y_{w}$.
\STATE Select the (fractional) sparsity parameters $\lambda_{\X}$ and $\lambda_{\Y}$
\STATE Randomly initialize $\bs \psi_{\X}^0$ and $\bs \psi_{\Y}^0$ ($\sim \mathcal{N}(0,1)$) and set $k=0$.

\WHILE {$\Delta$ Corr($\bs X_w \bs \psi_{\X}^{k+1}$, $\bs Y_w \bs \psi_{\Y}^{k+1}$) $<$ $\epsilon$}
\STATE Compute  $\bs \psi_{\X}^{k+1}= {\X_w}^T {\Y_w} \bs \psi_{\Y}^{k} -  {\X_w}^T  {\Z_w} {\Z_w}^T {\Y_w} \bs \psi_{\Y}^{k}$
\STATE Soft-Max Sparseness:  $\bs \psi_{\X}^{k+1} \leftarrow (\|\bs \psi_{\X}^{k+1}\|  - max(\bs \psi_{\X}^{k+1})*\lambda_{\X})_+ Sign(\bs \psi_{\X}^{k+1})$
\STATE Normalize: $\bs \psi_{\X}^{k+1} \leftarrow \frac{\bs \psi_{\X}^{k+1}}{\|\bs \psi_{\X}^{k+1}\|}$\\
//Repeat Same Procedure for $\bs \psi_{\Y}$ \\
\STATE Compute  $\bs \psi_{\Y}^{k+1}= {\Y_w}^T {\X_w} \bs \psi_{\X}^{k+1} -  {\Y_w}^T  {\Z_w} {\Z_w}^T {\X_w} \bs \psi_{\X}^{k+1}$
\STATE Soft-Max Sparseness: $\bs \psi_{\Y}^{k+1} \leftarrow (\|\bs \psi_{\Y}^{k+1}\|  - max(\bs \psi_{\Y}^{k+1})*\lambda_{\Y})_+ Sign(\bs \psi_{\Y}^{k+1})$
\STATE Normalize: $\bs \psi_{\Y}^{k+1} \leftarrow \frac{\bs \psi_{\Y}^{k+1}}{\|\bs \psi_{\Y}^{k+1}\|}$
\STATE k $\leftarrow$ k+1
\ENDWHILE
\end{algorithmic}
\end{algorithm}
We use permutation testing on $\X$, $\Y$ to assess significance where
the test statistic is the partial correlation between the two main views.

%\noindent{}
%\begin{description}
%\item [Whiten:]Apply the whitening transformation to {\X}, {\Y}, {\Z}.
%    VectorType temp=q*w_q;
%    wpnew=p.transpose()*( temp - this->m_MatrixRRt*temp );
%\item [Begin Loop:]for power iteration.
%\item [~~View 1:]Compute  $\x= {\X}^T {\Y} \y -  {\X}^T  {\Z} {\Z}^T {\Y} \y$.
%\item [~~Soft-Max Sparseness \& Normalization $\x$:] Enforce $\x$
%  sparseness and set $\x \leftarrow \frac{\x}{\|\x\|}$.
%\item [~~View 2:]Compute  $\y= {\Y}^T {\X} \x -  {\Y}^T  {\Z} {\Z}^T
%  {\X} \x$
%\item [~~Soft-Max Sparseness \& Normalization $\y$:] As in $\x$ step.
%\item [~~CC:]Compute $Corr( {\X} \x ,  {\Y} \y )$.
%\item [End loop:]Check the correlation and stop when converged.
%\end{description}

%For multiple eigenvectors, use the Lanczos algorithm.
\begin{comment}
\subsection{Assessing significance}
A well-known difficulty with neuroimaging studies, particularly when
sample sizes are small, is the potential for the methods to find biologically implausible structure in the data.  While the
potential for this problem can never be fully eliminated, we seek to
minimize the confound by using an empirical approach to significance
testing based on permutations:
\begin{enumerate}
\item Compute the true PSCCA correlation~$t=$PSCCA$(\X,\Y,\Z)$.
\item Initialize $p=0$.
\item {\bf For} $N$ simulations {\bf do }
\item ~~~Permute the rows of $\X$, $\Y$ to get $\X_p, \Y_p$.
\item ~~~Compute $t_p=$ PSCCA$(\X_p,\Y_p,\Z)$.
\item ~~~if $t_p > t , ~~p=p+1$.
\item {\bf done }
\item {\bf Return} the p-value, $p/N$.
\end{enumerate}
The number of simulations should be selected to provide a reasonable
sampling of the permutation space.
\end{comment}

\section{Results}
The code for the PSCCAN implementation, the simulation study and the
neuroimaging study will be made available at publication time.
\subsection{Simulations} Define a ``true'' linear signal vector with
$n$ entries, ${\bs v}$, such that the value of each entry is ${\bs
v}_i=i/n$ where $i$ indexes the vector.  A second signal is a vector drawn from a zero mean unit
variance Gaussian distribution, ${\bs g_x}$ with $p$ entries.  The
first view is then $\X ={\bs v}^T {\bs g_x}$ and we similarly generate
$\Y $ with $n \times q$ entries.  We optionally add noise to both
views.  In 100 low-noise simulations, SCCA produces a significant
association.  However, when we use $\Z = {\bs v} + $ {\em noise} as a
covariate in PSCCA on $\X$ and $\Y$, then no significant association
exists.  Both results are as expected and provide a sanity check on
our theory and implementation.  The second experimental validation of
our implementation and theory generates $\X$ and $\Y$ where the first
$p/2, q/2$ columns are derived from ${\bs v}$.  The second $p/2, q/2$
columns in $\X, \Y$ are derived from a different ``true'' signal (${\bs v}_2$) with
a less strong linear relationship than in the first half of the
matrices.  Thus, when we use SCCA with sparseness
$\lambda_{\X}=\lambda_{\Y}=0.25$, the first half of the matrix is
selected.  PSCCA selects the second half of the matrix when $\Z$ is
used as confounding covariate.  Both are significant across permutations.  Due to
noise, in some simulations, a few entries from the first half of the
matrix may enter the model with low weight.  If we add a column containing signal derived from ${\bs
  v}_2$ to $\Z$ then, as predicted, PSCCA results become insignificant. Figure~\ref{fig:sim}
shows the vectors $\bs\phi_{\X}$ selected by SCCA and PSCCA on the
same input data where PSCCA uses $\Z$ (derived from ${\bs v}$ alone)
as confounding covariate.
\begin{figure}
\begin{center}
\includegraphics[width=120mm]{simulation_result_mix.pdf}
\end{center}
\vspace{-0.2in}
\caption{The black hollow circles show the non-zero entries in
  $\bs\phi_{\X}$ that are selected by SCCA, that is, the value of the vector
  $\bs\phi_{\X}$.  The red full circles show the non-zero entries in
  the vector $\bs\phi_{\X}$ that are selected by PSCCA.  The $\Z$ signal factors
  out the confounding signal in the first half of the matrix leaving
  the second signal of interest in the second half to be the source of
the significant association.}
\label{fig:sim}
\end{figure}
% This analysis can be achieved by simulating imaging data and two other
% views (age, cognition) in such a way that the age is the true hidden variable that
% generates both cognition and imaging measurements.  PSCCA should then
% detect an insignificant association between cognition and imaging when
% age is used as the confounding variable.  Similarly, PSCCA should
% detect a significant association between age and imaging when
% cognition is a confounding variable.
\subsection{Comparison of regression and PSCCA on OASIS data}
Our first evaluation on real data employs PSCCA as a form of
multivariate regression between imaging, diagnosis and nuisance variables.
We employ a subset of the freely available OASIS dataset to compare
PSCCA to mass-univariate linear regression.  This subset of the OASIS
data contains elderly subjects (n=38) in addition to subjects with
Alzheimer's disease (n=31) of both genders (39 F, 30 M) and with ages
that range between 62 and 98 years.  Our evaluation criterion compares
both methods' power to detect the known anatomical distribution of
AD-related atrophy in gray matter (hippocampus, cuneus, temporal lobe)
\cite{Avants2010b} where gray matter was segmented and normalized by using standard
open source software.  We use the whole brain, in template space, as region of interest in order to
challenge the power of the MU method relative to the
single test performed by multivariate PSCCA.  We assume that the
researcher has pre-selected the sparseness parameter for the study.
We choose $\lambda$ (sparsity parameter) for the gray matter voxels such that 10\% of the
ROI (contained in the $\X$ matrix) will be selected by PSCCA.  The
$\Y$ matrix, in this case, is the diagnosis vector that defines
whether a subject is control or patient.  The nuisance matrix $\Z$
contains age and gender variables.  We run both the MU
statistics (via the {\bf R} program) and our own independently
developed PSCCA implementation (C++ based, BSD license, open-source)
on identical input data.  Using false discovery rate (FDR) correction
on the regression-based p-values for diagnosis, we find that the
minimum q-value is 0.183, thus insignificant after correction.  In
contrast, PSCCA shows significant effects at the $p=0.041$ level,
10000 permutations.  We visualize the regions that emerge from PSCCA
by overlaying the first canonical vector $\bs \psi_{\X}$ on the brain.
Figure~\ref{fig:comp} compares the PSCCA output with the regression
results overlaid on the brain at the level of $p=0.01$ uncorrected.
\begin{figure}
\begin{center}
\includegraphics[width=120mm]{figs/MUvPSCCAN.pdf}
% \includegraphics[width=50mm]{Pvalue_f_of_sparsenss_and_corr.pdf}
\end{center}
\vspace{-0.1in}
\caption{PSCCAN (right) versus mass-univariate uncorrected statistics
(left).  Both methods reveal similar areas of the brain.  However, the
mass-univariate results cannot be considered significant (after FDR
correction) due to the multiple comparisons problem.  It is possible
that another correction method would retain some of the mass-univariate
effects but we choose FDR because it is standard and only moderately
conservative.  We show, at right, the relationship of estimated
significance to variations in the sparseness parameter (for the image
voxel matrix $\X$) and PSCCA correlation.  The significant region is
outlined in a dashed box.  In a real study, one would only use the
pre-selected sparseness parameter.}
\label{fig:comp}
\end{figure}
\subsection{PBAC}
\paragraph{Description of cohort: }
104 subjects had complete cognitive evaluations as well as Siemens
3.0T T1 and DTI collected at the University of Pennsylvania. The
cohort contained subjects diagnosed with Alzheimer's disease (AD;
n=23), behavioral- variant frontotemporal degeneration (bvFTD; n=31),
primary progressive aphasia (PPA) variants of FTD (n=24), 17 with
extrapyramidal motor disorders, and 9 elderly controls. We use
multiple different disorders only to obtain variance in cognition but
do not include clinical diagnosis in subsequent analyses. We
normalized and segmented \cite{Avants2011a} the DT and T1 images using
the ITK-based open-source ANTs \cite{Avants2011} and Pipedream software.

\paragraph{Part 1-imaging \& cognition:} SCCAN identifies, for each PBAC domain, uniquely related WM regions. We perform the same type of study, independently, using GMD. The output from each run of SCCAN is the subset of WM / GM voxels that (as a set) relate most significantly to the cognitive domain of interest (e.g. language).
\newline
\newline
 We found significant associations between GM and each domain of
cognition consistent with putative neuroanatomical substrates at the
p<0.001 level. FA in WM was related to exec, soc, vs (p<0.05), weakly
related to memory (p<0.072) and unrelated to lang (p<0.89).
\newline
\paragraph{Part 2:}~We directly tested relationships between
 cognition-specific GMD and FA voxels derived from Part A. For
 example, we test if language-defined GMD voxels relate significantly
 to language-defined FA voxels, where SCCAN treats the voxels as a
 set.
\newline
\newline
 FA regions and GM regions were strongly related within each cognitive
domain (p<0.001) except for language where the relation was modest
(p<0.05). Fig 1 and 2 show the anatomic distribution of the
cognition-specific regions for both WM and GM for each cognitive
domain. Fig 3 shows the behav-based GMD and FA scatterplot.
\newline
\paragraph{Highlights:} Behav relates strongly to medial orbitofrontal cortex GM and genu in WM. Vs to occipital GM (cuneus) and occipital projections. Exec to insula, dorsolateral prefrontal, lateral orbitofrontal, and bilateral hippocampus GM regions and WM projections in the superior frontal lobe and the anterior callosum. Mem to GM insula, cuneus and posterior superior temporal gyrus, and WM fornix and superior longitudinal fasciculus.

\begin{figure}
\centering
\mbox{\subfigure{
    \includegraphics[height=1.5in]{figs/gm}
}
\quad
\subfigure{
    \includegraphics[height=1.5in]{figs/gm}
}
}
\caption{In this figure, we illustrate two dimensionality-reduction applications of the same
  class of the multivariate correlation-based method, sparse canonical
  correlation analysis (SCCA).  At left, {\bf we use SCCA as a direct tool for quantifying significant
  associations between cortical thickness and five neuropsychological
  batteries}: social behavior (apathy/disinhibition), executive
  function, language skill, visuospatial skill and memory.  SCCA draws out a network of
  voxels that, as a set, correlates optimally with each domain and
  the location of these networks  largely confirm putative brain-behavior
  relationships.  In a second study, right, {\bf we used SCCA as a feature
  selection tool to identify diagnosis-relevant imaging signatures of ADHD} from a large dataset of
  structural and resting state fMRI taken from ADHD and control
  subjects. The figure at right shows the features from the rsf MRI that are most relevant to ADHD-control classification and
improve performance by a factor of almost 10\% over using clinical variables
alone.  Lateral inferior prefrontal cortex, middle frontal gyrus and thalamus
connectivity with anterior cingulate were most important.} \label{fig:fig3}
\end{figure}

\section{Discussion and Conclusion}
In this paper we proposed a new statistical tool that is
ideal for multivariate imaging studies.
% We presented the theory behind
% PSCCA and also provided a highly efficient algorithm for solving the
% optimization problem. Our formulation also has two user defined
% sparsity parameters $\lambda_{\X}$ and $\lambda_{\Y}$ which the
% researcher can chose based on domain knowledge or select automatically
% by optimizing on a held out development set.
Results on synthetic and
real world data (OASIS) further corroborate our hypothesis that PSCCA
is able to increase detection power in the presence of covariates and
extract biologically plausible, multivariate patterns from neuroimaging
data.  Specifically, PSCCA reveals significant patterns of difference
between elderly and AD subjects that are within brain regions known to
be affected by Alzheimer's tauopathy.  Although the MU model fails to reveal
significant effects, there is notable similarity between regions selected by PSCCA and
those voxels in the brain that had uncorrected $p$-value $< 0.01$.  %This study has limitations.
In our experiments we only use the
primary eigenvector from PSCCA;
Future work will analyze the effect of including additional
eigenvectors and will seek to further investigate alternatives for
assessing PSCCA significance in interpretable ways. Finally, as in standard correlation, one should take care to visualize PSCCA results to investigate the potential impact of outliers.

% {\bf FINISH}
% despite the fact that we show similar biologically plausible patterns to univariate
% regression, though with greater power,
% difficulty of interpretation remains ....

 {\bf Our results confirm putative brain-behavior associations.}  At
 the least, they suggest unique relationships between cognitive variation
 and large-scale GM-WM networks that vary uniquely with cognitive domain. Furthermore,
 these results suggest that SCCAN may enhance detection power over
 traditional univariate approaches.  In particular, the significance
 of GM and cognition relationships ($\approx$  p<0.001) far exceeds those of the FA
 cognition relationships ($\approx$ p<0.05).  Despite this, there is
 significant association between FA-cognition identified voxels and GM-cognition
 identified voxels ($\approx$  p<0.001).

%\noindent{\bf Acknowledgment}
% This work is supported by Grant XXX
% 1R01EB006266-01
% from the ...
%National Institute Of Biomedical Imaging and Bioengineering and administered through the UCLA Center for Computational Biology.
\bibliographystyle{IEEEbib}
\bibliography{./cca}

\end{document}

\text{argmax}( \x,\y) :
~\text{Corr}~( \X \x , \Y \y) - \lambda_\x \| \x \|_1 - \lambda_\y \|  \y  \|_1 ,
\end{equation}
where $\X$ is a matrix with columns containing voxels from one set of
images of $n$ subjects,
and $\Y$ is a matrix with columns containing voxels from the second
set of images from the same $n$ subjects.
Corr computes Pearson correlation and the
$\lambda$ are inversely related to the sparseness costs, $C$.  %\vspace{-0.2in}

The covariance formulation of SCCA ....

Let's compute the canonical correlation between two matrices where we
assume the matrices have been normalized and, as such, CCA computes
$$ \rho = \frac{ x \X^T \Y y  }{ \sqrt{x  \X^T \X x}\sqrt{x  \Y^T \Y y}  } $$.  Now, we change bases by
using the whitening transform.
Redefine $\x =  ... $ Then, $\X \leftarrow \X \Sigma^{-1/2}_{XX}$ (same for $\Y$) and
$$ \rho = \frac{ x \X_w^T \Y_w \y  }{ ||x|| || y||} $$.
$$\rho = \frac{c^T \Sigma^{-1/2}_{XX} \Sigma_{XY}
  \Sigma^{-1/2}_{YY}}{\sqrt{c^Tc}\sqrt{d^Td}}$$

if matrices are whitened, then $\X \leftarrow \X \Sigma^{-1/2}_{XX}$
$$ \rho = \frac{c^T \Sigma_{XY}  d }{\sqrt{c^Tc}\sqrt{d^Td}}$$

The partial SCCA formulation will maximize

Generally, SCCA depends upon univariate models to
factor out the effects of confounding variables.  In this paper we present a
novel algorithm for computing partial sparse canonical correlation
analysis (PSCCA) and factor (``partial'') out the effect of unwanted covariates.

Sparse canonical correlation analysis (SCCA) is a powerful,
multivariate statistical tool for making unbiased inferences about the
relationship between different types of measurements taken on the same
population.