Created
March 13, 2019 07:10
-
-
Save SeanSyue/626456b785041383bf52a5c891b3facf to your computer and use it in GitHub Desktop.
Simple algorithm test in latex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage[utf8]{inputenc} | |
% \usepackage[linesnumbered,ruled]{algorithm2e} | |
\usepackage{algorithm, algorithmic} | |
% \usepackage{algorithm,algpseudocode} | |
% \usepackage{amsfonts} | |
% ---------- BEGIN of managing indent in algorithm ---------- | |
\newlength\myindent | |
\setlength\myindent{2em} | |
\newcommand\bindent{% | |
\begingroup | |
\setlength{\itemindent}{\myindent} | |
\addtolength{\algorithmicindent}{\myindent} | |
} | |
\newcommand\eindent{\endgroup} | |
% ---------- END of managing indent in algorithm ---------- | |
\begin{document} | |
\begin{algorithm}[H] | |
\begin{algorithmic} | |
\STATE \textbf{Input:} | |
\bindent | |
\STATE \textbullet~ $D$: Training dataset of $n$ data, each with a response variable $y_t$ and a set of variables $X_t$ composed of explanatory covariates $X^{explanatory}$ and categorical covariates $X^{category}$; | |
\STATE \textbullet~ $k^*$: pre-defined number of terms; | |
\STATE \textbullet~ $criterion()$: performance criterion for a model | |
\eindent | |
\STATE \textbf{Output:} best fit GAM model in terms of formula containing selected composing terms | |
\STATE \textbf{Step 0:} Setting initial values for variables | |
\STATE Let: | |
\bindent | |
\STATE \textbullet~ $CS_0 = \emptyset$; | |
\STATE \textbullet~ $formula = \emptyset$ | |
\STATE \textbullet~ $criterion = \infty$ {the $criterion$ can be MAPE, ACE, or AIC, etc.} | |
\eindent | |
\STATE \textbf{Step 1:} Construction of Candidate Set: $CS_0$ | |
\STATE Adding into $CS_0$ terms of the following forms: | |
\bindent | |
\STATE \textbullet~ single form: $f(x_{i}^{explanatory})$, | |
\STATE \textbullet~ indexed form: $\sum_{c = 1}^{C}${\bf 1}{($x^{category} = c$)}{$\it f_{c}^{'}(x_{i}^{explanatory})$}, | |
\STATE \textbullet~ cross form: {$g_{I,~j}$}($x_{i}^{explanatory}$, $x_{j}^{explanatory}$), and | |
\STATE \textbullet~ indexed cross forms $\sum_{c = 1}^{C}${\bf 1}{($x^{category} = c$)}{$\it g_{i, ~j, ~c}^{'}$}{($x_{i}^{explanatory}$, $x_{j}^{explanatory}$)} | |
\eindent | |
\STATE \textbf{Step 2: }Adding one by one until it exceeds limits or becomes no better | |
\STATE Loop for the $i$-the iteration of adding one new term $t_i$ into the fitting model: | |
\bindent | |
% \STATE \textbf{For each} $t_i^j \in CS_i$: | |
\FOR{each $t_i^j \in CS_i$} | |
\STATE find $gam.mod_i^j = gam(y \sim formula + t_i^j)$; | |
\STATE find the associated $criterion(gam.mod_i^j)$. | |
\ENDFOR | |
\STATE Pick $t_i$ as the term $t_i^j$ that yields the best $criterion(gam.mod _i^j)$; | |
\STATE also let $criterion_i = criterion(gam.mod _i^j)$ | |
\STATE Check for termination condition: | |
\IF{some condition is true} | |
\STATE break from the adding iteration; | |
\ELSE | |
\STATE $formula = formula + t_i$; | |
\STATE $CS_i = CS_{i-1} -\{t_i\}$ | |
\ENDIF | |
\eindent | |
\STATE \textbf{Step 3: }output the best fit GAM formula | |
\STATE Best.gam.mod = $formula$ | |
\end{algorithmic} | |
\end{algorithm} | |
% \begin{algorithm} | |
% \caption{MyAlgo} | |
% \begin{algorithmic}[1] | |
% \Statex \textbullet~\textbf{Parameters:} $n, t \in \mathbb{N}$, where $t < n$. | |
% \State First step | |
% \State Second step | |
% \State \ldots | |
% \end{algorithmic} | |
% \end{algorithm} | |
% \begin{algorithm}[H] | |
% \caption*{my algorithm} | |
% \begin{algorithmic} | |
% \STATE \textbf{Stage one:} this is stage one | |
% \bindent | |
% \FORALL{i} | |
% \STATE do something | |
% \ENDFOR | |
% \eindent | |
% \STATE \textbf{Stage two:} this is stage two | |
% \bindent | |
% \STATE Update the trie: | |
% \FORALL{j} | |
% \STATE do something | |
% \ENDFOR | |
% \eindent | |
% \end{algorithmic} | |
% \end{algorithm} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment