2021-04-08 11:29:37 -04:00
%root:main.tex
\begin { algorithm} [t]
\caption { $ \approxq ( \circuit , \vct { p } , \conf , \error ) $ }
\label { alg:mon-sam}
\begin { algorithmic} [1]
\Require \circuit : Circuit
\Require $ \vct { p } = ( \prob _ 1 , \ldots , \prob _ \numvar ) $ $ \in [ 0 , 1 ] ^ N $
\Require $ \conf $ $ \in [ 0 , 1 ] $
\Require $ \error $ $ \in [ 0 , 1 ] $
\Ensure \vari { acc} $ \in \mathbb { R } $
\State $ \accum \gets 0 $ \label { alg:mon-sam-global1}
\State $ \numsamp \gets \ceil { \frac { 2 \log { \frac { 2 } { \conf } } } { \error ^ 2 } } $ \label { alg:mon-sam-global2}
\State $ ( \circuit _ \vari { mod } , \vari { size } ) \gets $ \onepass ($ \circuit $ )\label { alg:mon-sam-onepass} \Comment { $ \onepass $ is \Cref { alg:one-pass-iter} }
\For { $ \vari { i } \in 1 \text { to } \numsamp $ } \label { alg:sampling-loop} \Comment { Perform the required number of samples}
2021-04-10 10:11:31 -04:00
\State $ ( \vari { M } , \vari { sgn } _ \vari { i } ) \gets $ \sampmon ($ \circuit _ \vari { mod } $ )\label { alg:mon-sam-sample} \Comment { \sampmon is \Cref { alg:sample} . Note that $ \vari { sgn } _ \vari { i } $ is the \emph { sign} of the monomial's coefficient and \emph { not} the coefficient itself}
2021-04-08 11:29:37 -04:00
\If { $ \vari { M } $ has at most one variable from each block} \label { alg:check-duplicate-block}
2021-09-03 12:34:08 -04:00
\State $ \vari { Y } _ \vari { i } \gets \prod _ { X _ j \in \vari { M } } p _ j $ \label { alg:mon-sam-assign1} \Comment { \vari { M} is the sampled monomial's set of variables (cref. \cref { subsec:sampmon-remarks} )}
2021-04-08 11:29:37 -04:00
\State $ \vari { Y } _ \vari { i } \gets \vari { Y } _ \vari { i } \times \; \vari { sgn } _ \vari { i } $ \label { alg:mon-sam-product}
\State $ \accum \gets \accum + \vari { Y } _ \vari { i } $ \Comment { Store the sum over all samples} \label { alg:mon-sam-add}
\EndIf
\EndFor
\State $ \vari { acc } \gets \vari { acc } \times \frac { \vari { size } } { \numsamp } $ \label { alg:mon-sam-global3}
\State \Return \vari { acc}
\end { algorithmic}
\end { algorithm}