Changeset 2563 for inundation/fit_interpolate/benchmark_least_squares.py
- Timestamp:
- Mar 21, 2006, 10:58:32 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/fit_interpolate/benchmark_least_squares.py
r2184 r2563 22 22 23 23 from pyvolution.least_squares import Interpolation 24 from fit_interpolate.interpolate import Interpolate 24 25 from pmesh.mesh import Mesh 25 26 … … 57 58 max_points_per_cell=4, 58 59 is_fit=True, 60 use_least_squares=True, 59 61 save=False): 60 62 ''' … … 66 68 #print "max_points_per_cell", max_points_per_cell 67 69 68 # make a mesh 70 mesh_dict = self._build_regular_mesh_dict(maxArea=maxArea, 71 save=save) 72 points_dict = self._build_points_dict(num_of_points=num_of_points) 73 74 #Initial time and memory 75 t0 = time.time() 76 #m0 = None on windows 77 m0 = mem_usage() 78 79 if use_least_squares is True: 80 interp = Interpolation(mesh_dict['vertices'], 81 mesh_dict['triangles'], 82 points_dict['points'], 83 expand_search=True, 84 verbose = False, 85 max_points_per_cell = max_points_per_cell) 86 if is_fit is True: 87 calc = interp.fit_points(points_dict['point_attributes']) 88 89 else: 90 # run an interploate problem. 91 print "Interpolate!" 92 calc = interp.interpolate(mesh_dict['vertex_attributes']) 93 else: 94 # need to change to fit_interpolate code 95 interp = Interpolate(mesh_dict['vertices'], 96 mesh_dict['triangles'], 97 max_vertices_per_cell = max_points_per_cell) 98 if is_fit is True: 99 #calc = interp.fit_points(point_atts) 100 pass 101 else: 102 # run an interploate problem. 103 print "Interpolate!" 104 calc = interp.interpolate(mesh_dict['vertex_attributes'] 105 ,points_dict['points'] 106 ,start_blocking_len = 500000) 107 108 time_taken_sec = (time.time()-t0) 109 m1 = mem_usage() 110 if m0 is None or m1 is None: 111 memory_used = None 112 else: 113 memory_used = (m1 - m0) 114 #print 'That took %.2f seconds' %time_taken_sec 115 return time_taken_sec, memory_used, len(mesh_dict['triangles']) 116 117 def _build_regular_mesh_dict(self, 118 maxArea=1000, 119 save=False): 120 # make a mesh 69 121 # pretty regular size, with some segments thrown in. 70 122 m = Mesh() … … 104 156 m.export_mesh_file("aaaa.tsh") 105 157 mesh_dict = m.Mesh2IOTriangulationDict() 106 #print "mesh_dict",mesh_dict 158 159 #Add vert attribute info to the mesh 160 mesh_dict['vertex_attributes'] = [] 161 # There has to be a better way of doing this.. 162 for vertex in mesh_dict['vertices']: 163 mesh_dict['vertex_attributes'].append([10.0]) 164 165 return mesh_dict 166 167 def _build_points_dict(self, num_of_points=20000): 168 169 points_dict = {} 107 170 points = [] 108 171 point_atts = [] 109 vertex_atts = []110 172 111 112 113 173 for point in range(num_of_points): 114 174 points.append([random()*100, random()*100]) 115 175 point_atts.append(10.0) 116 176 117 # There has to be a better way of doing this.. 118 for vertex in mesh_dict['vertices']: 119 vertex_atts.append(10.0) 120 121 #Initial time and memory 122 t0 = time.time() 123 #m0 = None on windows 124 m0 = mem_usage() 177 points_dict['points'] = points 178 points_dict['point_attributes'] = point_atts 179 return points_dict 125 180 126 interp = Interpolation(mesh_dict['vertices'],127 mesh_dict['triangles'], points,128 alpha=0.2, expand_search=True,129 verbose = False,130 max_points_per_cell = 4)131 if is_fit is True:132 calc = interp.fit_points(point_atts)133 181 134 else: 135 # run an interploate problem. 136 print "Interpolate!" 137 calc = interp.interpolate(vertex_atts) 138 139 time_taken_sec = (time.time()-t0) 140 m1 = mem_usage() 141 if m0 is None or m1 is None: 142 memory_used = None 143 else: 144 memory_used = (m1 - m0) 145 #print 'That took %.2f seconds' %time_taken_sec 146 return time_taken_sec, memory_used, len(mesh_dict['triangles']) 182 #------------------------------------------------------------- 183 if __name__ == "__main__": 184 b = BenchmarkLeastSquares() 185 b._build_regular_mesh_dict() 186 b._build_points_dict()
Note: See TracChangeset
for help on using the changeset viewer.