HI everyone!

I am super new to Stan/ pystan and I try to fit a custom likelihood function to fit one parameter to behavior. From looking online I managed to build the following code. The model compiles and runs, but I think it doesn’t give me what I need because I get a different result using a simple grid search in python. I want to find the parameter k that maximizes the custom function I defined. This is my code:

```
functions {
real softmax_lpdf(real k, int N, vector a, vector b, vector c, vector d) {
real ps;
real pl;
real sum_log_prob;
vector [N] pred;
for (n in 1:N) {
ps = exp(a[n] / (1 + k * c[n]));
pl = 1 - (exp(a[n] / (1 + k * c[n])));
if (d[n] == 0)
pred[n] = log(ps);
else if (d[n] == 1)
pred[n] = log(pl);
}
sum_log_prob = sum(pred);
return sum_log_prob;
}
}
data {
int<lower=0> N; // number of trials
vector[N] a;
vector[N] b;
vector[N] c;
vector[N] d;
}
parameters {
real<lower=0,upper=1> k;
}
model {
target += softmax_lpdf(k | N, a, b, c, d);
}
"""
```

Thank you!