#NEWLINE# def test_grad( self ) : #NEWLINE# #INDENT# a = np . array ( [ [ 0.1 , 0.2 ] , [ 0.3 , 0.9 ] ] ) #NEWLINE# y = np . array ( [ [ 1 , 0 ] , [ 0 , 1 ] ] ) #NEWLINE# with self . assertRaises ( Exception ) : #NEWLINE# #INDENT# active . grad ( a , grad_type = 'sgmoid_negative_log_likelihood' ) #NEWLINE# active . grad ( a , grad_type = 'linear_least_square' ) #NEWLINE# active . grad ( a , grad_type = 'linear_appro_l1_hinge' ) #NEWLINE# active . grad ( a , grad_type = 'linear_l2_hinge' ) #NEWLINE# #UNINDENT# grad = active . grad ( a , y , grad_type = 'sgmoid_negative_log_likelihood' ) #NEWLINE# tx = np . array ( [ [ ( - 0.9 ) , 0.2 ] , [ 0.3 , ( - 0.1 ) ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# grad = active . grad ( a , y , grad_type = 'linear_least_square' ) #NEWLINE# tx = np . array ( [ [ ( - 1.8 ) , 0.4 ] , [ 0.6 , ( - 0.2 ) ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# a = np . array ( [ [ 1 , 1 , ( - 2 ) , 1 ] ] ) #NEWLINE# y = np . array ( [ [ 1 , 1 , 0 , 0 ] ] ) #NEWLINE# grad = active . grad ( a , y , grad_type = common . grad . linear_weighted_approximate_rank_pairwise ) #NEWLINE# st = np . array ( [ [ ( - 1.0 ) , ( - 1.0 ) , 0 , 2 ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , st ) , True ) #NEWLINE# a = np . array ( [ [ 0.1 , ( - 2 ) ] , [ 0.3 , 9 ] ] ) #NEWLINE# y = np . array ( [ [ 1 , 0 ] , [ 0 , 1 ] ] ) #NEWLINE# '\n        grad = active.grad(a, y, grad_type = "linear_appro_l1_hinge");\n        tx   = np.array([[-1.17,0],[1,0]]);\n        self.assertTrue(is_matrix_equals(grad, tx), True);\n\n        grad = active.grad(a, y, grad_type = "linear_l2_hinge");\n        tx   = np.array([[-1.8,0],[2.6,0]]);\n        self.assertTrue(is_matrix_equals(grad, tx), True);\n        ' #NEWLINE# a = np . array ( [ [ 0.1 , 0.2 ] , [ 0.3 , 0.9 ] ] ) #NEWLINE# grad = active . grad ( a , grad_type = 'sgmoid' ) #NEWLINE# tx = np . array ( [ [ 0.09 , 0.16 ] , [ 0.21 , 0.09 ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# grad = active . grad ( a , grad_type = 'linear' ) #NEWLINE# tx = np . array ( [ [ 1 , 1 ] , [ 1 , 1 ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# grad = active . grad ( a , grad_type = 'tanh' ) #NEWLINE# tx = np . array ( [ [ 0.99 , 0.96 ] , [ 0.91 , 0.19 ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# a = np . array ( [ [ 0.1 , ( - 0.2 ) ] , [ ( - 0.3 ) , 10 ] ] ) #NEWLINE# grad = active . grad ( a , grad_type = 'relu' ) #NEWLINE# tx = np . array ( [ [ 1 , 0 ] , [ 0 , 1 ] ] ) #NEWLINE# self . assertTrue ( is_matrix_equals ( grad , tx ) , True ) #NEWLINE# with self . assertRaises ( Exception ) : #NEWLINE# #INDENT# active . grad ( a , y , 'unknow active_type' )