Changes and comments added to Auxiliary Sample.

This commit is contained in:
Aaron Huber 2020-08-18 09:57:04 -04:00
parent 6326005751
commit a2c9516147

View file

@ -138,8 +138,7 @@ For the running example, after one pass, \cref{alg:one-pass} would have learned
The following pseudo code assumes that $\polytree$ has the following members. $\polytree.val$ holds the value stored by $\polytree$, $\polytree.children$ contains all children of $\polytree$, $\polytree.weight$ is the probability of choosing $\polytree$, and $\polytree.partial$ is the coefficient of $\polytree$. A child of $\polytree$ is assumed to be an expression tree itself. The function $isnum(\cdot)$ returns true if the value is numeric.
\AH{{\bf Next:} 3) Move on to algo Sample.
4) Add comments.
\AH{{\bf Next:}
5) Prove correctness for all algos.
6) Don't forget to do run-time analysis.}
@ -176,35 +175,39 @@ The following pseudo code assumes that $\polytree$ has the following members. $
Algorithm ~\ref{alg:sample} takes $\polytree$ as input and performs the equivalent of outputting a sample $\randvar_i$ such that $\randvar_i \sim Uniform(S)$, where $S$ represents the multiset of monomials in $\expandtree$. While one cannot compute $\expandtree$ in time better than $O(N^k)$, the algorithm uses a technique on $\polytree$ which produces a uniform sample from $\expandtree$ without ever materializing $\expandtree$.
Algorithm ~\ref{alg:sample} then uniformly selects a monomial from $\expandtree$ by the following top-down traversal. For each leaf node, the monomial is returned with a coefficient reduced to either $\{-1, 1\}$ depending on its sign. For a parent $+$ node, a subtree is chosen over the previously computed weighted sampling distribution. When a parent $\times$ node is visited, the monomials are combined into one monomial. The algorithm concludes outputting $sign(c_i)\cdot\prob^{d_i}$.
Algorithm ~\ref{alg:sample} then uniformly selects a monomial from $\expandtree$ by the following top-down traversal. For a parent $+$ node, a subtree is chosen over the previously computed weighted sampling distribution. When a parent $\times$ node is visited, the monomials sampled from its subtrees are combined into one monomial. For the case of a parent node with children that are leaf nodes, if the parent is a $\times$ node, then each leaf node is returned, with the coefficient reduced to either $\{-1, 1\}$ depending on its sign. If the parent node is a $+$ node, then one of the chidlren is sampled as discussed previously. The algorithm concludes outputting $sign(c_i)\cdot\prob^{d_i}$. The pseudo code uses $isdist(\cdot)$ to mean a function that takes a single variable from $\vct{X}$ as input and outputs whether or not we have seen this variable while computing the current sample.
\subsubsection{Pseudo Code}
Algorithm ~\ref{alg:sample} should be placed here.
\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 \gets 1$
\State $monom \gets ""$
\If{$T.val = "+":$}\Comment{Sample at every $+$ node}
\State $T_{samp} \gets$ WeightedSample($T.children$, $T.weights$) \Comment{Currently considering sample generation as a 'black' box}
\State Return $Sample(T_{samp})$
\ElsIf{$T.val = "\times":$}\Comment{Multiply the sampled values of all subtree children}
\State $acc \gets 1$
\For {$child$ in $T.children:$}
\State $monom = monom ++ Sample(child)\_1$
\State $c_i \gets c_i \times Sample(child)\_2$
\State $acc \gets acc \times Sample(child)$
\EndFor
\ElsIf{$isnum(T.val)$}\Comment{The leaf is a coefficient non-variable}
\State Return $sign(T.val)$
\ElsIf{$isdist(T.val)$}\Comment{The leaf is a variable; we need to know if it is distinct}
\State Return $\prob$
\Else
\State Return $(T.head.val, 1 \times T.c_i)$
\State Return $1$
\EndIf
\end{algorithmic}
\end{algorithm}
\subsubsection{Correctness of Algorithm ~\ref{alg:one-pass}}
The algorithm begins with recursively visiting the root node and all of its children, until it reaches all leaves. Thus, every node is visited. When going from the bottom up, it is the case for a parent node $+$ that the algorithm records the sum of its children's coefficient values, and produces a weighted distribution based on the partial values. This weighted distribution across each child subtree is in exact proportion to the probability of choosing either child given that it's parent's subtree was chosen. Consider the base case, when we have $n$ leaf nodes whose parent (root) node is $+$. For each $|c_i|$, it is the case that $\frac{|c_i|}{\sum_{i \in [n]}|c_i|}$ is exactly the uniform distribution of $\expandtree$.
When a $\times$ node is visited, \cref{alg:one-pass} takes the product of each of its children. Note that this is correct, since it is the case that a product of polynomials has a sum of coefficients equal to the product of the sum of each polynomial's coefficients.
Note that for the case of a $+$ subtree of a parent $\times$ node, when the parent node passes its partial sum up to it's parent node, it is the case that the subtrees of the $+$ node probabilities are exactly the proportion of the parent's parent node.
%The algorithm begins with recursively visiting the root node and all of its children, until it reaches all leaves. Thus, every node is visited. When going from the bottom up, it is the case for a parent node $+$ that the algorithm records the sum of its children's coefficient values, and produces a weighted distribution based on the partial values. This weighted distribution across each child subtree is in exact proportion to the probability of choosing either child given that it's parent's subtree was chosen. Consider the base case, when we have $n$ leaf nodes whose parent (root) node is $+$. For each $|c_i|$, it is the case that $\frac{|c_i|}{\sum_{i \in [n]}|c_i|}$ is exactly the uniform distribution of $\expandtree$.
%
%When a $\times$ node is visited, \cref{alg:one-pass} takes the product of each of its children. Note that this is correct, since it is the case that a product of polynomials has a sum of coefficients equal to the product of the sum of each polynomial's coefficients.
%
%Note that for the case of a $+$ subtree of a parent $\times$ node, when the parent node passes its partial sum up to it's parent node, it is the case that the subtrees of the $+$ node probabilities are exactly the proportion of the parent's parent node.
\subsubsection{Run-time Analysis}