Changeset 5561
 Timestamp:
 Jul 23, 2008, 1:55:15 PM (15 years ago)
 Location:
 anuga_core/source/anuga/utilities
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

anuga_core/source/anuga/utilities/numerical_tools.py
r4735 r5561 184 184 if keyword relative is False, 185 185 absolute error is returned 186 187 If there is x and y, n=2 and relative=False, this will calc; 188 sqrt(sum_over_x&y((xi  yi)^2)) 189 190 Given this value (err), to calc the root mean square deviation, do 191 err/sqrt(n) 192 where n is the number of elements,(len(x)) 186 193 """ 187 194 
anuga_core/source/anuga/utilities/test_numerical_tools.py
r4551 r5561 18 18 def tearDown(self): 19 19 pass 20 21 20 22 21 def test_angle1(self): … … 30 29 assert allclose(angle([1.0, 1.0])/pi*180, 225.0) 31 30 assert allclose(angle([0.0, 1.0])/pi*180, 270.0) 32 assert allclose(angle([1.0, 1.0])/pi*180, 315.0) 31 assert allclose(angle([1.0, 1.0])/pi*180, 315.0) 33 32 34 33 … … 61 60 62 61 63 64 65 66 67 68 69 70 71 62 def test_anglediff(self): 72 63 assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0) 73 74 75 64 76 65 … … 85 74 assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4 86 75 87 88 76 A = [1,2,3.14,4] 89 77 B = ensure_numeric(A) … … 92 80 assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4 93 81 94 95 82 A = [1,2,3,4] 96 83 B = ensure_numeric(A, Float) … … 99 86 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 100 87 101 102 88 A = [1,2,3,4] 103 89 B = ensure_numeric(A, Float) … … 105 91 assert B.typecode() == 'd' 106 92 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 107 108 93 109 94 A = array([1,2,3,4]) … … 113 98 assert A == B 114 99 assert A is B #Same object 115 116 100 117 101 A = array([1,2,3,4]) … … 139 123 assert allclose(B, [104, 101, 108, 108, 111]) 140 124 125 141 126 def test_gradient(self): 142 127 x0 = 0.0; y0 = 0.0; z0 = 0.0 … … 149 134 assert zy == 0.0 150 135 136 151 137 def test_gradient_more(self): 152 138 x0 = 2.0/3; y0 = 2.0/3 … … 182 168 z2_computed = z0 + a*(x2x0) + b*(y2y0) 183 169 assert z2_computed == z2 170 184 171 185 172 def test_gradient2_more(self): … … 221 208 a = [1,1,1,1,1,2,1,3,2,3,1,2,3,4,1] 222 209 223 224 210 #There are four elements greater than or equal to 3 225 211 bins = [3] 226 212 assert allclose(histogram(a, bins), [4]) 227 213 228 229 214 bins = [ min(a) ] 230 215 assert allclose(histogram(a, bins), [len(a)]) 231 216 232 233 217 bins = [ max(a)+0.00001 ] 234 218 assert allclose(histogram(a, bins), [0]) 235 236 219 237 220 bins = [1,2,3,4] 238 221 assert allclose(histogram(a, bins), [8,3,3,1]) 239 240 222 241 223 bins = [1.1,2,3.1,4] 242 224 #print histogram(a, bins) 243 225 assert allclose(histogram(a, bins), [0,6,0,1]) 244 245 226 246 227 bins = [0,1.5,2,3] … … 263 244 a = [1.7] 264 245 bins = [1.7] 265 assert allclose(histogram(a, bins), [1]) 266 246 assert allclose(histogram(a, bins), [1]) 267 247 268 248 … … 312 292 q2 = uniform(7.0, 20.0, 4) 313 293 314 315 294 for i in range(4): 316 295 #Gradient of fitted pwl surface … … 326 305 assert abs(b  b_ref) < epsilon 327 306 328 329 307 308 def test_err(self): 309 x = [2,5] # diff at first position = 4, 4^2 = 16 310 y = [6,7] # diff at secnd position = 2, 2^2 = 4 311 # 16 + 4 = 20 312 313 # If there is x and y, n=2 and relative=False, this will calc; 314 # sqrt(sum_over_x&y((xi  yi)^2)) 315 err__1 = err(x,y,2,False) 316 assert err__1 == sqrt(20) 317 #print "err_", err_ 318 #rmsd_1 = err__1*sqrt(1./len(x)) 319 #print "err__1*sqrt(1./len(x))", err__1*sqrt(1./len(x)) 320 #print "sqrt(10)", sqrt(10) 321 322 x = [2,7,100] 323 y = [5,10,103] 324 err__2 = err(x,y,2,False) 325 assert err__2 == sqrt(27) 326 #rmsd_2 = err__2*sqrt(1./len(x)) 327 #print "err__2*sqrt(1./len(x))", err__2*sqrt(1./len(x)) 328 329 x = [2,5,2,7,100] 330 y = [6,7,5,10,103] 331 err_3 = err(x,y,2,False) 332 assert err_3 == sqrt(47) 333 334 #rmsd_3 = err_3*sqrt(1./len(x)) 335 #print "err__3*sqrt(1./len(x))", err__3*sqrt(1./len(x)) 336 #print "rmsd_3", rmsd_3 337 #print "sqrt(err_1*err__1+err__2*err__2)/sqrt(5)", \ 338 # sqrt(err__1*err__1+err__2*err__2)/sqrt(5) 339 #print "(rmsd_1 + rmsd_2)/2.", (rmsd_1 + rmsd_2)/2. 340 #print "sqrt((rmsd_1*rmsd_1 + rmsd_2*rmsd_2))/2.", \ 341 #sqrt((rmsd_1*rmsd_1 + rmsd_2*rmsd_2))/2. 342 343 344 330 345 331 346 # 332 347 if __name__ == "__main__": 333 348 suite = unittest.makeSuite(Test_Numerical_Tools,'test') 349 #suite = unittest.makeSuite(Test_Numerical_Tools,'test_err') 334 350 runner = unittest.TextTestRunner() 335 351 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.