11

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?

Jack Tanner
  • 4,552
  • 3
  • 27
  • 39

4 Answers4

5

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
  }
}
Jack Tanner
  • 4,552
  • 3
  • 27
  • 39
4

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.

guest
  • 2,381
  • 14
  • 11
2

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.

Tomas
  • 5,735
  • 11
  • 52
  • 93
  • What question does this reply address? It does not seem to be relevant here. – whuber Jan 06 '12 at 23:46
  • @whubber, why? It is perfectly relevant. Ok, I changed the post a little to be more clear. – Tomas Jan 06 '12 at 23:49
  • Yup, a for loop is what I've been doing so far; I'd just wondered if a vectorized version was possible. – Jack Tanner Jan 06 '12 at 23:59
  • I've submitted a feature request to JAGS: https://sourceforge.net/tracker/?func=detail&aid=3470513&group_id=176821&atid=878777 – Jack Tanner Jan 07 '12 at 00:04
  • Thanks, Tomas. Now I see the connection: you're not answering the question as stated, but you are offering a workaround. – whuber Jan 07 '12 at 00:08
2

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