Ignore:
Timestamp:
Oct 21, 2004, 5:54:28 PM (20 years ago)
Author:
duncan
Message:

reducing the # of errors when testing.
Adding fit_points function that doesn't rely on broadcasting, since cg_solve doesn't broadcast.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r428 r436  
    2525from LinearAlgebra import solve_linear_equations
    2626from scipy import sparse
    27 from cg_solve import conjugate_gradient
     27from cg_solve import conjugate_gradient, VectorShapeError
    2828
    2929try:
     
    130130                           alpha = alpha)
    131131   
    132     vertex_attributes = interp.fit(point_attributes)
     132    vertex_attributes = interp.fit_points(point_attributes)
    133133    return vertex_attributes
    134134
     
    212212        #Build n x m interpolation matrix       
    213213        m = self.mesh.coordinates.shape[0] #Nbr of basis functions (1/vertex)
    214         n = point_coordinates.shape[0]     #Nbr of data points         
    215 
     214        n = point_coordinates.shape[0]     #Nbr of data points
     215       
    216216        #self.A = zeros((n,m), Float)
    217217        self.A = sparse.dok_matrix()
     
    394394        #FIXME: Should we store the result here for later use? (ON)
    395395   
    396 
     396    def fit_points(self, z):
     397        """
     398        Like fit, but more robust when each point has two or more attributes
     399        """
     400        try:
     401            return self.fit(z)
     402        except VectorShapeError, e:
     403            # broadcasting is not supported.
     404
     405            #Convert input to Numeric arrays
     406            z = array(z).astype(Float)
     407           
     408            #Build n x m interpolation matrix       
     409            m = self.mesh.coordinates.shape[0] #Number of vertices
     410            n = z.shape[1]               #Number of data points         
     411
     412            f = zeros((m,n), Float)
     413            #f = sparse.dok_matrix() # even though it wont be sparse?
     414           
     415            for i in range(z.shape[1]):
     416                f[:,i] = self.fit(z[:,i])
     417            return f
     418           
     419       
    397420    def interpolate(self, f):
    398421        """Compute predicted values at data points implied in self.A.
Note: See TracChangeset for help on using the changeset viewer.