#NEWLINE# def test_functions( self ) : #NEWLINE# #INDENT# Case = namedtuple ( 'Case' , 'func input_data answer' ) #NEWLINE# testcases = [ Case ( func = cg . fletcher_reeves , input_data = ( np . array ( [ 1.35 , 0.3 ] ) , np . array ( [ 0.11 , ( - 0.5 ) ] ) , np . array ( [ 0 , 0 ] ) ) , answer = 0.137 ) , Case ( func = cg . polak_ribiere , input_data = ( np . array ( [ 1.0 , ( - 0.5 ) ] ) , np . array ( [ 1.2 , ( - 0.45 ) ] ) , np . array ( [ 0 , 0 ] ) ) , answer = 0.174 ) , Case ( func = cg . hentenes_stiefel , input_data = ( np . array ( [ 1.0 , ( - 0.5 ) ] ) , np . array ( [ 1.2 , ( - 0.45 ) ] ) , np . array ( [ 0.2 , 0.05 ] ) ) , answer = 5.118 ) , Case ( func = cg . conjugate_descent , input_data = ( np . array ( [ 1.0 , ( - 0.5 ) ] ) , np . array ( [ 1.2 , ( - 0.45 ) ] ) , np . array ( [ 0.2 , 0.05 ] ) ) , answer = ( - 7.323 ) ) , Case ( func = cg . liu_storey , input_data = ( np . array ( [ 1.0 , ( - 0.5 ) ] ) , np . array ( [ 1.2 , ( - 0.45 ) ] ) , np . array ( [ 0.2 , 0.05 ] ) ) , answer = 1.243 ) , Case ( func = cg . dai_yuan , input_data = ( np . array ( [ 1.0 , ( - 0.5 ) ] ) , np . array ( [ 1.2 , ( - 0.45 ) ] ) , np . array ( [ 0.2 , 0.05 ] ) ) , answer = 38.647 ) ] #NEWLINE# for testcase in testcases : #NEWLINE# #INDENT# input_data = asfloat ( np . array ( testcase . input_data ) ) #NEWLINE# variables = T . vectors ( 3 ) #NEWLINE# hack = ( asfloat ( 0 ) * variables [ ( - 1 ) ] [ 0 ] ) #NEWLINE# output_func = theano . function ( variables , ( testcase . func ( * variables ) + testcase ) ) #NEWLINE# result = output_func ( * input_data ) #NEWLINE# self . assertAlmostEqual ( result , testcase . answer , places = 3 )