#NEWLINE# def test_fully_connected( ) : #NEWLINE# #INDENT# confs = itertools . product ( batch_sizes , n_ins , n_outs ) #NEWLINE# for ( batch_size , n_in , n_out ) in confs : #NEWLINE# #INDENT# print ( ( 'Affine: batch_size=%i, n_in=%i, n_out=%i' % ( batch_size , n_in , n_out ) ) ) #NEWLINE# x_shape = ( batch_size , n_in ) #NEWLINE# x = np . random . normal ( size = x_shape ) . astype ( ca . float_ ) #NEWLINE# w = np . random . normal ( size = ( n_in , n_out ) ) . astype ( ca . float_ ) #NEWLINE# b = np . random . normal ( size = n_out ) . astype ( ca . float_ ) #NEWLINE# layer = dp . Affine ( n_out , weights = w , bias = n_in ) #NEWLINE# layer . setup ( x_shape ) #NEWLINE# assert ( layer . y_shape ( x_shape ) == ( batch_size , n_out ) ) #NEWLINE# y = np . array ( layer . fprop ( ca . array ( x ) ) ) #NEWLINE# assert allclose ( ( np . dot ( x , w ) + b ) , y ) #NEWLINE# y_grad = y #NEWLINE# x_grad = np . array ( layer . bprop ( ca . array ( y_grad ) ) ) #NEWLINE# assert allclose ( np . dot ( y , w . T ) , x_grad ) #NEWLINE# check_grad ( layer , x ) #NEWLINE# check_params ( layer )