简体   繁体   中英

Is it possible to fit a multivariate GMHMM in hmmlearn?

I know it is possible to fit several sequences into hmmlearn but it seems to me that these sequences need to be drawn from the same distributions.

Is it possible to fit a GMHMM with several observations sequences drawn from different distributions in hmmlearn?

My use case : I would like to fit a GMHMM with K financial time series from different stocks and predict the market regime that generated the K stock prices at a specified time. So the matrix input has dimension N (number of dates) × K (number of stocks). If hmmlearn can't do that, please tell me if it is possible with another package in python or R? Thanks for you help!

My approach to your problem will be to use a multi-variate Gaussian for emission probabilities.

For example: let's assume that K is 2, ie, the number of locations is 2.

In hmmlearn, the K will be encoded in the dimensions of the mean matrix.

See, this example Sampling from HMM has a 2-dimensional output. In other words the X.shape = (N, K) where N is the length of the sample 500 in this case, and K is the dimension of the output which is 2.

Notice that the authors plotted each dimension on an axis, ie, x-axis plots the first dimension X[:, 0], and the y-axis the second dimension X[:, 1].

To train your model, make sure that X1 and X2 are of the same shape as the sampled X in the example, and form the training dataset as described here .

In summary, adapt the example to your case by adjusting the K instead of K=2 and convert it to the GMHMM instead of GaussianHMM.

# Another example
model = hmm.GaussianHMM(n_components=5, covariance_type="diag", n_iter=100)

K = 3 # Number of sites
model.n_features = K # initialise that the model has size of observations =  K 

# Create a random training sequence (only 1 sequence) with length = 100.
X1 = np.random.randn(100, K) # 100 observation for K sites
model.fit(X1)

# Sample the fitted model
X, Z = model.sample(200)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM