Changeset 1969
- Timestamp:
- Oct 25, 2005, 10:49:31 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/fit_interpolate/benchmark_least_squares.py
r1943 r1969 2 2 3 3 measure the speed of least squares. 4 5 ________________________ 6 General comments 7 8 The max_points_per_cell does effect the time spent solving a 9 problem. The best value to use is probably dependent on the number 10 of triangles. Maybe develop a simple imperical algorithm, based on 11 test results. 4 12 5 13 Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou … … 15 23 from pyvolution.least_squares import Interpolation 16 24 from Numeric import allclose, array, transpose 17 18 from coordinate_transforms.geo_reference import Geo_reference 19 20 def distance(x, y): 21 return sqrt( sum( (array(x)-array(y))**2 )) 22 23 def linear_function(point): 24 point = array(point) 25 return point[:,0]+point[:,1] 25 import os 26 27 def report_memory(i): 28 pid = os.getpid() 29 a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() 30 print i, ' ', a2[1], 31 return int(a2[1].split()[1]) 32 33 34 def showmem(): os.system("ps axm | head -1 ; ps axm | grep py | grep -v grep") 35 36 def mem_usage(pid): 37 import string 38 p=os.popen('ps uwp %s'%pid) 39 lines=p.readlines() 40 print "lines", lines 41 status=p.close() 42 if status or len(lines)!=2: 43 return None 44 return int(string.split(lines[1])[4]) 45 46 26 47 27 48 … … 34 55 pass 35 56 36 def test_expand_search2(self):57 def ztest_expand_search2(self): 37 58 from random import seed, random 38 59 from pmesh.mesh import Mesh … … 75 96 #print 'points', points 76 97 t0 = time.time() 98 77 99 interp = Interpolation(mesh_dict['vertices'], 78 100 mesh_dict['triangles'], points, 79 alpha=0.2, expand_search= False, #True,101 alpha=0.2, expand_search=True, 80 102 verbose = False, 81 103 max_points_per_cell = 4) 82 104 calc = interp.fit_points(point_atts ) 105 #print "interp.expanded_quad_searches", interp.expanded_quad_searches 83 106 #print "calc", calc 84 107 print 'That took %.2f seconds' %(time.time()-t0) 108 109 110 def test_expand_search3(self): 111 from random import seed, random 112 from pmesh.mesh import Mesh 113 114 # takes 7.73 seconds 115 #num_of_points = 20000 116 #maxArea = 1000 117 #max_points_per_cell = 4 118 119 # took 9.84 secs 120 #num_of_points = 20000 121 #maxArea = 100 122 #max_points_per_cell = 4 123 124 # 16.61 secs 125 num_of_points = 20000 126 maxArea = 10 #836 basis functions 127 #max_points_per_cell = 4 #16.61 sec 128 129 #max_points_per_cell = 30 #31.17 sec 130 #max_points_per_cell = 2 #16.125 sec 131 max_points_per_cell = 8 #17.66 sec 132 133 134 # 16.61 secs 135 num_of_points = 20000 136 maxArea = 1 #7917 basis functions 137 max_points_per_cell = 4 # 76.047 sec 138 139 #max_points_per_cell = 30 # 140 #max_points_per_cell = 2 #78.97 sec 141 #max_points_per_cell = 16 # 82.33 sec 142 #max_points_per_cell = 8 #77.984 sec 143 144 # 8.44 secs 145 #num_of_points = 20000 146 #maxArea = 1 147 148 149 seed(2) 150 m = Mesh() 151 m.addUserVertex(0,0) 152 m.addUserVertex(100,0) 153 m.addUserVertex(0,100) 154 m.addUserVertex(100,100) 155 156 m.autoSegment(alpha = 100 ) 157 158 dict = {} 159 dict['points'] = [[10,10],[90,20]] 160 dict['segments'] = [[0,1]] 161 dict['segment_tags'] = ['wall1'] 162 m.addVertsSegs(dict) 163 164 dict = {} 165 dict['points'] = [[10,90],[40,20]] 166 dict['segments'] = [[0,1]] 167 dict['segment_tags'] = ['wall2'] 168 m.addVertsSegs(dict) 169 170 dict = {} 171 dict['points'] = [[20,90],[60,60]] 172 dict['segments'] = [[0,1]] 173 dict['segment_tags'] = ['wall3'] 174 m.addVertsSegs(dict) 175 176 dict = {} 177 dict['points'] = [[60,20],[90,90]] 178 dict['segments'] = [[0,1]] 179 dict['segment_tags'] = ['wall4'] 180 m.addVertsSegs(dict) 181 182 m.addVertsSegs(dict) 183 m.generateMesh(mode = "Q", maxArea = maxArea) 184 m.export_mesh_file("aaaa.tsh") 185 mesh_dict = m.Mesh2IOTriangulationDict() 186 187 points = [] 188 point_atts = [] 189 for point in range(num_of_points): 190 points.append([random()*100, random()*100]) 191 point_atts.append(10.0) 192 #m.autoSegment(alpha = 100 ) 193 194 #print 'points', points 195 t0 = time.time() 196 interp = Interpolation(mesh_dict['vertices'], 197 mesh_dict['triangles'], points, 198 alpha=0.2, expand_search=True, 199 verbose = True, #False, 200 max_points_per_cell = max_points_per_cell) 201 calc = interp.fit_points(point_atts ) 202 print "interp.expanded_quad_searches", interp.expanded_quad_searches 203 #print "calc", calc 204 print 'That took %.2f seconds' %(time.time()-t0) 85 205 86 206 #------------------------------------------------------------- 87 207 if __name__ == "__main__": 208 import os 209 #val = report_memory(1) 210 show_me = 'ps v %d' % os.getpid() 211 os.system(show_me) 88 212 suite = unittest.makeSuite(Test_Least_Squares,'test') 89 213 runner = unittest.TextTestRunner(verbosity=1) 90 runner.run(suite) 214 #runner.run(suite) 215 os.system(show_me) 216 #end = report_memory(2) 217 val = mem_usage(os.getpid()) 218 print 'val', val
Note: See TracChangeset
for help on using the changeset viewer.