temporal.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:SCaIP 作者: simonsfoundation 项目源码 文件源码
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')
#%%
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号