wwrechard / pydlm

A python library for Bayesian time series modeling
BSD 3-Clause "New" or "Revised" License
475 stars 98 forks source link

Is your package only suitable for univariate DLM? #3

Open ALiaoSha opened 8 years ago

wwrechard commented 8 years ago

No. The package can work for multivariate DLM, but in a way different from what you are thinking of. There are several ways for modeling multivariate DLM. The most straightforward way is to put all observation as a d-dimensional vector, and supply to the model. However, this is not a good approach. It has following issues.

  1. When the observation becomes d dimensional instead of 1 dimension, the underlying kalmanfilter will need to do matrix inversion when conducting forward filtering. In contrast, for univariate model, the forward filtering is free from matrix inversion. When d is large, this makes the whole computation slow. It also increases the risk of numerical instability.
  2. For univariate DLM, it already includes multivariate latent states (for trend, seasonality or other features) as a vector. If we extend the univariate DLM to multivariate by augmenting the observation vector, the underlying latent states will become a matrix instead of vector. Then the systematic covariance for the latent states will become a tensor. It dramatically increases the complexity for the analyzing the model with bad interpretation, and also increases the computation burden.

To avoid this issue, this package will model the multivariate DLM in a different way (as in many other time series packages). For d-dimensional observation, we model d different DLM's for each observation, so that each DLM is still univariate. Now, for a given univariate DLM, we treat all the other DLM's filtered results as a dynamic components (features) for fitting this particular univariate DLM. We do this for all d DLM's and repeat to update the filtered results for a given number of iterations.

For a given univariate DLM, you will notice that the coefficients of the other DLM's filtered results are closely related to the covariance matrix (the formula for conditional expectation). In fact, you can re-construct the d x d covariance from these coefficients. I will write a short note and post here later, how you can re-construct the covariance matrix from these coefficients.

Using this formulation, you can avoid inverting a d x d matrix every step. In addition, the fitting on the d univariate DLM's is parallelizable.

wwrechard commented 8 years ago

The note is already in doc/covariance.pdf : )

ALiaoSha commented 8 years ago

I have read it. It's really helpful. Thank you very much. 👍 :)