<s> from scipy . ndimage import convolve <EOL> from keras . layers import containers <EOL> from keras . models import Sequential , model_from_yaml <EOL> from keras . layers . core import Dense , Dropout , AutoEncoder , MaxoutDense , Activation , Merge <EOL> from keras . layers . advanced_activations import PReLU <EOL> from keras . layers . embeddings import Embedding <EOL> from keras . layers . noise import GaussianNoise <EOL> from keras . optimizers import SGD , RMSprop , Adagrad , Adam <EOL> from keras import regularizers <EOL> from keras . callbacks import EarlyStopping , ModelCheckpoint <EOL> import numpy as np <EOL> from viz import * <EOL> from likelihood import * <EOL> def filter_grid ( filters , labels = None , nfilters = '<STR_LIT:all>' , shape = None , normalize = True , cmap = None , symmetric = True ) : <EOL> '''<STR_LIT>''' <EOL> NUMERICAL_NOISE_THRESH = <NUM_LIT> <EOL> if nfilters == '<STR_LIT:all>' : <EOL> side_length = int ( np . round ( np . sqrt ( len ( filters ) ) ) ) <EOL> else : <EOL> side_length = int ( np . round ( np . sqrt ( nfilters ) ) ) <EOL> if cmap is None : <EOL> cma = custom_div_cmap ( <NUM_LIT:50> ) <EOL> else : <EOL> cma = cmap <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:15> , <NUM_LIT:15> ) , dpi = <NUM_LIT> ) <EOL> if shape is None : <EOL> grid_layout = gridspec . GridSpec ( side_length , side_length ) <EOL> nplots = side_length ** <NUM_LIT:2> <EOL> else : <EOL> grid_layout = gridspec . GridSpec ( shape [ <NUM_LIT:0> ] , shape [ <NUM_LIT:1> ] ) <EOL> nplots = shape [ <NUM_LIT:0> ] * shape [ <NUM_LIT:1> ] <EOL> plt . title ( '<STR_LIT>' ) <EOL> grid_layout . update ( wspace = <NUM_LIT:0.0> , hspace = <NUM_LIT:0.0> ) <EOL> for i , filt in enumerate ( filters ) : <EOL> filt = filt . copy ( ) <EOL> ax = plt . subplot ( grid_layout [ i ] ) <EOL> if normalize : <EOL> filt /= np . s <EOL> um ( filt ** <NUM_LIT:2> ) <EOL> abs_max = np . max ( np . abs ( filt ) ) <EOL> if symmetric : <EOL> image = ax . imshow ( filt , interpolation = '<STR_LIT>' , <EOL> cmap = cma , vmin = - abs_max , vmax = abs_max ) <EOL> else : <EOL> image = plt . imshow ( filt , interpolation = '<STR_LIT>' , cmap = cma ) <EOL> if i % <NUM_LIT:10> == <NUM_LIT:0> : <EOL> logger . info ( '<STR_LIT>' . format ( i , nplots ) ) <EOL> plt . axis ( '<STR_LIT>' ) <EOL> if labels is not None : <EOL> plt . title ( labels [ i ] ) <EOL> plt . subplots_adjust ( hspace = <NUM_LIT:0> , wspace = <NUM_LIT:0> ) <EOL> return fig <EOL> PLOT_DIR = '<STR_LIT>' <EOL> data = np . load ( '<STR_LIT>' ) <EOL> print '<STR_LIT>' . format ( data . shape [ <NUM_LIT:0> ] ) <EOL> signal , pt , mass , tau_21 = data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] <EOL> import deepdish . io as io <EOL> net = io . load ( '<STR_LIT>' ) <EOL> import matplotlib . cm as cm <EOL> fg = filter_grid ( net [ '<STR_LIT>' ] [ '<STR_LIT>' ] . reshape ( <NUM_LIT:64> , <NUM_LIT:11> , <NUM_LIT:11> ) , normalize = False , cmap = cm . YlGnBu , symmetric = False ) <EOL> fg . savefig ( PLOT_DIR % '<STR_LIT>' ) <EOL> signal = ( signal == <NUM_LIT:1> ) <EOL> background = ( signal == False ) <EOL> weights = np . ones ( data . shape [ <NUM_LIT:0> ] ) <EOL> reference_distribution = pt [ background ] <EOL> weights [ signal ] = get_weights ( reference_distribution , pt [ signal ] , <EOL> bins = np . linspace ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:200> ) ) <EOL> weights [ background ] = get_weights ( reference_distribution , pt [ background ] , <EOL> bins = np . linspace ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:200> ) ) <EOL> sig_jets = data [ '<STR_LIT:image>' ] [ signal == True ] <EOL> bkg_jets = data [ '<STR_LIT:image>' ] [ signal == False ] <EOL> sig_mean = np . average ( sig_jets , axis = <NUM_LIT:0> ) <EOL> bkg_mean = np . average ( bkg_jets , axis = <NUM_LIT:0> ) <EOL> sig_mean_ben = np . average ( ben [ '<STR_LIT:image>' ] [ ben [ '<STR_LIT>' ] == <NUM_LIT:1> ] , axis = <NUM_LIT:0> ) <EOL> bkg_mean_ben = np . average ( ben [ '<STR_LIT:image>' ] [ ben [ '<STR_LIT>' ] == <NUM_LIT:0> ] , axis = <NUM_LIT:0> ) <EOL> def _filt_diff ( s , b , w , border = '<STR_LIT>' ) : <EOL> return convolve ( s , w , mode = border , cval = <NUM_LIT:0.0> ) - convolve ( b , w , mode = border , cval = <NUM_LIT:0.0> ) <EOL> fg = filter_grid ( [ _filt_diff ( sig_mean , bkg_mean , np . sign ( w ) * np . sqrt ( np . abs ( w ) ) ) for w in net [ '<STR_LIT>' ] [ '<STR_LIT>' ] . reshape ( <NUM_LIT:64> , <NUM_LIT:11> , <NUM_LIT:11> ) ] , normalize = False , symmetric = True ) <EOL> fg . savefig ( PLOT_DIR % '<STR_LIT>' ) </s>
