#NEWLINE# def test_standardize1( ) : #NEWLINE# #INDENT# np . random . seed ( 123 ) #NEWLINE# x = ( 1 + np . random . randn ( 5 , 4 ) ) #NEWLINE# transf = StandardizeTransform ( x ) #NEWLINE# xs1 = transf ( x ) #NEWLINE# assert_allclose ( transf . mean , x . mean ( 0 ) , rtol = 1e-13 ) #NEWLINE# assert_allclose ( transf . scale , x . std ( 0 , ddof = 1 ) , rtol = 1e-13 ) #NEWLINE# xs2 = stats . zscore ( x , ddof = 1 ) #NEWLINE# assert_allclose ( xs1 , xs2 , rtol = 1e-13 , atol = 1e-20 ) #NEWLINE# xs4 = transf ( ( 2 * x ) ) #NEWLINE# assert_allclose ( xs4 , ( ( ( 2 * x ) - transf . mean ) / transf . scale ) , rtol = 1e-13 , atol = 1e-20 ) #NEWLINE# x2 = ( ( 2 * x ) + np . random . randn ( 4 ) ) #NEWLINE# transf2 = StandardizeTransform ( x2 ) #NEWLINE# xs3 = transf2 ( x2 ) #NEWLINE# assert_allclose ( xs3 , xs1 , rtol = 1e-13 , atol = 1e-20 ) #NEWLINE# x5 = np . column_stack ( ( np . ones ( x . shape [ 0 ] ) , x ) ) #NEWLINE# transf5 = StandardizeTransform ( x5 ) #NEWLINE# xs5 = transf5 ( x5 ) #NEWLINE# assert_equal ( transf5 . const_idx , 0 ) #NEWLINE# assert_equal ( xs5 [ : , 0 ] , np . ones ( x . shape [ 0 ] ) ) #NEWLINE# assert_allclose ( xs5 [ : , 1 : ] , xs1 , rtol = 1e-13 , atol = 1e-20 )