Adding functions, Bi-linear interpolation

39 views
Skip to first unread message

Jóhannes Guðbrandsson

unread,
Jan 2, 2017, 6:04:59 AM1/2/17
to LibBi Users
Hi everyone

I am trying to develop a state-space model for fish movement at sea. I have data from data-storage-tags (DST) that the fish is tagged with and it records temperature and depth once every hour for over 400 days.
So the location (lon, lat) are my states. So for each day I have a matrix (dim 240x80) with known temperature at specific coordinates (1/4° resolution) and to get the expected temperature at my state I have been using
bi-linear interpolation. I have filtered the data to get only one temperature measurement per day.
 
I have been trying to use Jags and Stan for this problem with limited results. I have been able to run it in Jags but as expected the convergences has been very slow and some chains get stuck and do not convergence at all. 
So my questions are

1. Can I easily add functions such as bilinear interpolation to LibBi? Or should I just have a very complex observation block?
2. How much data can LibBi handle or what kind of a machine do I need to able to run this kind of problems?

Thanks
Jóhannes

Lawrence Murray

unread,
Jan 2, 2017, 7:41:18 AM1/2/17
to libbi...@googlegroups.com

Hi Jóhannes,

In answer to your questions:

1. Your known temperatures can be an input variable in LibBi, with your matrices stored in a NetCDF file. While there is no bilinear interpolation function in LibBi, from your lon/lat state you can look up the four grid points needed from your input matrix using floor() and ceil() functions and then interpolate them in a single line of code. Does that achieve what you need?

2. You can run LibBi on anything from your laptop up to, in our latest work (see https://arxiv.org/abs/1612.03319) a cluster of 128 GPUs. Difficult to know how much compute might be necessary for your given problem though, without knowing more about the model, both its size (number of dimensions) and its complexity (behaviour, e.g. nonlinearity). I understand you have a time series of 400 observations (daily, after filtering) from each tag. How many tags are there? Do the states (fish) interact in the model or are they assumed independent?

Cheers,

Lawrence

--
You received this message because you are subscribed to the Google Groups "LibBi Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libbi-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jóhannes Guðbrandsson

unread,
Jan 2, 2017, 9:30:03 AM1/2/17
to LibBi Users
Hi Lawrence thanks for a quick response.

1. Yes it does.
2. I didn't really tell the whole story. I would model each fish independently (at least to begin with). I also use the depths to get information about location as my species (salmon) stays near the surface during the night but dives down during the day. So I calculate the solar elevation from the location and time. So in addition to the 400+ temperature measurements I am using 24x400+ depth measurements. My feeling is that this is very non-linear. The fish is not nice enough to always behave in this informative way so I would like to model depth behavioral states as well; the one described before, staying near the surface all day and finally rare deep dives (much deeper than the regular ones) not related to day/night. These different behavioral states are also interesting biologically although they do not give information about the location of the fish.

It seems to me that I am more likely to get some results with LibBi than jags or stan for this model. I will try your software and be in touch if I get into trouble.

I like to add one more question
3. Can I specify a known final state in LibBi?

Thanks again
Jóhannes

Jóhannes Guðbrandsson

unread,
Jan 3, 2017, 8:17:13 AM1/3/17
to LibBi Users
One more question
4. Can the transition parameters change over time.
My salmon grows from 20cm to 65cm over the time series and it maximum swimming speed increases accordingly. I have model the movement in polar coordinates and transformed to longitude and latitude
size_lim #vector of size n with the maximum travel length for each day
u ~ uniform(0,1)#vector of size n
theta ~ uniform(-pi,pi) #vector of size n
r <- size_lim*sqrt(u)
for (i in 2:n){
    lon[i] <- lon[i-1] + r[i]*cos(theta[i]) * 360 / (2* pi*6371*cos(lat[i-1]*pi()/180));
    lat[d] <- lat[i-1] + r[i]*sin(theta[i]) / 111.2;
    
Can I do something similar in LibBi or do I need to have the transition constant over time?

Cheers
Jóhannes

Lawrence Murray

unread,
Jan 10, 2017, 9:55:09 AM1/10/17
to libbi...@googlegroups.com
3. A known final state can be very difficult to do inference for, as for a complex model like this you hit the realm of Approximate Bayesian Computation (ABC). LibBi does have some means of dealing with this, most notably the bridge particle filter (see http://epubs.siam.org/doi/10.1137/15M1011214). I'd suggest you start simple and just use your other observations to start with, and try to incorporate the final state later.

4. By way of terminology, in LibBi (indeed in the statistics community more broadly) parameters do not change in time, whereas state variables do. What you'll want to do here is turn what were your original parameters into state variables, and introduce some transition model that allows them to slowly vary in time, e.g. an autoregressive process. This process might itself have some (static) parameters that need to be estimated. So yes, you can model what you want, it's just that in LibBi's chosen terminology, the idea of parameters changing in time is an oxymoron! You might find this paper interesting, where we did precisely this (using a prehistoric version of LibBi): http://onlinelibrary.wiley.com/doi/10.1890/12-0312.1/abstract. The associated code is in the NPZD package (http://libbi.org/packages/NPZD.html).

Jóhannes Guðbrandsson

unread,
Jan 10, 2017, 11:28:16 AM1/10/17
to LibBi Users
Thanks Lawrence

I think I get the idea. I must confess that the papers are a bit to much for me with limited background in the algorithms behind Bayesian statistics. 
I just discovered Biips which I think will be easier for me develop my model since it uses the bugs-langues.
I might try LibBi out if it does not work out.

Thanks again for taking the time to answer my questions
Jóhannes
Reply all
Reply to author
Forward
0 new messages