#NEWLINE# def validate_all_samples( model , layer_to_state ) : #NEWLINE# #INDENT# '\n    Validate samples\n\n    Parameters\n    ----------\n    model: pylearn2 DBM model\n    layer_to_state: dict\n    ' #NEWLINE# layers = ( [ model . visible_layer ] + model . hidden_layers ) #NEWLINE# def check_batch_size( l ) : #NEWLINE# #INDENT# if isinstance ( l , ( list , tuple ) ) : #NEWLINE# #INDENT# map ( check_batch_size , l ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( l . get_value ( ) . shape [ 0 ] == m ) #NEWLINE# #UNINDENT# #UNINDENT# for layer in layers : #NEWLINE# #INDENT# state = layer_to_state [ layer ] #NEWLINE# space = layer . get_total_state_space ( ) #NEWLINE# space . validate ( state ) #NEWLINE# if ( 'DenseMaxPool' in str ( type ( layer ) ) ) : #NEWLINE# #INDENT# ( p , h ) = state #NEWLINE# p = p . get_value ( ) #NEWLINE# h = h . get_value ( ) #NEWLINE# assert np . all ( ( space == h ) ) #NEWLINE# assert is_binary ( p ) #NEWLINE# #UNINDENT# if ( 'BinaryVisLayer' in str ( type ( layer ) ) ) : #NEWLINE# #INDENT# v = state . get_value ( ) #NEWLINE# assert is_binary ( v ) #NEWLINE# #UNINDENT# if ( 'Softmax' in str ( type ( layer ) ) ) : #NEWLINE# #INDENT# y = state . get_value ( ) #NEWLINE# assert is_binary ( y ) #NEWLINE# s = y . sum ( axis = 1 ) #NEWLINE# assert np . all ( ( s == 1 ) ) #NEWLINE# #UNINDENT# if ( 'Ising' in str ( type ( layer ) ) ) : #NEWLINE# #INDENT# s = state . get_value ( ) #NEWLINE# assert is_binary ( ( ( s + 1.0 ) / 2.0 ) )