11
$\begingroup$

In R, c(3,1,0) * c(2,0,1) == c(6,0,0). This is not dot product and it's not cross product. First, what is the name for this product, and second, does it work in WinBUGS, OpenBUGS and/or JAGS?

$\endgroup$
1
  • 2
    $\begingroup$ this is just element-wise multiplication. i'm not sure if it works in WinBUGS, OpenBUGS, or JAGS. $\endgroup$ Commented Jan 6, 2012 at 7:05

4 Answers 4

4
$\begingroup$

Unlike JAGS, WinBUGS and OpenBUGS does not do this form of vectorization; you have to write a loop, and compute each element 'by hand', as described above.

$\endgroup$
7
$\begingroup$

Martyn Plummer points out that this is implemented in JAGS, which I missed when reading the manual. From Ch 5:

Scalar functions taking scalar arguments are automatically vectorized. They can also be called when the arguments are arrays with conforming dimensions, or scalars. So, for example, the scalar $c$ can be added to the matrix $A$ using

B <- A + c

instead of the more verbose form

D <- dim(A)
for (i in 1:D[1])
  for (j in 1:D[2]) {
    B[i,j] <- A[i,j] + c
  }
}
$\endgroup$
2
$\begingroup$

To do element-wise multiplication you can just make a for loop in those languages and that's it! I've used for loops in WinBUGS with no problems.

$\endgroup$
5
  • $\begingroup$ What question does this reply address? It does not seem to be relevant here. $\endgroup$
    – whuber
    Commented Jan 6, 2012 at 23:46
  • $\begingroup$ @whubber, why? It is perfectly relevant. Ok, I changed the post a little to be more clear. $\endgroup$
    – Tomas
    Commented Jan 6, 2012 at 23:49
  • $\begingroup$ Yup, a for loop is what I've been doing so far; I'd just wondered if a vectorized version was possible. $\endgroup$ Commented Jan 6, 2012 at 23:59
  • $\begingroup$ I've submitted a feature request to JAGS: sourceforge.net/tracker/… $\endgroup$ Commented Jan 7, 2012 at 0:04
  • $\begingroup$ Thanks, Tomas. Now I see the connection: you're not answering the question as stated, but you are offering a workaround. $\endgroup$
    – whuber
    Commented Jan 7, 2012 at 0:08
2
$\begingroup$

Incidentally, element-wise multiplication of two equal length vectors is called the Hadamard product (aka the Schur product).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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