Skip to content

Instantly share code, notes, and snippets.

@JosephKJ
Created May 15, 2021 16:21
Show Gist options
  • Save JosephKJ/6609d67e96b99717ed2f0fae0a23b2b1 to your computer and use it in GitHub Desktop.
Save JosephKJ/6609d67e96b99717ed2f0fae0a23b2b1 to your computer and use it in GitHub Desktop.
Algorithm in Latex
# Add in the preamble
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
# Content
\begin{algorithm}
\caption{\footnotesize \method \textsc{Inference}}
\label{algo:Inference}
\begin{algorithmic}[1]
\footnotesize
\Require{Decoder: $p_{\boldsymbol \theta}(\boldsymbol \psi|\boldsymbol z, \boldsymbol t)$; Last seen task: $\boldsymbol \tau_k$; Task priors: $\mathcal{\boldsymbol P} = \{\boldsymbol P_i\}_{i=1}^{k}$, $\boldsymbol P_i = (\boldsymbol \mu_i, \boldsymbol \Sigma_i)$; Exemplars: $\mathcal{E} = \{Ex_i\}_{i=1}^{m}$, $Ex_i = \{(\boldsymbol x_i, \boldsymbol y_i)\}$; Number of base models to ensemble from: $E$ }
% \Ensure{Consolidated Encoder and Decoder parameters: $\phi$ and $\theta$}
\If {\textit{Task-agnostic inference}} \Comment{\textit{Task-agnostic inference}}
\State $\boldsymbol z \sim \mathcal{N} (\boldsymbol z | \boldsymbol \mu, \boldsymbol \Sigma) $ where $\boldsymbol \mu \gets \frac{1}{k}\sum_{i=1}^{k} \boldsymbol \mu_i$ and $\boldsymbol \Sigma \gets \frac{1}{k}\sum_{i=1}^{k} \boldsymbol \Sigma_i$
\State $\boldsymbol \Psi \gets $ Sample $E$ models from $p_{\boldsymbol \theta}(\boldsymbol \psi | \boldsymbol z)$
\State $\boldsymbol \Psi \gets $ Fine-tune $\boldsymbol \Psi$ on $\mathcal{E}$
\State Ensemble results from $\boldsymbol \Psi$ to solve all tasks ($\boldsymbol \tau_1,\cdots,\boldsymbol \tau_k$)
\EndIf
\If {\textit{Task-aware inference}} \Comment{\textit{Task-aware inference}}
\For{j = 1 to k}
\State $\boldsymbol z_j \sim \mathcal{N}(\boldsymbol z|\boldsymbol \mu_j, \boldsymbol \Sigma_j)$ where $\boldsymbol \mu_j, \boldsymbol \Sigma_j \gets \boldsymbol P_j$
\State $\boldsymbol \Psi_j \gets $ Sample $E$ models from $p_{\boldsymbol \theta}(\boldsymbol \psi | \boldsymbol z_j, \boldsymbol t_j)$
\State $\boldsymbol \Psi_j \gets $ Fine-tune $\boldsymbol \Psi_j$ on $Ex_j$
\State Ensemble results from $\boldsymbol \Psi_j$ to solve task $\boldsymbol \tau_j$.
\EndFor
\EndIf
\end{algorithmic}
\end{algorithm}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment