#NEWLINE# def test_core_layers( self ) : #NEWLINE# #INDENT# X = [ [ 0.0 , 0.0 ] , [ 0.0 , 1.0 ] , [ 1.0 , 0.0 ] , [ 1.0 , 1.0 ] ] #NEWLINE# Y_nand = [ [ 1.0 ] , [ 1.0 ] , [ 1.0 ] , [ 0.0 ] ] #NEWLINE# Y_or = [ [ 0.0 ] , [ 1.0 ] , [ 1.0 ] , [ 1.0 ] ] #NEWLINE# with tf . Graph ( ) . as_default ( ) : #NEWLINE# #INDENT# g = tflearn . input_data ( shape = [ None , 2 ] ) #NEWLINE# g_nand = tflearn . fully_connected ( g , 32 , activation = 'linear' ) #NEWLINE# g_nand = tflearn . fully_connected ( g_nand , 32 , activation = 'linear' ) #NEWLINE# g_nand = tflearn . fully_connected ( g_nand , 1 , activation = 'sigmoid' ) #NEWLINE# g_nand = tflearn . regression ( g_nand , optimizer = 'sgd' , learning_rate = 2.0 , loss = 'binary_crossentropy' ) #NEWLINE# g_or = tflearn . fully_connected ( g , 32 , activation = 'linear' ) #NEWLINE# g_or = tflearn . fully_connected ( g_or , 32 , activation = 'linear' ) #NEWLINE# g_or = tflearn . fully_connected ( g_or , 1 , activation = 'sigmoid' ) #NEWLINE# g_or = tflearn . regression ( g_or , optimizer = 'sgd' , learning_rate = 2.0 , loss = 'binary_crossentropy' ) #NEWLINE# g_xor = tflearn . merge ( [ g_nand , g_or ] , mode = 'elemwise_mul' ) #NEWLINE# m = tflearn . DNN ( g_xor ) #NEWLINE# m . fit ( g , [ Y_nand , Y_or ] , n_epoch = 400 , snapshot_epoch = False ) #NEWLINE# self . assertLess ( m . predict ( [ [ 0.0 , 0.0 ] ] ) [ 0 ] [ 0 ] , 0.01 ) #NEWLINE# self . assertGreater ( m . predict ( [ [ 0.0 , 1.0 ] ] ) [ 0 ] [ 0 ] , 0.9 ) #NEWLINE# self . assertGreater ( m . predict ( [ [ 1.0 , 0.0 ] ] ) [ 0 ] [ 0 ] , 0.9 ) #NEWLINE# self . assertLess ( m . predict ( [ [ 1.0 , 1.0 ] ] ) [ 0 ] [ 0 ] , 0.01 ) #NEWLINE# #UNINDENT# with tf . Graph ( ) . as_default ( ) : #NEWLINE# #INDENT# net = tflearn . input_data ( shape = [ None , 2 ] ) #NEWLINE# net = tflearn . flatten ( net ) #NEWLINE# net = tflearn . reshape ( net , new_shape = [ ( - 1 ) ] ) #NEWLINE# net = tflearn . activation ( net , 'relu' ) #NEWLINE# net = tflearn . dropout ( net , 0.5 ) #NEWLINE# net = tflearn . single_unit ( net )