0
$\begingroup$

Is there a smart way to formulate the following as one matrix multiplication, $$\sum_{i=1}^nh_i \sum_{k=1}^KH_{ik} p_{ik}$$ as something like $\mathbf{h*(H*p)}$?

The only way I can think of is to augment $\mathbf{H}$ and $\mathbf{p}$ with 0 to be n-by-nK, nK-by-nK matrices respectively.

$\endgroup$
  • $\begingroup$ This appears to be mathematics rather than stats, and likely belongs on math.SE. $\endgroup$ – Glen_b Sep 16 '15 at 12:46
  • $\begingroup$ @Glen_b, I see. I thought about where I should put this too. Thanks. Regardless, it got some good answers. I will post accordingly next time! $\endgroup$ – villybyun Sep 16 '15 at 17:20
0
$\begingroup$

Also if you define $*$ as coordinate-wise multiplication, and $\mathbf{1_k}$ as the $k$ dimension column vector, $$ \mathbf{ h^T (H * p) 1_k } $$ does the trick. And it should be fewer operations.

$\endgroup$
1
$\begingroup$

If $\mathbf{H}$ and $\mathbf{p}$ are $n\times K$ matrices and $\mathbf{h}$ is $n\times 1$ vector then you write this product as

$$\mathbf{h}^T\mathrm{diag}(\mathbf{H}\mathbf{p}^T)$$

where $\mathrm{diag}$ is the operator which takes a matrix and returns its main diagonal as a vector.

$\endgroup$
  • $\begingroup$ This indeed does the operation but is quite redundant in the operations. $\endgroup$ – villybyun Sep 16 '15 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.