Comments (9)
Currently there isn't. I'm using a three vector approach to sparse matrices, but each vector is a private attribute right now. Can you describe what type of constraints you'd like to put in? You can tie edges and add edge inertia during training, if either of those help.
from pomegranate.
I'd like to learn an autoregressive (AR)HMM. In this model, there is an inner hidden variable that is connected to itself at next time point and an outer hidden variable. The outer hidden variable is connected to itself in the next time point and to the observation.
This model can be simulated and used for inference in a regular HMM by by creating a single hidden variable whose state space is the Cartesian product of the states of the original hidden variables, plus some tying of the distributions.
To learn this ARHMM, the hmm learning procedure needs a modification. I run the Baum-Welch procedure with the Cartesian-product model, use the returned expected_transitions matrix (which I made Baum-Welch return just like forward-backward does) to calculate the sufficient statistics of the AR model and turn those back into the transition probabilities of the Cartesian-product HMM. This is the point where I need to update the model's transition probabilities.
A possible work-around would be to re-build the model from scratch every iteration but I would have thought that others may find such a feature useful.
Another use-case for this is a program for what-if scenario analysis where the user may want to make modifications to a model and re-run it. The same workaround (regeneration the model) would apply.
from pomegranate.
(edited my previous comment to clarify it a bit)
from pomegranate.
Autoregressive HMMs are super cool, and I would like to add more functionality to both the HMM section and the Bayes net section to make them (and other wild HMM models) easier to build/train/use. However, time is a major limitation in my life right now--I haven't even had time to flesh out factor graphs, which was my goal for this quarter.
Rebuilding the model from scratch is a currently viable solution, though very hacky and inefficient. I agree there should be a better way; and adding it shouldn't be too difficult. I'll add in a method which takes in either a dense or sparse matrix and calculates a new internal transition matrix from that.
If you need something very soon, the model regeneration technique shouldn't be too difficult to code (just computationally intensive) and would be something like the following:
from pomegranate import HiddenMarkovModel
distributions = [ list of distributions, not states ]
transition_matrix = [ transitions here ]
for i in xrange( max_iterations ):
model = HiddenMarkovModel.from_matrix( transition_matrix, distributions, starts=[ probability of starting in each state], ends=[ probability of ending in each state ], state_names = [ state names ] )
model.bake()
model.train( training_data, max_iterations=1 )
expected_transitions = model.forward_backward( training_data )[0]
transition_matrix = * AR calculation magic *
** edited code slightly **
Let me know if this helps. When I have time I'll add in the new function.
from pomegranate.
Thanks.
In your code snippet you'd need to pass distributions
to from_matrix()
(instead of states
).
In my use case, I'd also need to do some distribution tying but I guess I can do it by properly arranging the distributions in the distributions vector.
Question - in this code snippet I'd be running forward-backward twice per iteration (once within Baum-Welch). I imagine that letting Baum-Welch return the expected_transitions matrix would eliminate the need and significantly shorten each iteration. What do you think?
from pomegranate.
Whoops, my bad. I actually went and checked if it took distributions or states, then updated the distributions
at the top, but forgot to in the actual call.
As long as you know which distributions you want to tie, remembering which indices refer to the same distribution shouldn't be too bad, and then just passing in one distribution object for each index in the future.
There is a cost, but you don't want to just return the matrix Baum-Welch calculates, because you're updating your parameters using it causing it to be out of date. You're replicating effort because the forward_backward matrix you calculate in iteration 3 should be the same as the Baum-Welch matrix in iteration 4.
Though, now that I think about it, if you're externally regularizing parameters based on autoregression that isn't even true anymore. The Baum-Welch matrix is going to be different (I think) than the previous iterations forward_backward, because you've changed parameters between the two calculation.
I would start off with the possible duplication of effort as a proof of concept, and then see if the forward_backward matrix and the Baum-Welch are the same.
from pomegranate.
You're right, both about the out-of date Baum Welch and the changes caused by the external transition probability updates invalidating the forward-backward result.
Thanks.
from pomegranate.
Is there a bette way to achieve this now? Or a complete example that demonstrates the use of modifying the transition matrix to enforce some simple constraints (like a certain transition being impossible, ie probability of 0.0)?
from pomegranate.
Looking into the code, it seems the on_epoch_end
callback is called on each iteration of the E-M / Baum-Welch learning loop. So maybe it is possible to hook that up to a function that manipulates the transition matrix to enforce some constraints? This would avoid having to re-create a new model and to make a custom training loop.
from pomegranate.
Related Issues (20)
- [BUG]Speed issue HOT 3
- [Question] Fitting multivariate Markov Chain throws Index out of bounds error HOT 3
- [BUG] HMM edges matrix initialization contains NaNs
- How to save and load a GMM model? HOT 1
- Question: Can i build a HMM, where the distribution depends on a value of a specific position HOT 3
- [Question] How to properly preprocess data for Markov Chain? HOT 5
- Markov Chain - Index out of bounds error HOT 2
- [Suggestion] Better description of how to implement HMM's HOT 1
- [Question] HMM Function to calculate joint probability P(O | λ) based on learned HMM λ HOT 1
- [Question] How to retrieve dense transition matrix for a fitted hmm in version 1.0.4 HOT 3
- [Question] How to calculate marginals for Bayesian net in new pomegranate? (+input format for ConditionalCategorical) HOT 3
- [QUESTION] Is this speed as expected for inference in Bayesian networks? HOT 7
- [Question] What is the difference between predict_proba and log_probability methods for HMMs HOT 6
- [Request] Complexity Information HOT 4
- conditional_categorical.py : RuntimeError: scatter(): Expected self.dtype to be equal to src.dtype[BUG] HOT 1
- [QUESTION] I would like to fix the transition matrix upon running. Can I have some help pointing to what update steps need to be commented? HOT 14
- import pomegranate error HOT 1
- HMM with covariates? HOT 6
- [BUG] ragged input to HMM HOT 1
- Gaussian Mixture yields large negative improvement on first step using weighted data with large range in weights HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pomegranate.