When do you adjust for the jacobian?
option1: You can either not worry about the jacobian
with pm.Model() as transform_model:
y = pm.Gamma('y', 2, 4)
y_inv = pm.Deterministic('y_inv', 1 / y)
mydata = pm.Normal('mydata', mu=0, tau=y_inv, observed=obs)
option2: or adjust for it like following:
with pm.Model() as transform_model:
y = pm.Gamma('y', 2, 4)
y_inv = pm.Deterministic('y_inv', 1 / y)
constrain = pm.Potential('constrain', -2 * tt.log(y_inv))
mydata = pm.Normal('mydata', mu=0, tau=y_inv, observed=obs)
The above examples are borrowed from the stan manual.
I am confused because in stan, it seems that you don’t have to correct for the jacobian if the parameter of interest in the parameter
block like following:
parameters {
real<lower=0> y;
}
transformed parameters {
real<lower=0> y_inv;
y_inv = 1 / y;
}
model {
y ~ gamma(2,4);
}
whereas if the transformed variable is in the parameter
block but you sample the untransformed variable, you want to correct for the jacobian
parameters {
real<lower=0> y_inv;
}
transformed parameters {
real<lower=0> y;
y = 1 / y_inv; // change variables
}
model {
y ~ gamma(2,4);
target += -2 * log(y_inv); // Jacobian adjustment;
}
parameter
, transformed parameter
concepts are not present in the pymc3 context… so which one is the correct way?