flatironinstitute / bayes-kit

Bayesian inference and posterior analysis for Python
MIT License
43 stars 3 forks source link

For samplers, check that initialization values for parameters match the size/dimensions of the input model #29

Open jsoules opened 1 year ago

jsoules commented 1 year ago

The goal of this issue is to implement a more robust fix for the issue exposed through PR #28.

Many samplers in this package can accept a set of explicit initial parameter values (constructor parameter init). Currently, there's no check that the supplied prior for the model parameters actually has the right size/shape, leading to possible undefined behavior.

Most likely the fix is going to be something like modifying the constructors of the affected samplers to throw an error if init.shape != model.dims(), but there's a few issues to discuss:

  1. Do we have a clear design decision that model dimensions are always linear?
  2. In the event that the init parameter has the right overall length but a different shape from _theta, do we want to reshape or throw?
  3. Can/should we generalize this check to avoid code repetition among the different affected models, either through a Protocol with a partial implementation, or through a shared utility function, etc? We've talked about inheritance vis-a-vis samplers, but haven't really implemented anything like it yet.

I expect the overall code changes to be minimal (unless we get really ambitious with project structure), but I'd like to have a record of the discussion in case we need to refer back to it.