Syntax error, message(s) from parser:

Hi, do you know why does this error message generate?
In my function block, first I defined integral function and then defined likelihood function as likelihood_log(){…} . I am trying to do some integrations within likelihood function and return log likelihood. Any help?

SYNTAX ERROR, MESSAGE(S) FROM PARSER:
 error in 'model2e9c734b369_44cdcf1353fac8db7bb5ebd1e42635a8' at line 88, column 96
  -------------------------------------------------
    86:       }
    87:       
    88:       D[1]=beta_t[2]*integrate_1d(WQ_integral,t[1], t[2], { mu, sigma2, alpha, lambda }, {t[2]}, {}, 1e-8);
                                                                                                       ^
    89:       
  -------------------------------------------------

PARSER EXPECTED: <expression>

The parser has problems with empty arrays so you can’t write {}. A non-empty array like {0} should work. Alternatively you can declare a size zero array in transformed data and use that

transformed data {
  int x_int[0]; // x_int is an empty array
}

It says fifth argument is the problem. Where is t defined? It must be in data or transformed data block.
Or maybe you could put t[3] in the previous array that is allowed to have parameters.

integrate_1d(WQ_integral,t[1], t[2],{ mu, sigma2, alpha, lambda, t[3] }, {0.0}, {0}, 1e-8))

As I think, in my case, it is not possible to define t in data or transformed data block because vector t updates over a for loop as this,
functions{
.
.
.

real likelihood_log(){
.
.
.
for (i in 1:rows(DataTable)){

  t = rep_vector(0,K+2); 
  t[1]=0;
  t[2]=DataTable[i,1]; 
  
  for (j in 3:6) {    
    t[j]=t[j-1]+delta;
  }

  D[1]=beta_t[2]*(integrate_1d(WQ_integral,t[1], t[2], { mu, sigma2, alpha, lambda }, {t[2]}, {0}, 1e-8));

.
.
.
.

}

}

Then you have to put it in the same array as mu, sigma2, alpha, and lambda.

Thank you. Here, as t is a vector of six elements (say) and then I got an error again because I parse mu , sigma2 , alpha , and lambda through real[] theta. Any idea is highly appreciated.

real WQ_integral(real x,
real xc,
real[] theta,
real[] x_r,
int[] x_i){

       real mu = theta[1];
       real sigma2 = theta[2];
       real lambda = theta[3];
       real alpha = theta[4];
       vector t= theta[5];
      .
      .
      .
       return(WQ);
  }
integrate_1d(WQ_integral,t[1], t[2], { mu, sigma2, alpha, lambda, t }, {t[2]}, {0}, 1e-8)

In the earlier code you only had t[2] but now you’re passing the full vector (and also t[2] in the other array which should not be there).
I don’t quite follow what you are trying to do. Can you post the full model?

This will help you to grasp some idea.
real WQ_integral(real x,
real xc,
real[] theta,
real[] x_r,
int[] x_i){

       real mu = theta[1];
       real sigma2 = theta[2];
       real lambda = theta[3];
       real alpha = theta[4];
       //vector t= theta[5];
       real WQ;
       int t1;
       WQ = (0.3*exp(-((log(x)-mu)^2)/(2*sigma2))/(sqrt(2*pi()*sigma2)*x))*(exp(-(lambda*((t1-x)^alpha))));
       return(WQ);
  }

t = c(0,50,51,52,53,54);
integrate_1d(WQ_integral,t[1], t[2], { mu, sigma2, alpha, lambda, t}, {t[2]}, {0}, 1e-8)

Here, t1 should have one particular value from vector t.

Maybe something like this

real WQ_integral(real x,
      real xc,
      real[] theta,
      real[] x_r,
      int[] x_i){

  real mu = theta[1];
  real sigma2 = theta[2];
  real lambda = theta[3];
  real alpha = theta[4];
  real tn = theta[5];
  real WQ;
  int t1;
  WQ = (0.3*exp(-((log(x)-mu)^2)/(2*sigma2))/(sqrt(2*pi()*sigma2)*x))*(exp(-(lambda*((tn-x)^alpha))));
  return(WQ);
}

t = c(0,50,51,52,53,54);

integrate_1d(WQ_integral,t[1], t[2], { mu, sigma2, alpha, lambda, t[n]}, {0.0}, {0}, 1e-8)

where n is the particular element of t you want.

Thanks. Will try for that. :)

In the above mentioned integrate_1d() function, I should parse a real value for t[n], but my t is a vector of integers. Do I want to convert it as a real number of vectors? I mean t = c(50.0,51.0,52.,53.,)

Stan converts integers automatically to real number when needed. It’s the other direction (going from a real number to an integer) that’s difficult.

If so it is not the error in my code.

Do you have any idea about

file2c585b18381.cpp:375:1452: note: cannot convert ‘stan::math::array_builder::array() with T = stan::math::var’ (type ‘std::vectorstan::math::var’) to type ‘const std::vector&’

This is a part of error what I got earlier.

A C++ error? That’s an error in the Stan compiler. Can you share the model that caused it?

Yes it is the compilation error in Stan, As the code is so long I can share some parts.
Within my likelihood function I am doing some integrations as mentioned earlier comments,

real likelihood_log(matrix RT, real[] param, int K, int L){
.
.
vector[4] t= c(50,55,60,65) ;
integrate_1d(integral_func,t[1], t[2],{ mu, sigma2, alpha, lambda, t[2]}, {0.0}, {0}, (1e-8));
.
.
return loglikelihood;
}

model{
//prior distributions
mu ~ uniform(4.0,4.5);
sigma2 ~ uniform(0.01,0.05);
lambda ~ uniform(0.01,0.5);
alpha ~ uniform(1.5,4.0);
DT ~ likelihood({mu,sigma2,lambda,alpha}, 4, 1);
}

Once defining integral function in the function block, is it possible to parse this integration with the likelihood function which is defined in the function block?
If someone can give me some idea on this?