Spatiotemporal matrix definition

136 views
Skip to first unread message

Michael Redman

unread,
Jan 13, 2017, 8:57:00 PM1/13/17
to stan-...@googlegroups.com
Hi all!

Sorry, I have a really basic question but couldn't find the answer from the error message. I have a model where there are separate space and time components (random walk and CAR) but i'm getting an error when trying to define the model. Here's the error,

ValueError: Failed to parse Stan model 'anon_model_297587f7140f457644e8760d4e424878'. Error message:
SYNTAX ERROR
, MESSAGE(S) FROM PARSER:


No matches for:


  vector
~ poisson_log(vector)


Available argument signatures for poisson_log:


 
int ~ poisson_log(real)
 
int ~ poisson_log(real[])
 
int ~ poisson_log(vector)
 
int ~ poisson_log(row vector)
 
int[] ~ poisson_log(real)
 
int[] ~ poisson_log(real[])
 
int[] ~ poisson_log(vector)
 
int[] ~ poisson_log(row vector)


require real scalar return type for probability function.


ERROR at line
94


 
93:        for (t in 1:nt){
 
94:     observed[t] ~ poisson_log(log_expected + rep_vector(temporal[t], numRegions) + v);
                                                                                             
^
 
95:        }

observed and log_expected are defined in data as, 

vector[nt] observed[numRegions];
vector[numRegions] log_expected; // The expected number of counts based on demographics etc

which I tried after using

matrix[numRegions, nt] observed;  // The observed counts at each point

for (t in 1:nt){
col(observed, t) ~ poisson_log(log_expected + rep_vector(temporal[t], numRegions) + v);
}

and v and temporal are defined as parameters,

vector[nt] temporal;
vector
[numRegions] v; // Spatial smoothing component


I know I'm doing something very basic wrong here but I can't figure out the syntax! Also, is this the most efficient way of defining this? And with observed defined as a vector of vectors will passing a numpy matrix as the data work?

Any help would be appreciated - thanks!



 

Bob Carpenter

unread,
Jan 13, 2017, 9:49:53 PM1/13/17
to stan-...@googlegroups.com
Stan separates integer and real types. The left-hand side
of poisson_log has to be an integer or array of integers.
That's what the "available signatures" is trying to tell you.
You supplied a vector, which has real values.

- Bob

> On Jan 13, 2017, at 8:57 PM, Michael Redman <michaelal...@gmail.com> wrote:
>
> Hi all!
>
> Sorry, I have a really basic question but couldn't find the answer from the error message. I have a model where there are separate space a time components (random walk and CAR) but i'm getting an error when trying to define the model. Here's the error,
>
> ValueError: Failed to parse Stan model 'anon_model_297587f7140f457644e8760d4e424878'. Error message:
> SYNTAX ERROR, MESSAGE(S) FROM PARSER:
>
>
> No matches for:
>
>
> vector ~ poisson_log(vector)
>
>
> Available argument signatures for poisson_log:
>
>
> int ~ poisson_log(real)
> int ~ poisson_log(real[])
> int ~ poisson_log(vector)
> int ~ poisson_log(row vector)
> int[] ~ poisson_log(real)
> int[] ~ poisson_log(real[])
> int[] ~ poisson_log(vector)
> int[] ~ poisson_log(row vector)
>
>
> require real scalar return type for probability function.
>
>
> ERROR at line 94
>
>
> 93: for (t in 1:nt){
> 94: observed[t] ~ poisson_log(log_expected + rep_vector(temporal[t], numRegions) + v);
> ^
> 95: }
>
> observed and log_expected are defined in data as,
>
> vector[nt] observed[numRegions];
> vector[numRegions] log_expected; // The expected number of counts based on demographics etc
>
> which I tried after using
>
> matrix[numRegions, nt] observed; // The observed counts at each point
>
> and v and temporal are defined as parameters,
>
> vector[nt] temporal;
> vector[numRegions] v; // Spatial smoothing component
>
>
> I know I'm doing something very basic wrong here but I can't figure out the syntax! Also, is this the most efficient way of defining this? And with observed defined as a vector of vectors will passing a numpy matrix as the data work?
>
> Any help would be appreciated - thanks!
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michael Redman

unread,
Jan 13, 2017, 10:24:51 PM1/13/17
to Stan users mailing list


Ah ok - thanks! I knew it must have been something simple.

p.s. wow did the model run quickly. I've been using pymc3 and the same model took ~12hours to get something reasonable with metropolis (couldn't use NUTS as advi initialisation wasn't budging from NaN EBLO and it couldn't find the hessian for scaling) but this took less than a minute. Awesome!   
Reply all
Reply to author
Forward
0 new messages