<s> """<STR_LIT>""" <EOL> import os <EOL> import pylearn2 . scripts . dbm . show_negative_chains as negative_chains <EOL> import pylearn2 . scripts . dbm . show_reconstructions as show_reconstruct <EOL> import pylearn2 . scripts . dbm . show_samples as show_samples <EOL> import pylearn2 . scripts . dbm . top_filters as top_filters <EOL> from pylearn2 . config import yaml_parse <EOL> from pylearn2 . models . dbm . layer import BinaryVector , BinaryVectorMaxPool <EOL> from pylearn2 . datasets . mnist import MNIST <EOL> from pylearn2 . models . dbm . dbm import DBM <EOL> from nose . tools import with_setup <EOL> from pylearn2 . datasets import control <EOL> from pylearn2 . utils import serial <EOL> from theano import function <EOL> from theano . compat . six . moves import cPickle <EOL> def setup ( ) : <EOL> """<STR_LIT>""" <EOL> control . push_load_data ( False ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:wb>' ) as f : <EOL> dataset = MNIST ( which_set = '<STR_LIT:train>' , start = <NUM_LIT:0> , stop = <NUM_LIT:100> , binarize = True ) <EOL> vis_layer = BinaryVector ( nvis = <NUM_LIT> , bias_from_marginals = dataset ) <EOL> hid_layer1 = BinaryVectorMaxPool ( layer_name = '<STR_LIT>' , pool_size = <NUM_LIT:1> , <EOL> irange = <NUM_LIT> , init_bias = - <NUM_LIT> , <EOL> detector_layer_dim = <NUM_LIT:50> ) <EOL> hid_layer2 = BinaryVectorMaxPool ( layer_name = '<STR_LIT>' , pool_size = <NUM_LIT:1> , <EOL> irange = <NUM_LIT> , init_bias = - <NUM_LIT> , <EOL> detector_layer_dim = <NUM_LIT:10> ) <EOL> model = DBM ( batch_size = <NUM_LIT:20> , niter = <NUM_LIT:2> , visible_layer = vis_layer , <EOL> hidden_layers = [ hid_layer1 , hid_layer2 ] ) <EOL> model . dataset_yaml_src = """<STR_LIT>""" <EOL> model . layer_to_chains = model . make_layer_to_state ( <NUM_LIT:1> ) <EOL> cPickle . dump ( model , f , protocol = cPickle . HIGHEST_PROTOCOL ) <EOL> def teardown ( ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isfile ( '<STR_LIT>' ) : <EOL> os . remove ( '<STR_LIT>' ) <EOL> control . pop_load_data ( ) <EOL> @ with_setup ( setup , teardown ) <EOL> def test_show_negative_chains ( ) : <EOL> """<STR_LIT>""" <EOL> negative_chains . show_negative_chains ( '<STR_LIT>' ) <EOL> @ with_setup ( setup , teardown ) <EOL> def test_show_reconstructions ( ) : <EOL> """<STR_LIT>""" <EOL> rows = <NUM_LIT:5> <EOL> cols = <NUM_LIT:10> <EOL> m = rows * cols <EOL> model = show_reconstruct . load_model ( '<STR_LIT>' , m ) <EOL> dataset = show_reconstruct . load_dataset ( model . dataset_yaml_src , <EOL> use_test_set = '<STR_LIT:n>' ) <EOL> batch = model . visible_layer . space . make_theano_batch ( ) <EOL> reconstruction = model . reconstruct ( batch ) <EOL> recons_func = function ( [ batch ] , reconstruction ) <EOL> vis_batch = dataset . get_batch_topo ( m ) <EOL> patch_viewer = show_reconstruct . init_viewer ( dataset , rows , cols , vis_batch ) <EOL> show_reconstruct . update_viewer ( dataset , batch , rows , cols , patch_viewer , <EOL> recons_func , vis_batch ) <EOL> @ with_setup ( setup , teardown ) <EOL> def test_show_samples ( ) : <EOL> """<STR_LIT>""" <EOL> rows = <NUM_LIT:10> <EOL> cols = <NUM_LIT:10> <EOL> m = rows * cols <EOL> model = show_samples . load_model ( '<STR_LIT>' , m ) <EOL> dataset = yaml_parse . load ( model . dataset_yaml_src ) <EOL> samples_viewer = show_samples . init_viewer ( dataset , rows , cols ) <EOL> vis_batch = dataset . get_batch_topo ( m ) <EOL> show_samples . update_viewer ( dataset , samples_viewer , vis_batch , rows , cols ) <EOL> @ with_setup ( setup , teardown ) <EOL> def test_top_filters ( ) : <EOL> """<STR_LIT>""" <EOL> model = serial . load ( '<STR_LIT>' ) <EOL> layer_1 , layer_2 = model . hidden_layers [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> W1 = layer_1 . get_weights ( ) <EOL> W2 = layer_2 . get_weights ( ) <EOL> top_filters . get_mat_product_viewer ( W1 , W2 ) <EOL> dataset_yaml_src = model . dataset_yaml_src <EOL> dataset = yaml_parse . load ( dataset_yaml_src ) <EOL> imgs = dataset . get_weights_view ( W1 . T ) <EOL> top_filters . get_connections_viewer ( imgs , W1 , W2 ) </s>
