Hello Stan community! I have been struggling with this issue for a few days, and I suspect it may be due to a problem with matrix multiplication:

```
data {
int<lower=1> N;
int<lower=0> D;
matrix[N,N] T_dis;
matrix[N,2] d;
vector[N] s;
int<lower =0> y[N];
real tau;
}
parameters {
real<lower=0> a0;
real<lower=0> a1;
simplex[D] theta[N];
vector[D] G[N];
}
transformed parameters{
matrix[N, D] Z;
vector[N] p;
vector[N] ones_vector = rep_vector(1, N);
for(n in 1:N){
Z[n] = softmax((log(theta[n]) + G[n])/tau)';
}
for(n in 1:N){
//p[n] = 100
for(j in 1:N){
if(j!=n){
p[n] += dot_product(Z[n], Z[j])*pow(T_dis[n,j], -2) + (1-dot_product(Z[n],Z[j]))*pow(distance((d'*Z*(Z[j])')/(ones_vector'*Z*(Z[j])'),d[n]),-2);
}
}
p[n] = 1-exp(-(a0+a1*s[n])*p[n]);
}
}
model {
a0 ~ gamma(3,1);
a1 ~ gamma(3,1);
for(n in 1:N){
theta[n] ~ uniform(0,1);
G[n] ~ gumbel(0,1);
target += bernoulli_lpmf(y[n]|p[n]);
}
}
```

The error message looks like:

Chain 1: Rejecting initial value:

Chain 1: Error evaluating the log probability at the initial value.

Chain 1: Exception: bernoulli_lpmf: Probability parameter is nan, but must be in the interval [0, 1] (in ‘anon_model’, line 39, column 4 to column 40)

Chain 1: Initialization between (-2, 2) failed after 100 attempts.

Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

Any thought or suggestions would be helpful! Thank you!