Many thanks to those who replied to my query on how to use (nonexistant)
inverse trig functions in WinBUGS. Most of the solutions, unfortunately,
were computationally impractical in the context of my particulcar model.
However, they may work well for non-state-space applications and/or with
much smaller datasets than mine (>500 observations). In the end, I realised
that I could simply use the identity cos(arctan x) = 1/sqrt(1+x^2) and
back-transform the model output in S+. Not ideal but it works! Details of
some of the suggested solutions are posted below. Original post is at the
end.
Cheers,
__________________________
Ian Jonsen
Department of Biology
Dalhousie University
Halifax, NS CANADA B3H 4J1
phone: (902) 494-3910
fax: (902) 494-3736
[log in to unmask]
Andrew Millard suggested the following work-arounds which, for my particular
model, work to some degree but at a very large computational price.
>
>There may be a work-around, depending on your model. if you would like to
write
>alpha <- arctan((true.x-obs.x)/(true.y-obs.y))
>then you may be able to write
>true.x <- obs.x + (true.y-obs.y) * sin(alpha)/cos(alpha)
>and infer a posterior distribution for alpha, but it will depend on
>whether your directed acyclic graph can be redrawn with this dependency.
>Alternatively approximate values can be gained by
>
>tan.alpha <- (true.x-obs.x)/(true.y-obs.y)
>alpha.tan <- sin(alpha)/cos(alpha)
>p <- tan.alpha - alpha.tan
>zero <- 0
>zero ~ dnorm(p, M)
>M <- 100000000
># and a prior on alpha, for example
>alpha ~ dunif (0, 3.14)
Steve Graighead kindly faxed me a series of approximation for transcendental
functions (from Abramowitz & Stegun. Handbook of mathematical functions.
Dover Publications)...also available in most Calculus textbooks. The
approximations were generally reasonable but slowed down the sampling
considerably.
Andrew Thomas promised that he would add code for arctan (and presumably
arccos & arcsin) to WinBUGs in the near future.
-----
Hello,
I'm attempting to code a state-space model in WinBUGS (1.3 or 1.4) that
requires finding the angular distance between a 'true' location and an
observed location. eg. arctan((true.x-obs.x)/(true.y-obs.y))
Unfortunately, only sin and cos functions appear to be available in the BUGs
language (is this true?). The only Taylor series that I am aware of to
approximate arctan x, only works for x<=1 and requires a computationally
impractical number of iterations as x approaches 1. So, I'm wondering if
anyone has any other tricks for using arctan (or inverse trig functions in
general) in BUGs?
Thanks,
Ian Jonsen
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|