def make_G_matrix(T,g):
''' create matrix of autoregression to enforce indicator dynamics
Inputs:
T: positive integer
number of time-bins
g: nd.array, vector p x 1
Discrete time constants
Output:
G: sparse diagonal matrix
Matrix of autoregression
'''
if type(g) is np.ndarray:
if len(g) == 1 and g < 0:
g=0
# gs=np.matrix(np.hstack((-np.flipud(g[:]).T,1)))
gs=np.matrix(np.hstack((1,-(g[:]).T)))
ones_=np.matrix(np.ones((T,1)))
G = spdiags((ones_*gs).T,range(0,-len(g)-1,-1),T,T)
return G
else:
raise Exception('g must be an array')
#%%
评论列表
文章目录