Пример #1
0
 def updatedata(self, A):
     if self.update:
         if self.corr:
             self.data.B = self.data.w*(linalg.norm(A,1)/linalg.norm(self.data.w,1))
             self.data.C = self.data.v*(linalg.norm(A,Inf)/linalg.norm(self.data.v,1))
         else:
             # Note: Problem when singular vectors switch smallest singular value (See NewLorenz).
             #       To overcome this, I have implemented a 1e-8 random nudge.
             try:
                 ALU = linalg.lu_factor(A)
                 BC = linalg.lu_solve(ALU, c_[linalg.lu_solve(ALU, self.data.B + 1e-8*self.data.Brand), \
                                      self.data.C + 1e-8*self.data.Crand], trans=1)
                 C = linalg.lu_solve(ALU, BC[:,-1*self.data.q:])
                 B = BC[:,0:self.data.p]
             except:
                 if self.C.verbosity >= 1:
                     print 'Warning: Problem updating border vectors.  Using svd...'
                 U, S, Vh = linalg.svd(A)
                 B = U[:,-1*self.data.p:]
                 C = num_transpose(Vh)[:,-1*self.data.q:]
         
             bmult = cmult = 1
             if matrixmultiply(transpose(self.data.B), B) < 0:
                 bmult = -1
             if matrixmultiply(transpose(self.data.C), C) < 0:
                 cmult = -1
             self.data.B = bmult*B*(linalg.norm(A,1)/linalg.norm(B))
             self.data.C = cmult*C*(linalg.norm(A,Inf)/linalg.norm(C))
Пример #2
0
 def updatedata(self, A):
     # Update b, c
     try:
         ALU = linalg.lu_factor(A)
         BC = linalg.lu_solve(ALU, c_[linalg.lu_solve(ALU, self.data.b + 1e-8*self.data.Brand[:,:1]), \
                              self.data.c + 1e-8*self.data.Crand[:,:1]], trans=1)
         C = linalg.lu_solve(ALU, BC[:,-1:])
         B = BC[:,:1]
     except:
         if self.C.verbosity >= 1:
             print 'Warning: Problem updating border vectors.  Using svd...'
         U, S, Vh = linalg.svd(A)
         B = U[:,-1:]
         C = num_transpose(Vh)[:,-1:]
 
     bmult = cmult = 1
     if matrixmultiply(transpose(self.data.b), B) < 0:
         bmult = -1
     if matrixmultiply(transpose(self.data.c), C) < 0:
         cmult = -1
     self.data.b = bmult*B*(linalg.norm(A,1)/linalg.norm(B))
     self.data.c = cmult*C*(linalg.norm(A,Inf)/linalg.norm(C))
     
     # Update
     if self.update:
         self.data.B[:,0] = self.data.b*(linalg.norm(A,1)/linalg.norm(self.data.b))
         self.data.C[:,0] = self.data.c*(linalg.norm(A,Inf)/linalg.norm(self.data.c))
         
         self.data.B[:,1] = self.data.w[:,2]*(linalg.norm(A,1)/linalg.norm(self.data.w,1))
         self.data.C[:,1] = self.data.v[:,2]*(linalg.norm(A,Inf)/linalg.norm(self.data.v,1))
         
         self.data.D[0,1] = self.data.g[0,1]
         self.data.D[1,0] = self.data.g[1,0]
Пример #3
0
 def process(self, X, V, C):
     BifPoint.process(self, X, V, C)
     
     # Finds the new branch
     J_coords = C.CorrFunc.jac(X, C.coords)
     J_params = C.CorrFunc.jac(X, C.params)
     A = r_[c_[J_coords, J_params], [V]]
     W, VR = linalg.eig(A)
     W0 = [ind for ind, eig in enumerate(W) if abs(eig) < 1e-5]
     V1 = real(VR[:,W0[0]])
     
     H = C.CorrFunc.hess(X, C.coords+C.params, C.coords+C.params)
     c11 = matrixmultiply(self.data.psi,[bilinearform(H[i,:,:], V, V) for i in range(H.shape[0])])
     c12 = matrixmultiply(self.data.psi,[bilinearform(H[i,:,:], V, V1) for i in range(H.shape[0])])
     c22 = matrixmultiply(self.data.psi,[bilinearform(H[i,:,:], V1, V1) for i in range(H.shape[0])])
     
     beta = 1
     alpha = -1*c22/(2*c12)
     V1 = alpha*V + beta*V1
     V1 /= linalg.norm(V1)
     
     self.found[-1].eigs = W
     self.found[-1].branch = todict(C, V1)
     
     self.info(C, -1)
     
     return True
Пример #4
0
    def func(self, X, V):
        H = self.F.sysfunc.hess(X, self.F.coords, self.F.coords)
        q = self.F.testfunc.data.v/linalg.norm(self.F.testfunc.data.v)
        p = self.F.testfunc.data.w/matrixmultiply(transpose(self.F.testfunc.data.w),q)

        return array(0.5*matrixmultiply(transpose(p), reshape([bilinearform(H[i,:,:], q, q) \
             for i in range(H.shape[0])],(H.shape[0],1)))[0])
Пример #5
0
    def func(self, X, V):
        k = self.C.TFdata.k
        v1 = self.C.TFdata.v1
        w1 = self.C.TFdata.w1
        
        if k >=0:
            J_coords = self.F.sysfunc.J_coords
            w = sqrt(k)
        
            q = v1 - (1j/w)*matrixmultiply(self.F.sysfunc.J_coords,v1)
            p = w1 + (1j/w)*matrixmultiply(transpose(self.F.sysfunc.J_coords),w1)
            
            p /= linalg.norm(p)
            q /= linalg.norm(q)

            p = reshape(p,(p.shape[0],))
            q = reshape(q,(q.shape[0],))
            
            direc = conjugate(1/matrixmultiply(transpose(conjugate(p)),q))
            p = direc*p

            l1 = firstlyapunov(X, self.F.sysfunc, w, J_coords=J_coords, p=p, q=q)
            
            return array([l1])
        else:
            return array([1])
Пример #6
0
    def __locate_newton(self, X, C):
        """x[0:self.dim] = (x,alpha)
           x[self.dim] = beta
           x[self.dim+1:2*self.dim] = p
        """
        J_coords = C.CorrFunc.jac(X[0:C.dim], C.coords)
        J_params = C.CorrFunc.jac(X[0:C.dim], C.params)

        return r_[C.CorrFunc(X[0:C.dim]) + X[C.dim]*X[C.dim+1:], \
                  matrixmultiply(transpose(J_coords),X[C.dim+1:]), \
                  matrixmultiply(transpose(X[C.dim+1:]),J_params), \
                  matrixmultiply(transpose(X[C.dim+1:]),X[C.dim+1:]) - 1]
Пример #7
0
def bialttoeig(q, p, n, A):
	v1, v2 = invwedge(q, n)
	w1, w2 = invwedge(p, n)
	
	A11 = bilinearform(A,v1,v1)
	A22 = bilinearform(A,v2,v2)
	A12 = bilinearform(A,v1,v2)
	A21 = bilinearform(A,v2,v1)
	v11 = matrixmultiply(transpose(v1),v1)
	v22 = matrixmultiply(transpose(v2),v2)
	v12 = matrixmultiply(transpose(v1),v2)
	D = v11*v22 - v12*v12
	k = (A11*A22 - A12*A21)/D

	return k[0][0], v1, w1
Пример #8
0
def bialttoeig(q, p, n, A):
    v1, v2 = invwedge(q, n)
    w1, w2 = invwedge(p, n)

    A11 = bilinearform(A, v1, v1)
    A22 = bilinearform(A, v2, v2)
    A12 = bilinearform(A, v1, v2)
    A21 = bilinearform(A, v2, v1)
    v11 = matrixmultiply(transpose(v1), v1)
    v22 = matrixmultiply(transpose(v2), v2)
    v12 = matrixmultiply(transpose(v1), v2)
    D = v11 * v22 - v12 * v12
    k = (A11 * A22 - A12 * A21) / D

    return k[0][0], v1, w1
Пример #9
0
    def info(self, C, ind=None):
        if ind is None:
            ind = range(len(self.found))
        elif isinstance(ind, int):
            ind = [ind]

        strlist = []
        for n, i in enumerate(ind):
            strlist.append('Period doubling branch angle = ' + repr(matrixmultiply(tocoords(C, self.found[i].V), \
                tocoords(C, self.found[i].branch))))
            
        BifPoint.info(self, C, ind, strlist)
Пример #10
0
 def diff(self, X, ind=None):
     try:
         n = len(ind)
     except:
         n = self.n
         ind = range(n)
     
     F_n = zeros((self.period, self.n), Float)
     F_n[0] = X
     for k in range(1,self.period):
         F_n[k] = c_[self.F(F_n[k-1]), X[self.F.params]]
     
     xslice = slice(self.F.coords[0], self.F.coords[-1]+1, 1)
     pslice = slice(self.F.params[0], self.F.params[-1]+1, 1)
     J = self.F.jac(F_n[0])
     for k in range(1,self.period):
         J2 = self.F.jac(F_n[k])
         J[:,xslice] = matrixmultiply(J2[:,xslice] ,J[:,xslice])
         J[:,pslice] = matrixmultiply(J2[:,xslice], J[:,pslice]) + J2[:,pslice]
         
     return J[:, ind[0]:ind[-1]+1]
Пример #11
0
    def process(self, X, V, C):
        """Do I need to compute the branch, or will it always be in the direction of freepar = constant?"""
        BifPoint.process(self, X, V, C)

        F = DiscreteMap(C.sysfunc, period=2*C.sysfunc.period)
        FP = FixedPointMap(F)

        J_coords = FP.jac(X, C.coords)
        J_params = FP.jac(X, C.params)
        
        # Locate branch of double period map
        W, VL = linalg.eig(J_coords, left=1, right=0)
        ind = argsort([abs(eig) for eig in W])[0]
        psi = real(VL[:,ind])
        
        A = r_[c_[J_coords, J_params], [V]]
        W, VR = linalg.eig(A)
        W0 = argsort([abs(eig) for eig in W])[0]
        V1 = real(VR[:,W0])
        
        H = FP.hess(X, C.coords+C.params, C.coords+C.params)
        c11 = matrixmultiply(psi,[bilinearform(H[i,:,:], V, V) for i in range(H.shape[0])])
        c12 = matrixmultiply(psi,[bilinearform(H[i,:,:], V, V1) for i in range(H.shape[0])])
        c22 = matrixmultiply(psi,[bilinearform(H[i,:,:], V1, V1) for i in range(H.shape[0])])
        
        beta = 1
        alpha = -1*c22/(2*c12)
        V1 = alpha*V + beta*V1
        V1 /= linalg.norm(V1)
        
        J_coords = C.sysfunc.jac(X, C.coords)
        W = linalg.eig(J_coords, right=0)
        
        self.found[-1].eigs = W
        self.found[-1].branch_period = 2*C.sysfunc.period
        self.found[-1].branch = todict(C, V1)
        
        self.info(C, -1)
        
        return True
Пример #12
0
    def process(self, X, V, C):
        BifPoint.process(self, X, V, C)
        
        # Compute normal form coefficient 
        # NOTE: These are for free when using bordering technique!)
        # NOTE: Does not agree with MATCONT output! (if |p| = |q| = 1, then it does)
        J_coords = C.CorrFunc.jac(X, C.coords)
        W, VL, VR = linalg.eig(J_coords, left=1, right=1)
        minW = min(abs(W))
        ind = [(abs(eig) < minW+1e-8) and (abs(eig) > minW-1e-8) for eig in W].index(True)
        p, q = real(VL[:,ind]), real(VR[:,ind])
        p /= matrixmultiply(p,q)

        B = C.CorrFunc.hess(X, C.coords, C.coords)
        self.found[-1].a = abs(0.5*matrixmultiply(p,[bilinearform(B[i,:,:], q, q) for i in range(B.shape[0])]))
        self.found[-1].eigs = W
        
        numzero = len([eig for eig in W if abs(eig) < 1e-4])
        if numzero > 1:
            if C.verbosity >= 2:
                print 'Fold-Fold!\n'
            del self.found[-1]
            return False
        elif numzero == 0:
            if C.verbosity >= 2:
                print 'False positive!\n'
            del self.found[-1]
            return False

        if C.verbosity >= 2:
            print '\nChecking...'
            print '  |q| = %f' % linalg.norm(q)
            print '  <p,q> = %f' % matrixmultiply(p,q) 
            print '  |Aq| = %f' % linalg.norm(matrixmultiply(J_coords,q))
            print '  |transpose(A)p| = %f\n' % linalg.norm(matrixmultiply(transpose(J_coords),p))

        self.info(C, -1)
        
        return True
Пример #13
0
def firstlyapunov(X, F, w, J_coords=None, V=None, W=None, p=None, q=None, check=False):
	if J_coords is None:
		J_coords = F.jac(X, F.coords)
	
	if p is None:
		alpha = bilinearform(transpose(J_coords),V[:,0],V[:,1]) - \
				1j*w*matrixmultiply(V[:,0],V[:,1])
		beta = -1*bilinearform(transpose(J_coords),V[:,0],V[:,0]) + \
				1j*w*matrixmultiply(V[:,0],V[:,0])
		q = alpha*V[:,0] + beta*V[:,1]
		
		alpha = bilinearform(J_coords,W[:,0],W[:,1]) + \
				1j*w*matrixmultiply(W[:,0],W[:,1])
		beta = -1*bilinearform(J_coords,W[:,0],W[:,0]) - \
				1j*w*matrixmultiply(W[:,0],W[:,0])
		p = alpha*W[:,0] + beta*W[:,1]
		
		p /= linalg.norm(p)
		q /= linalg.norm(q)
		
		direc = conjugate(1/matrixmultiply(conjugate(p),q))
		p = direc*p
	
	if check:
		print 'Checking...'
		print '  |q| = %f' % linalg.norm(q)
		temp = matrixmultiply(conjugate(p),q)
		print '  |<p,q> - 1| = ', abs(temp-1) 	
		print '  |Aq - iwq| = %f' % linalg.norm(matrixmultiply(J_coords,q) - 1j*w*q)
		print '  |A*p + iwp| = %f\n' % linalg.norm(matrixmultiply(transpose(J_coords),p) + 1j*w*p)
	
	# Compute first lyapunov coefficient
	B = F.hess(X, F.coords, F.coords)
	D = hess3(F, X, F.coords)
	b1 = array([bilinearform(B[i,:,:], q, q) for i in range(B.shape[0])])
	b2 = array([bilinearform(B[i,:,:], conjugate(q), linalg.solve(2*1j*w*eye(F.m) - J_coords, b1)) \
			for i in range(B.shape[0])])
	b3 = array([bilinearform(B[i,:,:], q, conjugate(q)) for i in range(B.shape[0])])
	b4 = array([bilinearform(B[i,:,:], q, linalg.solve(J_coords, b3)) for i in range(B.shape[0])])
	temp = array([trilinearform(D[i,:,:,:],q,q,conjugate(q)) for i in range(D.shape[0])]) + b2 - 2*b4

	l1 = 0.5*real(matrixmultiply(conjugate(p), temp))
	
	return l1
Пример #14
0
    def process(self, X, V, C):
        BifPoint.process(self, X, V, C)
        
        J_coords = C.CorrFunc.sysfunc.jac(X, C.coords)

        W, VL, VR = linalg.eig(J_coords, left=1, right=1)
        
        self.found[-1].eigs = W     

        if C.verbosity >= 2:
            if C.CorrFunc.testfunc.data.B.shape[1] == 2:
                b = matrixmultiply(transpose(J_coords), C.CorrFunc.testfunc.data.w[:,0])
                c = matrixmultiply(J_coords, C.CorrFunc.testfunc.data.v[:,0])
            else:
                b = C.CorrFunc.testfunc.data.w[:,0]
                c = C.CorrFunc.testfunc.data.v[:,0]
            print '\nChecking...'
            print '  <b,c> = %f' % matrixmultiply(transpose(b), c)
            print '\n'
        
        self.info(C, -1)
        
        return True
Пример #15
0
    def process(self, X, V, C):
        BifPoint.process(self, X, V, C)

        J_coords = C.CorrFunc.sysfunc.jac(X, C.coords)
        B = C.CorrFunc.sysfunc.hess(X, C.coords, C.coords)
        
        W, VL, VR = linalg.eig(J_coords, left=1, right=1)
        
        q = C.CorrFunc.testfunc.data.C/linalg.norm(C.CorrFunc.testfunc.data.C)
        p = C.CorrFunc.testfunc.data.B/matrixmultiply(transpose(C.CorrFunc.testfunc.data.B),q)
        
        self.found[-1].eigs = W     

        a = 0.5*matrixmultiply(transpose(p), reshape([bilinearform(B[i,:,:], q, q) \
                for i in range(B.shape[0])],(B.shape[0],1)))[0][0]
        if C.verbosity >= 2:
            print '\nChecking...'
            print '  |a| = %f' % a
            print '\n'
        
        self.info(C, -1)
        
        return True
Пример #16
0
def subspace_angles(A, B):
    """
    Return the principle angles and vectors between two subspaces. 

    See Bjorck and Golub, "Numerical Methods for Computing Between Linear 
           Subspaces" _Mathematics_of_Computation_, 27(123), 1973, pp. 579-594
    Or, for a more understandable exposition, Golub and Van Loan, 
           _Matrix_Computations_ (3rd ed.) pp. 603-604
    """
    A, B = scipy.asarray(A), scipy.asarray(B)
    if A.shape[0] != B.shape[0]:
        raise ValueError('Input subspaces must live in the same dimensional '\
                'space.')

    # Get orthogonal bases for our two subspaces.
    QA, QB = scipy.linalg.orth(A), scipy.linalg.orth(B)

    M = scipy.matrixmultiply(scipy.transpose(scipy.conjugate(QA)), QB)
    Y, C, Zh = scipy.linalg.svd(M)

    U = scipy.matrixmultiply(QA, Y)
    V = scipy.matrixmultiply(QB, scipy.transpose(scipy.conjugate(Zh)))
    return scipy.arccos(C), U, V
Пример #17
0
    def process(self, X, V, C):
        """Tolerance for eigenvalues a possible problem when checking for neutral saddles."""
        BifPoint.process(self, X, V, C)
                
        J_coords = C.CorrFunc.jac(X, C.coords)
        eigs, LV, RV = linalg.eig(J_coords,left=1,right=1)
        
        # Check for neutral saddles
        found = False
        for i in range(len(eigs)):
            if abs(imag(eigs[i])) < 1e-5:
                for j in range(i+1,len(eigs)):
                    if C.verbosity >= 2:
                        if abs(eigs[i]) < 1e-5 and abs(eigs[j]) < 1e-5:
                            print 'Fold-Fold point found in Hopf!\n'
                        elif abs(imag(eigs[j])) < 1e-5 and abs(real(eigs[i]) + real(eigs[j])) < 1e-5:
                            print 'Neutral saddle found!\n'
            elif abs(real(eigs[i])) < 1e-5:
                for j in range(i+1, len(eigs)):
                    if abs(real(eigs[j])) < 1e-5 and abs(real(eigs[i]) - real(eigs[j])) < 1e-5:
                        found = True
                        w = abs(imag(eigs[i]))
                        if imag(eigs[i]) > 0:
                            p = conjugate(LV[:,j])/linalg.norm(LV[:,j])
                            q = RV[:,i]/linalg.norm(RV[:,i])
                        else:
                            p = conjugate(LV[:,i])/linalg.norm(LV[:,i])
                            q = RV[:,j]/linalg.norm(RV[:,j])

        if not found:
            del self.found[-1]
            return False

        direc = conjugate(1/matrixmultiply(conjugate(p),q))
        p = direc*p

        # Alternate way to compute 1st lyapunov coefficient (from Kuznetsov [4])
        
        #print (1./(w*w))*real(1j*matrixmultiply(conjugate(p),b1)*matrixmultiply(conjugate(p),b3) + \
        #   w*matrixmultiply(conjugate(p),trilinearform(D,q,q,conjugate(q))))

        self.found[-1].w = w
        self.found[-1].l1 = firstlyapunov(X, C.CorrFunc, w, J_coords=J_coords, p=p, q=q, check=(C.verbosity==2)) 
        self.found[-1].eigs = eigs
        
        self.info(C, -1)
        
        return True
Пример #18
0
 def func(self, X, V):
     return array(matrixmultiply(transpose(self.F.testfunc.data.w), self.F.testfunc.data.v)[0])
Пример #19
0
 def func(self, X, V):
     BorderMethod.func(self, matrixmultiply(self.F.J_coords,self.F.J_coords) + X[-1]*eye(self.F.m))
     return array([self.data.g[0,0], self.data.g[1,1]])
Пример #20
0
 def setdata(self, X, V):
     BorderMethod.setdata(self, matrixmultiply(self.F.J_coords,self.F.J_coords) + X[-1]*eye(self.F.m))
Пример #21
0
# for i in range(30):
#     # ignore header
#     k=f.readline()

#     for j in range(1024):
#         k=f.readline()
#         s=k.split()
#         for l in range(256):
#             data4[j][l]=float(s[l])

# for i in range(1024):
#     for j in range(256):
#         summe4[i]+=data4[i][j]

#corrsumme=matrixmultiply(summe,corrmat)
corrsumme = matrixmultiply(summe, corrmat)
corrsumme2 = matrixmultiply(summe2, corrmat)
corrsumme3 = zeros([1024], Float)

for i in range(0, 1022):
    corrsumme3[i] = corrsumme[i + 2]

cmgd = GridData(data)
data2grid = GridData(data)

gp = Gnuplot()
#gp("set logscale z")
#gp("set zrange[1:80]")
#gp("set palette rgbformula -3,-3,-3")
#gp("test palette")
#gp("set xrange[400:800]")
Пример #22
0
def firstlyapunov(X,
                  F,
                  w,
                  J_coords=None,
                  V=None,
                  W=None,
                  p=None,
                  q=None,
                  check=False):
    if J_coords is None:
        J_coords = F.jac(X, F.coords)

    if p is None:
        alpha = bilinearform(transpose(J_coords),V[:,0],V[:,1]) - \
          1j*w*matrixmultiply(V[:,0],V[:,1])
        beta = -1*bilinearform(transpose(J_coords),V[:,0],V[:,0]) + \
          1j*w*matrixmultiply(V[:,0],V[:,0])
        q = alpha * V[:, 0] + beta * V[:, 1]

        alpha = bilinearform(J_coords,W[:,0],W[:,1]) + \
          1j*w*matrixmultiply(W[:,0],W[:,1])
        beta = -1*bilinearform(J_coords,W[:,0],W[:,0]) - \
          1j*w*matrixmultiply(W[:,0],W[:,0])
        p = alpha * W[:, 0] + beta * W[:, 1]

        p /= linalg.norm(p)
        q /= linalg.norm(q)

        direc = conjugate(1 / matrixmultiply(conjugate(p), q))
        p = direc * p

    if check:
        print 'Checking...'
        print '  |q| = %f' % linalg.norm(q)
        temp = matrixmultiply(conjugate(p), q)
        print '  |<p,q> - 1| = ', abs(temp - 1)
        print '  |Aq - iwq| = %f' % linalg.norm(
            matrixmultiply(J_coords, q) - 1j * w * q)
        print '  |A*p + iwp| = %f\n' % linalg.norm(
            matrixmultiply(transpose(J_coords), p) + 1j * w * p)

    # Compute first lyapunov coefficient
    B = F.hess(X, F.coords, F.coords)
    D = hess3(F, X, F.coords)
    b1 = array([bilinearform(B[i, :, :], q, q) for i in range(B.shape[0])])
    b2 = array([bilinearform(B[i,:,:], conjugate(q), linalg.solve(2*1j*w*eye(F.m) - J_coords, b1)) \
      for i in range(B.shape[0])])
    b3 = array(
        [bilinearform(B[i, :, :], q, conjugate(q)) for i in range(B.shape[0])])
    b4 = array([
        bilinearform(B[i, :, :], q, linalg.solve(J_coords, b3))
        for i in range(B.shape[0])
    ])
    temp = array([
        trilinearform(D[i, :, :, :], q, q, conjugate(q))
        for i in range(D.shape[0])
    ]) + b2 - 2 * b4

    l1 = 0.5 * real(matrixmultiply(conjugate(p), temp))

    return l1
Пример #23
0
def bilinearform(A, x1, x2):
	return matrixmultiply(transpose(x2),matrixmultiply(A,x1))
Пример #24
0
def trilinearform(A, x1, x2, x3):
    dim = A.shape
    return matrixmultiply(
        transpose([bilinearform(A[i, :, :], x1, x2) for i in range(dim[0])]),
        x3)
Пример #25
0
def bilinearform(A, x1, x2):
    return matrixmultiply(transpose(x2), matrixmultiply(A, x1))
Пример #26
0
def getMaps(pt, pttype, output=False, screen=False, cyclic=True):
    jac0 = pt.labels['LC']['data'].jac0
    jac1 = pt.labels['LC']['data'].jac1
    flow = pt.labels[pttype]['flow']
    
    n = jac0.shape[0]

    # Compute jacobian times vec
    J = linalg.solve(jac1, jac0)
    if output:
        print "Jacobian J*x"
        print "------------\n"
        print J
        print "\n"
        
        print "Check Jacobian"
        print "--------------\n"
        print "   eigs = ", linalg.eig(J)[0]
        print "   eigs = ", pt.labels['LC']['data'].evals

    # Compute composition of flow maps
    
        print "Flow maps"
        print "---------\n"

    ntst = len(flow)/2
    maps = []
    if not cyclic:
        for i in range(ntst):
            I = identity(n)
            for j in mod(arange(i, i + ntst), ntst):
                j = int(j)
                I = linalg.solve(flow[2*j+1], matrixmultiply(flow[2*j], I))
            
            maps.append(I)
    
        # Check eigs of maps
        evals = []
        levecs = []
        revecs = []
        for m in maps:
            w, vl, vr = linalg.eig(m, left=1, right=1)
            evals.append(w)
            levecs.append(vl)
            revecs.append(vr)
            
        if output:
            for i in range(ntst):
                print evals[i]
            
        # Get left evecs along curve associated with 1 evalue
        evec1 = []
        good = []
        for i in range(ntst):
            ind = argsort(abs(evals[i]-1.))[0]
            if abs(evals[i][ind]-1) > 0.05:
                print "Bad floquet multipliers!"
            else:
                good.append(i)
            evec1.append(levecs[i][:,ind])
    else:
        # CYCLIC METHOD
        print "Similarity method!\n"
        I = identity(n)
        for i in range(ntst):
            I = linalg.solve(flow[2*i+1], matrixmultiply(flow[2*i], I))
            
        evec1 = []
        w, vl, vr = linalg.eig(I, left=1, right=1)
        print w, vl
        ind = argsort(abs(w-1.))[0]
        if abs(w[ind]-1) > 0.05:
            raise "Bad floquet multipliers!"
        else:
            v = vl[:,ind]
            print v
        
        for i in range(ntst):
            v = matrixmultiply(transpose(flow[2*i]), linalg.solve(transpose(flow[2*i+1]), v))
            evec1.append(v/linalg.norm(v))
            
        # print "Cyclic method!\n"
        # evals = []
        # levecs = []
        # revecs = []
        # C0 = zeros((n*ntst, n*ntst), Float64)
        # C1 = zeros((n*ntst, n*ntst), Float64)
        # for i in range(ntst):
            # C0[(n*i):(n*(i+1)), int(mod(n*(i+1), n*ntst)):int(mod(n*(i+2), n*ntst))] = flow[2*i]
            # C1[(n*i):(n*(i+1)), (n*i):(n*(i+1))] = flow[2*i+1]
            # 
        # w, vl, vr = linalg.eig(C0, C1, left=1, right=1)
        # print w
                
    # Same direction - if right eigenvector
    cycle = pt.labels[pttype]['cycle']
    coords = cycle.coordnames
    #for i in range(ntst):
    #    if matrixmultiply(evec1[i], (cycle[4*i+1]-cycle[4*i]).toarray()) < 0:
    #        evec1[i] = -1*evec1[i]
            
    if screen:
        x = cycle[coords[0]]
        y = cycle[coords[1]]
        pylab.plot(x,y)
        for i in good:
            a = [x[4*i], x[4*i] + 10*evec1[i][0]]
            b = [y[4*i], y[4*i] + 10*evec1[i][1]]
            pylab.plot(a, b, 'r', linewidth=1)
            pylab.plot([x[4*i]], [y[4*i]], 'gs')
            #pylab.plot([x[4*i], x[4*i] + 0.5*vhd[0]], [y[4*i], y[4*i] + 0.5*vhd[1]], 'b')
            #print evec1[i], vhd, "\n"
            #print matrixmultiply(evec1[i], vhd)
                  
    if screen:
        Je, JE = linalg.eig(jac0, jac1)
        ind = argsort(abs(Je-1.))[0]
        #if abs(Je[ind]-1) > 0.05:
        if 0:
            print "Jacobian: Bad floquet multipliers!"
        else:
            u, s, vh = linalg.svd(jac0-jac1, compute_uv=1)
            evec2 = [transpose(vh)[:,-1]]
            #evec2 = [JE[:,ind]]
             
            for i in range(ntst):
                evec2.append(linalg.solve(flow[2*i+1], matrixmultiply(flow[2*i], evec2[i])))
                 
            # Same direction
            for i in range(ntst):
                if matrixmultiply(evec2[i], (cycle[4*i+1]-cycle[4*i]).toarray()) < 0:
                    evec2[i] = -1*evec2[i]
                     
            for i in range(ntst):
                a = [x[4*i], x[4*i] + 0.5*evec2[i][0]]
                b = [y[4*i], y[4*i] + 0.5*evec2[i][1]]
                #pylab.plot(a, b, 'r', linewidth=1)
                #pylab.plot([x[4*i]], [y[4*i]], 'gs')
                                
    return J, maps, evec1
Пример #27
0
def getMaps(pt, pttype, output=False, screen=False, cyclic=True):
    jac0 = pt.labels['LC']['data'].jac0
    jac1 = pt.labels['LC']['data'].jac1
    flow = pt.labels[pttype]['flow']

    n = jac0.shape[0]

    # Compute jacobian times vec
    J = linalg.solve(jac1, jac0)
    if output:
        print "Jacobian J*x"
        print "------------\n"
        print J
        print "\n"

        print "Check Jacobian"
        print "--------------\n"
        print "   eigs = ", linalg.eig(J)[0]
        print "   eigs = ", pt.labels['LC']['data'].evals

        # Compute composition of flow maps

        print "Flow maps"
        print "---------\n"

    ntst = len(flow) / 2
    maps = []
    if not cyclic:
        for i in range(ntst):
            I = identity(n)
            for j in mod(arange(i, i + ntst), ntst):
                j = int(j)
                I = linalg.solve(flow[2 * j + 1],
                                 matrixmultiply(flow[2 * j], I))

            maps.append(I)

        # Check eigs of maps
        evals = []
        levecs = []
        revecs = []
        for m in maps:
            w, vl, vr = linalg.eig(m, left=1, right=1)
            evals.append(w)
            levecs.append(vl)
            revecs.append(vr)

        if output:
            for i in range(ntst):
                print evals[i]

        # Get left evecs along curve associated with 1 evalue
        evec1 = []
        good = []
        for i in range(ntst):
            ind = argsort(abs(evals[i] - 1.))[0]
            if abs(evals[i][ind] - 1) > 0.05:
                print "Bad floquet multipliers!"
            else:
                good.append(i)
            evec1.append(levecs[i][:, ind])
    else:
        # CYCLIC METHOD
        print "Similarity method!\n"
        I = identity(n)
        for i in range(ntst):
            I = linalg.solve(flow[2 * i + 1], matrixmultiply(flow[2 * i], I))

        evec1 = []
        w, vl, vr = linalg.eig(I, left=1, right=1)
        print w, vl
        ind = argsort(abs(w - 1.))[0]
        if abs(w[ind] - 1) > 0.05:
            raise "Bad floquet multipliers!"
        else:
            v = vl[:, ind]
            print v

        for i in range(ntst):
            v = matrixmultiply(transpose(flow[2 * i]),
                               linalg.solve(transpose(flow[2 * i + 1]), v))
            evec1.append(v / linalg.norm(v))

        # print "Cyclic method!\n"
        # evals = []
        # levecs = []
        # revecs = []
        # C0 = zeros((n*ntst, n*ntst), Float64)
        # C1 = zeros((n*ntst, n*ntst), Float64)
        # for i in range(ntst):
        # C0[(n*i):(n*(i+1)), int(mod(n*(i+1), n*ntst)):int(mod(n*(i+2), n*ntst))] = flow[2*i]
        # C1[(n*i):(n*(i+1)), (n*i):(n*(i+1))] = flow[2*i+1]
        #
        # w, vl, vr = linalg.eig(C0, C1, left=1, right=1)
        # print w

    # Same direction - if right eigenvector
    cycle = pt.labels[pttype]['cycle']
    coords = cycle.coordnames
    #for i in range(ntst):
    #    if matrixmultiply(evec1[i], (cycle[4*i+1]-cycle[4*i]).toarray()) < 0:
    #        evec1[i] = -1*evec1[i]

    if screen:
        x = cycle[coords[0]]
        y = cycle[coords[1]]
        pylab.plot(x, y)
        for i in good:
            a = [x[4 * i], x[4 * i] + 10 * evec1[i][0]]
            b = [y[4 * i], y[4 * i] + 10 * evec1[i][1]]
            pylab.plot(a, b, 'r', linewidth=1)
            pylab.plot([x[4 * i]], [y[4 * i]], 'gs')
            #pylab.plot([x[4*i], x[4*i] + 0.5*vhd[0]], [y[4*i], y[4*i] + 0.5*vhd[1]], 'b')
            #print evec1[i], vhd, "\n"
            #print matrixmultiply(evec1[i], vhd)

    if screen:
        Je, JE = linalg.eig(jac0, jac1)
        ind = argsort(abs(Je - 1.))[0]
        #if abs(Je[ind]-1) > 0.05:
        if 0:
            print "Jacobian: Bad floquet multipliers!"
        else:
            u, s, vh = linalg.svd(jac0 - jac1, compute_uv=1)
            evec2 = [transpose(vh)[:, -1]]
            #evec2 = [JE[:,ind]]

            for i in range(ntst):
                evec2.append(
                    linalg.solve(flow[2 * i + 1],
                                 matrixmultiply(flow[2 * i], evec2[i])))

            # Same direction
            for i in range(ntst):
                if matrixmultiply(
                        evec2[i],
                    (cycle[4 * i + 1] - cycle[4 * i]).toarray()) < 0:
                    evec2[i] = -1 * evec2[i]

            for i in range(ntst):
                a = [x[4 * i], x[4 * i] + 0.5 * evec2[i][0]]
                b = [y[4 * i], y[4 * i] + 0.5 * evec2[i][1]]
                #pylab.plot(a, b, 'r', linewidth=1)
                #pylab.plot([x[4*i]], [y[4*i]], 'gs')

    return J, maps, evec1
Пример #28
0
def trilinearform(A, x1, x2, x3):
	dim = A.shape
	return matrixmultiply(transpose([bilinearform(A[i,:,:],x1,x2) for i in range(dim[0])]),x3)