Esempio n. 1
0
def pwcgc(tsdata, p):
    
    import numpy as np
    from series_mod.gc import tsdata_to_var


    n = tsdata.shape[0]
    F = np.zeros([n,n])
    
    # full regression   
    [AF,SIG,E] = tsdata_to_var(tsdata, p)    
    LSIG = np.log(abs(np.diag(SIG)))
    
    for j_ in range(n):
    
        # reduced regression
        jo = np.arange(n) # omit j
        jo = np.delete(jo,j_)

        [AF,SIGj,E] = tsdata_to_var(tsdata[jo], p)  
        LSIGj = np.log(abs(np.diag(SIGj)))
    
        F[jo,j_] = LSIGj-LSIG[jo]
    
#        for ii_ in range(n-1):
#            i_ = jo[ii_]
#            F[i_,j_] = LSIGj[ii_]-LSIG[i_]
        
    return F
Esempio n. 2
0
def mvgc(tsdata, x, y, p):
    
    import numpy as np
    from series_mod import tsdata_to_var

    # Local Variables: G, F, xzy, n, xz, SIGR, SIG, y, x, z
    # Function calls: autocov_to_var, log, det, NaN, length, autocov_to_mvgc, size
    n = tsdata.shape[0]
    
    
     #WARNING PART 1!!
#    x = x.flatten(0).conj() #be carefull for multi variate case
#    # vectorise
#    y = y.flatten(0).conj()
#    # vectorise
    
    
    z = np.arange(n)
    z = np.delete(z,[np.array(np.hstack((x, y)))])
    # indices of other variables (to condition out)
    xz = np.array(np.hstack((x, z)))
    xzy = np.array(np.hstack((xz, y)))
    F = 0
    # full regression
    ixgrid1 = np.ix_(xzy,xzy)
    [AF,SIG,E] = tsdata_to_var(tsdata[ixgrid1], p) #G[ixgrid1,:])
    # reduced regression
    ixgrid2 = np.ix_(xz,xz)
    [AF,SIGR,E] = tsdata_to_var(tsdata[ixgrid2], p) #G[ixgrid2,:])
    # reduced regression
    
    #WARNING PART 2!!
    #x = np.arange(np.size(x,axis=1)+1)
    
    ###########
    ixgrid3 = np.ix_(x,x)
    F = np.log(abs(np.linalg.det(SIGR[ixgrid3])))-np.log(abs(np.linalg.det(SIG[ixgrid3]))) 
    #####  not tested
    return F