# Expectation of Quadratic Product of Bernoulli Vector and Gaussian Matrix?

I have a $$K$$-dimensional vector $$z$$ of Bernoulli random variables with success probabilities vector $$p$$ and a $$K \times D$$ dimensional matrix $$A$$ such that each row $$A_k$$ is a $$D$$-dimensional Gaussian random variable with mean vector $$\mu_k$$ and covariance matrix $$\Sigma_k$$. I would like to compute the following expected value:

$$\mathbb{E}_{z, \{A_k\}}[\operatorname{diag}(z)\, A A^T \, \operatorname{diag}(z)]$$

where $$\operatorname{diag}(z)$$ is a square $$K \times K$$ matrix with $$z$$ as its diagonal elements.

How can I do this?

Also, if anyone can suggest a better title, please let me know :)

• If $z_i$ is independent from both $z_j$ and $A_j$, then the expected value is the matrix $\operatorname{diag}(p)\, \bigl(\Sigma + \mu\mu^T\bigr)\, \operatorname{diag}(p)$. Can we assume that these variables are independent? Oct 13 at 20:45
• Yes, they are independent! Oct 13 at 21:30

Define $$B:=\mathrm{diag}(z)A = \pmatrix{&z_1 A_1& \\ &\vdots& \\ &z_K A_K}$$. Note that $$M :=\mathbb{E}[\mathrm{diag}(z)\, A A^T \, \mathrm{diag}(z)] = \mathbb{E}[BB^T]$$.
Let's do some calculations: $$M_{ij} = \mathbb{E}[(BB^T)_{ij}]=\mathbb{E}[z_i A_i (z_j A_j)^T]=\mathbb{E}[z_iz_jA_i{A_j}^T]=\mathbb{E}[z_iz_j]\,\mathbb{E}[A_i{A_j}^T]=\mathbb{E}[z_i]\,\mathbb{E}[z_j]\,\mathbb{E}[A_i{A_j}^T]=p_ip_j\bigl(\mathrm{Cov}(A_i, A_j) + \mathbb{E}[A_i]\mathbb{E}[{A_j}^T]\bigr) = p_i\bigl(\mathrm{Cov}(A_i, A_j)+\mu_i{\mu_j}^T\bigr)p_j$$
Hence the result is $$M = \mathrm{diag}(p)\bigr(\Sigma + \mu{\mu}^T\bigr)\mathrm{diag}(p)$$ where $$\mu=\pmatrix{&\mu_1&\\&\vdots&\\&\mu_K&}$$ and $$\Sigma_{ij}=\mathrm{Cov}(A_i,A_j)$$
• I think this is almost correct. The one problem is that you can't just replace $z$ with $p$ in the expectation. To see why, suppose E[A A^T] = I and z is 1 dimensional. Then we have $E[z_1^2]= E[z_1] = p_1$. But your answer gives $p_1^2$. Oct 14 at 1:34
• You are right! The calculation of $M_{ii}$ must be treated separately Oct 14 at 8:09