Add input format checks for HMM models: Initialization, Transition and select Emission #434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This PR aims to improve the usability of the package and solve 2 issues.
params
variable after initialization.Reproducible sample of issue
Result is a hidden state vector of
[1,0,0,0,0]
corresponding to an immediate transition from state 1 to state 0 due to the implicit "padding" of the transition matrix with 0's. The biases vector is also used in a row-wise expanded form.Solution
The idea is to add shape/sanity checks as early as possible within model definition which is usually when
model.initialize(**kwargs)
is called. Checks integrated as follows:StandardHMMInitialState
: uniform across HMM models; assertion error with exact shape requirement output if different shape given, also stochasticity of the vector (non-negative entries summing to 1);StandardHMMTransitions
: same as above; each row of the matrix checked for stochasticity;CategoricalHMM
andLinearAutoregressiveHMM
because I use them currently. Given positive feedback it is straightforward to extend to remaining models.Let me know if there are any questions or you need further clarification!