Further revised correctness proof SampleMonomial.

This commit is contained in:
Aaron Huber 2020-08-26 13:33:43 -04:00
parent e82c3e5bdf
commit 5e1318eb71

View file

@ -53,10 +53,9 @@ Denote $poly(\etree)$ to be the function that takes as input expression tree $\e
Note that \cref{def:express-tree-set} implies that $\etree \in \etreeset{\smb}$.
\begin{Definition}[Expanded T]\label{def:expand-tree}
$\expandtree$ is the pure SOP expansion of $\etree$, where non-distinct monomials are not combined after the product operation.
\end{Definition}
$\expandtree$ is the pure SOP expansion of $\etree$, where non-distinct monomials are not combined after the product operation. The logical view of \expandtree ~is a list of tuples $(c_i, v_i)$, where $c_i$ is the coefficient and $v_i$ the set of variables of the $i^{th}$ monomial.\end{Definition}
To illustrate \cref{def:expand-tree} with an example, consider the product $(x + 2y)(2x - y)$ and its expression tree $\etree$. The pure expansion of the product is $2x^2 - xy + 4xy - 2y^2 = \expandtree$. (For preciseness, note that $\etree$ would use a $+$ node to model the second factor ($\etree_\vari{R}$), while storing a child coefficient of $-1$ for the variable $y$. The subtree $\etree_\vari{R}$ would be $+(\times(2, x), \times(-1, y))$, and one can see that $\etree_R$ is indeed equivlent to $(2x - y)$).
To illustrate \cref{def:expand-tree} with an example, consider the product $(x + 2y)(2x - y)$ and its expression tree $\etree$. The pure expansion of the product is $2x^2 - xy + 4xy - 2y^2 = \expandtree$, logically viewed as $[(2, x^2), (-1, xy), (4, xy), (-2, y^2)]$. (For preciseness, note that $\etree$ would use a $+$ node to model the second factor ($\etree_\vari{R}$), while storing a child coefficient of $-1$ for the variable $y$. The subtree $\etree_\vari{R}$ would be $+(\times(2, x), \times(-1, y))$, and one can see that $\etree_R$ is indeed equivlent to $(2x - y)$).
\begin{Definition}[Positive T]\label{def:positive-tree}
Let $\abstree$ denote the resulting expression tree when each coefficient $c_i$ in $\etree$ is exchanged with its absolute value $|c_i|$.
@ -296,17 +295,23 @@ Algorithm ~\ref{alg:sample} correctly samples the $i^{th}$ monomial from $\rpoly
\begin{proof}[Proof of Lemma ~\ref{lem:sample}]
First, note that for any monomial sampled by algorithm ~\ref{alg:sample}, the nodes traversed form a subgraph of $\etree$ that is \textit{not} a subtree in the general case. We thus seek to prove that the subgraph traversed produces the correct probability corresponding to the monomial sampled.
Prove by structural induction on the depth $d$ of $\etree$. For the base case $d = 0$, by definition ~\ref{def:express-tree} we know that the root has to be either a coefficient or a variable. When the root is a variable $x$, we have the fact that $P(\randvar_i = x) = 1$, the algorithm correctly returns $(\{x\}, 1 )$, upholding correctness. When the root is a coefficient, it returns $sign(c_i) \times 1$. For $|c_i| \leq 1$, $P(\randvar_i = c_i) = 1$, and correctness follows as the algorithm returns $sign(c_i) \times 1$. When $|c_i| \geq 2$, $P(|\randvar_i| = 1) = \frac{1}{|c_i|}$, and $sign(c_i) \times 1$ yields a properly weighted sampling for the case when $|c_i| \geq 2$.
Prove by structural induction on the depth $d$ of $\etree$. For the base case $d = 0$, by definition ~\ref{def:express-tree} we know that the root has to be either a coefficient or a variable. When the root is a variable $x$, we have the fact that $P(\randvar_i = x) = 1$, the algorithm correctly returns $(\{x\}, 1 )$, upholding correctness. When the root is a coefficient, \sampmon correctly returns $sign(c_i) \times 1$.
\AH{I don't know if I need to state why the latter statement (for the case of the root being a coefficient )is correct. I am not sure how to properly argue this either, whether is suffices to say that this follows by definition of our sampling scheme--or if there is a statistical claime, etc...}
%By definition of sampling scheme, this %For $|c_i| \leq 1$, $P(\randvar_i = c_i) = 1$, and correctness follows as the algorithm returns $sign(c_i) \times 1$. When $|c_i| \geq 2$, $P(|\randvar_i| = 1) = \frac{1}{|c_i|}$, and $sign(c_i) \times 1$ yields a properly weighted sampling for the case when $|c_i| \geq 2$.
For the inductive hypothesis, assume that for $d \leq k \geq 0$ lemma ~\ref{lem:sample} is true.
Prove now, that when $d = k + 1$ lemma ~\ref{lem:sample} holds. It is the case that the root of $\etree$ has up to two children $\etree_L$ and $\etree_R$. Since we have a maximal path of 1 from the root to either child, we know that by inductive hypothesis, $\etree_L$ and $\etree_R$ are both depth $d = k$, and lemma ~\ref{lem:sample} holds for either of them, thus, the probabilities computed on the sampled subgraph of nodes visited in $\etree_L$ and $\etree_R$ are therefore correct.
Prove now, that when $d = k + 1$ lemma ~\ref{lem:sample} holds. It is the case that the root of $\etree$ has up to two children $\etree_L$ and $\etree_R$. Since we have a maximal path of 1 from the root to either child, we know that by inductive hypothesis, $\etree_L$ and $\etree_R$ are both depth $d = k$, and lemma ~\ref{lem:sample} holds for either of them, thus, the probabilities computed on the sampled subgraphs of nodes visited in $\etree_L$ and $\etree_R$ are therefore correct.
Then the root has to be either a $+$ or $\times$ node. When it is the former, algorithm ~\ref{alg:sample} will sample from $\etree_L$ and $\etree_R$ according to their computed weights in algorithm ~\ref{alg:one-pass}, and by inductive hypothesis correctness is ensured.
Then the root has to be either a $+$ or $\times$ node.
Consider the case when the root is $\times$. Note that we are sampling a term from $\expandtree$. Consider the $i^{th}$ term in $\expandtree$, and call the sampled element $m$. Notice also that it is the case that $m = m_L \times m_R$, where $m_L$ is coming from $\etree_L$ and $m_R$ from $\etree_R$. Denote $\randvar_{\etree_\vari{L}}$ as the random variable sampling over $\etree_\vari{L}$. Further note that $P(\randvar_{\etree_{\vari{L}}} = m_L ) = \frac{|c_{m_L}|}{|\etree_L|(1,\ldots, 1)}$ and symmetrically for $m_R$. The final probability for the $i^{th}$ monomial sampled is then $P(\randvar_{\etree} = m) = \frac{|c_{m_L}| \cdot |c_{m_R}|}{|\etree_L|(1,\ldots, 1) \cdot |\etree_R|(1,\ldots, 1)}$. For the $i^{th}$ term in \expandtree, it is indeed the case that $|c_i| = |c_{m_L}| \cdot |c_{m_R}|$ and that $\abstree(1,\ldots, 1) = |\etree_L|(1,\ldots, 1) \cdot |\etree_R|(1,\ldots, 1)$, and therefore the $i^{th}$ monomial $m$ sampled is sampled with correct probability $\frac{|c_i|}{\abstree(1,\ldots, 1)}$.
%When it is the former, algorithm ~\ref{alg:sample} will sample from $\etree_L$ and $\etree_R$ according to their computed weights in algorithm ~\ref{alg:one-pass}, and by inductive hypothesis correctness is ensured.
%the call to $WeightedSample$ over both subtrees will return either of the two subtrees with probability proportional to the distribution computed by \textsc{OnePass}, which is precisely $P(T_L) = \frac{|c_L|}{|T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1)}$ and $P(T_R) = \frac{|c_R|}{|T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1)}$. By inductive hypothesis, we know that $|c_L|$ and $|c_R|$ are correct, and combined with the fact that $|T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1) = \abstree(1,\ldots, 1)$, since the algorithm makes a call to $WeightedSample$, this then proves the inductive step for the case when the root of $\etree$ is $+$.
For the case when the root is a $\times$ node, it is the case that both subtrees compose together one monomial. Here we have that the joint probability of selecting both $\etree_{\vari{L}}$ and $\etree_{\vari{R}}$ is $P(\etree_{\vari{L}} \text{ and } \etree_{\vari{R}}) = P(\etree_{\vari{L}}) \cdot \etree_{\vari{R}})$ which is the same computation made in $\onepass$, and by inductive hypothesis we have correctness.
For the case when the root is a $+$ node, \sampmon ~will sample the $i^{th}$ monomial $m$ from either $\etree_\vari{L}$ or $\etree_\vari{R}$. Since algorithm ~\ref{alg:sample} is choosing $m$ from either \vari{E}($\etree_\vari{L}$) or \vari{E}($\etree_\vari{R}$), we are choosing $m$ out of $|\etree_\vari{L}|(1,\ldots, 1) + |\etree_\vari{R}|(1,\ldots, 1) = \abstree(1,\ldots, 1)$ possible choices, thus $P(\randvar = m) = \frac{|c_i|}{\abstree(1,\ldots, 1)}$, and correctness follows.% Suppose the algorithm chooses the sample from $\etree_\vari{L}$. Then $P(\randvar = m) = \frac{|c_m|}{|\etree_\vari{L}|(1,\ldots, 1) + |\etree_\vari{R}|(1,\ldots, 1)}$. Since the algorithm is selecting between $m_i$ and $m_j$ in $\expandtree$
%, it is the case that both subtrees compose together one monomial. Here we have that the joint probability of selecting both $\etree_{\vari{L}}$ and $\etree_{\vari{R}}$ is $P(\etree_{\vari{L}} \text{ and } \etree_{\vari{R}}) = P(\etree_{\vari{L}}) \cdot \etree_{\vari{R}})$ which is the same computation made in $\onepass$, and by inductive hypothesis we have correctness.
%, thus no more sampling is necessary, and the algorithm correctly returns the product of the sample output for existing subtrees. This behavior is correct since it is the equivalent of the weights precomputed by \textsc{OnePass} for a $\times$ node, where we select both subtrees of the node with probability $\frac{|c_L| \cdot |c_R|}{|T_L|(1,\ldots, 1) + |T_R|(1,\ldots, 1)}$. This concludes the proof.
\end{proof}
@ -315,6 +320,9 @@ For the case when the root is a $\times$ node, it is the case that both subtrees
\subsubsection{Run-time Analysis}
Algorithm ~\ref{alg:sample} has a runtime between $\Omega(depth(\etree))$ and $O(|\etree|)$.
\AH{I am concerned that I am not approaching this either correctly or the way Atri is viewing this. There is no $k$ product width factor in this analysis. Please let me know how I can make this better.}
Note that for the case that all internal nodes were $\times$ nodes, every node would be visited with a constant number of operations, yielding $O(|\etree|)$ time. For the case of when all internal nodes are $+$ nodes, then we have a runtime of $\Omega(depth(\etree))$, since for each node, the algorithm would sample one of its two children, until it reached a leaf.
\begin{Lemma}\label{lem:alg-sample-runtime}
For $k = deg(\etree)$, algorithm ~\ref{alg:sample} has a runtime $O(k \cdot depth(\etree))$.
\end{Lemma}
For any $\etree$ of degree $k$, it is the case that the number of leaf nodes visited will be $O(k)$, since at most $k$ variable and $k$ coefficient leaves are visited.
Second, consider that in each level of binary tree $\etree$, $O(k)$ nodes are visited. It follows that algorithm ~\ref{alg:sample} runs in $O(k \cdot depth(\etree))$ time.