liesel
liesel copied to clipboard
Should Liesel.model be more strict about consistent parameter and observed nodes?
At the moment, Liesel lets you initialize a variable with a distribution without declaring it as a parameter or an observed variable. This can lead to inconsistencies in the model, such that it could be that:
lsl.Model.log_prob ≠ (lsl.Model.log_lik + lsl.Model.log_prior)
i.e. the posterior is not equal to the likelihood plus the prior. This is, because the log_lik
and log_prior
attributes rely on the lsl.Var.parameter
and lsl.Var.observed
attributes to identify the variables to count for the respective values.
Possible options would be:
- Add
parameter: bool
andobserved: bool
as init arguments tolsl.Var
.- raise an error with both are true.
- raise an error if the variable is being initialized with a distribution and both
parameter
andobserved
are false. - Loophole: For parameters with a constant prior, you do not usually specify a distribution. So these parameters are not covered by this case: you could have a
lsl.Var
object that should be a parameter, but that does not have a distribution. At the moment, nothing bad will happen as a result - but it is a little unsatisfying to me.
- Check for consistent decomposition of the
log_prob
in thelsl.Model
initialization. Raise an error if the decomposition is inconsistent.- The same constant-prior-loophole as above applies.
- Loophole: If a Var with
.parameter=False
just so happens to haveVar.log_prob = 0.0
, the test will not discover an inconsistency in the log prob decomposition caused by this var.
I am not sure if this should be solved with code, but I'd like to discuss the issue.