#NEWLINE# def test_set_get_weights_Softmax( ) : #NEWLINE# #INDENT# '\n    Tests setting and getting weights for Softmax layer.\n    ' #NEWLINE# num_classes = 2 #NEWLINE# dim = 3 #NEWLINE# conv_dim = [ 3 , 4 , 5 ] #NEWLINE# layer = Softmax ( num_classes , 's' , irange = 0.1 ) #NEWLINE# softmax_mlp = MLP ( layers = [ layer ] , input_space = VectorSpace ( dim = dim ) ) #NEWLINE# vec_weights = np . random . randn ( dim , num_classes ) . astype ( config . floatX ) #NEWLINE# layer . set_weights ( vec_weights ) #NEWLINE# assert np . allclose ( layer . W . get_value ( ) , vec_weights ) #NEWLINE# layer . W . set_value ( vec_weights ) #NEWLINE# assert np . allclose ( layer . get_weights ( ) , vec_weights ) #NEWLINE# layer = Softmax ( num_classes , 's' , irange = 0.1 ) #NEWLINE# softmax_mlp = MLP ( layers = [ layer ] , input_space = Conv2DSpace ( shape = ( conv_dim [ 0 ] , conv_dim [ 1 ] ) , num_channels = conv_dim [ 2 ] ) ) #NEWLINE# conv_weights = np . random . randn ( conv_dim [ 0 ] , conv_dim [ 1 ] , conv_dim [ 2 ] , num_classes ) . astype ( config . floatX ) #NEWLINE# layer . set_weights ( conv_weights . reshape ( np . prod ( conv_dim ) , conv_weights ) ) #NEWLINE# assert np . allclose ( layer . W . get_value ( ) , conv_weights . reshape ( np . prod ( conv_dim ) , num_classes ) ) #NEWLINE# layer . W . set_value ( conv_weights . reshape ( np . prod ( conv_dim ) , num_classes ) ) #NEWLINE# assert np . allclose ( layer . get_weights_topo ( ) , np . transpose ( conv_weights , axes = ( 3 , 0 , 1 , 2 ) ) )