<s> import theano <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from sklearn import datasets <EOL> from neupy import algorithms , layers , environment <EOL> environment . reproducible ( ) <EOL> theano . config . floatX = '<STR_LIT>' <EOL> def reduce_dimension ( network , data ) : <EOL> """<STR_LIT>""" <EOL> minimized_data = network . input_layer . output ( data ) <EOL> return minimized_data . eval ( ) <EOL> mnist = datasets . fetch_mldata ( '<STR_LIT>' ) <EOL> data = mnist . data / <NUM_LIT> <EOL> features_mean = data . mean ( axis = <NUM_LIT:0> ) <EOL> data = ( data - features_mean ) . astype ( np . float32 ) <EOL> np . random . shuffle ( data ) <EOL> x_train , x_test = data [ : <NUM_LIT> ] , data [ <NUM_LIT> : ] <EOL> autoencoder = algorithms . Momentum ( <EOL> [ <EOL> layers . Dropout ( proba = <NUM_LIT:0.5> ) , <EOL> layers . Sigmoid ( <NUM_LIT> ) , <EOL> layers . Sigmoid ( <NUM_LIT:100> ) , <EOL> layers . Output ( <NUM_LIT> ) , <EOL> ] , <EOL> step = <NUM_LIT> , <EOL> verbose = True , <EOL> momentum = <NUM_LIT> , <EOL> nesterov = True , <EOL> ) <EOL> autoencoder . train ( x_train , x_train , x_test , x_test , epochs = <NUM_LIT:100> ) <EOL> n_samples = <NUM_LIT:4> <EOL> image_vectors = x_test [ : n_samples , : ] <EOL> images = ( image_vectors + features_mean ) * <NUM_LIT> <EOL> predicted_images = autoencoder . predict ( image_vectors ) <EOL> predicted_images = ( predicted_images + features_mean ) * <NUM_LIT> <EOL> fig , axes = plt . subplots ( <NUM_LIT:4> , <NUM_LIT:2> , figsize = ( <NUM_LIT:12> , <NUM_LIT:8> ) ) <EOL> iterator = zip ( axes , images , predicted_images ) <EOL> for ( left_ax , right_ax ) , real_image , predicted_image in iterator : <EOL> real_image = real_image . reshape ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> predicted_image = predicted_image . reshape ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> left_ax . imshow ( real_image , cmap = plt . cm . binary ) <EOL> right_ax . imshow ( predicted_image , cmap = plt . cm . binary ) <EOL> plt . show ( ) </s>
