Changeset 5561


Ignore:
Timestamp:
Jul 23, 2008, 1:55:15 PM (11 years ago)
Author:
duncan
Message:

Clarifying err

Location:
anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r4735 r5561  
    184184       if keyword relative is False,
    185185       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))
    186193    """
    187194
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r4551 r5561  
    1818    def tearDown(self):
    1919        pass
    20 
    2120
    2221    def test_angle1(self):
     
    3029        assert allclose(angle([-1.0, -1.0])/pi*180, 225.0)
    3130        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)
    3332               
    3433                                                         
     
    6160
    6261
    63                
    64        
    65                                
    66                
    67        
    68                
    69 
    70 
    7162    def test_anglediff(self):
    7263        assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    73 
    74 
    7564
    7665       
     
    8574        assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4
    8675
    87 
    8876        A = [1,2,3.14,4]
    8977        B = ensure_numeric(A)
     
    9280        assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4
    9381
    94 
    9582        A = [1,2,3,4]
    9683        B = ensure_numeric(A, Float)
     
    9986        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    10087
    101 
    10288        A = [1,2,3,4]
    10389        B = ensure_numeric(A, Float)
     
    10591        assert B.typecode() == 'd'
    10692        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    107 
    10893
    10994        A = array([1,2,3,4])
     
    11398        assert A == B   
    11499        assert A is B   #Same object
    115 
    116100
    117101        A = array([1,2,3,4])
     
    139123        assert allclose(B, [104, 101, 108, 108, 111])
    140124
     125
    141126    def test_gradient(self):
    142127        x0 = 0.0; y0 = 0.0; z0 = 0.0
     
    149134        assert zy == 0.0
    150135
     136
    151137    def test_gradient_more(self):
    152138        x0 = 2.0/3; y0 = 2.0/3
     
    182168        z2_computed = z0 + a*(x2-x0) + b*(y2-y0)
    183169        assert z2_computed == z2
     170
    184171       
    185172    def test_gradient2_more(self):
     
    221208        a = [1,1,1,1,1,2,1,3,2,3,1,2,3,4,1]
    222209
    223 
    224210        #There are four elements greater than or equal to 3
    225211        bins = [3]
    226212        assert allclose(histogram(a, bins), [4])
    227213
    228 
    229214        bins = [ min(a) ]
    230215        assert allclose(histogram(a, bins), [len(a)])
    231216
    232 
    233217        bins = [ max(a)+0.00001 ]
    234218        assert allclose(histogram(a, bins), [0])       
    235 
    236219       
    237220        bins = [1,2,3,4]
    238221        assert allclose(histogram(a, bins), [8,3,3,1])
    239 
    240222
    241223        bins = [1.1,2,3.1,4]
    242224        #print histogram(a, bins)
    243225        assert allclose(histogram(a, bins), [0,6,0,1])
    244 
    245226
    246227        bins = [0,1.5,2,3]
     
    263244        a = [-1.7]
    264245        bins = [-1.7]
    265         assert allclose(histogram(a, bins), [1])
    266        
     246        assert allclose(histogram(a, bins), [1])       
    267247       
    268248
     
    312292        q2 = uniform(7.0, 20.0, 4)
    313293
    314 
    315294        for i in range(4):
    316295            #Gradient of fitted pwl surface
     
    326305            assert abs(b - b_ref) < epsilon
    327306
    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                                   
    330345
    331346#-------------------------------------------------------------
    332347if __name__ == "__main__":
    333348    suite = unittest.makeSuite(Test_Numerical_Tools,'test')
     349    #suite = unittest.makeSuite(Test_Numerical_Tools,'test_err')
    334350    runner = unittest.TextTestRunner()
    335351    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.