Exemple #1
0
    def setdata(self, X, V):
        A = self.bialtprodeye(2*self.F.J_coords)
        """Note: p, q <= min(n,m)"""

        self.data.Brand = 2*(random((A.shape[0],self.data.p))-0.5)
        self.data.Crand = 2*(random((A.shape[1],self.data.q))-0.5)
        self.data.B = zeros((A.shape[0],self.data.p), Float)
        self.data.C = zeros((A.shape[1],self.data.q), Float)
        self.data.D = zeros((self.data.q,self.data.p), Float)

        U, S, Vh = linalg.svd(A)
        self.data.b = U[:,-1:]
        self.data.c = num_transpose(Vh)[:,-1:]
        
        if self.update:
            self.data.B[:,1] = self.data.b
            self.data.C[:,1] = self.data.c
            
            U2, S2, Vh2 = linalg.svd(c_[r_[A, transpose(self.data.C[:,1])], r_[self.data.B[:,1], [[0]]]])
            self.data.B[:,2] = U2[0:A.shape[0],-1:]
            self.data.C[:,2] = num_transpose(Vh2)[0:A.shape[1],-1:]
            self.data.D[0,1] = U2[A.shape[0],-1]
            self.data.D[1,0] = num_transpose(Vh2)[A.shape[1],-1]
        else:
            self.data.B = self.data.Brand
            self.data.C = self.data.Crand
Exemple #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]
Exemple #3
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))
Exemple #4
0
    def setdata(self, A):
        """Note: p, q <= min(n,m)"""
        self.data.Brand = 2*(random((A.shape[0],self.data.p))-0.5)
        self.data.Crand = 2*(random((A.shape[1],self.data.q))-0.5)
        self.data.D = zeros((self.data.q,self.data.p), Float)

        if self.update:
            U, S, Vh = linalg.svd(A)
            self.data.B = U[:,-1*self.data.p:]
            self.data.C = num_transpose(Vh)[:,-1*self.data.q:]
        else:
            self.data.B = self.data.Brand
            self.data.C = self.data.Crand
    def newCurve(self, initargs):
        """Create new curve with arguments specified in the dictionary initargs."""
        curvetype = initargs['type']
        curvetype = curvetype.upper()
        
        if curvetype not in curve_list:
            raise TypeError(curvetype + ' not an allowable curve type')

        # Check name
        if initargs['name'] in self.curves.keys():
            raise AttributeError('Ambiguous name field: ' + initargs['name'] + ' already exists')
        
        # Check parameters
        if self.model.pars == {}:
            raise ValueError('No parameters defined for this system!')

        # Process initial point
        if 'initpoint' not in initargs:
            # Default to initial conditions for model
            if self.model.icdict == {}:
                raise ValueError('No initial point defined for this system!')
            initargs['initpoint'] = self.model.icdict.copy()
            #for p in initargs['freepars']:
            #    initargs['initpoint'][p] = self.model.pars[p]
        else:
            if isinstance(initargs['initpoint'], dict):
                initargs['initpoint'] = initargs['initpoint'].copy()
                #for p in initargs['freepars']:
                #    if p not in initargs['initpoint'].keys():
                #        initargs['initpoint'][p] = self.model.pars[p]
            elif isinstance(initargs['initpoint'], str):
                curvename, pointname = initargs['initpoint'].split(':')
                pointtype = pointname.strip('0123456789')
                if not self.curves.has_key(curvename):
                    raise KeyError('No curve of name ' + curvename + ' exists.')
                else:
                    point = self.curves[curvename].getSpecialPoint(pointtype, pointname)
                    if point is None:
                        raise KeyError('No point of name ' + pointname + ' exists.')
                    else:
                        initargs['initpoint'] = point
                    
            # Separate from if-else above since 'str' clause returns type Point
            if isinstance(initargs['initpoint'], Point):
                # Check to see if point contains a cycle.  If it does, assume
                #   we are starting at a cycle and save it in initcycle
                for v in initargs['initpoint'].labels.itervalues():
                    if v.has_key('cycle'):
                        initargs['initcycle'] = v   # Dictionary w/ cycle, name, and tangent information

                # Save initial point information
                initargs['initpoint'] = initargs['initpoint'].todict()
                #for p in initargs['freepars']:
                #    if p not in initargs['initpoint'].keys():
                #        initargs['initpoint'][p] = self.model.pars[p]
                        
        # Process cycle
        if 'initcycle' in initargs:
            if isinstance(initargs['initcycle'], NumArray):
                c0 = {}
                c0['data'] = args(V = {'udotps': None, 'rldot': None})
                c0['cycle'] = Pointset({'coordnames': self.gensys.funcspec.vars,
                                        'coordarray': num_transpose(initargs['initcycle'][:,1:]).copy(),
                                        'indepvarname': 't',
                                        'indepvararray': num_transpose(initargs['initcycle'][:,0]).copy()
                                       })
                initargs['initcycle'] = c0
            elif isinstance(initargs['initcycle'], Pointset):
                c0 = {}
                c0['data'] = args(V = {'udotps': None, 'rldot': None})
                c0['cycle'] = initargs['initcycle']
                initargs['initcycle'] = c0

        # Load auto module if required
        automod = None
        if curvetype in auto_list:
            if self._autoMod is None:
                self.loadAutoMod()
            automod = self._autoMod
            
        self.curves[initargs['name']] = curve_list[curvetype](self.model, self.gensys, automod, self.plot, initargs)
    def newCurve(self, initargs):
        """Create new curve with arguments specified in the dictionary initargs."""
        curvetype = initargs['type']
        curvetype = curvetype.upper()

        if curvetype not in curve_list:
            raise TypeError(curvetype + ' not an allowable curve type')

        # Check name
        if initargs['name'] in self.curves.keys():
            raise AttributeError('Ambiguous name field: ' + initargs['name'] +
                                 ' already exists')

        # Check parameters
        if self.model.pars == {}:
            raise ValueError('No parameters defined for this system!')

        # Process initial point
        if 'initpoint' not in initargs:
            # Default to initial conditions for model
            if self.model.icdict == {}:
                raise ValueError('No initial point defined for this system!')
            initargs['initpoint'] = self.model.icdict.copy()
            #for p in initargs['freepars']:
            #    initargs['initpoint'][p] = self.model.pars[p]
        else:
            if isinstance(initargs['initpoint'], dict):
                initargs['initpoint'] = initargs['initpoint'].copy()
                #for p in initargs['freepars']:
                #    if p not in initargs['initpoint'].keys():
                #        initargs['initpoint'][p] = self.model.pars[p]
            elif isinstance(initargs['initpoint'], str):
                curvename, pointname = initargs['initpoint'].split(':')
                pointtype = pointname.strip('0123456789')
                if not self.curves.has_key(curvename):
                    raise KeyError('No curve of name ' + curvename +
                                   ' exists.')
                else:
                    point = self.curves[curvename].getSpecialPoint(
                        pointtype, pointname)
                    if point is None:
                        raise KeyError('No point of name ' + pointname +
                                       ' exists.')
                    else:
                        initargs['initpoint'] = point

            # Separate from if-else above since 'str' clause returns type Point
            if isinstance(initargs['initpoint'], Point):
                # Check to see if point contains a cycle.  If it does, assume
                #   we are starting at a cycle and save it in initcycle
                for v in initargs['initpoint'].labels.itervalues():
                    if v.has_key('cycle'):
                        initargs[
                            'initcycle'] = v  # Dictionary w/ cycle, name, and tangent information

                # Save initial point information
                initargs['initpoint'] = initargs['initpoint'].todict()
                #for p in initargs['freepars']:
                #    if p not in initargs['initpoint'].keys():
                #        initargs['initpoint'][p] = self.model.pars[p]

        # Process cycle
        if 'initcycle' in initargs:
            if isinstance(initargs['initcycle'], NumArray):
                c0 = {}
                c0['data'] = args(V={'udotps': None, 'rldot': None})
                c0['cycle'] = Pointset({
                    'coordnames':
                    self.gensys.funcspec.vars,
                    'coordarray':
                    num_transpose(initargs['initcycle'][:, 1:]).copy(),
                    'indepvarname':
                    't',
                    'indepvararray':
                    num_transpose(initargs['initcycle'][:, 0]).copy()
                })
                initargs['initcycle'] = c0
            elif isinstance(initargs['initcycle'], Pointset):
                c0 = {}
                c0['data'] = args(V={'udotps': None, 'rldot': None})
                c0['cycle'] = initargs['initcycle']
                initargs['initcycle'] = c0

        # Load auto module if required
        automod = None
        if curvetype in auto_list:
            if self._autoMod is None:
                self.loadAutoMod()
            automod = self._autoMod

        self.curves[initargs['name']] = curve_list[curvetype](self.model,
                                                              self.gensys,
                                                              automod,
                                                              self.plot,
                                                              initargs)