示例#1
0
    if (t == tobs[mcn]): 
    
        ldelay = integ + mcn*ns
        Jac = Jac0
        for m in range(t,ldelay+1):            
            if m == t:
                random = np.zeros(N)
                x[:,m+1] = mod.lorenz96(x[:,m],random,dt) 
    
                dsdx[scount,:] = Jac[0,:] 

                #Jac calculation with Runge-Kutta4 scheme
                Jacsize = N**2
                Jacv = Jac.reshape(Jacsize)       # creates an array (Jacsize,)
                Jacvec = Jacv.reshape(Jacsize,1)  # creates an array (Jacsize,1)
                Jac = mod.rk4_J3(Jacvec,N,x[:,m],dt)
                         
                #Jac calculation with Euler scheme
                ###dfdx = mod.df(x[:,m])
                ###Jac = Jac + dt*(np.dot(dfdx,Jac))   
                
                
                #######Jacsize = N**2
                #######Jacv = Jac.reshape(Jacsize) 
                #######Jacvec = Jacv.reshape(Jacsize,1)
                #dxdt = mod.dxdt(x[:,m],Jacvec,N,dt)
                #######f, Jac = mod.dxdt(x[:,m],Jacvec,N,dt)
                #######x[:,m+1] = mod.rk4(f,dt)
                #xtran = mod.rk4(dxdt,dt)
                #x[:,m+1] = xtran[0:N]
                #Jact = xtran[N:]
示例#2
0
    #print 'dsdx', dsdx
    xx = x[:,n]
    ###xx = xx.reshape(D,1)
    Jac = Jac0
    #print 'Jac', Jac
    #print 'Initial xx is', xx

    for m in range(2,M+1):
        for i in range(1,int(nTau)+1):
            tt = t + dt*(i-1+(m-1)*nTau)
            
            #Jac calculation with Runge-Kutta4 scheme
            Jacsize = D**2
            Jacv = Jac.reshape(Jacsize)       # creates an array (Jacsize,)
            Jacvec = Jacv.reshape(Jacsize,1)  # creates an array (Jacsize,1)
            Jac = mod.rk4_J3(Jacvec,D,xx,dt)
            
                                 
            #Jac calculation with Euler scheme
            #####dfdx = mod.df(xx)
            #####Jac = Jac + dt*(np.dot(dfdx,Jac))
            #Jac = np.dot(dfdx,Jac)
            #Jac = dt*(np.dot(dfdx,Jac))           
            #print 'dfdx', dfdx
            #print 'Dfdx min:', np.min(dfdx),'max:', np.max(dfdx)

            random = np.zeros(D)
            #random = np.random.rand(D)-0.5
            xx = mod.lorenz96(xx,random,dt) 
            
            #print 'n=', n, 'xx at m', m, 'is', xx
示例#3
0
                #xx = xxx[:,0]
                #for i in range(1,int(nTau)+1):
                ##########Jac calculation with Runge-Kutta4 scheme##############

                ################# Jacs to construct P #######################
                ##############xx = xxx[:,s-1]
                #print 'xx at', i, 'th cycle is', xx, 'for m =', m

                # Calculating all elements in the upper part of the diagonal#
                Jacsize = D**2

                Jacv2 = Jac2.reshape(Jacsize)
                Jacvec2 = Jacv2.reshape(Jacsize, 1)

                Jac2 = mod.rk4_J3(Jacvec2, D, xx, dt)

                # Calculating all elements in the lower part of the diagonal#
                Jacv3 = Jac3.reshape(Jacsize)
                Jacvec3 = Jacv3.reshape(Jacsize, 1)

                Jac3 = mod.rk4_J3(Jacvec3, D, xx, dt)

                # Calculating all elements in the diagonal#
                if m == 1:
                    ########if i == 1:
                    ########    Jac4 = Jac3
                    #########   Jacv4 = Jac4.reshape(Jacsize)
                    ########Jacvec4 = Jacv4.reshape(Jacsize,1)

                    ########Jac4 = mod.rk4_J3(Jacvec4,D,xx,dt)
示例#4
0
    #print 'dsdx', dsdx
    xx = x[:, n]
    ###xx = xx.reshape(D,1)
    Jac = Jac0
    #print 'Jac', Jac
    #print 'Initial xx is', xx

    for m in range(2, M + 1):
        for i in range(1, int(nTau) + 1):
            tt = t + dt * (i - 1 + (m - 1) * nTau)

            #Jac calculation with Runge-Kutta4 scheme
            Jacsize = D**2
            Jacv = Jac.reshape(Jacsize)  # creates an array (Jacsize,)
            Jacvec = Jacv.reshape(Jacsize, 1)  # creates an array (Jacsize,1)
            Jac = mod.rk4_J3(Jacvec, D, xx, dt)
            ##dxdt = mod.dxdt(xx,Jacvec,D,dt)
            ##xtran = mod.rk4(dxdt,dt)
            ##xx = xtran[0:D]
            ##print 'n=', n, 'xx at m', m, 'is', xx
            ##Jact = xtran[D:]
            ##Jac = Jact.reshape(D,D)

            ############dfdx = mod.df(xx)
            #print 'dfdx', dfdx
            #print 'Dfdx min:', np.min(dfdx),'max:', np.max(dfdx)

            random = np.zeros(D)
            #random = np.random.rand(D)-0.5
            xx = mod.lorenz96(xx, random, dt)
示例#5
0
                ##############xx = xxx[:,s-1]
                #print 'xx at', i, 'th cycle is', xx, 'for m =', m

                # Calculating all elements in the upper part of the diagonal#
                Jacsize = D**2

                Jacv2 = Jac2.reshape(Jacsize)       
                Jacvec2 = Jacv2.reshape(Jacsize,1)  
         
                Jac2 = mod.rk4_J6(Jacvec2,D,xx,dt)  ###running another module J6

                # Calculating all elements in the lower part of the diagonal#
                Jacv3 = Jac3.reshape(Jacsize)       
                Jacvec3 = Jacv3.reshape(Jacsize,1)  
          
                Jac3 = mod.rk4_J3(Jacvec3,D,xx,dt) 

                P[id1] = Jac2 
                #***F1 = P[id1]            
                #***F1T = np.transpose(F1)
                #***Jac2 = F1T

                # Calculating all elements in the diagonal#  
                if m == 1:
                        ########if i == 1:
                        ########    Jac4 = Jac3                     
                        #########   Jacv4 = Jac4.reshape(Jacsize)       
                        ########Jacvec4 = Jacv4.reshape(Jacsize,1) 
                    
                        ########Jac4 = mod.rk4_J3(Jacvec4,D,xx,dt) 
示例#6
0
    if (t == tobs[mcn]): 
    
        ldelay = integ + mcn*ns
        Jac = Jac0
        for m in range(t,ldelay+1):            
            if m == t:
                random = np.zeros(N)
                x[:,m+1] = mod.lorenz96(x[:,m],random,dt) 
    
                dsdx[scount,:] = Jac[0,:] 

                #Jac calculation with Runge-Kutta4 scheme
                Jacsize = N**2
                Jacv = Jac.reshape(Jacsize)       # creates an array (Jacsize,)
                Jacvec = Jacv.reshape(Jacsize,1)  # creates an array (Jacsize,1)
                Jac = mod.rk4_J3(Jacvec,N,x[:,m],dt)
                         
                #Jac calculation with Euler scheme
                ###dfdx = mod.df(x[:,m])
                ###Jac = Jac + dt*(np.dot(dfdx,Jac))   
                
                #U, G, V = mod.svd(Jac)
                #print 'G', G.shape
                #print 'ln(G)', np.log(G)

                #######Jacsize = N**2
                #######Jacv = Jac.reshape(Jacsize) 
                #######Jacvec = Jacv.reshape(Jacsize,1)
                #dxdt = mod.dxdt(x[:,m],Jacvec,N,dt)
                #######f, Jac = mod.dxdt(x[:,m],Jacvec,N,dt)
                #######x[:,m+1] = mod.rk4(f,dt)
示例#7
0
def Pmatrix(x,Jac0):
    #################### Initial settings ################################
    N = 10000
    Obs = 100
    dt = 0.01    #original value=0.01

    D = 20 
    F=8.17

    M = 40
   
    ##################### Seeding for 20 variables#######################
    r=37 #for x[:,0] = xtrue[:,0]
    np.random.seed(r)  

    #################### Constructing h (obs operator) ##################
    observed_vars = range(1)    
    L = len(observed_vars) 
    h = np.zeros([L,D])       
    for i in range(L):
        h[i,observed_vars[i]] = 1.0   

    xx = np.zeros([D,1])      
    
    Jac = np.zeros([D,D])    

    for i in range(D):
        Jac[i,i] = 1.

    #Jac0 = np.copy(Jac)  

    run = 1
    ################### Main loop ##########################################
    for n in range(1,run+1):
        xx = x
    
        #Jac = Jac0
        P = {}
        P['00'] = Jac0
    
        for s in range(1,M):    
            idxs = s
    
            for m in range(1,M):
                ii = idxs - m
                iid = idxs + 1
            
                id1 = str(0)+str(idxs)
                id2 = str(0)+str(idxs-1)
                id21 = str(m-1)+str(idxs)

                id3 = str(iid-1)+str(ii)
                id4 = str(iid-2)+str(ii)

                id5 = str(iid-1)+str(iid-1)
                id6 = str(iid-2)+str(iid-2)
            
                if ii >= 0:
                    Jac3 = P[id4]
                    
                    # Calculating the first row of Ps
                    if  m == 1:
                        Jac2 = P[id2]
                        
                        #########################
                        Jac2 = np.transpose(Jac2)
                        #########################

                        # Calculating all elements in the upper part of the diagonal#
                        Jacsize = D**2

                        Jacv2 = Jac2.reshape(Jacsize)       
                        Jacvec2 = Jacv2.reshape(Jacsize,1)  
         
                        Jac2 = mod.rk4_J3(Jacvec2,D,xx,dt)
                
                        Jac2 = np.transpose(Jac2)             
                        P[id1] = Jac2 
                      
                    if m > 1:
                        # Calculating all elements in the upper part of the diagonal#
                        Jacsize = D**2

                        Jacv2 = Jac2.reshape(Jacsize)       
                        Jacvec2 = Jacv2.reshape(Jacsize,1)  
         
                        Jac2 = mod.rk4_J3(Jacvec2,D,xx,dt)
                
                        P[id21] = Jac2
                    
                    # Calculating all elements in the lower part of the diagonal#
                    Jacv3 = Jac3.reshape(Jacsize)       
                    Jacvec3 = Jacv3.reshape(Jacsize,1)  
          
                    Jac3 = mod.rk4_J3(Jacvec3,D,xx,dt) 
                    
                    P[id3] = Jac3

                    # Calculating all elements in the diagonal#  
                    Jacv4 = Jac2.reshape(Jacsize)       
                    Jacvec4 = Jacv4.reshape(Jacsize,1)  
                
                    Jac4 = mod.rk4_J3(Jacvec4,D,xx,dt)
                
                    P[id5] = Jac4  
               
                    if m == (M-1):         
                        random = np.zeros(D)
                        xx = mod.lorenz96(xx,random,dt) 
               
    return P
示例#8
0
                #xx = xxx[:,0] 
                for i in range(1,int(nTau)+1):
                    ##########Jac calculation with Runge-Kutta4 scheme##############
            
                    ################# Jacs to construct P #######################
                    xx = xxx[:,i-1]
                    #print 'xx at', i, 'th cycle is', xx, 'for m =', m

                    # Calculating all elements in the upper part of the diagonal#
                    Jacsize = D**2

                    Jacv2 = Jac2.reshape(Jacsize)       
                    Jacvec2 = Jacv2.reshape(Jacsize,1)  
            
                    Jac2 = mod.rk4_J3(Jacvec2,D,xx,dt)  

                    # Calculating all elements in the lower part of the diagonal#
                    Jacv3 = Jac3.reshape(Jacsize)       
                    Jacvec3 = Jacv3.reshape(Jacsize,1)  
            
                    Jac3 = mod.rk4_J3(Jacvec3,D,xx,dt) 

                    # Calculating all elements in the diagonal#                
                    if m == 1:
                        Jacv4 = Jac4.reshape(Jacsize)       
                        Jacvec4 = Jacv4.reshape(Jacsize,1)  
                
                        #Jac4 = mod.rk4_J4(Jacvec4,D,xx,dt)   ### it runs another module to multiply dkdx with Jold!
                        Jac4 = mod.rk4_J5(Jacvec4,D,xx,dt)
                    ########## Unperturbed inside-loop Lorenz runs################   
示例#9
0
def Pmatrix(x, Jac0):
    #################### Initial settings ################################
    N = 10000
    Obs = 100
    dt = 0.01  #original value=0.01

    D = 20
    F = 8.17

    M = 40

    ##################### Seeding for 20 variables#######################
    r = 37  #for x[:,0] = xtrue[:,0]
    np.random.seed(r)

    #################### Constructing h (obs operator) ##################
    observed_vars = range(1)
    L = len(observed_vars)
    h = np.zeros([L, D])
    for i in range(L):
        h[i, observed_vars[i]] = 1.0

    xx = np.zeros([D, 1])

    Jac = np.zeros([D, D])

    for i in range(D):
        Jac[i, i] = 1.

    #Jac0 = np.copy(Jac)

    run = 1
    ################### Main loop ##########################################
    for n in range(1, run + 1):
        xx = x

        #Jac = Jac0
        P = {}
        P['00'] = Jac0

        for s in range(1, M):
            idxs = s

            for m in range(1, M):
                ii = idxs - m
                iid = idxs + 1

                id1 = str(0) + str(idxs)
                id2 = str(0) + str(idxs - 1)
                id21 = str(m - 1) + str(idxs)

                id3 = str(iid - 1) + str(ii)
                id4 = str(iid - 2) + str(ii)

                id5 = str(iid - 1) + str(iid - 1)
                id6 = str(iid - 2) + str(iid - 2)

                if ii >= 0:
                    Jac3 = P[id4]

                    # Calculating the first row of Ps
                    if m == 1:
                        Jac2 = P[id2]

                        #########################
                        Jac2 = np.transpose(Jac2)
                        #########################

                        # Calculating all elements in the upper part of the diagonal#
                        Jacsize = D**2

                        Jacv2 = Jac2.reshape(Jacsize)
                        Jacvec2 = Jacv2.reshape(Jacsize, 1)

                        Jac2 = mod.rk4_J3(Jacvec2, D, xx, dt)

                        Jac2 = np.transpose(Jac2)
                        P[id1] = Jac2

                    if m > 1:
                        # Calculating all elements in the upper part of the diagonal#
                        Jacsize = D**2

                        Jacv2 = Jac2.reshape(Jacsize)
                        Jacvec2 = Jacv2.reshape(Jacsize, 1)

                        Jac2 = mod.rk4_J3(Jacvec2, D, xx, dt)

                        P[id21] = Jac2

                    # Calculating all elements in the lower part of the diagonal#
                    Jacv3 = Jac3.reshape(Jacsize)
                    Jacvec3 = Jacv3.reshape(Jacsize, 1)

                    Jac3 = mod.rk4_J3(Jacvec3, D, xx, dt)

                    P[id3] = Jac3

                    # Calculating all elements in the diagonal#
                    Jacv4 = Jac2.reshape(Jacsize)
                    Jacvec4 = Jacv4.reshape(Jacsize, 1)

                    Jac4 = mod.rk4_J3(Jacvec4, D, xx, dt)

                    P[id5] = Jac4

                    if m == (M - 1):
                        random = np.zeros(D)
                        xx = mod.lorenz96(xx, random, dt)

    return P