Ill-typed argument error for custom log likelihood function

Hi, I am a beginner to PyStan and I am trying to implement a custom log likelihood function, but am getting “Ill-typed arguments to ‘~’ statement. No distribution ‘prochloro’ was found with the correct signature” no matter what. Even when I try out a very simple function such as

functions {
  real prochloro_lpdf(real u) {
    return u;
  }
}
data {
  int steps;
  int numrows;
  int numcols;
  real nonsyn_df[numrows, numcols];
  real syn_df[numrows, numcols];
  real u;
  real aN;
  real bN;
  real aS;
  real bS;
  real outcome[steps];
}
parameters {
  real<lower=pow(10, 6), upper=pow(10, 10)> Ne;
}
model {
  for (n in 1:steps) {
    outcome[n] ~ prochloro(u);
  }
}

It does not work. The real likelihood function that I was trying out is shown below. Any help or clarification is greatly appreciated!

functions {
  real H(real u, int k, real Ne, real a, real b) {
    real eN1 = u + (a - 2) / Ne;
    real eN2 = u + (b - 2) / Ne;
    real ln1 = log(tgamma(a + b) / (tgamma(2 + a) * (tgamma(b))));
  
    real ln2 = log(eN1 / ((1 + eN1) * eN2) + e());
    real ln3 = log((1 + a * (2 - b)) * eN1 * eN2 + e() * (1 + a * (2 - b)) * (1 + eN1) * pow(eN2, 2));
    real ln4 = log(eN2 * (eN1 + e()* (1 + eN1)) * eN2);
    return k * (ln1 + ln2 + ln3 - ln4);
  }

  real prochloro_lpdf(real u, real Ne, real aN, real bN, real aS, real bS, int numrows, real[,] nonsyn_df, real[,] syn_df) {
    real res = 0;
    int C2_INDEX = 6;
    for (k in 1:numrows) {
      real sNk = nonsyn_df[k, C2_INDEX];
      real sSk = syn_df[k, C2_INDEX];
      real HNk = H(u, k-1, Ne, aN, bN);
      real HSk = H(u, k-1, Ne, aS, bS);
      res += sNk * HNk + sSk * HSk;
      return res;
    }
  }
}

data {
  int steps;
  int numrows;
  int numcols;
  real nonsyn_df[numrows, numcols];
  real syn_df[numrows, numcols];
  real u;
  real aN;
  real bN;
  real aS;
  real bS;
  real outcome[steps];
}

parameters {
  real<lower=pow(10, 6), upper=pow(10, 10)> Ne;
}

model {
  for (n in 1:steps) {
    outcome[n] ~ prochloro(u, Ne, aN, bN, aS, bS, numrows, nonsyn_df, syn_df);
  }
}

It seems like you’re defining lpdf functions with too few arguments. For example, the line

is equivalent to calling target += prochloro_lpdf(outcome[n], u) (up to normalizing constants), but the signature you wrote down only expects 1 argument, not two.

This is covered more in depth in the user’s guide: 22.3 User-defined Distributions | Stan User’s Guide