#NEWLINE# def test_composite( self ) : #NEWLINE# #INDENT# ls = MS . GradientDescent ( lr = 0.1 ) #NEWLINE# cost = MC . NegativeLogLikelihood ( ) #NEWLINE# inp = ML . Input ( 2 , 'inp' ) #NEWLINE# h1 = ML . Hidden ( 5 , activation = MA . Tanh ( ) , name = 'h1' ) #NEWLINE# h2 = ML . Hidden ( 5 , activation = MA . Tanh ( ) , name = 'h2' ) #NEWLINE# o = ML . SoftmaxClassifier ( 2 , learningScenario = ls , costObject = cost , name = 'out' ) #NEWLINE# c = ML . Composite ( name = 'Comp' ) #NEWLINE# ( inp > h1 > c ) #NEWLINE# ( inp > h2 > c ) #NEWLINE# mlp = ( c > o ) #NEWLINE# self . xor_ins = numpy . array ( self . xor_ins ) #NEWLINE# self . xor_outs = numpy . array ( self . xor_outs ) #NEWLINE# for i in xrange ( 10000 ) : #NEWLINE# #INDENT# ii = ( i % len ( self . xor_ins ) ) #NEWLINE# mlp . train ( o , inp = [ self . xor_ins [ ii ] ] , targets = [ self . xor_outs [ ii ] ] ) #NEWLINE# #UNINDENT# self . assertEqual ( mlp . predict ( o , inp = [ self . xor_ins [ 0 ] ] ) [ 0 ] , 0 ) #NEWLINE# self . assertEqual ( mlp . predict ( o , inp = [ self . xor_ins [ 1 ] ] ) [ 0 ] , 1 ) #NEWLINE# self . assertEqual ( mlp . predict ( o , inp = [ self . xor_ins [ 2 ] ] ) [ 0 ] , 1 ) #NEWLINE# self . assertEqual ( mlp . predict ( h1 , inp = [ self . xor_ins [ 3 ] ] ) [ 0 ] , 0 )