\documentclass[12pt]{article}
\usepackage{amsmath, amssymb, amsfonts, bm}
\usepackage{amsthm}
\usepackage{mathtools}

\usepackage{cite}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{color}
\usepackage{enumitem}
\usepackage{xspace}
\usepackage{units}

\usepackage[colorlinks=true,citecolor=blue,bookmarksnumbered=true,hyperfootnotes=true]{hyperref}
\usepackage{cleveref}

\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\newcounter{secnum}
\newcommand{\mysection}[1]{
   \refstepcounter{secnum}
   \subsubsection*{\large \textbf{\S\arabic{secnum}. #1}}
}

\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{remark}
\newtheorem*{notation}{Notation}
\newtheorem*{remark}{Remark}
\newtheorem*{note}{Note}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem*{fact}{Fact}
\newtheorem*{observation}{Observation}
\newtheorem*{condition}{Condition}
\newtheorem*{claim}{Claim}
\newtheorem*{example}{Example}

%Referencing
%cref declarations
\crefname{theorem}{Theorem}{Theorems}
\crefname{lemma}{Lemma}{Lemmas}
\crefname{proposition}{Proposition}{Propositions}
\crefname{corollary}{Corollary}{Corollaries}

\crefname{fact}{Fact}{Facts}
\crefname{observation}{Observation}{Observations}
\crefname{claim}{Claim}{Claims}
\crefname{condition}{Condition}{Conditions}

\crefname{example}{Example}{Examples}
\crefname{definition}{Definition}{Definitions}
\crefname{remark}{Remark}{Remarks}
\crefname{note}{Note}{Notes}
\crefname{notation}{Notation}{Notations}
\crefname{section}{Section}{Sections}
\crefname{appendix}{Appendix}{Appendices}

\crefname{secnum}{Section}{Sections}
\creflabelformat{secnum}{#2\S#1#3}

% Fancy lists using enumitem package
\setlist{leftmargin=*}
%\setitemize[1]{label=$\blacktriangleright$}
%\setitemize[2]{label=--}
\setenumerate[1]{label=\arabic*)}

\definecolor{Red}{rgb}{1,0,0}
\newcommand{\red}{\color{Red}}
\newcommand{\tsjnote}[1]{$\ll$\textsf{\red #1}$\gg$\marginpar{\tiny\bf TSJ}}

%\addtolength{\multlinegap}{1cm} % to squeeze in the equations

\newcommand{\etal}{\textit{et al.\/}\xspace}

\newcommand{\Reals}{\mathbb{R}}
\newcommand{\Ints}{\mathbb{Z}}

\newcommand{\zo}{\{0,1\}}
\newcommand{\eps}{\varepsilon}
\newcommand{\half}{\tfrac{1}{2}} % horizontal /
\newcommand{\slhalf}{\nicefrac{1}{2}} % slanted /

%\newcommand{\T}{\top}w
\newcommand{\T}{\mathsf{T}}

\newcommand{\ceq}{\coloneqq}

\DeclareMathOperator*{\E}{\mathbb{E}}
\DeclareMathOperator*{\argmin}{arg\,min}

\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\tuple}{\langle}{\rangle}
\DeclarePairedDelimiterX{\ip}[2]{\langle}{\rangle}{#1,#2}

\newcommand{\cX}{\mathcal{X}}
\newcommand{\cY}{\mathcal{Y}}

\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\vx}{\vect{x}}
\newcommand{\vy}{\vect{y}}

\newcommand{\dotp}{\ \tikz[baseline=-0.65ex]\draw[black,fill=black,radius=0.8pt] (0,0) circle ;\ }%
\newcommand{\argdot}{\,\tikz[baseline=-0.5ex]\draw[black,fill=black,radius=1pt] (0,0) circle ;\,}%

\newcommand{\COMMENT}[1]{}

\newcommand{\tk}{\hat{k}}

\begin{document}

Idealized equations:

\mysection{Control Unit}

\begin{align*}
&q_i = U_i^{[d \times 2d]} q + b_i^{[d]}  \tag{c0} \\
\cline{1-2}
&cq_i = W_{\textsf{cq}}^{[d \times d]} c_{i-1} + q_i  \tag{c1} \\
&ca_{is} = W_{\textsf{ca}}^{[1 \times d]} (cq_i \odot \mathbf{cw}_s)  \tag{c2.1}\\
&cv_{is} = \textrm{softmax}(ca_{is}) \tag{c2.2}\\
&\mathbf{c}_i = \sum_s cv_{is} \, \mathbf{cw}_s  \tag{c2.3}
\end{align*}
Only eqn.~(c0) above is \emph{position dependent}

\mysection{Read Unit}

\begin{align*}
&\mathbf{\tk}_{hw} = U_{\textsf{proj}}^{[d \times d]} \mathbf{k}_{hw} + b_{\textsf{proj}}^{[d]} \tag{r0} \\
\cline{1-2}
&I_{ihw} = \mathbf{m}_{i-1} \odot \mathbf{\tk}_{hw} \tag{r1} \\
&I'_{ihw} = \mathbf{\tk}_{hw}  + W_{\textsf{I}}^{[d \times d]} I_{ihw} + b_{\textsf{I}}^{[d]}  \tag{r2} \\
&ra_{ihw} = W_{\textsf{ra}}^{[1 \times d]} (\mathbf{c}_i \odot I'_{ihw})  \tag{r3.1}\\
&rv_{ihw} = \textrm{softmax}(ra_{ihw}) \tag{r3.2}\\
&\mathbf{r}_i = \sum_s rv_{ihw} \, \mathbf{\tk}_{hw}  \tag{r3.3}
\end{align*}

Note that $\mathbf{\tk}_{hw}$ can be \emph{precomputed} before the reasoning steps.

\mysection{Write Unit}

\begin{equation}
\mathbf{m}_i = W_{\textsf{m}}^{[d \times d]} \mathbf{r}_i + b_{\textsf{m}}^{[d]} \tag{w1}
\end{equation}

\end{document}


\section{Integer: Integers}

\subsection*{Types}
The various short cardinals and integers are for convenience.  The
Array is used as an index array several places in the library.

\subsection*{fmt, fmtArray}
Convenience functions.

\subsection*{Factoring: isprime}
This is defined in the xPrime module, but accessed from Integer.  [HGG: At one
time it was implemented in the Integer module, but compiling the
bitmap took too long.]

xPrime is mainly a bitmap of the cardinals from
0..46933.  Primes are marked 1 and nonprimes are marked 0.  The array is
0-based for processing convenience.  46933 was chosen as the sqrt of
the largest CARDINAL ($46933 > \sqrt{2^{31}}$).  In factoring problems,
we will not get anything larger than this.

The primes themselves were obtained from Project Gutenberg's prime11.txt
list.  They were converted to the bitmap format via a perl script:

\begin{tt} \begin{verbatim}
#file:     mkprime.pl
#abstract: Make a bitstring of primes
#          for use in Modula-3
#
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "$0 $mon/$mday/$year  $hour:$min\n";
print "Copyright (c) 1996, Harry George\n";

#---configuration---
$inname ="prime11.txt";
$outname="prime.m3";
$linewidth=60;
$maxline=4850;

#---open files---
open(INFILE,"<$inname") || die "cannot open $inname\n";
open(OUTFILE,">$outname") || die "cannot open $outname\n";

#---skip to line 300---
for ($i=0; $i<299; $i++) {
  $line=<INFILE>;
};

#---read data into array---
for ($i=1; $i<$maxline; $i++) {
  $line=<INFILE>; chop($line);
  push(@primes,$line);
};
$minprime=$primes[0];
$maxprime=$primes[$#primes];

#---generate the bitarray---
###select(STDOUT);
select(OUTFILE);

print "CONST MAXPRIME = $maxprime;\n";
print "TYPE  PrimeMap = ARRAY [0..MAXPRIME] OF BITS 1 FOR [0..1];\n";
print "CONST Primes   = PrimeMap{0\n";

$width=0; $currprime=shift(@primes);
for ($i=1; $i<$maxprime; $i++) {
    #---check linewidth---
    if ($width>=$linewidth/2) {
      $width=0;
      print "\n";
    };
    $width++;

    #---print map---
    if ($i<$currprime) {
      print ",0";
    }
    else {
      print ",1";
    	$currprime=shift(@primes);
    };
};

print "\n};\n";
select(STDOUT);

#---fini
close(OUTFILE);
print "min=$minprime, max = $maxprime\n";
\end{verbatim} \end{tt}

Numbers beyond 46933 are checked by trying to factor them.
If any factor is found, we return FALSE immediately.  If nothing is
found up to the number's sqrt, then we return TRUE.

\subsection*{Factoring: factor}
[HGG: This is a crude algorithm.  Surely there are better approaches
available.]  We start with the lowest prime and determine (via mod)
whether or not it divides evenly into the number being examined.
If it is divisible, we collect as many repititions of that factor
as we can, and then go on to the next prime.  As we go, the number being
examined is being divided by its factors, so it is getting smaller.
We continually check to see if it has become smaller than the next prime to
be checked.  When that is true, we quit.
Due to the halting criterion, primes are reported as themselves
to the 1st power.

We could probably add a test for exceeding the
maximum prime in the prime map.  In that case, we are (I think)
dealing with a prime in the range $\sqrt{2^{31}} \ldots 2^{31}$.

\subsection*{Factoring: gcd}
Greatest Common Demoninator is determined by Euclid's algorithm, which
is described in many sources.  We will reference Sedg88, pp 8-9.
Sedgewick gives an implementation in Pascal, and mentions an improvement
using mod.  We have implemented the improvement.

The idea is to find the largest factor (prime or not) which divides evenly
both the numerator and denominator of a fraction.  E.g.:
  $$\frac{12}{18}=\frac{2*6}{3*6}\mbox{\  thus\  }gcd=6$$

\subsection*{sqrt}
This comes from Hein96.  His example 2b was translated to
Modula-3.  Heinrich also provides several assembler implementations.

The idea is find $\sqrt{N}$ as the sum of two numbers: $N=
(u+v)^2=u^2+2uv+v^2$.  P. Heinrich notes that chosing $u$ and $v$
to fit base 2 operations (e.g., shift) allows a fast implementation.
Read his analysis for the full discussion.

The approach is based on recognition that
$\lfloor \log_2{N}\rfloor$ is found from the highest set bit.  And
$\lfloor \log_2{\sqrt{N}}\rfloor = \lfloor\log_2N^{1/2}\rfloor
= \lfloor 1/2\log_2{N}\rfloor$
is the highest set bit in $\lfloor \sqrt{N}\rfloor$.  It also depends on
the fact that if a number {\tt v} is a power of 2 such that it
has only one bit, {\tt vbit}, set, then we can multiply any number
by {\tt v} just be leftshifting {\tt vbit} times.

Given this, let $u=2^{\lfloor 1/2\log_2{N}\rfloor}$, so that u is the value
of the highest set bit.  Let $v$ be the value of the next lower bit.
Then calc $u^2+2uv+v^2$.  If this comes out $\le N$ then (at least) the
next lower bit must be set.  In that case let $u:=(u+v)$ and
go again.  The payoff is in being able to compute $u^2+2uv+v^2$ using
addition and shifts.  If we take $2uv+v^2 = v(2u+v)=v(u+u+v)$, we
need leftshift(u+u+v,vbit).  NOTE: Heinrich uses {\tt l2} for vbit,
but that is easily confused with the number twelve, and the significance
may be misunderstood.  In our implementation, we use vbit and we
reorder calculations to emphasize the importance of vbit and v.

How do we find vbit in the first place?
We could start at 31 and leftshift
until $u<0$, indicating that the 31st bit was set.  Or we could
start at 0 and rightshift until $u=0$, indicating there were no
more set bits. Which one works best depends on where vbit
resides on average.  We often use integer sqrt's in two places:
\begin{enumerate}
\item Graphics, where one might compute a distance as $\sqrt{x^2+y^2}$.
Given x and y in the range 0..1000, the sum is 0..1,000,000, or
vbit up to 20.
\item Data analysis, where one might compute $\sqrt{1/N\sum{(\bar{x}-x_i^2)}}$.
Data values here might be from 16-bit ADC's, with an average at mid range
or vbit around 15.
\end{enumerate}

This suggests that working from 0 upward is a good approach.
See the code comments for details.

Now that we have an approach, what is the interface?  Heinrich doesn't
statistice a specific domain in his article, but experimentation shows
that the algorithm cannot handle inputs whose sqrts are
larger than half the bits in the word.  In other words, for a 32-bit word,
$\sqrt{N} < 2^{16}$.  Examining the algorithm, we see this is because
u2 is obtained by leftshifting by vbits twice.  If vbit is over
halfway, we end up shifting data out of the word.
Thus, we need to place a range limitation on the inputs.

\subsection*{sin\_cos}
Coordinate Rotation Digital Computer (CORDIC) began with Volder in 1959.
We followed Jarv90, Bert92, and Turkowski's article in Gems90 (pg
494 and code on pg 773). While CORDICs can be used for other
transcendentals (see Jarv90), we just do sin and cos.  Mainly we
follow Bert92, though with bits=16 instead of 14.

The idea is to approximatrixe transcendental functions in ways that
require only integer-type operations such as shift and add.  The analysis
leads to the following equations:
\begin{eqnarray}
\mbox{bits} & = & \mbox{(whatever you choose)}\\
\mbox{base} & = & 2^{\mbox{bits}}\\
\mbox{radians\_to\_cordic} & = & \frac{\mbox{base}}{\pi / 2}\\
\mbox{cordic\_to\_real} & = & \frac{1}{\mbox{base}}\\
\mbox{expansion\_factor} & = & \prod_{i=0}^{\mbox{bits}}
      \sqrt{\frac{2^{2 \cdot i}+1}{2^{2 \cdot i}}}\\
\mbox{init\_val} & = & \frac{1}{\mbox{expansion\_factor}}\\
j & = & 0 \ldots \mbox{bits}\\
\mbox{atan\_table} & = & \arctan (\frac{1}{2^j})
      \cdot \mbox{radians\_to\_cordic}
\end{eqnarray}

It all starts with the number of bits.  We chose 16 as a convenient
number.  That gives 64K increments per quadrant or 256K around the
circle.  The numbers were computed in MathCad and copy-and-pasted
into Integer.m3. We used Turkowski's idea of hardcoding the
arctan table.  We used Bertrandom's idea of presetting x to a correction
factor prior to starting work.

The algorithm works by trying to coax the angle theta to 0, by
adding and subtracting smaller and smaller angles, obtained from the
arctan table. In lock step, we adjust x and y by the associated amounts
via shifting.  In the end, when theta reaches 0, x and y will be the
cos and sin in CORDIC units.  If we wish, we can divide the x and y values
by the base to get real numbers values, though this step is not
needed in an all-integer project.

The basic algorithm works in the first quadrant.  Jarvis warns that
the system doesn't always converge in other quadrants.  Bertrandom
works only in the first quadrant, and adjusts other values into
this quadrant.  We followed Bertrandom, but had trouble with his actual
quadrant decomposition.  As coded in Integer.m3, it works.  [HGG:
I wonder if there was a typo in the published article.]


\chapter{Integration of Non-Inclusive Contacts in Posture Generation}

\section{abstract}
In this paper we propose a simple way to formulate geometric contact formation to have an arbitrary intersection shape in a robotic (humanoid) posture generation problem. The contact shape is the outcome of our posture generator that is formulated as a non-linear optimization programming to fulfill a large variety of robot intrinsic limitations (e.g. joint and torque limits) and tasks (e.g. desired contact). Starting by defining convex areas of contact on the robot's body and the environment, that we call contact patches, we can generate contacts with arbitrary intersection of a pair of any of these predefined patches. Our geometric contact modeling writes very simply as additional constraints and variables added to the optimization problem, translating the search for an ellipse inscribed in the intersection of the pair of patches we want in contact. The result of our posture generator is then a configuration where contact patches are not necessarily included in one another. This allows our posture generator to propose contacts of different shapes with a non-predefined number of contact points (used later to compute reaction/contact forces). We illustrate the efficiency of our method in multi-contact posture generation with the HRP-2 and ATLAS humanoid robots with results that can not be generated automatically by existing methods.
%That is to say, the constraints formulating a new contact in the posture generator (that writes as a non-linear optimization problem), state that a surface is totally included into another. Moreover contact surfaces are modelled by four vertices only and are rectangular. This modelling has several limitations: (i) it excludes several viable solutions that the planar could exploit, (ii) it requires patching (by hand) the robot or the environment surfaces into somehow equivalent pieces of rectangles, (iii) do not allow singular contacts of type edge/plan (ladder) or rarely edge/edge and vertex/plan. The solution we provide solves this problem and extend our multi-contact planner possibilities to handle more complex scenarios without patching the robot or the environment surfaces and without limiting the number of contact points per surface of contact.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}
\label{sec:intro}

Generating viable robotic postures is a common problem encountered in sampling-based planning techniques and simulation of virtual characters. Generating desired initial, intermediary or finale posture configurations requires defining static task goals (e.g. reach a target point in 6D) to be done under intrinsic constraints such as joint limits, torque limits, avoiding non-desired self-collisions... and perceptual or extrinsic ones such as keeping an object in the embedded camera field-of-view, avoiding non-desired collisions with surrounding objects, etc. A common task objective assigned to virtual characters, avatars, or humanoid robots is to contact one or more of its links with the environment (e.g. feet touching the ground). Since our main applications target humanoid robots, we consider here posture generation problems inherent to these robots. However, the formalism applies to any kind of robots achieving contacts with its surroundings or itself.

Our problem is to generate multi-contact viable postures. As far as humanoids are concerned, we may add to the previously cited constraints, equilibrium and non-sliding. This paper is dedicated to the focused issue of how contact constraints can be written geometrically. Generating postures often uses state-of-the-art enhanced inverse kinematics or general-purpose non-linear optimization programming (where inverse kinematics can be seen as a particular solver case).

%\begin{figure}
%\centering
%\begin{subfigure}{.5\columnwidth}
%  \centering
%  \setlength\fboxsep{0pt}
%  \setlength\fboxrule{1pt}
%  \fbox{\includegraphics[width=\linewidth]{figure/hrp2_ladder_jrl.png}}
%  \label{fig:hrp2_jrl}
%\end{subfigure}%
%\begin{subfigure}{.5\columnwidth}
%  \centering
%  \setlength\fboxsep{0pt}
%  \setlength\fboxrule{1pt}
%  \fbox{\includegraphics[width=\linewidth]{figure/hrp2_ladder_jrl_zoom.pdf}}
%  \label{fig:hrp2_jrl_zoom}
%\end{subfigure}
%\caption{Using non-inclusive contacts for ladder climbing\\(green/red: contact polygons; blue: contact ellipse)}
%\label{fig:hrp2_jrl_complete}
%\end{figure}

\begin{figure}
\centering
  \centering
  \setlength\fboxsep{0pt}
  \setlength\fboxrule{1pt}
  \fbox{\includegraphics[width=.95\linewidth]{papers/IROS2014/figure/hrp2_ladder_jrl_5_combo.pdf}}
\caption{Using non-inclusive contacts for ladder climbing (green/red: contact polygons; blue: contact ellipse; red arrows: contact forces resultants)}
\label{fig:hrp2_jrl_complete}
\end{figure}

In general, desired contacts write as hard constraints to fulfill in an optimization problem. Yet, we need to write the maths for, say, put the gripper on the wall and the left foot on the ground. In general, the maths of a gripper is a complex geometric description, so is often that of the environment. A contact is generally defined by a pair of points (one on each object in contact) and a pair of normal vectors. A hard contact constraint boils down to finding a posture in which the predefined authorized contact points and normal of each body match~\cite{zhang:TePRA:2013}\cite{hauser:IJRR:2008}. Likewise, in~\cite{osswald:iros:2011}, the position of the feet of the NAO robot is manually tuned in order to obtain statically stable position during the climbing of a spiral staircase. In~\cite{Chestnutt:2009:BNR:1733023.1733314}, the surface in contact is chosen according to two criteria: the position of the force sensors of the feet, and the type of contact desired. In~\cite{sentis:itro:2010}, the problem of contact discovery in not considered. In~\cite{mordatch:acm:2012}, two surfaces are considered in contact as soon as the center point of one of them touches the other one and their normals match. Although used in many papers, it is not difficult to see that this definition of contact excludes a series of possibilities that would have been obtained if the predefined points were placed in different configurations within their respective patches. Once the contact is established, one determines the intersection of contacting surfaces in order to find points on which reaction forces are to be computed. Several approaches require fixing the number of contact points or to have inclusive contact (i.e. one patch is fully included in the other)~\cite{bouyarmane:ar:2012}.

We provide a simple solution that relaxes hard contact constraints and gets rid of predefining the contact points by allowing them to travel within the patches. We consider that a contact is valid if the intersection between two distinct patches has an area greater than a given threshold. To enforce this, we require this intersection to contain an ellipse whose surface can possibly be maximized. Convex patches allow writing the inscription constraints easily by means of half-spaces. We finally implement our solution and present some examples for complex multi-contact posture generations with the HRP-2 and ATLAS robots, as shown in~\Figref{fig:hrp2_jrl_complete}.

\section{Contact geometry formulation}

For our formulation, we consider a situation where a set of contacts between the robot and its environment are already made, and therefore fixed, and we want to add a new contact to this set. This doesn't induce any loss of generality since it just comes down to adding the contacts one by one.
To ensure that the new contact can be reached in a quasi-static way, we look for a configuration where the new contact is ``barely" made: the position of contact is reached, but that contact does not support any contact forces (this is a necessary step to generate a sequence of quasi-static transitions). We call it a geometric contact. Let us consider that the contact to add is defined by two flat surfaces $S_1$ and $S_2$ which are respectively delimited by two convex polygons $P_1$ and $P_2$. For this contact to be valid, it is obviously necessary that the intersection $P_1 \cap P_2$ is not empty. We propose a method in which the size of the contact area is approximated by the size of an ellipse that is inscribed in it. If such an ellipse is found and is of a sufficient size, then the contact is valid. This allows to consider contacts between surfaces that do not necessarily include each other.

An important remark is that the number of sides of the intersection polygon is not known a priori and, as shown on~\Figref{fig:polygon-inter}{}, this number can change depending on the configuration. Each time this number changes, the gradient of the area of the intersection is discontinuous. This is an issue for integrating any constraint or objective based on the area because we use a solver for smooth optimization problems. This issue could be dealt with by using non-smooth optimization routines, but such algorithms are slower and less available, and our posture generator is not designed to use them.
\begin{figure}[!htb]
 \centering
 \includegraphics[width=0.8\columnwidth]{papers/IROS2014/figure/polygon-inter.pdf}
 \caption{Topological instability of $P_1 \cap P_2$}
 \label{fig:polygon-inter}
\end{figure}
Moreover, supposing that we want to write constraints based on the sides of the contact area, then, the number of constraints would change with the number of vertex of $P_1 \cap P_2$. The large majority of the optimization softwares cannot deal with a non-constant number of constraints. The solution proposed in section~\ref{sec:ellipse} overcomes these issues by defining a set of constraints that is independent from the topology of the intersection area.

\section{Posture generation}
\label{sec:pg}

The posture generation process aims at finding a posture that satisfies a set of tasks $\left\{ \mathcal{T}_i \right\}$ and that minimizes a cost function $\mbox{\emph{Cost}}$ by solving the following problem:
\begin{align}
\min_{\bf q, \bf f, \tau} & \quad \mbox{\emph{Cost}}({\bf q,f,\tau}) \nonumber\\
\text{s.t.}&
\left\{
\begin{array}{lr}
q_i^- \le q_i \le q_i^+\ \ \forall i=1,...,n \\
\tau_i^- \le \tau_i \le \tau_i^+\ \ \forall i=1,...,n \\
\epsilon_{ij} \le d(r_i({\bf q}), r_j({\bf q})),\ \ \forall(i,j)\in\mathcal{I}_{auto} \\
\epsilon_{ik} \le d(r_i({\bf q}, O_k)),\ \ \forall(i,k)\in\mathcal{I}_{coll}\\
\tau + J({\bf q})^T{\bf f} = {\bf g(q)}\\
s({\bf q,f})\le 0,\\
g_i({\bf q,f,\tau}) = 0\ \ \forall\mathcal{T}_i,\\
h_i({\bf q,f,\tau}) \le 0\ \ \forall\mathcal{T}_i.
\end{array}\right.
\label{eq:PG}
\end{align}
where the optimization variables $\bf q$, $\bf f$ and $\tau$ stand for the configuration, contact forces and joint torques of the robot.
Those constraints are illustrated in~\Figref{fig:PG}{} and are, in order of appearance:
\begin{itemize}
\item Joint limits
\item Torque limits
\item Auto-collisions, with $d(X,Y)$ the signed distance between objects $X$ and $Y$ and $r_i(\bf q)$ is the i-th body of the robot at configuration $\bf q$. $\mathcal{I}_{auto}$ is the set of pairs of bodies to monitor.
\item Collisions with the environment, $O_k$ being the k-th object in the environment and $\mathcal{I}_{coll}$ the set of pairs to monitor
\item Equation of static stability, with $J$ the Jacobian matrix of all points where the contact forces are applied, and $\bf g$ the gravity term.
\item Stability constraints describing the friction cones
\item Equality constraints describing the task $\mathcal{T}_i$
\item Inequality constraints describing the task $\mathcal{T}_i$
\end{itemize}

\begin{figure}[!htb]
 \centering
 \includegraphics[width=.9\linewidth]{papers/IROS2014/figure/PG.png}
 \caption{Posture Generation's usual constraints}
 \label{fig:PG}
\end{figure}

A usual task $\mathcal{T}_i$ in the posture generation is to ensure that two surfaces are in contact. We consider 2 polygons $P_1$ and $P_2$ described in 2 frames $\mathcal{F}_1$ and $\mathcal{F}_2$, respectively. Each frame is defined by an origin point ${\bf O_i} = (o_i^x, o_i^y, o_i^z)$ and 3 orthogonal vectors $[{\bf T_i, B_i, N_i}]$. In those frames, the polygons are described as a set of $n_i$ bi-dimensional points $[p_i^0, p_i^1,\ldots, p_i^{n_i-1}]$ lying in the $[{\bf O_i, T_i, B_i}]$ plane.
To ensure the contact between those two surfaces, it is necessary that the planes defined by $[{\bf O_1, T_1, B_1}]$ and $[{\bf O_2, T_2, B_2}]$ are coplanar. This is expressed by the set of equations~(\ref{eq:coplanarity}). Those equations define a floating contact, where the co-planarity is ensured and the surfaces can translate along $\bf T_1$ and $\bf B_1$ and rotate around $\bf N_1$.
\begin{equation}
\left\{
\begin{array}{lr}
{\bf (O_2-O_1).N_1} = 0 \\
{\bf T_2.N_1} = 0 \\
{\bf B_2.N_1} = 0 \\
{\bf -N_2.N_1} \le 0
\end{array}
\right.
\label{eq:coplanarity}
\end{equation}

However, this is not sufficient since nothing ensures that the intersection of $P_1$ and $P_2$ is not empty.
Up to now, to avoid the problems described in section~\ref{sec:background}, we were requiring that one of the two polygons was completely included into the other (which restricted the contact configuration possibilities) or by defining a fixed contact position by hand, in which case the non-emptiness is ensured by the user. The next section presents a more general formulation
%The inclusion of the polygon $P_i$ in the polygon $P_j$ is imposed by making sure that each vertex of $P_i$ is on the left side of every edge of $P_j$, that is, assuming that both polyg polygonsons are described counter-clockwise around the ${\bf N}$ vector of the frame to which they are attached, the algorithm \ref{alg:inclusion} summarizes that constraint.
%\begin {algorithm}
%\caption{Surface inclusion constraints for $S_i \subset S_j$}
%\begin{algorithmic}
%\STATE {Let $S_i$ and $S_j$ be two coplanar plane surfaces}
%\STATE {$S_i = {p_0, p_1, \ldots, p_n}$ and $S_j = {q_0, q_1, \ldots, q_m}$}
%\STATE {$\vec{N}$ is $S_i$'s normal vector}
%\FOR{$k = 0 \to n$}
%\FOR{$l = 0 \to m$}
%\STATE { Constraint $: %\left[\overrightarrow{q_lp_k}\times\overrightarrow{q_lq_{l+1}}\right].\vec{N} \leq 0$}
%\ENDFOR
%\ENDFOR
%\end{algorithmic}
%\label{alg:inclusion}
%\end{algorithm}

\section{Non inclusive contact constraints}
\label{sec:ellipse}
\subsection{Main Idea}
\label{subsec:idea}
We present our main contribution: a smooth formulation of the non empty intersection between two contact surfaces. We assume that co-planarity of $S_1$ and $S_2$ is obtained by using the constraints presented in the previous section. Here we focus on the intersection of the two polygons $P_1$ and $P_2$, respectively describing the contours of $S_1$ and $S_2$.
As we pointed out earlier, a problem with computing the area of intersection of two polygons comes from the fact that depending on their positions in space, the number of edges of their intersection can change (cf.~\Figref{fig:polygon-inter}{}), which induces discontinuity of the gradient of the area and change of the number of constraints associated with this contact.

To avoid dealing with these changes of topology, we consider using an ellipse $\mathcal{E}$ included in $P_1 \cap P_2$ to estimate the area of the intersection. Since $P_1$ and $P_2$ are convex polygons, then $P_1 \cap P_2$ is also a convex polygon. A convex polygon can be seen as an intersection of half-planes based on the lines supporting its edges. Thus, an ellipse is inside a convex polygon if it lies entirely in the corresponding half-planes. Having the ellipse be included in the intersection of two polygons is equivalent to having it included in both polygons:
\begin{equation}
\mathcal{E} \subset P_1 \cap P_2 \ \Longleftrightarrow \
\mathcal{E} \subset P_1 \ \ \wedge \ \  \mathcal{E} \subset P_2
\end{equation}
Even if the number of edges of $P_1 \cap P_2$ can change, the numbers of edges of $P_1$ and $P_2$ respectively are fixed.
%\begin{wrapfigure}{r}{0.4\columnwidth}
%  \begin{center}
%    \includegraphics[width=0.4\columnwidth]{papers/IROS2014/figure/distance.pdf}
%    \caption{Distance ellipse-polygons}
%  \end{center}
%  \label{fig:distance}
%\end{wrapfigure}
%Therefore, if we ensure that the ellipse $\mathcal{E}$ is on the left side of each segment defining $P_1$ and $P_2$, then it is inside $P_1 \cap P_2$.
To assert that an ellipse lies in a half-plane, we need a function that is positive when the ellipse is in it (with zero value when the ellipse is on the edge) and negative if not. The signed distance to the line defining the half-space is a good candidate (distance ellipse-line if the ellipse is in the half-plane, opposite of the penetration distance if not), but actually, any pseudo-distance does the job. And a sufficient condition for the ellipse to be inside the polygons intersection is that the pseudo-distance between the ellipse and each edge of both polygons is positive (see~\Figref{fig:distance}{}). By considering each edge separately as opposed to the (pseudo-)distance of the ellipse to a whole polygon, we can write smooth constraints with a simple pseudo-distance function. We develop such a pseudo-distance in the next subsection.
%In order to measure the fact that a point is on the left side of an oriented segment we use a signed distance $d_s$, this signed distance is positive and equal to a usual distance when the point is on the left side of the segment and is negative and equal to the opposite of the usual distance when the point is on the right side of the segment.
% and algorithm~\ref{alg:ellipse-in-intersection} where $d_s$ stand for the pseudo-distance.
%\begin {algorithm}
%\caption{Inclusion of ellipse $\mathcal{E}$ in polygon intersection}
%\begin{algorithmic}
%\STATE {Let $P_1$ and $P_2$ be two coplanar convex polygons}
%\STATE {Let {\bf V} be an empty vector}
%\FORALL{Edge E in $P_1$}
%\STATE {Add $d_s(\mathcal{E}, E)$ to {\bf V}}
%\ENDFOR
%\FORALL{Edge E in $P_2$}
%\STATE {Add $d_s(\mathcal{E}, E)$ to {\bf V}}
%\ENDFOR
%\IF {{\bf V}$\succ 0$ (all terms of {\bf V} are positive)}
%\STATE {Return $\mathcal{E} \subset P_1 \cap P_2$}
%\ELSE
%\STATE {Return $\mathcal{E} \not\subset P_1 \cap P_2$}
%\ENDIF
%\end{algorithmic}
%\label{alg:ellipse-in-intersection}
%\end{algorithm}
%
\begin{figure}[!htb]
 \centering
 \includegraphics[width=0.4\columnwidth]{papers/IROS2014/figure/distance.pdf}
 \caption{Distance between $\mathcal{E}$ and $P_1 \cap P_2$}
 \label{fig:distance}
\end{figure}

\subsection{Pseudo-distance}
\label{subsec:formulation}
To estimate the constraint of inclusion of the ellipse $\mathcal{E}$ in both polygons $P_1$ and $P_2$, we need to compute the signed distance between $\mathcal{E}$ and each segment of the polygons. Computing the distance between an ellipse and a line is not straightforward, whereas the distance between a line and a circle is very easy to compute. Also, we note that in the frame $F_\mathcal{E}$ defined by the ellipse's axes and pseudo-radius, the ellipse is a circle of radius $r_{\mathcal{E}}=1$ (The x-unit along the first axis of the ellipse is $r_x$, the first radius of the ellipse, the y-unit along the second axis of the ellipse is $r_y$, the second radius). The transformation from the original frame $F_0$ in which the ellipse and the polygons are described to the ellipse's frame $F_\mathcal{E}$ is just the composition of a rotation and a scaling of the space along the axes of the ellipse with a scaling vector $[\frac{1}{r_x}, \frac{1}{r_y}]$. The effect of such a transformation applied to an ellipse and two polygons is shown in~\Figref{fig:pseudo-distance}{}. %Also, those transformations will not modify the validity of our constraint, indeed, the distance between $\mathcal{E}$ and any segment $E$, computed in $F_\mathcal{E}$, is a pseudo-distance in $F_0$. Therefore, we still get all the information needed to ensure the inclusion of $\mathcal{E}$ in $P_1 \cap P_2$.
We thus defined the following pseudo-distance from an ellipse to a half-plane as the signed Euclidean distance from the corresponding unit circle to the transformed half-plane in the frame $F_\mathcal{E}$.

\begin{figure}[!htb]
 \centering
 \includegraphics[width=\linewidth]{papers/IROS2014/figure/pseudo-distance.pdf}
 \caption{Transformation from $F_0(O_0, X_0, Y_0)$ to $F_\mathcal{E}(O_\mathcal{E},X_\mathcal{E},Y_\mathcal{E})$}
 \label{fig:pseudo-distance}
\end{figure}

Now let us consider a single segment $p_i p_j$ and an ellipse $\mathcal{E}$ defined in $F_0$.
The expression of a vector ${\bf v}_{F_0}^T = [v_x, v_y]_{F_0}$ in $F_\mathcal{E}$ is obtained by applying the formula~(\ref{eq:F0-to-FE})
\begin{equation}
{\bf v}_{F_\mathcal{E}} =
\begin{pmatrix}
\frac{1}{r_x} & 0 \\
0 & \frac{1}{r_y}
\end{pmatrix}
.\begin{pmatrix}
\cos(\theta) & \sin(\theta) \\
-\sin(\theta) & \cos(\theta)
\end{pmatrix}
.{\bf v}_{F_0}
\label{eq:F0-to-FE}
\end{equation}
In $F_\mathcal{E}$, the distance between the circumference of $\mathcal{E}$ and the segment $p_i p_j$ is:
\begin{equation}
	d_s(\mathcal{E}, p_i p_j) = \frac{ \left(\overrightarrow{p_i p_j}\right)_{F_\mathcal{E}} \times \left(\overrightarrow{p_i O_\mathcal{E}}\right)_{F_\mathcal{E}}}{\| \overrightarrow{p_i p_j}\|_{F_\mathcal{E}}}-r_{\mathcal{E}}
\end{equation}
where $\times$ denotes the cross product and $O_{\mathcal{E}}$ is the center of the ellipse.

To avoid numerical problems when the segment $p_i p_j$ is small, (see sec.~\ref{subsec:singular cases}), it is preferable to multiply this distance by $\| \overrightarrow{p_i p_j}\|_{F_\mathcal{E}}$ before using it as a constraint. Then we get the following constraint:
\begin{equation}
	-\left(\overrightarrow{p_i p_j}\right)_{F_\mathcal{E}} \times \left(\overrightarrow{p_i O_\mathcal{E}}\right)_{F_\mathcal{E}}+\| \overrightarrow{p_i p_j}\|_{F_\mathcal{E}} r_{\mathcal{E}} \leq 0
\label{eq:pseudo-distance}
\end{equation}

The combination of these equations~(\ref{eq:F0-to-FE}) and (\ref{eq:pseudo-distance}) applied for each edge of the polygons gives us all the necessary tools to develop a set of constraints that ensures that an ellipse is in the intersection of two polygons.

\subsection{Modification of the optimization problem}
To include the above idea in our posture generation, we need to modify the optimization problem~(\ref{eq:PG}) as follows.
Each non inclusive geometrical contact adds five variables to the optimization vector, corresponding to the position, orientation and radiuses of the ellipse ($x$, $y$, $\theta$, $r_x$ and $r_y$). One constraint of ellipse inclusion (as described above) is added to the problem for each edge of the polygons. The parameters $r_x$ and $r_y$ are given lower positive bounds to ensure that the ellipse is not empty. The existence of a contact between $S_1$ and $S_2$ is thus transformed into the existence of $r_x$ and $r_y$ respecting their bounds.
In summary, this kind of constraint adds 5 variables and $card(P_1)+card(P_2)$ constraints to the optimization problem, while the ``usual" inclusion constraint adds 0 variable and $card(P_1)card(P_2)$ constraints.
The existence of the contact can alternatively be enforced by imposing a minimum area for the ellipse.

\subsection{Maximization of the contact area}
\label{subsec:optim-ellipse-area}

%The previous section showed how to write a constraint describing the inclusion on any ellipse in the intersection of polygons. But it does not guarantee anything about the size of this ellipse nor about the size of the contact area.
The formulation in the above section only ensures the existence of a contact of minimal size.
However, one could want to make sure to find a contact area as large as possible, so that it is more likely to be able to support strong forces and ensure strong friction forces, which is helpful to ensure the stability of the robot. Therefore, it seems appropriate to try and maximize the area of contact between two polygons. As explained before, computing the area of the intersection surface is not a good practice in our case. But we know that the ellipse computed as above gives a lower bound of the contact area.
\begin{equation}
\mathcal{E} \subset P_1 \cap P_2 \Longrightarrow  \mathcal{A}(\mathcal{E}) \le \mathcal{A}(P_1 \cap P_2)
\end{equation}
with $\mathcal{A}(X)$ being the area of $X$.\newline
Therefore we can maximize the size of the ellipse in order to maximize the contact area. This is readily obtained by minimizing the value $\mbox{\emph{Cost}} = -\pi r_x r_y$ in the modified problem~(\ref{eq:PG}).
%This method can be applied by adding the opposite of the ellipse area multiplied by an appropriate weight factor to the cost function of the posture generator.
%Finding a suitable weight factor for this term of the cost function can be really difficult, because the range of value of the ellipse's area goes from $0$ to $\min (\mathcal{A}(P_1), \mathcal{A}(P_2))$, and this upper bound can be very small compared to other costs of the cost function. Then the area of the ellipse becomes negligible and is not maximized. So we decided to use the cost described in equation~\ref{eq:cost-ellipse} to maximize the area of contact. With this expression, we can be sure that the range of this cost is between $0$ and $W_\mathcal{E}$ which is chosen beforehand by the user.
In case there are other cost functions, the above cost can be added to them with a desired weight. This requires however to scale properly the cost so as to have a meaningful and easy-to-tune weight: the range of value of the ellipse's area goes from $0$ to $\mathcal{A}(P_1 \cap P_2) \leq \min (\mathcal{A}(P_1), \mathcal{A}(P_2))$. This latter quantity can be small (a typical area of contact of a humanoid robot is about $0.01m^2$, some environment surfaces can be smaller). To get a basic cost (before weighting) of magnitude around $1$, we use the following scaling:
\begin{equation}
\text{cost}(\mathcal{E}) = - \frac{ \pi r_x r_y}{ \min (\mathcal{A}(P_1), \mathcal{A}(P_2))}
\label{eq:cost-ellipse}
\end{equation}
This cost's absolute value will always be less than $1$, but not much less around the optimum, in most cases.

%That type of cost can be useful for posture generations in which the user can adjust the weight of the different costs to get the best result, but it would not be fit to be used for a whole multi contact planning because that would require too much human work to adjust the weight factor for each leaf of the planning. Then, another method must be used to ensure an acceptable size of the contact area. The simplest way to do that would be to impose a constraint that would set a lower bound to the radius of the ellipse $r_x^{\min} \le r_x$ and $r_y^{\min} \le r_y$

\subsection{Using a non inclusive contact to maintain stability}
\label{subsec:stability}
The method we presented so far allows finding a configuration in which a new non-inclusive contact is added, but this contact does not bear any force. It is found as a geometrical contact, but will eventually have to bear some forces, and thus, become a stability contact.
Usually, for a stability contact, each vertex of the contact area is considered as the application point of a force that has to be in a friction cone. Since our method allows dealing with surfaces that are intersecting each other, the contact surface is not known beforehand. Therefore, as soon as a non inclusive contact is going to be used for the stability, we compute the intersection of the two polygons $P_1$ and $P_2$ that are involved, and that intersection $P_1 \cap P_2$ is the contact surface, and its vertices will bear the forces. We do not present here the algorithm to compute the intersection of two convex polygons, as it can be found in the literature easily.
%Since this computation is done outside of the posture generation, it does not imply any numerical problems.

\subsection{Extension to singular cases}
\label{subsec:singular cases}
Our method can be extended to be used to approximate singular situations, such as finding an optimal contact with a linear or even punctual surface. This is done by giving a slight width to the point or the line. This approximation is physically grounded:
%The main problem with that kind of approach is that it is not possible to deal with a perfectly linear surface, that's why we call "line" a very thin rectangle and "point" a very small square.
in terms of real contacts, linear or punctual contacts do not exist. In fact, since all objects are deformable, even slightly, the contact area between two objects cannot be a perfect line, and must have a non-null area. Which justifies that linear and punctual contacts can be modeled as thin contact surfaces. By defining such a surface, we impose partly the orientation of the contact.
%A problem we encountered with that extension is that if the contact area is thin, then the ellipse  found inside this area will be thin too and thus have a small area. This lead to some conditioning problems and at first the solver would stop without optimizing the size of the ellipse. That was due to the fact that the area of the ellipse was negligible compared to the other costs involved in the cost function. That is why we divided the area of the ellipse by $\min (\mathcal{A}(P_1), \mathcal{A}(P_2))$ to get the equation~\ref{eq:cost-ellipse} in the first place.
Here again, one must be careful with numerical issues. Dealing with small numbers (here we would like to take width of a fraction of centimeter) may induce conditioning problems. Also, having two close parallel constraints of opposite direction (i.e. $g(x)\leq \alpha$ and  $-g(x)\leq \alpha$ with $\alpha$ small) is not a good practice in optimization as it will lead the solver to take small steps. Therefore, it is best to apply a scaling to the constraints by applying a geometrical scaling to $P_1$ and $P_2$ in the appropriate direction.\newline
Likewise, constraints on the area of the ellipse should be based on the same formulation as in equation~(\ref{eq:cost-ellipse}).

\section{Simulation results}
\label{sec:simu}

We dedicated considerable efforts in proposing a general multi-contact motion planner to solve cases of non-gaited acyclic planning. Given a humanoid robot, an environment, a start and a final desired postures, our planner generates a sequence of contact stances allowing any part of the humanoid to make contact with any part of the environment to achieve motion towards the goal. Our planner is thoroughly described in~\cite{escande:ras:2013}. Extensions of this multi-contact planner to multi-agent robots and objects gathering locomotion and manipulation are presented in~\cite{bouyarmane:ar:2012}, and preliminary validations with some DARPA challenge scenarios, such as climbing a ladder, ingress/egress a utility car or crossing through a relatively constrained pathway are presented in~\cite{bouyarmane:humanoids:2012}. In~\cite{escande:ras:2013} and~\cite{bouyarmane:ar:2012}, we describe works in multi-contact that are achieved by other colleagues in robotics.
In order to illustrate our method, we present some examples starring the HRP-2 and ATLAS humanoid robots, that are typical posture generations encountered in multi-contact planning.
%All the computations of the following experiments are performed on a single thread of an Intel(R) Core(TM) i7-3840QM CPU at 2.80GHz, with 16Go of RAM.
For the implementation of our posture generator, we use the RobOptim optimization framework~\cite{moulard:jsme:2013}{} relying on the IPOPT solver~\cite{wachter:mp:2006}{}.

\subsection{Inclined ladder climbing}
\label{subsec:Inclined ladder Climbing}

In this first example, we generate a posture that is part of an inclined ladder climbing planning.
We consider that the robot HRP-2 reached a posture in which its right foot is on the first step and its right hand is grasping the right guardrail, both of those contacts are bearing forces.
Those contacts are fixed, and we search a posture that adds to it a geometrical contact between the left foot and the second step.
We require the contact to include an ellipse with both radiuses bigger than 40\% of the ladder step's width.
The resulting posture and a close-up view of the contact areas are shown in~\Figref{fig:hrp2_darpa_complete}{}.
The latter shows clearly how an ellipse of sufficient size is found, included in the contact area between the left foot and the second step.
It also shows that the contact forces on the right foot are located on the vertex of the intersection of the contact surfaces between the right foot and the first step, which was also generated with our method, in a prior posture generation. One can note that we use a contact area slightly smaller than the actual surface under the foot of the robot. We use indeed safety margins to account for modeling errors so that the obtained posture is achievable by the real robot.
%\begin{figure*}
%\centering
%\begin{subfigure}{.5\textwidth}
%  \centering
%  \setlength\fboxsep{0pt}
%  \setlength\fboxrule{1pt}
%  %\fbox{\includegraphics[width=\linewidth]{papers/IROS2014/figure/hrp2_ladder_darpa.png}}
%  %\fbox{\includegraphics[width=\linewidth]{figure/hrp2_ladder_darpa_40.png}}
%  \fbox{\includegraphics[width=\linewidth]{figure/hrp2_darpa_small.png}}
%  %\caption{HRP2-10 ladder climbing posture}
%  \label{fig:hrp2_darpa}
%\end{subfigure}%
%\begin{subfigure}{.5\textwidth}
%  \centering
%  \setlength\fboxsep{0pt}
%  \setlength\fboxrule{1pt}
%  %\fbox{\includegraphics[width=\linewidth]{figure/hrp2_ladder_darpa_zoom.pdf}}
%  %\fbox{\includegraphics[width=\linewidth]{figure/hrp2_ladder_darpa_40_zoom.pdf}}
%  \fbox{\includegraphics[width=\linewidth]{figure/hrp2_darpa_small_zoom.pdf}}
%  %\caption{Upclose view of the contact areas (green and red: contact polygon, blue: ellipse found in contact area, Red arrows: contact forces resultants)}
%  \label{fig:hrp2_darpa_zoom}
%\end{subfigure}
%\caption{(a)HRP2-10 ladder climbing posture; (b)Upclose view of the contact areas\\(green/red: contact polygons; blue: ellipse found in contact area; red arrows: contact forces resultants)}
%\label{fig:hrp2_darpa_complete}
%\end{figure*}
\begin{figure}
\centering
\begin{subfigure}{.3325\columnwidth}
  \centering
  \setlength\fboxsep{0pt}
  \setlength\fboxrule{1pt}
  \fbox{\includegraphics[width=\linewidth]{papers/IROS2014/figure/hrp2_darpa_small_cut.png}}
  \label{fig:hrp2_darpa}
\end{subfigure}%
\begin{subfigure}{.6175\columnwidth}
  \centering
  \setlength\fboxsep{0pt}
  \setlength\fboxrule{1pt}
  \fbox{\includegraphics[width=\linewidth]{papers/IROS2014/figure/hrp2_darpa_small_zoom_cut.pdf}}
  \label{fig:hrp2_darpa_zoom}
\end{subfigure}
\caption{HRP2-10 ladder climbing posture and up close view of the contact areas (green/red: contact polygons; blue: contact ellipse; red arrows: contact forces resultants)}
\label{fig:hrp2_darpa_complete}
\end{figure}

\begin{figure*}
\centering
\setlength\fboxsep{0pt}
\setlength\fboxrule{1pt}
\fbox{\includegraphics[width=0.95\linewidth]{papers/IROS2014/figure/atlas_1_2_3_yellow.pdf}}
\caption{Atlas climbing stairs with small steps by maximizing the size of the contact areas\\(green/red: contact polygons; blue: contact ellipse; red arrows: contact forces resultants)}
\label{fig:atlas_SmallStairs}
\end{figure*}

\subsection{Vertical ladder climbing}
\label{subsec:ladder}

In the second example we generate a posture in which the robot climbs a vertical ladder.
In this particular step, the robot is using its right foot and both hands to maintain its stability on top of the first rung of the ladder. We search a posture that keeps those previous contacts and adds a geometrical contact between the left foot and the second rung of the ladder.
The result of that optimization can be observed on ~\Figref{fig:hrp2_jrl_complete}, with the robot posture on the left and a close-up look at the contact areas on the right.
The difficulty of this situation is that a contact has to be made with a very thin surface of the environment (the ladder rung). Usual contact generation method would reduce a lot the span of possible contact position (by patching the robot's foot with a very small surface or by imposing a set of authorized contact positions).
Whereas with our method, the contact configuration is found during the optimization process without requiring any extra human work. The contact chosen by our software includes an ellipse which first axis is the width of the robot's foot and second axis is as thin as the ladder rung.
One problem to expect is that numerical instability might happen if the surface of the rung is given too thin. But that would also happen with full inclusion constraints.
This example also illustrates one limitation of our method: it only considers planar contacts and if one wants to model a purely linear contact an other contact model must be used, since our modeling of those singular cases is approximative.
%is the first step of the HRP-2 robot climbing a ladder. The two hands are in bilateral contact with the two side bars of the ladder, the left foot is fixed on the ground and is the only part of the robot involved in the stability. The right foot is to make a contact with the first rung of the ladder. The rungs of the ladder are modeled by rectangles with a 6mm width which approximates the contact line as explained in section~\ref{subsec:singular cases}. %Therefore, the ellipse area maximization takes place in the intersection of the polygons representing the rung and the foot.
%The result of that optimization can be observed on ~\Figref{fig:ladder}{}.
%On the right of the simulation image is shown the disposition of the foot (in green) that is in geometrical non inclusive contact with a rung (in blue) and the optimal ellipse that has been found.

%From a planning point of view, this particular result is obviously not achievable as the right leg of the robot goes through the ladder, this will be discussed in the next section. Yet, the posture is perfectly valid as it respects of the constraints of problem~(\ref{eq:PG}). This example illustrates our method in a multi-contact environment with almost linear contacts.
%

\subsection{Climbing Stairs}
\label{subsec:smallStairs}

In a third simulation, the ATLAS robot climbs a flight of stairs.
All the steps are too small for the robot to put its entire foot on.
Therefore, it has to make a non inclusive contact and we propose to maximize the size of the contact area with the ellipse included in it, as explained in \ref{subsec:optim-ellipse-area}.
The size of the contact area is limited by the fact that the foot cannot penetrate the wall behind each step.
On~\Figref{fig:atlas_SmallStairs}, we present 3 postures generated on this environment.
On each of those postures, we see that the ellipse's size is maximized until the foot enters in collision with the vertical wall behind each step. And when possible, like on the last step, the contact area is maximized without collision limitation and the foot is positioned as fully included in the support surface.
We can see here that even when the size of the ellipse is maximized while competing with other non-linear constraints like collision avoidance, our method still works well and leads us to a satisfactory solution.

%Under each simulation result, an image presents the disposition of the foot (in green) that is in geometrical non inclusive contact with a step (in blue) and the optimal ellipse that has been found.
%It has to be noted that the green contact surface under a foot of the robot (green rectangle) is actually smaller than the actual foot due to our use of security margin for stability reason when experimenting with real robot and take into account an un-modeled flexibility at the ankle.
%That is why, with the collision avoidance activated between the foot and the next step, it seems that the foot is still far from the limit of the step (blue rectangle).
%Actually the foot is almost in collision with the vertical part of the next step.
%We decided not to present the initial and final steps of this hypothetical movement because they do not bear any interesting aspect as they both consist of the robot standing on a large flat surface.

%\begin{figure*}
%\centering
%\begin{subfigure}{.319\textwidth}
%  \centering
%  \includegraphics[width=\linewidth]{figure/SmallStairs2.png}
%\end{subfigure}%
%\begin{subfigure}{.3\textwidth}
%  \centering
%  \includegraphics[width=\linewidth]{figure/SmallStairs3.png}
%\end{subfigure}
%\begin{subfigure}{.3\textwidth}
%  \centering
%  \includegraphics[width=\linewidth]{figure/SmallStairs4.png}
%\end{subfigure}
%\caption{Using non-inclusive contacts for ladder climbing}
%\label{fig:hrp2_SmallStairs}
%\end{figure*}

%\subsection{Walking along a path made of small objects}
%
%In the second simulation, the HRP-2 robot has to cross a gap by making contacts
%with small surfaces. As well as for the previous simulation, the two objects
%with which the feet of the robot will be in contact are too small for making a
%complete contact, instead, non inclusive geometric contacts are found by
%maximizing the area of an ellipse that fits in the intersection of the polygons
%involved in the contact. Results are presented in ~\Figref{fig:riviere}. As
%we can see, the feet turns slightly, to be more aligned with the support
%surfaces, yet they do not become completely aligned with these supports, which would permit to get the biggest ellipse area. This is due to the fact that a posture cost is competing with the area cost, yielding this compromise.
%%Under each simulation result, an image presents the disposition of the foot (in green) that is in geometrical non inclusive contact with a step (in blue) and the optimal ellipse that has been found. We decided not to present the initial and final steps of this hypothetical movement because they do not bear any interesting aspect as they both consist of the robot standing on a large flat surface.
%
%\label{subsec:riviere}
%\begin{figure*}[!htb]
% \centering
% \includegraphics[width=0.75\textwidth]{figure/riviere3steps.pdf}
% \caption{Simulation results for crossing a gap by walking on small items}
% \label{fig:riviere}
%\end{figure*}
%
\section{Discussion and conclusion}
Generating arbitrary shaped contact areas proved to be doable very simply in an optimization-based posture generation module. We focused on writing constraints that have continuous gradients, since the posture generate problem is dominantly smooth. Hence, our geometric contact model can be useful for other optimization-based purposes, for example control or trajectory optimization, and any gradient-based descent scheme which handles inequalities (e.g.~\cite{escande:icra:2010}).
While we were expecting an increase of computation time due to the addition of new variables in the problem,
% (5 more for a total of 80-100 variables)
we noticed that the timings obtained with this method are sensibly the same that our previous version of the posture generator with full contact surface inclusion. Consequently, this method offering a richer contact search (exploration) during planning comes without degrading computation time. In fact, it truly allows us to substantially reduce the time spent by the user in ad-hoc tuning the shapes of the contact patches, or fixing the contact positions that were previously done by hand. Also, it is fairly easy to implement and extends a multi-contact planning algorithms like the one described in~\cite{escande:ras:2013}{} to give it richer planning possibilities.

There are several opportunities for future work. For example, we could improve the generality of our contact constraint formulation even further to manage linear and punctual contacts without the approximations we currently use. Also we could extend our method to allow dealing with non-convex surfaces. And finally we would like to apply our method to other fields that use contact generation, like trajectory or control optimization. Our methods extends straightforwardly to point cloud data as far as polygonal patches can be extracted.
%While we were expecting an increase of computation time due to the addition of new variables in the problem (5 more for a total of 80-100 variables), we were surprised by the obtained timings, around $10s$ while a usual posture generation is less than $1s$. Part of this increase is obviously due to the fact that we used finite differences to compute the gradients of the new constraints and objectives, and one of the immediate on-going works is to derive and implement efficiently analytical gradients. Still, we will also investigate more thoroughly how the new constraints interact with the existing ones to look for potential other causes for this increase.

%Finally, on a planning point of view, ~\Figref{fig:ladder} shows us a new challenge: while the posture found is perfectly correct as the robot is stable, not colliding with its environment and the contacts are where we asked them to be, the posture is obviously difficult to attain, if possible at all. We will need to investigate what type of heuristic to use to avoid this kind of results in the middle of a plan.


%
% CMPT 379: Principles of Compiler Design - A Course Overview
% Section: Optimization
%
% Author: Jeffrey Leung
%

\section{Optimization}
	\label{sec:optimization}
\begin{easylist}

& \textbf{Constant folding:} Compile-time preprocessing of constant values to avoid predictable runtime computation
& \textbf{Constant propagation:} If a variable is set to a constant, then replace all future variable uses with the constant (until the variable is reassigned)
& \textbf{Copy propagation:} Simplification of multiple computations of the same values
& \textbf{Dead code elimination:} Removal of code which will never be executed, used, or have any side effects

& \textbf{Algebraic simplification:} Basic arithmetic and algebraic simplifications which are computed during compile-time such as addition by 0 or multiplication by 0 or 1
& \textbf{Reduction of strength:} Replacement of exponentiation with multiplication

& Correctness: Optimizations must not change the meaning of a performance

\end{easylist}
\clearpage


%!TEX root = /Users/stevenmartell/Documents/iSCAM-project/docs/iSCAM-guide/userGuide/usrGuide.tex
\section{Model Documentation} % (fold)
\label{sec:model_documentation}

\begin{multicols}{2}

The section contains the documentation in mathematical form of the underlying age-structured model, and its steady state version that is used to calculate reference points, the observation models used in predicting observations, and the components of the objective function that formulate the statistical criterion (i.e., the objective function) that is used to estimate model parameters.  All of the model equations are laid out in tables and are intended to represent the order of operations, or pseudocode, in which to implement the model.  \iscam\ was implemented in AD Model Builder version 10.0 \citep{otterResearch,ADMB2009}.

\subsection{List of symbols} % (fold)
\label{sub:list_of_symbols}
A documented list of symbols for the \iscam program is found in Table~\ref{tab:list_of_symbols} on page~\pageref{tab:list_of_symbols}.

% subsection list_of_symbols (end)

\end{multicols}

% List of symbols
\begin{center}
\begin{longtable}{lll}
\caption[list of symbols]{A list of symbols, constants and description for variables used in \iscam.}
\label{tab:list_of_symbols} \tabularnewline

\hline
\multicolumn{1}{l}{\textbf{Symbol}} &
\multicolumn{1}{l}{\textbf{Value}} &
\multicolumn{1}{l}{\textbf{Description}} \tabularnewline
\hline
\endfirsthead

\multicolumn{3}{l}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}}
\tabularnewline
\hline
\multicolumn{1}{l}{\textbf{Symbol}} &
\multicolumn{1}{l}{\textbf{Value}} &
\multicolumn{1}{l}{\textbf{Description}} \tabularnewline
\hline
\endhead

\hline \multicolumn{3}{l}{{Continued on next page}} \tabularnewline
\hline
\endfoot

\hline \hline
\endlastfoot

\multicolumn{3}{l}{\underline{Indexes}}\\
a & & index for age\\
t & & index for year\\
k & & index for gear\\
\multicolumn{3}{l}{\underline{Model dimensions}}\\
$\acute{a}, A$  & 2, 10         & youngest and oldest age class ($A$ is a plus group)\\
$\acute{t}, T$  & 1951, 2010    & first and last year of catch data\\
$K$             & 5             & Number of gears including survey gears\\
\multicolumn{3}{l}{\underline{Observations (data)}}\\
$C_{k,t}$       & & catch in weight by gear $k$ in year $t$\\
$I_{k,t}$       & & relative abundance index for gear $k$ in year $t$\\
$p_{k,t,a}$     & & observed proportion-at-age $a$ in year $t$ for gear $k$\\
\multicolumn{3}{l}{\underline{Estimated parameters}}\\
$R_o$               & & Age-$\acute{a}$ recruits in unfished conditions\\
$\kappa$            & & recruitment compensation\\
$M$                 & & instantaneous natural mortality rate \\
$\bar{R}$           & & average age-$\acute{a}$ recruitment from year $\acute{t}$ to $T$\\
$\ddot{R}$          & & average age-$\acute{a}$ recruitment in year $\acute{t}-1$\\
$\rho$              & & fraction of the total variance associated with observation error\\
$\vartheta$         & & total precision (inverse of variance) of the total error\\
$\vec{\gamma}_k$    & & vector of selectivity parameters for gear $k$\\
$\digamma_{k,t}$    & & logarithm of the instantaneous fishing mortality for gear $k$ in year $t$\\
$\ddot{\omega}_a$   & & age-$\acute{a}$ deviates from $\ddot{R}$ for year $\acute{t}$\\
$\omega_t$          & & age-$\acute{a}$ deviates from $\bar{R}$ for years $\acute{t}$ to $T$\\
$\varphi_t$         & & logarithm of annual change in natural mortality rate\\
\multicolumn{3}{l}{\underline{Standard deviations}}\\
$\sigma_M$          &0.1    & standard deviation in random walk for natural mortality\\
$\sigma$            &       & standard deviation for observation errors in survey index\\
$\tau$              &       & standard deviation in process errors (recruitment deviations)\\
$\sigma_C$          &0.0707 & standard deviation in observed catch by gear\\
\multicolumn{3}{l}{\underline{Residuals}}\\
$\delta_t$      &   & annual recruitment residual\\
$\eta_t$        &   & residual error in predicted catch\\

\end{longtable}
\end{center}

\subsection{Analytic methods: equilibrium considerations} % (fold)
\label{sub:analytic_methods_equilibrium_considerations}

\begin{multicols}{2}
\subsubsection{A steady-state age-structured model} % (fold)
\label{ssub:a_steady_state_age_structured_model}

% subsubsection a_steady_state_age_structured_model (end)

For the steady-state conditions represented in Table~\ref{tab:equilibrium_model}, we assume the parameter vector $\Theta$ in \eqref{T2.1} is unknown and would eventually be estimated by fitting \iscam\ to data.  For a given set of growth parameters and maturity-at-age parameters defined by \eqref{T2.3}, growth is assumed to follow von Bertalanffy \eqref{T2.4}, mean weight-at-age is given by the allometric relationship in \eqref{T2.5}, and the age-specific vulnerability is given by a logistic function \eqref{T2.6}.  Note, however, there are alternative selectivity functions implemented in \iscam, the logistic function used here is simply for demonstration purposes.  Mean fecundity-at-age is assumed to be proportional to the mean weight-at-age of mature fish, where maturity at age is specified by the parameters $\dot{a}$ and $\dot{\gamma}$ for the logistic function.

Survivorship for unfished and fished populations is defined by \eqref{T2.8} and \eqref{T2.9}, respectively.  It is assumed that all individuals ages $A$ and older (i.e., the plus group) have the same total mortality rate.  The incidence functions refer to the life-time or per-recruit quantities such as spawning biomass per recruit ($\phi_E$) or vulnerable biomass per recruit ($\phi_b$).  Note that upper and lower case subscripts denote unfished and fished conditions, respectively.  Spawning biomass per recruit is given by \eqref{T2.10}, the vulnerable biomass per recruit is given by \eqref{T2.11} and the per recruit yield to the fishery is given by \eqref{T2.11b}.  Unfished recruitment is given by \eqref{T2.12} and the steady-state equilibrium recruitment  for a given fishing mortality rate $F_e$ is given by \eqref{T2.13}.  Note that in \eqref{T2.13} we assume that recruitment follows either a  Beverton-Holt or a Ricker model in the forms:
\[
R_e=\begin{cases}
    \dfrac{s_o R_e \phi_e}{1+\beta R_e \phi_e},& \mbox{Beverton-Holt}\\[5ex]
    s_o R_e \phi_e \exp(-\beta R_e \phi_e)& \mbox{Ricker}
\end{cases}
\]
where the maximum juvenile survival rate is the same for both forms of the recruitment model and is given by:
\[
s_o = \kappa/\phi_E,
\]
and the density-dependent term is given by:
\[
\beta =\begin{cases}
    \dfrac{(\kappa-1)}{R_o\phi_E}, & \mbox{Beverton-Holt}\\[5ex]
    {\dfrac {\ln  \left( \kappa \right) }{R_{{o}}\phi_{{E}}}} & \mbox{Ricker}
\end{cases}
\]
which simplifies to \eqref{T2.13}.
 The equilibrium yield for a given fishing mortality rate is \eqref{T2.14}.  These steady-state conditions are critical for determining various reference points such as \fmsy\ and \bmsy.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tablehere}
  %\centering
\caption{Steady-state age-structured model assuming unequal
vulnerability-at-age, age-specific natural mortality, age-specific
fecundity and Beverton-Holt type recruitment.}\label{tab:equilibrium_model}
\tableEq
    \begin{gather}
           \hline
        \mbox{Parameters} \nonumber \\
            \Theta = (B_o,\kappa,M_a,\hat{a},\hat{\gamma})      \label{T2.1}\\
            B_o>0; \kappa > 1; M_a > 0\\
            \Phi = (l_\infty, k, t_o,a,b,\dot{a},\dot{\gamma})  \label{T2.3}\\[1ex]
        %%
        %%
        \mbox{Age-schedule information} \nonumber\\
            l_a=l_\infty(1-\exp(-k(a-t_o)))                     \label{T2.4}\\
            w_a=a(l_a)^b                                        \label{T2.5}\\
            v_a=(1+\exp(-(\hat{a}-a)/\gamma))^{-1}              \label{T2.6}\\
            f_a=w_a(1+\exp(-(\dot{a}-a)/\dot{\gamma}))^{-1}     \label{T2.7}\\[1ex]
        %%
        %%
        \mbox{Survivorship} \nonumber\\
            \iota_a=\begin{cases} 1, &\quad a=1                 \label{T2.8}\\
            \iota_{a-1}e^{-M_{a-1}},&\quad a>1\\
            \iota_{a-1}/(1-e^{-M_a}),&\quad a=A \end{cases}\\
            \hat{\iota}_a=\begin{cases} 1, & a=1\\
            \hat{\iota}_{a-1}e^{-M_{a-1}-F_e v_{a-1}},& a>1\\
            \hat{\iota}_{a-1}e^{-M_{a-1}-F_e v_{a-1}}/(1-e^{-M_{a}-F_e v_{a}}),& a=A
            \end{cases}                                         \label{T2.9}\\[1ex]
        %%
        %%
        \mbox{Incidence functions} \nonumber \\
            \phi_E=\sum_{a=1}^\infty \iota_a f_a, \quad
            \phi_e=\sum_{a=1}^\infty \hat{\iota}_a f_a          \label{T2.10}\\
            \phi_B=\sum_{a=1}^\infty \iota_a w_a v_a, \quad
            \phi_b=\sum_{a=1}^\infty \hat{\iota}_a w_a v_a      \label{T2.11}\\
            \phi_q=\sum_{a=1}^\infty
                \frac{ \hat{\iota}_a w_a v_a}{M_a+F_ev_a}
                \left(1-e^{(-M_a-F_ev_a)}\right)                \label{T2.11b}\\[1ex]
        %%
        %%
        \mbox{Steady-state conditions} \nonumber \\
            R_o=B_o/ \phi_B                                     \label{T2.12}\\
            R_e=R_o\begin{cases}
            \dfrac{\kappa-\phi_E/\phi_e}{\kappa-1}&\mbox{Beverton-Holt}\\[2ex]
            \dfrac{\ln(\kappa)-\ln(\phi_E/\phi_e)}{\ln(\kappa)}& \mbox{Ricker}
            \end{cases}                                         \label{T2.13}\\
            C_e=F_e R_e \phi_q                                  \label{T2.14}\\[1ex]
        \hline \hline \nonumber
    \end{gather}
    \normalEq
\end{tablehere}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% subsection sub:analytic_methods_equilibrium_considerations (end)
\input{ModelAPI/msyBasedReferencePoints.tex}

\end{multicols}

\subsection{Analytic methods: state-dynamics} % (fold)
\label{sub:analytic_methods_state_dynamics}

\begin{multicols}{2}
The estimated parameter vector in \iscam\ is defined in \eqref{T4.1}, where $R_0, \kappa$ and $M$ are the leading unknown population parameters that define the overall population scale in the form of unfished recruitment and productivity in the form of recruitment compensation and natural mortality.  The total variance $\vartheta^2$ and the proportion of the total variance that is associated with observation errors $\rho$ are also estimated, then the variance is partitioned into observation errors ($\sigma^2$) and process errors ($\tau^2$) using \eqref{T4.2}.

The unobserved state variables \eqref{T4.3} include the numbers-at-age year year $t$ ($N_{t,a}$), the spawning stock biomass ($B_t$) and the total age-specific total mortality rate ($Z_{t,a}$).

The initial numbers-at-age in the first year \eqref{T4.4} and the annual recruits \eqref{T4.5} are treated as estimated parameters and used to initialize the numbers-at-age matrix.  Age-specific selectivity for gear type $k$ is a function of the selectivity parameters $\gamma_k$ \eqref{T4.6}, and the annual fishing mortality for each gear $k$ in year $t$ ($\digamma_{k,t}$).  The vector of log fishing mortality rate parameters $\digamma_{k,t}$ is a bounded vector with a minimum value of -30 and an upper bound of 3.0.  In arithmetic space this corresponds to a minimum value of 9.36e-14 and a maximum value of 20.01 for annual fishing mortality rates.  In years where there are 0 reported catches for a given fleet, no corresponding fishing mortality rate parameter is estimated and the implicit assumption is there was no fishery in that year.

There is an option to treat natural mortality as a random walk process \eqref{T4.6b}, where the natural mortality rate in the first year is the estimated leading parameter \eqref{T4.1} and in subsequent years the mortality rate deviates from the previous year based on the estimated deviation parameter $\varphi_t$.  If the mortality deviation parameters are not estimated, then $M$ is assumed to be time invariant.

State variables in each year are updated using equations \ref{T4.8}--\ref{T4.11}, where the spawning biomass is the product of the numbers-at-age and the mature biomass-at-age \eqref{T4.8}.  The total mortality rate is given by \eqref{T4.9}, and the total catch (in weight) for each gear is given by \eqref{T4.10} assuming that both natural and fishing mortality occur simultaneously throughout the year.  The numbers-at-age are propagated over time using \eqref{T4.11}, where members of the plus group (age $A$) are all assumed to have the same total mortality rate.

Recruitment to age $k$ can follow either a Beverton-Holt model \eqref{T4.12} or a Ricker model \eqref{T4.13} where the maximum juvenile survival rate ($s_o$) in either case is defined by $s_o=\kappa/\phi_E$.  For the Beverton-Holt model, $\beta$ is derived by solving \eqref{T4.12} for $\beta$ conditional on estimates of $\kappa$ and $R_o$:
\[
\beta = \frac{\kappa-1}{R_o \phi_E},
\]
and for the Ricker model this is given by:
\[
\beta = \frac{\ln(\kappa)}{R_o \phi_E}
\]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tablehere}
  \centering
\caption{Statistical catch-age model using the Baranov catch.}
\label{tab:statistical_catch_age_model}
\tableEq
    \begin{align}
        \hline \nonumber \\
        &\mbox{Estimated parameters} \nonumber\\
        \begin{split}
        \Theta&=
                (R_0,\kappa,M,\bar{R},\rho,\vartheta^2,\gamma_{k},%\bar{F}_k,
                \digamma_{k,t},\\
        &\quad \{\omega_t\}_{t=1-A}^{t=T},
                \{\varphi_t \}_{t=2}^T)
    \end{split} \label{T4.1}\\
        \sigma^2&=\rho /\vartheta^2, \quad
        \tau^2=(1-\rho)/\vartheta^2\label{T4.2}\\[1ex]
        %\vartheta^2=\sigma^2+\tau^2, \quad
        %\rho=\frac{\sigma^2}{\sigma^2+\tau^2}\label{T4.3}\\[1ex]
        %%
        %%
        &\mbox{Unobserved states} \nonumber\\
        &N_{t,a},B_t,Z_{t,a}    \label{T4.3}\\
    %%
    %%
        &\mbox{Initial states} \nonumber\\
        %v_a=\left[1+e^{-(\hat{a}-a)/\hat{\gamma}}\right]^{-1}\label{T4.7}\\
        N_{t,a}&=\bar{R}e^{\omega_{t-a}} \exp(-M_t)^{(a-1)};\quad t=1;  2\leq a\leq A \label{T4.4}\\
        N_{t,a}&=\bar{R}e^{\omega_{t}} ;\quad 1\leq t\leq T;  a=1 \label{T4.5}\\
        v_{k,a}&=f(\gamma_k) \label{T4.6}\\
        M_t &= M_{t-1} \exp(\varphi_t), \quad t>1 \label{T4.6b}\\
        F_{k,t}&=\exp(\digamma_{k,t}) \label{T4.7}\\[1ex]
        %%
        %%
        &\mbox{State dynamics (t$>$1)} \nonumber\\
        B_t&=\sum_a N_{t,a}f_a \label{T4.8}\\
        Z_{t,a}&=M_t+\sum_k F_{k,t} v_{k,t,a}\label{T4.9}\\
        \hat{C}_{k,t}&=\sum _ a\frac {N_{{t,a}}w_{{a}}F_{k,t} v_{{k,t,a}}
        \left( 1-{e^{-Z_{t,a}}} \right) }{Z_{t,a}}^{\eta_t} \label{T4.10}\\
        %F_{t_{i+1}}= \ F_{t_{i}} -\frac{\hat{C}_t-C_t}{\hat{C}_t'} \label{T4.12}\\
        N_{t,a}&=\begin{cases}
            %\dfrac{s_oE_{t-1}}{1+\beta E_{t-1}} \exp(\omega_t-0.5\tau^2) &a=1\\ \\
            N_{t-1,a-1} \exp(-Z_{t-1,a-1}) &a>1\\
            N_{t-1,a} \exp(-Z_{t-1,a}) & a=A
        \end{cases}\label{T4.11}\\[1ex]
        %%
        %%
        &\mbox{Recruitment models} \nonumber\\
        R_t &= \frac{s_oB_{t-k}}{1+\beta B_{t-k}}e^{\delta_{t}-0.5\tau^2} \quad \mbox{Beverton-Holt} \label{T4.12}\\
        R_t &= s_oB_{t-k}e^{-\beta B_{t-k}+\delta_t-0.5\tau^2} \quad \mbox{Ricker} \label{T4.13}\\
    %%        \mbox{Residuals \& predicted observations} \nonumber\\
    %%        \epsilon_t=\ln\left(\frac{I_t}{B_t}\right)-\frac{1}{n}\sum_{t \in I_t}\ln\left(\frac{I_t}{B_t}\right)\label{T4.15}\\
    %%        \hat{A}_{t,a}=\dfrac{N_{t,a}\dfrac{F_tv_a}{Z_{t,a}}\left(1-e^{-Z_{t,a}}\right)}
    %%        {\sum_a N_{t,a}\dfrac{F_tv_a}{Z_{t,a}}\left(1-e^{-Z_{t,a}}\right)}\label{T4.16}\\
        \hline \hline \nonumber
    \end{align}

    \normalEq
\end{tablehere}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsubsection{Options for selectivity ($v_{k,t,a}$)} \label{ModelDocSelectivity}

At present, there are six alternative age-specific selectivity options in \iscam.  The simplest of the selectivity options is a simple logistic function with two parameters where it is assumed that selectivity is time-invariant.  The more complex selectivity options assume that selectivity may vary over time a may have as many as (A-1)$\cdot$T parameters.  For time-varying selectivity, cubic and bicubic splines are used to reduce the number of estimated parameters.  Prior to parameter estimation, \iscam\ will determine the exact number of selectivity parameters that need to be estimated based on which selectivity option was chosen for each gear type.  It is not necessary for all gear types to have the same selectivity option.  For example it is possible to have a simple two parameter selectivity curve for say a survey gear, and a much more complicated selectivity option for a commercial fishery.

\paragraph{Logistic selectivity}
The logistic selectivity option is a two parameter model of the form
\[
v_a = \frac{1}{1+ \exp{(-(a-\mu_{a})/\sigma_a)}}
\]
where $\mu_a$ and $\sigma_a$ are the two estimated parameters representing the age-at-50\% vulnerability and the standard deviation, respectively.

\paragraph{Age-specific selectivity coefficients}
The second option also assumes that selectivity is time-invariant and estimates at total of $A$-1 selectivity coefficients, where the plus group age-class is assumed to have the same selectivity as the previous age-class.  For example, if the ages in the model range from 1 to 15 years, then a total of 14 selectivity parameters are estimated, and age-15+ animals will have the same selectivity as age-14 animals.

When estimating age-specific selectivity coefficients, there are two additional penalties that are added to the objective function that control how much curvature there is and limit how much dome-shaped can occur.  To penalize the curvature, the square of the second differences of the vulnerabilities-at-age are added to the objective function:
\[
\lambda_k^{(1)} \sum_{a=2}^{A-1}(v_{k,a} - 2v_{k,a-1} + v_{k,a-2})^2
\]
The dome-shaped term penalty as:
\[
\begin{cases}
\lambda_k^{(2)} \sum_{a=1}^{A-1}(v_{k,a} - v_{k,a+1})^2& \mbox(if) v_{k,a+1}< v_{k,a}\\
0 & \mbox(if) v_{k,a+1}\geq v_{k,a}
\end{cases}
\]
For this selectivity option the user must specify the relative weights ($\lambda_k^{(1)},\lambda_k^{(2)}$) to add to these two penalties.

\paragraph{Cubic spline interpolation}
The third option also assumes time-invariant selectivity and estimates a selectivity coefficients for a series age-nodes (or spline points) and uses a natural cubic spline to interpolate between these nodes (Figure \ref{Fig2}). Given $n+1$ distinct knots $x_i$, selectivity can be interpolated in the intervals defined by
\[
S(x) = \begin{cases}
    S_0(x) & x \in [x_0,x_1]\\
    S_1(x) & x \in [x_1,x_2]\\
    ...\\
    S_{n-1}(x) & x \in [x_{n-1},x_n]
\end{cases}
\]
where  $S''(x_0) = S''(x_n)=0$  is the condition that defines a natural cubic spline.
\begin{figurehere}
    \centering
    % Requires \usepackage{graphicx}
    \includegraphics[width=\columnwidth]{iscamFigs/SplineEg.eps}\\
    \caption{Example of a natural cubic spline interpolation for estimating selectivity coefficients.  In \iscam\ the user specifies the number of nodes (circles) to estimate; then age-specific selectivity coefficients are interpolated using a natural cubic spline.}\label{Fig2}
\end{figurehere}

The same penalty functions for curvature and dome-shaped selectivity are also invoked for the cubic spline interpolation of selectivity.

\paragraph{Time-varying selectivity with cubic spline interpolation} A fourth option allows for cubic spline interpolation for age-specific selectivity  in each year.  This option adds a considerable number of estimated parameters but the most extreme flexibility.  For example, given 40 years of data and estimated 5 age nodes, this amounts 200 (40 years times 5 ages) estimated selectivity parameters.  Note that the only constraints at this time are the dome-shaped penalty and the curvature penalty; there is no constraint implemented for say a random walk (first difference) in age-specific selectivity).  As such this option should only be used in cases where age-composition data is available for every year of the assessment.

\paragraph{Bicubic spline to interpolate over time and ages}  The fifth option allows for a two-dimensional interpolation using a bicubic spline (Figure \ref{Fig3}).  In this case the user must specify the number of age and year nodes.  Again the same curvature and dome shaped constraints are implemented.  It is not necessary to have age-composition data each and every year as in the previous case, as the bicubic spline will interpolate between years.  However, it is not advisable to extrapolate selectivity back in time or forward in time where there are no age-composition data unless some additional constraint, such as a random-walk in age-specific selectivity coefficients is implemented (as of \today, this has not been implemented).

\begin{figure*}[!tbp]
    % Requires \usepackage{graphicx}
    \centering
    \includegraphics[width=0.9\textwidth]{iscamFigs/BicubicEg.eps}\\
    \caption{Example of a time-varying cubic spline (left) and bicubic spline (right) interpolation for selectivity as applied to the Pacific hake data. The panel on the left contains 165 estimated selectivity parameters and the bicubic interpolation estimates 85 selectivity parameters, or 5 age nodes and 17 year nodes. There are 495 actual nodes being interpolated.}\label{Fig3}
\end{figure*}
%\end{multicols}

\subsection{Residuals, likelihoods \& objective function value components}
%\begin{multicols}{2}
There are 3 major components to the overall objective function that are minimized while \iscam\ is performing maximum likelihood estimation.  These components consist of the likelihood of the data, prior distributions and penalty functions that are invoked to regularize the solution during intermediate phases of the non-linear parameter estimation.  This section discusses each of these in turn, starting first with the residuals between observed and predicted states followed by the negative loglikelihood that is minimized.

\subsubsection{Catch data}
It is assumed that the measurement errors in the catch observations are log-normally distributed, and the residuals is given by:
\begin{equation}\label{eq2}
\eta_{k,t}=\ln(C_{k,t}+o) -  \ln(\hat{C}_{k,t}+o),
\end{equation}
where $o$ is  a small constant (1.e-10) to ensure the residual is defined in the case of a 0 catch observation.  The residuals are assumed to be normally distributed with a user specified standard deviation $\sigma_{C}$.  At present, it is assumed that observed catches for each gear $k$ is assumed to have the same standard deviation.  To aid in parameter estimation, two separate standard deviations are specified in the control file: the first is the assumed standard deviation used in the first, second, to N-1 phases, and the second is the assumed standard deviation in the last phase.  The negative loglikelihood (ignoring the scaling constant) for the catch data is given by:
\begin{equation}\label{eq3}
\ell_C = \sum_k\left[  T_k\ln(\sigma_C)+\frac{\sum_t(\eta_{k,t})^2}{2\sigma_C^2}\right],
\end{equation}
where $T_k$ is the total number of catch observations for gear type $k$.

\subsubsection{Relative abundance data}
The relative abundance data are assumed to be proportional to biomass that is vulnerable to the sampling gear:
\begin{equation}\label{eq4}
 V_{k,t} = \sum_a N_{t,a} e^{-\lambda_{k,t} Z_{t,a}} v_{k,a} w_a,
\end{equation}
where $v_{k,a}$ is the age-specific selectivity of gear $k$, and $w_a$ is the mean-weight-at-age. A user specified fraction of the total mortality $\lambda_{k,t}$ adjusts the numbers-at-age to correct for survey timing.  The residuals between the observed and predicted relative abundance index is given by:
\begin{equation}\label{eq5}
\epsilon_{k,t} = \ln(I_{k,t}) - \ln(q_k)+\ln(V_{k,t}),
\end{equation}
where $I_{k,t}$ is the observed relative abundance index, $q_k$ is the catchability coefficient for index $k$, and $V_{k,t}$ is the predicted vulnerable biomass at the time of sampling.  The catchability coefficient $q_k$ is evaluated at its conditional maximum likelihood estimate:
\[
  q_k =\frac{1}{N_k} \sum_{t \in I_{k,t}} \ln(I_{k,t}) - \ln(V_{k,t}),
\]
where $N_k$ is the number of relative abundance observations for index $k$ \citep[see][for more information]{walters1994calculation}. The negative loglikelihood for relative abundance data is given by:
\begin{align}
\ell_I &= \sum_k \sum_{t \in I_{k,t}}  \ln(\sigma_{k,t})+\frac{\epsilon_{k,t}^2}{2\sigma_{k,t}^2} \label{eq6}\\
&\mbox{where}\nonumber\\
\sigma_{k,t} &= \frac{\rho \varphi^2}{ \omega_{k,t}},  \nonumber
\end{align}
where $\rho \varphi^2$ is the proportion of the total error that is associated with observation errors, and $\omega_{k,t}$ is a user specified relative weight for observation $t$ from gear $k$.  The $ \omega_{k,t}$ terms allow each observation to be weighted relative to the total error $\rho \varphi^2$; for example, to omit a particular observation, set $\omega_{k,t}=0$, or to give 2 times the weight, then set  $\omega_{k,t}=2.0$. To assume all observations have the same variance then simply set  $\omega_{k,t}=1$.  Note that if  $\omega_{k,t}=0$ then equation \eqref{eq6} is undefined; therefore, \iscam\ adds a small constant to  $\omega_{k,t}$ (1.e-10, which is equivalent to assuming an extremely large variance)  to ensure the likelihood can be evaluated.

\subsubsection{Age composition data}\label{agecomps}
Sampling theory suggest that age composition data are derived from a multinomial distribution \citep{fournier1982general}; however, \iscam\ assumes that age-proportions are obtained from a multivariate logistic distribution \citep{schnute1995influence,richards1997visualizing}.  The main reason \iscam\ departs from the traditional multinomial model has to do with how the age-composition data are weighted in the objective function.  First, the multinomial distribution requires the specification of an effective sample size; this may be done arbitrarily or through iterative re-weighting \citep{MCALLISTER1997,gavaris2002sif}, and in the case of multiple and potentially conflicting age-proportions this procedure may fail to converge properly.  The assumed effective sample size can have a large impact on the overall model results.

A nice feature of the multivariate logistic distribution is that the age-proportion data can be weighted based on the conditional maximum likelihood estimate of the variance in the age-proportions.  Therefore, the contribution of the age-composition data to the overall objective function is ``self-weighting'' and is conditional on other components in the model.

Ignoring the subscript for gear type for clarity, the observed and predicted proportions-at-age must satisfy the constraint
\[
 \sum_{a=1}^A p_{t,a} = 1
\]
for each year. The residuals between the observed ($p_{t,a}$) and predicted proportions ($\widehat{p_{t,a}}$) is given by:
\begin{equation}\label{eq7}
\eta_{t,a}=\ln(p_{t,a})-\ln(\widehat{p_{t,a}})-\frac{1}{A}\sum_{a=1}^A\left[\ln(p_{t,a})-\ln(\widehat{p_{t,a}}) \right].
\end{equation}
The conditional maximum likelihood estimate of the variance is given by
\[
\widehat{\tau}^2=\frac{1}{(A-1)T}\sum_{t=1}^T\sum_{a=1}^A \eta_{t,a}^2,
\]
and the negative loglikelihood evaluated at the conditional maximum likelihood estimate of the variance is given by:
\begin{equation}\label{eq8}
    \ell_A = (A-1)T \ln(\widehat{\tau}^2).
\end{equation}
In short, the multivariate logistic likelihood for age-composition data is just the log of the residual variance weighted by the number observations over years and ages.

%Add technical details about requiring the minimum p_{t,a} to be greater than 2% "Grouping".
There is also a technical detail in \eqref{eq7}, where observed and predicted proportions-at-age must be greater than 0.  It is not uncommon in catch-age data sets to observe 0 proportions for older, or young, age classes.  \iscam\ adopts the same approach described by \cite{richards1997visualizing} where the definition of age-classes is altered to require that $p_{t,a}\geq 0.02$ for every age in each year.  This is accomplished by grouping consecutive ages, where $p_{t,a} <0.02$, into a single age-class and reducing the effective number of age-classes in the variance calculation ($\widehat{\tau}^2$) by the number of groups created.  The choice of 2\% is arbitrary and the user can specify the minimum proportion (including 0) to consider when pooling age-proportion data.  In the case of an exact 0 in the observed age-proportions the pooling of the adjacent age-class still occurs, this ensures that \eqref{eq7} is defined.

A \textbf{WARNING} about extremely weak year classes is required here.  A potential problem exists if in fact there is a very small cohort relative to the adjacent cohorts such that it never makes up more than say 2\% (or whatever minimum is specified) of the age-proportions in any given year.  In such cases, the information in the age-composition data about this weak year class relative to of that the adjacent (younger) year class because its always pooled into the younger year class.  \iscam\ will actually estimate two strong cohorts instead of correctly estimating one strong and one weak cohort in the following year.

\subsubsection{Stock-recruitment}
There are two alternative stock-recruitment models available in \iscam: the Beverton-Holt model and the Ricker model.  Annual recruitment and the initial age-composition are treated as latent variables in \iscam, and residuals between estimated recruits and the deterministic stock-recruitment models are used to estimate unfished spawning stock biomass and recruitment compensation.  The residuals between the estimated and predicted recruits is given by
\begin{equation}\label{eq9}
    \delta_t = \ln(\bar{R}e^{w_t}) - f(B_{t-k})
\end{equation}
where $f(B_{t-k})$ is given by either \eqref{T4.12} or \eqref{T4.13}, and $k$ is the age at recruitment.  Note that a bias correction term for the lognormal process  errors is included in  \eqref{T4.12} and \eqref{T4.13}.

The negative log likelihood for the recruitment deviations is given by the normal density (ignoring the scaling constant):
\begin{equation}\label{eq10}
 \ell_\delta = n\ln(\tau) + \frac{\sum_{t=1+k}^T \delta^2_t}{2\tau^2}
\end{equation}
Equations \eqref{eq9} and \eqref{eq10} are key for estimating unfished spawning stock biomass and recruitment compensation via the recruitment models.  The relationship between ($s_o,\beta$) and ($B_o,\kappa$) is defined as:
\begin{align}
s_o &= \kappa/\phi_E\\
\beta&=\begin{cases}
\frac{\kappa-1}{B_o} \quad \mbox{Beverton-Holt}\\[1ex]
\frac{\ln(\kappa)}{B_o} \quad \mbox{Ricker}
\end{cases}
\end{align}
where $s_o$ is the maximum juvenile survival rate, and $\beta$ is the density effect on recruitment.

\end{multicols}
% subsection analytic_methods_state_dynamics (end)
% section model_documentation (end)
% \clearpage


\section{Theoretical framework}
\label{sec:theory}
\paragraph{}In order to be convenient for the future combination in different Higgs decay channel, the basic theory considered in this analysis keeps consistency with previous Higgs CP test in di-tau channel. The effective Lagrangian is the SM Lagrangian augmented with CP-odd operator of mass dimension 6, involving the Higgs field and electroweak gauge field. The other interaction between Higgs/vector boson and fermions/gluons is assumed to be the same with SM prediction. The Lagrangian could be written as:

\begin{center}
\begin{math}
\mathcal{L}_{eff} = \mathcal{L}_{SM}+ \tilde{g}_{HAA}H\tilde{A}_{\mu\nu}A^{\mu\nu} + \tilde{g}_{HAZ}H\tilde{A}_{\mu\nu}Z^{\mu\nu} + \tilde{g}_{HZZ}H\tilde{Z}_{\mu\nu}Z^{\mu\nu} + \tilde{g}_{HWW}H\tilde{W}_{\mu\nu}^{+}W^{-\mu\nu}
\end{math}
\end{center}

Where $V^{\mu\nu}$ and $\tilde{V}^{\mu\nu}=\epsilon^{\mu\nu\rho\sigma}V_{\rho\sigma} $ (with $V=W^{\pm},Z,A$) denotes the vector field strength. Among the 4 coupling constants $g_{HVV}$ only 2 of them are independent due to the U(1)*SU(2) constrain, they can be written into 2 dimensionless coupling $\tilde{d}$ and $\tilde{d}_B$. As the different contribution from various vector electroweak gauge boson fusion process could not be distinguished experimentally, an arbitrary choice $\tilde{d}$ = $\tilde{d}_B$ is adopt. So the following relation could be derived:

\begin{center}
\begin{math}
\tilde{g}_{HAA} = \tilde{g}_{HZZ} = \frac{1}{2} \tilde{g}_{HWW} = \frac{g}{2m_{W}}\tilde{d} \qquad and \qquad \tilde{g}_{HAZ}=0
\end{math}
\end{center}

The parameter $\tilde{d}$ becomes the only one describing the CP violation in VBF Higgs production. The corresponding matrix element could be written as the sum of a CP-even SM contribution $\mathcal{M}_{SM}$ and a CP-odd contribution $\mathcal{M}_{CP-odd}$ from EFT, and $\tilde{d}$ could be factorized out:

\begin{center}
\begin{math}
\mathcal{M}=\mathcal{M}_{SM}+\tilde{d}\cdot\mathcal{M}_{CP-odd}
\end{math}
\end{center}

The VBF cross section is proportional to the squared matrix element:

\begin{center}
\begin{math}
|\mathcal{M}|^2 = |\mathcal{M}_{SM}|^2 + \tilde{d}\cdot2 Re(\mathcal{M}^{\ast}_{SM} \mathcal{M}_{CP-odd}) + \tilde{d}^2\cdot|\mathcal{M}_{CP-odd}|^2
\end{math}
\end{center}

The first term and last term are both CP-even, only the second term from the interference of 2 matrix element is CP-odd, representing a new source of CPV in Higgs field. This CP-odd term would vanish after integrated after a CP-symmetric phase space, so it does not contribute to the total cross section and observed event yields after applying CP-symmetric selection criteria. The third term could increase the total cross section by an amount of $\tilde{d}^2$.

\begin{comment}
\paragraph{}In the decay mode the EFT operator brings new source for Higgs decay to di-photon final state. At tree level these effective operators will contribute to the partial decay width of Higgs boson in $H\to\gam\gam$, $H\to\gam Z$, $H\to ZZ$ and $H\to WW$ channels. The helicity configuration of the particles in the final state is orthogonal to the SM case, so the interference term is zero. The angular distribution for the final state photon would not be influenced so only the change in number of branching ratio is considered:

\begin{equation}
\label{eq:Bryy}
\small
\begin{aligned}
Br(H\to\gam\gam) &= \frac{\Gamma(H\to\gam\gam)_{SM}+\delta\Gamma(H\to\gam\gam)}{\Gamma(H)_{SM}+\delta\Gamma(H\to\gam\gam)+\delta\Gamma(H\to\gam Z) + \delta\Gamma(H\to Z^{\ast}Z) + \delta\Gamma(H\to W^{\ast}W)} \\
 & = \frac{0.227\% \times 4.066MeV + 155.425MeV \tilde{g}_{HAA}^2} { 4.088MeV+155.425MeV \tilde{g}_{HAA}^2+7.957MeV \tilde{g}_{HAZ}^2 + 0.00065MeV \tilde{g}_{HZZ}^2 + 0.0036MeV \tilde{g}_{HWW}^2 }
\end{aligned}
\end{equation}

The numerical contribution from the branching ratio is significant compared with the SM prediction, only using the event yield can already provide a strict constraint on the CPV in this model. However, considering the cross section could be influenced by other CP-conserving new physics, event yields are unconstrained in the main part of this analysis.

\begin{figure}[h]
   \centering
   \includegraphics[width=.7\textwidth]{figure/BrHyy.png}
   \caption{Higgs to di-photon branching ratio as a function of CP mixing parameter $\tilde{d}$. }
   \label{fig:BrHyy}
\end{figure}
\end{comment}

\paragraph{}The VBF Higgs decay final state contains the reconstructed Higgs boson and two tagging jets from VBF topology. This can be characterized in a seven-dimension phase space, when fixing the Higgs mass, neglecting jet masses and exploiting the transverse momentum conservation. The Optimal Observable combines the information from total phase space into one single variable, so it shows much better performance than traditional operators. It is defined as the ratio of the interface term in the matrix element to the SM contribution:

\begin{center}
\begin{math}
\mathcal{OO} = \frac{2Re(\mathcal{M}^{\ast}_{SM} \mathcal{M}_{CP-odd})}{|\mathcal{M}_{SM}|^2}
\end{math}
\end{center}

\paragraph{}The Optimal Observable is a CP-odd variable, so it can be a probe of CPV in the HVV vertex. In the SM the expectation value would vanish(<OO>=0), so any non-zero mean value or asymmetry in distribution of Optimal Observable indicates the physics beyond SM, either stemming from CPV, or originating from rescattering effects ~\cite{Brehmer_2018}. Plot ~\ref{fig:OOwithd} shows the distribution of Optimal Observable for several $\tilde{d}$ VBF signal model, with obvious non-zero mean value and asymmetry shape.

\begin{figure}[h]
	\centering
	\includegraphics[width=.7\textwidth]{figure/OOind.png}
	\caption{Optimal Observable distribution in VBF process, with $\tilde{d}=-0.02$, $\tilde{d}=0$ (SM) and $\tilde{d}=0.02$}
	\label{fig:OOwithd}
\end{figure}

\paragraph{}The package HAWK ~\cite{HAWK_2015} provides a calculation for VBF and VH process matrix element, with the kinematic variables in final state (4-momenta of the Higgs boson and 2 tagging jets in VBF). For the initial state, the momentum fraction Bjorken $x_1$($x_2$) of parton can be derived by energy-momentum conservation:

\begin{center}
\begin{math}
x_{1,2}^{reco}=\frac{m_{Hjj}}{\sqrt{s}}e^{\pm y_{Hjj}}
\end{math}
\end{center}

Where $m_{Hjj}$ and $y_{Hjj}$ are the invariant mass and pseudo rapidity of Higgs+2 tagging jets system. The matrix element calculation performs a summation of all possible flavor configurations in initial and final state ij->klH weighted by CT10 leading order parton distribution functions(PDFs.).

\begin{center}
\begin{math}
2Re(\mathcal{M}^{\ast}_{SM}\mathcal{M}_{CP-odd}) = \sum_{i,j,k,l} f_i(x_1)f_j(x_2)2Re((\mathcal{M}_{SM}^{ij \to klH})^{\ast} \mathcal{M}_{CP-odd}^{ij\to klH} )
\end{math}
\\
\begin{math}
|\mathcal{M}_{SM}|^2 = \sum_{i,j,k,l} f_i(x_1)f_j(x_2)|\mathcal{M}_{SM}^{ij \to klH}|^2
\end{math}
\end{center}