RJT1990 / pyflux

Open source time series library for Python
BSD 3-Clause "New" or "Revised" License
2.11k stars 240 forks source link

VAR will not initialize with a lag - Python 2.7 only issue #67

Closed lsuttle closed 7 years ago

lsuttle commented 7 years ago

If I run a model with lags = 0, the model will initialize. Lags above zero give the below error. Seems to be an error with the shape.

`

ValueError Traceback (most recent call last)

in () 1 import pyflux as pf 2 ----> 3 var_model = pf.VAR(data=df,lags=1) C:\Anaconda2\envs\py27dev\lib\site-packages\pyflux\var\var.pyc in __init__(self, data, lags, target, integ, use_ols_covariance) 71 self.ylen = self.data_name.shape[0] 72 ---> 73 self._create_latent_variables() 74 75 # Other attributes C:\Anaconda2\envs\py27dev\lib\site-packages\pyflux\var\var.pyc in _create_latent_variables(self) 124 self.latent_variables.add_z(str(self.data_name[other]) + ' to ' + str(self.data_name[variable]) + ' AR(' + str(lag_no+1) + ')', fam.Normal(0,0.5,transform=None), fam.Normal(0,3)) 125 --> 126 starting_params_temp = self._create_B_direct().flatten() 127 128 # Variance latent variables C:\Anaconda2\envs\py27dev\lib\site-packages\pyflux\var\var.pyc in _create_B_direct(self) 102 103 Y = np.array([reg[self.lags:reg.shape[0]] for reg in self.data]) --> 104 Z = self._create_Z(Y) 105 return np.dot(np.dot(Y,np.transpose(Z)),np.linalg.inv(np.dot(Z,np.transpose(Z)))) 106 C:\Anaconda2\envs\py27dev\lib\site-packages\pyflux\var\var.pyc in _create_Z(self, Y) 157 158 Z = np.ones(((self.ylen*self.lags +1),Y[0].shape[0])) --> 159 return create_design_matrix(Z, self.data, Y.shape[0], self.lags) 160 161 def _forecast_mean(self,h,t_params,Y,shock_type=None,shock_index=0,shock_value=None,shock_dir='positive',irf_intervals=False): pyflux/var/var_recursions.pyx in pyflux.var.var_recursions.create_design_matrix (pyflux\var\var_recursions.c:1523)() ValueError: could not broadcast input array from shape (0) into shape (78) `
RJT1990 commented 7 years ago

Thanks for reporting - I'm putting out a release tonight so hopefully can get a solution for this for you.

lsuttle commented 7 years ago

Hi, just wanted to check in on this. The error is still happening in 0.4.11

RJT1990 commented 7 years ago

Yes, apologies, forgot about this - will write a fix tomorrow.

RJT1990 commented 7 years ago

This issue is now resolved and in 0.4.12.