Hello!
I am trying to write a model for a 2D point process where the number of points (locations) is fixed and known by design, and the locations themselves (the coordinates) are random, and what I am trying to model. I am not sure whether I am doing something wrong or whether this is just not possible in Stan.
Setup
For now I am just simulating data to ensure my model is working
I defined a gaussian process on a 1x1 unit square, \phi(s) , and pick n observed locations s_1,...s_n with probability p(s) = exp(\phi(s))/\int(\phi(s))ds.
My observations and what I consider the data are just the locations (coordinates) of the points that I observe (which I can use to define a variance covariance matrix for the prior of the spatial process \phi(s)) and the number of points that I observe.
So my observations would have a distribution from an inhomogenous Poisson Process with log intensity \phi(s), but where the number of observations is known.
The likelihood then is be for s=(s_1,s_2,\dots, s_n) :
L(s | params ) = P(N=n)*\frac{\prod_{i = 1:n} exp(\phi(s))}{\int\phi(s)ds} = \\ = 1\times \frac{\prod_{i = 1:n} exp(\phi(s))}{\int\phi(s)ds}
The log likelihood=
log(L(s,params) = \sum_{i=1:n}(\phi(s_i)) - n*\int(exp(\phi(s))ds)
With priors:
Where \sigma^2 and \rho are hyperparameters of the variance-covariance matrix \Sigma.
Stan model
I first consider the case in which I already know the integral and pass its value to the model as is (I am simulating data so I can know a very good approximation to this integral for now).
I tried implementing this in Stan by adding a likelihood part for the probability of being sampled, but there is something wrong because the likelihood explodes (becomes very large). I wanted to see if anyone can provide recommendations on whether I am implementing something incorrectly or if this is even possible.
functions{
real pp_lp(int s, vector phi_locs, real est_integral){
return (sum(phi_locs)) - s*log(est_integral);
}
}
data {
int<lower=0> s;
array[s] vector[2] coords;
real est_integral;
}
parameters {
real<lower=0> sigma2;
real<lower=0> rho;
vector[s] phi_locs;
real phi_mean;
}
transformed parameters{
matrix[s,s] SIGMA;
matrix[s,s] L_SIGMA;
SIGMA = gp_exponential_cov(coords, sqrt(sigma2), rho);
L_SIGMA = cholesky_decompose(SIGMA);
}
model {
target += normal_lpdf(phi_mean | 0, 1);
target += inv_gamma_lpdf(sigma2 | 4, 0.5);
target += gamma_lpdf(rho | 2, 4);
target += multi_normal_cholesky_lpdf(phi_locs|rep_vector(phi_mean,s),L_SIGMA);
// likelihood
target += pp_lp(s,phi_locs,est_integral);
}
Thanks for any help!