Pseudo Code for Sample Auxiliary and OnePass Algos.
parent
44e314db13
commit
3e4d42afd5
|
@ -84,6 +84,52 @@ For the running example, after the first pass, \textit{Sample} would have learne
|
|||
|
||||
\subsubsection{Psuedo Code}
|
||||
|
||||
\begin{algorithm}
|
||||
\caption{OnePass($\polytree$)}
|
||||
\label{alg:one-pass}
|
||||
\begin{algorithmic}[1]
|
||||
\State $acc \gets 0$
|
||||
\If{$\polytree.head.val == "+"$}
|
||||
\For{$child$ in $T.children$}
|
||||
\State $acc = acc + OnePass(child)$
|
||||
\EndFor
|
||||
\State $T.partial \gets acc$
|
||||
\For{$child$ in $T.children$}
|
||||
\State $child.weight = \frac{child.c_i}{T.partial}$
|
||||
\EndFor
|
||||
\State Return $T.partial$
|
||||
\ElsIf{$T.head.val == "\times"$}
|
||||
\State $acc \gets 1$
|
||||
\For{$child$ in $T.children$}
|
||||
\State $acc = acc \times= OnePass(child)$
|
||||
\EndFor
|
||||
\State $T.partial \gets acc$
|
||||
\Else
|
||||
\State Return $T.c_i$
|
||||
\EndIf
|
||||
\end{algorithmic}
|
||||
\end{algorithm}
|
||||
|
||||
\begin{algorithm}
|
||||
\caption{Sample($\polytree$)}
|
||||
\label{alg:sample}
|
||||
\begin{algorithmic}[1]
|
||||
\If{$T.head.val == "+":$}
|
||||
\State $T_{samp} \gets$ WeightedSample($T.children$, $T.weights$)
|
||||
\State $Sample(T_{samp})$
|
||||
\ElsIf{$T.head.val == "\times":$}
|
||||
\State $c_i = 1$
|
||||
\State $monom \gets ""$
|
||||
\For {$child$ in $T.children:$}
|
||||
\State $monom = monom ++ Sample(child)\_1$
|
||||
\State $c_i = c_i \times Sample(child)\_2$
|
||||
\EndFor
|
||||
\Else
|
||||
\State Return $(T.head.val, 1 \times T.c_i)$
|
||||
\EndIf
|
||||
\end{algorithmic}
|
||||
\end{algorithm}
|
||||
|
||||
\subsubsection{Correctness}
|
||||
|
||||
\subsubsection{Run-time Analysis}
|
||||
|
|
Loading…
Reference in New Issue