This is my first Stan model, so please be gentle ;)
I am trying to set up a robust linear regression model using the probability density proposed by Barron in
Barron, Jonathan T. “A general and adaptive robust loss function.” Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition . 2019.
Here is the code:
functions {
real barron_lpdf(vector x, vector mu, real alpha, real c) {
vector[num_elements(x)] prob;
for (i in 1:num_elements(x)) {
if (alpha == 2) {
prob[i] = -0.5*((x[i]-mu[i])/c)^2;
} else if (alpha == 0) {
prob[i] = -log(0.5*((x[i]-mu[i])/c)^2+1);
} else if (alpha == negative_infinity()) {
prob[i] = exp(-0.5*((x[i]-mu[i])/c)^2) - 1;
} else {
prob[i] = - abs(alpha-2)/alpha*(pow(((x[i]-mu[i])/c)^2/abs(alpha-2)+1,alpha/2)-1);
}
return sum(log(prob));
}
}
}
data {
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real y0; // intercept
real slope;
real<lower=0> alpha;
real<lower=0> c;
}
model {
y0 ~ normal(0,1);
slope ~ normal(0,1);
alpha ~ normal(0,1);
c ~ normal(0,1);
y ~ barron(y0 + slope * x, alpha, c);
}
The idea behind the Barron density/loss is to have a parameter (alpha
) that can be tuned to control the shape of the loss. I am getting this error:
RuntimeError: Exception during call to services function: `ValueError("Initialization failed. Rejecting
initial value: Log probability evaluates to log(0), i.e. negative infinity. Stan can't start sampling from this
initial value. Rejecting initial value: ...")`, traceback: `[' File
"/Users/arrigo/opt/anaconda3/envs/warp-env/lib/python3.10/asyncio/tasks.py", line 232, in
__step\n result = coro.send(None)\n', ' File "/Users/arrigo/opt/anaconda3/envs/warp-
env/lib/python3.10/site-packages/httpstan/services_stub.py", line 185, in call\n future.result()\n', ' File
"/Users/arrigo/opt/anaconda3/envs/warp-env/lib/python3.10/asyncio/futures.py", line 201, in
result\n raise self._exception.with_traceback(self._exception_tb)\n']`
The model seems correct to me. Any ideas?