\RequirePackage{mathtools}
\RequirePackage{etextools}
\RequirePackage{ifthen}
\RequirePackage{xspace}
\RequirePackage{xcolor}
\RequirePackage{soul}
\RequirePackage{amsthm}
\RequirePackage{mleftright,xparse}
\RequirePackage{xifthen}
\RequirePackage{amssymb}
\RequirePackage{dsfont}
\RequirePackage{hhline}
\RequirePackage{bbm}
\RequirePackage{calc}
\RequirePackage{fp}
\RequirePackage{array}
\RequirePackage{adjustbox}
\RequirePackage{longtable}
\RequirePackage{hhline}
\RequirePackage[warn]{textcomp}
\RequirePackage{multirow}
% \RequirePackage[finalizecache=true]{minted}
\RequirePackage[frozencache=true]{minted}
% \RequirePackage{minted}
\RequirePackage{enumitem}
\RequirePackage{listings}
\RequirePackage{amssymb}
\RequirePackage{pifont}
\RequirePackage{mdframed}
\RequirePackage{setspace}
\RequirePackage{algorithm}
\RequirePackage{algpseudocode}
\RequirePackage{capt-of}
\RequirePackage{environ}
\RequirePackage{pdftexcmds}
\RequirePackage{siunitx}
\RequirePackage{expl3}
\ExplSyntaxOn
    \cs_new_eq:NN \fpcmpTF \fp_compare:nTF
\ExplSyntaxOff

% https://tex.stackexchange.com/a/51288
\RequirePackage{thmtools}
\RequirePackage{thm-restate}
\RequirePackage{hyperref}
\RequirePackage{cleveref}

\makeatletter
\renewcommand*{\@textcolor}[3]{%
  \protect\leavevmode
  \begingroup
    \color#1{#2}#3%
  \endgroup
}
\makeatother

\newcommand {\postsubmission}[2]{
\relax\ifmmode%
{{\color{gray}(#1 \rightarrow)} {\color{orange}#2}}%
\else%
\textcolor{gray}{(#1 $\rightarrow$)} \textbf{\textcolor{orange}{#2}}%
\fi%
}
\renewcommand {\postsubmission}[2]{\textcolor{orange}{#2}}
% \renewcommand {\postsubmission}[2]{#2}

\newcommand {\phillip}[1]{{\color{blue} \bf [Phillip:  #1 ]}}
\newcommand {\tongzhou}[1]{{\color{magenta} \bf [Tongzhou:  #1 ]}}

\newtheoremstyle{thmstyle}
  {\topsep} % Space above
  {0.5pt} % Space below
  {} % Body font
  {} % Indent amount
  {\bfseries} % Theorem head font
  {.} % Punctuation after theorem head
  {.5em} % Space after theorem head
  {} % Theorem head spec (can be left empty, meaning `normal')
% \theoremstyle{thmstyle}
% \declaretheorem[style=thmstyle,name=Theorem,numberwithin=section]{thm}
% \declaretheorem[style=thmstyle,name=Lemma,numberwithin=section]{lemma}
% \declaretheorem[style=thmstyle,name=Corollary,sharenumber=thm]{cor}
% \declaretheorem[style=thmstyle,name=Proposition,sharenumber=thm]{prop}
% \declaretheorem[style=thmstyle,name=Fact,sharenumber=thm]{fact}
% \declaretheorem[style=thmstyle,name=Remark,sharenumber=thm]{rmk}
% \declaretheorem[style=thmstyle,name=Observation,sharenumber=thm]{obs}
% \theoremstyle{definition}
% \declaretheorem[style=thmstyle,name=Definition,numberwithin=section]{defn}

% args = desc,type,label,restatable_cmd
\makeatletter
\NewEnviron{repthm}[4][]{
  \@ifundefined{repthmXRRR}{
    % Not XR, def+label or restate.
    \@ifundefined{#4}{%
      \begin{restatable}[#1]{#2}{#4}
        \label{#3}
        \BODY
      \end{restatable}
    }{%
      \def\restate{\csname #4\endcsname}%
      \restate*%
    }%
  }{%
    % XR. Can't restate, Manipulate the numbers...
    \addtocounter{#2}{-1}
    \expandafter\def\csname the#2\endcsname{\ref{#3}}
    \begin{restatable}[#1]{#2}{#4}
      \BODY
    \end{restatable}
  }
}

\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\newcommand*{\mi}{\mathcal{I}}
\newcommand{\bb}[1]{\boldsymbol{#1}}

% colorful subscripts
\newcommand*{\ci}{{\textcolor{red}{i}}}
\newcommand*{\cj}{{\textcolor{blue}{j}}}
\newcommand*{\cl}{{\textcolor{orange}{l}}}
\newcommand*{\ch}{{\textcolor{teal}{h}}}
\newcommand*{\cipl}{{\textcolor{red}{i'_\mathsf{left}}}}
\newcommand*{\cjpl}{{\textcolor{blue}{j'_\mathsf{left}}}}
\newcommand*{\clpl}{{\textcolor{orange}{l'_\mathsf{left}}}}
\newcommand*{\chpl}{{\textcolor{teal}{h'_\mathsf{left}}}}
\newcommand*{\cil}{{\textcolor{red}{i_\mathsf{left}}}}
\newcommand*{\cjl}{{\textcolor{blue}{j_\mathsf{left}}}}
\newcommand*{\cll}{{\textcolor{orange}{l_\mathsf{left}}}}
\newcommand*{\chl}{{\textcolor{teal}{h_\mathsf{left}}}}
\newcommand*{\cir}{{\textcolor{red}{i_\mathsf{right}}}}
\newcommand*{\cjr}{{\textcolor{blue}{j_\mathsf{right}}}}
\newcommand*{\clr}{{\textcolor{orange}{l_\mathsf{right}}}}
\newcommand*{\chr}{{\textcolor{teal}{h_\mathsf{right}}}}

\newcommand\evalat[1]{\bigg\rvert_{#1}}
% \newcommand\ulsm[1]{\underline{\smash{#1}}}
\setul{1.5pt}{.4pt}% 1pt below contents

\newcommand{\itempara}[1]{\textbf{#1\vspace{2pt}}\par}

\newcommand\narroweq{\mkern1.5mu{=}\mkern1.5mu}

\newcommand{\fixme}[1]{{\color{red}\textbf{ FIXME: #1}\@\xspace}}

\newcommand{\round}[2]{%
  \FPset{\a}{#1}
  \FPround{\a}{\a}{#2}
  \a
}

\newcommand{\convexpath}[2]{
  [
  create hullcoords/.code={
    \global\edef\namelist{#1}
    \foreach [count=\counter] \nodename in \namelist {
      \global\edef\numberofnodes{\counter}
      \coordinate (hullcoord\counter) at (\nodename);
    }
    \coordinate (hullcoord0) at (hullcoord\numberofnodes);
    \pgfmathtruncatemacro\lastnumber{\numberofnodes+1}
    \coordinate (hullcoord\lastnumber) at (hullcoord1);
  },
  create hullcoords
  ]
  ($(hullcoord1)!#2!-90:(hullcoord0)$)
  \foreach [
  evaluate=\currentnode as \previousnode using \currentnode-1,
  evaluate=\currentnode as \nextnode using \currentnode+1
  ] \currentnode in {1,...,\numberofnodes} {
    let \p1 = ($(hullcoord\currentnode) - (hullcoord\previousnode)$),
    \n1 = {atan2(\y1,\x1) + 90},
    \p2 = ($(hullcoord\nextnode) - (hullcoord\currentnode)$),
    \n2 = {atan2(\y2,\x2) + 90},
    \n{delta} = {Mod(\n2-\n1,360) - 360}
    in
    {arc [start angle=\n1, delta angle=\n{delta}, radius=#2]}
    -- ($(hullcoord\nextnode)!#2!-90:(hullcoord\currentnode)$)
  }
}

\NewDocumentCommand\xDeclarePairedDelimiter{mmm}
 {%
  \NewDocumentCommand#1{som}{%
   \IfNoValueTF{##2}
    {\IfBooleanTF{##1}{#2##3#3}{\mleft#2##3\mright#3}}
    {\mathopen{##2#2}##3\mathclose{##2#3}}%
  }%
 }
% \newcommand{\hide}[1]{}
\newcommand*{\stext}[1]{\text{ #1 }}
\newcommand*{\iid}{\ifmmode \stext{i.i.d.} \else i.i.d.\@\xspace \fi}
\newcommand*{\iidsim}{\overset{\text{i.i.d.}}{\sim}}
\newcommand*{\weakconv}{\overset{*}{\rightarrow}}
\newcommand{\given}{\mathrel{\vert}}
\newcommand*{\eg}{e.g.\@\xspace}
\newcommand*{\ie}{i.e.\@\xspace}
\newcommand*{\Eg}{E.g.\@\xspace}
\newcommand*{\Ie}{I.e.\@\xspace}
\newcommand*{\esp}{esp.\@\xspace}
\newcommand*{\wrt}{\ifmmode \stext{w.r.t.} \else w.r.t.\@\xspace \fi}
\newcommand*{\aever}{\ifmmode \stext{a.e.} \else a.e.\@\xspace \fi}
\newcommand*{\asurely}{\ifmmode \stext{a.s.} \else a.s.\@\xspace \fi}
% \newcommand*{\st}{\ifmmode \stext{s.t.} \else s.t.\@\xspace \fi}
\newcommand*{\wprob}{\ifmmode \stext{w.p.} \else w.p.\@\xspace \fi}
\makeatletter
\newcommand*{\etc}{%
    \@ifnextchar{.}%
        {etc}%
        {etc.\@\xspace}%
}
\makeatother
\newcommand{\lhs}[0]{\hspace{2em}&\hspace{-2em}}
\newcommand{\trieq}[0]{\triangleq}
\newcommand{\eqin}[1]{\overset{#1}{=}}
\newcommand{\defeq}[0]{\overset{\mbox{\normalfont\tiny def}}{=}}

\DeclareMathOperator{\arctantwo}{arctan2}
\DeclareMathOperator{\supp}{supp}

\newcommand{\sphere}[0]{\mathcal{S}}
\newcommand{\bigO}[0]{\mathcal{O}}
\newcommand{\N}[0]{\mathbb{N}}
\newcommand{\Z}[0]{\mathbb{Z}}
\newcommand{\Q}[0]{\mathbb{Q}}
\newcommand{\R}[0]{\mathbb{R}}
\newcommand{\C}[0]{\mathbb{C}}
\newcommand{\F}[0]{\mathbb{F}}
\newcommand{\T}[0]{^{\mathsf{T}}}
\newcommand{\eps}[0]{\epsilon}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}
\newcommand{\diff}[0]{\mathop{}\!\mathrm{d}}
\newcommand{\kl}[2]{D_\mathsf{KL}(#1 \mathrel{||} #2)}
\newcommand\wcdot{\,\cdot\,}
\newcommand\wildcdot{\wcdot}
\DeclareDocumentCommand{\distn}{mO{}mO{}O{}}{%
    {#1}\ifthenelse{\isempty{#2}}{}{_{#2}}%
    \ifthenelse{\isempty{#3}}{}{\left[{#3}\ifthenelse{\isempty{#4}}{}{\mathrel{}\middle\vert\mathrel{}#4}\ifthenelse{\isempty{#5}}{}{; {#5}}\right]}
}
\DeclareDocumentCommand{\prob}{O{}mO{}O{}}{%
    \distn{\mathbb{P}}[#1]{#2}[#3][#4]
}
\DeclareDocumentCommand{\expect}{O{}mO{}}{%
    \mathbb{E}\ifthenelse{\isempty{#1}}{}{_{#1}}%
    \ifthenelse{\isempty{#2}}{}{\left[{#2}\ifthenelse{\isempty{#3}}{}{\mathrel{}\middle\vert\mathrel{}#3}\right]}
}
\DeclareDocumentCommand{\expectunder}{O{}mO{}}{%
    \underset{{#1}}{\mathbb{E}}%
    \ifthenelse{\isempty{#2}}{}{\hspace{-3pt}\left[{#2}\ifthenelse{\isempty{#3}}{}{\mathrel{}\middle\vert\mathrel{}#3}\right]}
}
\DeclareDocumentCommand{\expectundernear}{O{}mO{}}{%
    \underset{{#1}}{\mathbb{E}}%
    \ifthenelse{\isempty{#2}}{}{\hspace{-5pt}\left[{#2}\ifthenelse{\isempty{#3}}{}{\mathrel{}\middle\vert\mathrel{}#3}\right]}
}
\DeclareDocumentCommand{\var}{O{}mO{}}{%
    \text{Var}\ifthenelse{\isempty{#1}}{}{_{#1}}%
    \ifthenelse{\isempty{#2}}{}{\left[{#2}\ifthenelse{\isempty{#3}}{}{\mathrel{}\middle\vert\mathrel{}#3}\right]}
}
\DeclareDocumentCommand{\indic}{O{}mO{}}{%
    \mathds{1}\ifthenelse{\isempty{#1}}{}{_{#1}}%
    \ifthenelse{\isempty{#2}}{}{\hspace{-0.5ex}\left({#2}\right)}
}
\xDeclarePairedDelimiter{\size}{\lvert}{\rvert}
\xDeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\xDeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\xDeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
\xDeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}

% \theoremstyle{plain}
\newtheorem*{claim}{Claim}
% \newtheorem{lemma}{Lemma}
\newtheorem{corollary}{Corollary}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}{Proposition}

\theoremstyle{definition}
\newtheorem*{definition}{Definition}
\newtheorem*{assumption}{Assumption}

\theoremstyle{remark}
\newtheorem*{remark}{Remark}


\newcommand\tblcelllabel[2]{#1\def\@currentlabel{#1}\label{#2}}

\def\LTHH@let#1{\futurelet\@tempb\LTHH@loop}


\def\LTHH@loop{%
  \ifx\@tempb`\edef\next##1{%
  \the\toks@\cr
  \noalign{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
  \omit
  \the\toks@\cr
  \noalign{\nobreak}%
  }\else\let\next\LTHH@let
  \ifx\@tempb:\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
      \HH@add{\@tempc\vline\@tempc}\else
  \ifx\@tempb~\@tempswafalse
           \if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
              \HH@add{\hfil}\else
  \ifx\@tempb-\@tempswafalse
           \if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
              \HH@add{\leaders\hrule\@height\arrayrulewidth\hfil}\else
  \errortoken
  \fi\fi\fi\fi
  \next}


\def\ltcline#1{%
  \noalign{\nobreak}%
  \omit\@firstamptrue\@tempswafalse
  \xdef\@tempc{\ifx\extrarowheight\HH@undef\hskip-.5\arrayrulewidth\fi}%
  \HH@xexpast\relax#1*0x\@@\toks@{}%
  \expandafter\LTHH@let\@tempa`%
}


\RequirePackage{subcaption}
\RequirePackage{tikz}
\usetikzlibrary{arrows, decorations.markings, chains, fit, shapes, decorations.pathreplacing, decorations.pathmorphing, positioning, calc, backgrounds, hobby}
\tikzset{square arrow/.style={to path={-- ++(0,.15) -| (\tikztotarget)}}}
\tikzstyle{bayes_net}=[->, >=stealth', shorten >=1pt, auto, node distance=2cm, thick]
\tikzstyle{markov_random_field}=[>=stealth', auto, node distance = 2cm, thick]
\tikzstyle{main_node}=[circle, rounded corners, draw, minimum size = 0.85cm]
\tikzstyle{dummy_node}=[circle, rounded corners, minimum size = 0.85cm]
\tikzstyle{box_node}=[draw, minimum size = 0.7cm]

\newlength{\continueindent}
\setlength{\continueindent}{3em}

\renewenvironment{algorithmic}[1][0]%
   {%
   \edef\ALG@numberfreq{#1}%
   \def\@currentlabel{\theALG@line}%
   %
   \setcounter{ALG@line}{0}%
   \setcounter{ALG@rem}{0}%
   %
   \let\\\algbreak%
   %
   \expandafter\edef\csname ALG@currentblock@\theALG@nested\endcsname{0}%
   \expandafter\let\csname ALG@currentlifetime@\theALG@nested\endcsname\relax%
   %
   \begin{list}%
      {\ALG@step}%
      {%
      \rightmargin\z@%
      \itemsep\z@ \itemindent\z@ \listparindent2em%
      \partopsep\z@ \parskip\z@ \parsep\z@%
      \labelsep 0.5em \topsep 0.2em%\skip 1.2em
      \ifthenelse{\equal{#1}{0}}%
         {\labelwidth 0.5em}%
         {\labelwidth 1.2em}%
       \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}
      \ALG@tlm\z@%
      }%
      \parshape 2 \leftmargin \linewidth \continueindent \dimexpr\linewidth-\continueindent\relax
   \setcounter{ALG@nested}{0}%
   \ALG@beginalgorithmic%
   }%
   {% end{algorithmic}
   % check if all blocks are closed
   \ALG@closeloops%
   \expandafter\ifnum\csname ALG@currentblock@\theALG@nested\endcsname=0\relax%
   \else%
      \PackageError{algorithmicx}{Some blocks are not closed!!!}{}%
   \fi%
   \ALG@endalgorithmic%
   \end{list}%
   }%
\makeatother