liesel icon indicating copy to clipboard operation
liesel copied to clipboard

Should Liesel.model be more strict about consistent parameter and observed nodes?

Open jobrachem opened this issue 5 months ago • 0 comments

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 and observed: bool as init arguments to lsl.Var.
    • raise an error with both are true.
    • raise an error if the variable is being initialized with a distribution and both parameter and observed 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 the lsl.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 have Var.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.

jobrachem avatar Aug 28 '24 16:08 jobrachem