Classes | Variables
test Namespace Reference

Classes

class  HitNormCheck
 
class  pandoraAnalysis
 

Variables

string __version__ = '1.0'
 
string __author__ = 'Saul Alonso-Monsalve'
 
string __email__ = "saul.alonso.monsalve@cern.ch"
 
 stream
 
 stdout
 
 level
 
 config = configparser.ConfigParser()
 
 SEED = int(config['random']['seed'])
 
 SHUFFLE = ast.literal_eval(config['random']['shuffle'])
 
 IMAGES_PATH = config['images']['path']
 
 VIEWS = int(config['images']['views'])
 
 PLANES = int(config['images']['planes'])
 
 CELLS = int(config['images']['cells'])
 
 STANDARDIZE = ast.literal_eval(config['images']['standardize'])
 
 DATASET_PATH = config['dataset']['path']
 
 PARTITION_PREFIX = config['dataset']['partition_prefix']
 
 LABELS_PREFIX = config['dataset']['labels_prefix']
 
 CHECKPOINT_PATH = config['model']['checkpoint_path']
 
 CHECKPOINT_PREFIX = config['model']['checkpoint_prefix']
 
 CHECKPOINT_SAVE_MANY = ast.literal_eval(config['model']['checkpoint_save_many'])
 
 CHECKPOINT_SAVE_BEST_ONLY = ast.literal_eval(config['model']['checkpoint_save_best_only'])
 
 PRINT_SUMMARY = ast.literal_eval(config['model']['print_summary'])
 
 BRANCHES = ast.literal_eval(config['model']['branches'])
 
 PARALLELIZE = ast.literal_eval(config['model']['parallelize'])
 
 OUTPUTS = int(config['model']['outputs'])
 
 OUTPUT_PATH = config['test']['output_path']
 
 OUTPUT_PREFIX = config['test']['output_prefix']
 
 CUT_NUE = float(config['test']['cut_nue'])
 
 CUT_NUMU = float(config['test']['cut_numu'])
 
 CUT_NUTAU = float(config['test']['cut_nutau'])
 
 CUT_NC = float(config['test']['cut_nc'])
 
 TEST_BATCH_SIZE = int(config['test']['batch_size'])
 
list test_values = []
 
dictionary TEST_PARAMS
 
 partition = pickle.load(partition_file)
 
 labels = pickle.load(labels_file)
 
 prediction_generator = DataGenerator(**TEST_PARAMS).generate(labels, partition['test'], False)
 
list files = [f for f in os.listdir(CHECKPOINT_PATH) if os.path.isfile(os.path.join(CHECKPOINT_PATH, f))]
 
 reverse
 
 r = re.compile(CHECKPOINT_PREFIX[1:] + '-.*-.*.h5')
 
 model
 
list is_antineutrino_target_names = ['neutrino', 'antineutrino', 'NULL']
 
list flavour_target_names = ['CC Numu', 'CC Nue', 'CC Nutau', 'NC']
 
list interaction_target_names = ['CC QE', 'CC Res', 'CC DIS', 'CC Other', 'NULL']
 
list categories_target_names
 
list protons_target_names = ['0', '1', '2', '>2']
 
list pions_target_names = ['0', '1', '2', '>2']
 
list pizeros_target_names = ['0', '1', '2', '>2']
 
list neutrons_target_names = ['0', '1', '2', '>2']
 
 Y_pred
 
 y_pred_categories = np.argmax(Y_pred, axis=1).reshape((Y_pred.shape[0], 1))
 
 Y_pred_flavour = np.zeros((Y_pred.shape[0], 4))
 
 y_test_categories = np.array([12 if aux['y_value'] == 13 else aux['y_value'] for aux in test_values]).reshape(y_pred_categories.shape)
 
 y_test_flavour = np.zeros(y_test_categories.shape, dtype=int)
 
 p = Y_pred[i]
 
 y_pred_flavour = np.argmax(Y_pred_flavour, axis=1)
 
 flavour_conf_matrix = confusion_matrix(y_pred_flavour, y_test_flavour)
 
 categories_conf_matrix = confusion_matrix(y_pred_categories, y_test_categories)
 
 weighted_conf_matrix = np.zeros((4,4), dtype='float32')
 
 cut_weighted_conf_matrix = np.zeros((4,4), dtype='float32')
 
 pred_flavour = int(y_pred_flavour[sample])
 
 test_flavour = int(y_test_flavour[sample])
 
 weight = test_values[sample]['fEventWeight']
 
string float_formatter = lambdax:"%.4f"
 
 formatter
 
 purity_conf_matrix = np.copy(cut_weighted_conf_matrix)
 
 row_sum = np.sum(purity_conf_matrix[i])
 
 efficiency_conf_matrix = cut_weighted_conf_matrix.astype('float32')/np.add.reduce(weighted_conf_matrix)
 
 y_pred_is_antineutrino = np.around(Y_pred[0]).reshape((Y_pred[0].shape[0], 1)).astype(int)
 
 y_pred_interaction = np.argmax(Y_pred[2], axis=1).reshape((Y_pred[2].shape[0], 1))
 
 y_pred_protons = np.argmax(Y_pred[3], axis=1).reshape((Y_pred[3].shape[0], 1))
 
 y_pred_pions = np.argmax(Y_pred[4], axis=1).reshape((Y_pred[4].shape[0], 1))
 
 y_pred_pizeros = np.argmax(Y_pred[5], axis=1).reshape((Y_pred[5].shape[0], 1))
 
 y_pred_neutrons = np.argmax(Y_pred[6], axis=1).reshape((Y_pred[6].shape[0], 1))
 
 y_test_is_antineutrino = np.array([aux['y_value'][0] for aux in test_values]).reshape(y_pred_is_antineutrino.shape)
 
 y_test_interaction = np.array([aux['y_value'][2] for aux in test_values]).reshape(y_pred_interaction.shape)
 
 y_test_protons = np.array([aux['y_value'][3] for aux in test_values]).reshape(y_pred_protons.shape)
 
 y_test_pions = np.array([aux['y_value'][4] for aux in test_values]).reshape(y_pred_pions.shape)
 
 y_test_pizeros = np.array([aux['y_value'][5] for aux in test_values]).reshape(y_pred_pizeros.shape)
 
 y_test_neutrons = np.array([aux['y_value'][6] for aux in test_values]).reshape(y_pred_neutrons.shape)
 
 is_antineutrino_conf_matrix = confusion_matrix(y_pred_is_antineutrino, y_test_is_antineutrino)
 
 interaction_conf_matrix = confusion_matrix(y_pred_interaction, y_test_interaction)
 
 protons_conf_matrix = confusion_matrix(y_pred_protons, y_test_protons)
 
 pions_conf_matrix = confusion_matrix(y_pred_pions, y_test_pions)
 
 pizeros_conf_matrix = confusion_matrix(y_pred_pizeros, y_test_pizeros)
 
 neutrons_conf_matrix = confusion_matrix(y_pred_neutrons, y_test_neutrons)
 
dictionary test_info
 

Detailed Description

This is the test module.

Variable Documentation

string test.__author__ = 'Saul Alonso-Monsalve'
private

Definition at line 6 of file test.py.

string test.__email__ = "saul.alonso.monsalve@cern.ch"
private

Definition at line 7 of file test.py.

string test.__version__ = '1.0'
private

Definition at line 5 of file test.py.

test.BRANCHES = ast.literal_eval(config['model']['branches'])

Definition at line 78 of file test.py.

test.categories_conf_matrix = confusion_matrix(y_pred_categories, y_test_categories)

Definition at line 244 of file test.py.

list test.categories_target_names
Initial value:
1 = ['category 0', 'category 1', 'category 2', 'category 3', 'category 4', 'category 5', 'category 6',
2  'category 7', 'category 8', 'category 9', 'category 10', 'category 11', 'category 13']

Definition at line 191 of file test.py.

test.CELLS = int(config['images']['cells'])

Definition at line 62 of file test.py.

test.CHECKPOINT_PATH = config['model']['checkpoint_path']

Definition at line 73 of file test.py.

test.CHECKPOINT_PREFIX = config['model']['checkpoint_prefix']

Definition at line 74 of file test.py.

test.CHECKPOINT_SAVE_BEST_ONLY = ast.literal_eval(config['model']['checkpoint_save_best_only'])

Definition at line 76 of file test.py.

test.CHECKPOINT_SAVE_MANY = ast.literal_eval(config['model']['checkpoint_save_many'])

Definition at line 75 of file test.py.

test.config = configparser.ConfigParser()

Definition at line 43 of file test.py.

test.CUT_NC = float(config['test']['cut_nc'])

Definition at line 89 of file test.py.

test.CUT_NUE = float(config['test']['cut_nue'])

Definition at line 86 of file test.py.

test.CUT_NUMU = float(config['test']['cut_numu'])

Definition at line 87 of file test.py.

test.CUT_NUTAU = float(config['test']['cut_nutau'])

Definition at line 88 of file test.py.

test.cut_weighted_conf_matrix = np.zeros((4,4), dtype='float32')

Definition at line 252 of file test.py.

test.DATASET_PATH = config['dataset']['path']

Definition at line 67 of file test.py.

test.efficiency_conf_matrix = cut_weighted_conf_matrix.astype('float32')/np.add.reduce(weighted_conf_matrix)

Definition at line 291 of file test.py.

list test.files = [f for f in os.listdir(CHECKPOINT_PATH) if os.path.isfile(os.path.join(CHECKPOINT_PATH, f))]

Definition at line 151 of file test.py.

test.flavour_conf_matrix = confusion_matrix(y_pred_flavour, y_test_flavour)

Definition at line 236 of file test.py.

list test.flavour_target_names = ['CC Numu', 'CC Nue', 'CC Nutau', 'NC']

Definition at line 189 of file test.py.

string test.float_formatter = lambdax:"%.4f"

Definition at line 274 of file test.py.

test.formatter

Definition at line 275 of file test.py.

test.IMAGES_PATH = config['images']['path']

Definition at line 59 of file test.py.

test.interaction_conf_matrix = confusion_matrix(y_pred_interaction, y_test_interaction)

Definition at line 359 of file test.py.

list test.interaction_target_names = ['CC QE', 'CC Res', 'CC DIS', 'CC Other', 'NULL']

Definition at line 190 of file test.py.

test.is_antineutrino_conf_matrix = confusion_matrix(y_pred_is_antineutrino, y_test_is_antineutrino)

Definition at line 343 of file test.py.

list test.is_antineutrino_target_names = ['neutrino', 'antineutrino', 'NULL']

Definition at line 188 of file test.py.

test.labels = pickle.load(labels_file)

Definition at line 122 of file test.py.

test.LABELS_PREFIX = config['dataset']['labels_prefix']

Definition at line 69 of file test.py.

test.level

Definition at line 41 of file test.py.

test.model
Initial value:
1 = load_model(CHECKPOINT_PATH + '/' + fil,
2  custom_objects={'masked_loss':my_losses.masked_loss,
3  'multitask_loss': my_losses.multitask_loss,
4  'masked_loss_binary': my_losses.masked_loss_binary,
5  'masked_loss_categorical': my_losses.masked_loss_categorical})
def load_model(name)

Definition at line 158 of file test.py.

test.neutrons_conf_matrix = confusion_matrix(y_pred_neutrons, y_test_neutrons)

Definition at line 399 of file test.py.

list test.neutrons_target_names = ['0', '1', '2', '>2']

Definition at line 196 of file test.py.

test.OUTPUT_PATH = config['test']['output_path']

Definition at line 84 of file test.py.

test.OUTPUT_PREFIX = config['test']['output_prefix']

Definition at line 85 of file test.py.

test.OUTPUTS = int(config['model']['outputs'])

Definition at line 80 of file test.py.

test.p = Y_pred[i]

Definition at line 223 of file test.py.

test.PARALLELIZE = ast.literal_eval(config['model']['parallelize'])

Definition at line 79 of file test.py.

test.partition = pickle.load(partition_file)

Definition at line 119 of file test.py.

test.PARTITION_PREFIX = config['dataset']['partition_prefix']

Definition at line 68 of file test.py.

test.pions_conf_matrix = confusion_matrix(y_pred_pions, y_test_pions)

Definition at line 383 of file test.py.

list test.pions_target_names = ['0', '1', '2', '>2']

Definition at line 194 of file test.py.

test.pizeros_conf_matrix = confusion_matrix(y_pred_pizeros, y_test_pizeros)

Definition at line 391 of file test.py.

list test.pizeros_target_names = ['0', '1', '2', '>2']

Definition at line 195 of file test.py.

test.PLANES = int(config['images']['planes'])

Definition at line 61 of file test.py.

test.pred_flavour = int(y_pred_flavour[sample])

Definition at line 255 of file test.py.

test.prediction_generator = DataGenerator(**TEST_PARAMS).generate(labels, partition['test'], False)

Definition at line 136 of file test.py.

test.PRINT_SUMMARY = ast.literal_eval(config['model']['print_summary'])

Definition at line 77 of file test.py.

test.protons_conf_matrix = confusion_matrix(y_pred_protons, y_test_protons)

Definition at line 375 of file test.py.

list test.protons_target_names = ['0', '1', '2', '>2']

Definition at line 193 of file test.py.

test.purity_conf_matrix = np.copy(cut_weighted_conf_matrix)

Definition at line 279 of file test.py.

test.r = re.compile(CHECKPOINT_PREFIX[1:] + '-.*-.*.h5')

Definition at line 154 of file test.py.

test.reverse

Definition at line 152 of file test.py.

test.row_sum = np.sum(purity_conf_matrix[i])

Definition at line 281 of file test.py.

test.SEED = int(config['random']['seed'])

Definition at line 48 of file test.py.

bool test.SHUFFLE = ast.literal_eval(config['random']['shuffle'])

Definition at line 54 of file test.py.

test.STANDARDIZE = ast.literal_eval(config['images']['standardize'])

Definition at line 63 of file test.py.

test.stdout

Definition at line 41 of file test.py.

test.stream

Definition at line 41 of file test.py.

test.TEST_BATCH_SIZE = int(config['test']['batch_size'])

Definition at line 90 of file test.py.

test.test_flavour = int(y_test_flavour[sample])

Definition at line 256 of file test.py.

test.test_info
Initial value:
1 = {'test_values':test_values, # Energy and weight values
2  'Y_pred':Y_pred, # 3-DIM array of original probability predicted values
3  'y_pred_is_antineutrino':y_pred_is_antineutrino, # 1-DIM array of is_antineutrino predicted values
4  'y_test_is_antineutrino':y_test_is_antineutrino, # 1-DIM array of is_antineutrino test values
5  'y_pred_flavour':y_pred_flavour, # 1-DIM array of flavour predicted values
6  'y_test_flavour':y_test_flavour, # 1-DIM array of flavour test values
7  'y_pred_interaction':y_pred_interaction, # 1-DIM array of interaction predicted values
8  'y_test_interaction':y_test_interaction, # 1-DIM array of interaction test values
9  'y_pred_categories':y_pred_categories, # 1-DIM array of categories predicted values
10  'y_test_categories':y_test_categories, # 1-DIM array of categories test values
11  'y_pred_protons':y_pred_protons, # 1-DIM array of protons predicted values
12  'y_test_protons':y_test_protons, # 1-DIM array of protons test values
13  'y_pred_pions':y_pred_pions, # 1-DIM array of pions predicted values
14  'y_test_pions':y_test_pions, # 1-DIM array of pions test values
15  'y_pred_pizeros':y_pred_pizeros, # 1-DIM array of pizeros predicted values
16  'y_test_pizeros':y_test_pizeros, # 1-DIM array of pizeros test values
17  'y_pred_neutrons':y_pred_neutrons, # 1-DIM array of neutrons predicted values
18  'y_test_neutrons':y_test_neutrons, # 1-DIM array of neutrons test values
19  'is_antineutrino_cm':is_antineutrino_conf_matrix, # is_antineutrino confusion matrix
20  'flavour_cm':flavour_conf_matrix, # flavour confusion matrix
21  'interaction_cm':interaction_conf_matrix, # interaction confusion matrix
22  'categories_cm':categories_conf_matrix, # categories confusion matrix
23  'protons_cm':protons_conf_matrix, # protons confusion matrix
24  'pions_cm':pions_conf_matrix, # pions confusion matrix
25  'pizeros_cm':pizeros_conf_matrix, # pizeros confusion matrix
26  'neutrons_cm':neutrons_conf_matrix, # neutrons confusion matrix
27  'cut_weighted_cm':cut_weighted_conf_matrix, # Weighted neutrino types confusion matrix (after the cut)
28  'purity_cm':purity_conf_matrix, # Purity confusion matrix
29  'efficiency_cm':efficiency_conf_matrix # Efficiency confusion matrix
30  }

Definition at line 453 of file test.py.

dictionary test.TEST_PARAMS
Initial value:
1 = {'planes':PLANES,
2  'cells':CELLS,
3  'views':VIEWS,
4  'batch_size':TEST_BATCH_SIZE,
5  'branches':BRANCHES,
6  'outputs': OUTPUTS,
7  'images_path':IMAGES_PATH,
8  'standardize':STANDARDIZE,
9  'shuffle':SHUFFLE,
10  'test_values':test_values}

Definition at line 96 of file test.py.

test.test_values = []

Definition at line 94 of file test.py.

test.VIEWS = int(config['images']['views'])

Definition at line 60 of file test.py.

test.weight = test_values[sample]['fEventWeight']

Definition at line 257 of file test.py.

test.weighted_conf_matrix = np.zeros((4,4), dtype='float32')

Definition at line 251 of file test.py.

test.Y_pred
Initial value:
1 = model.predict_generator(generator = prediction_generator,
2  steps = len(partition['test'])//TEST_BATCH_SIZE,
3  verbose = 1
4  )

Definition at line 200 of file test.py.

test.y_pred_categories = np.argmax(Y_pred, axis=1).reshape((Y_pred.shape[0], 1))

Definition at line 211 of file test.py.

test.Y_pred_flavour = np.zeros((Y_pred.shape[0], 4))

Definition at line 212 of file test.py.

test.y_pred_flavour = np.argmax(Y_pred_flavour, axis=1)

Definition at line 229 of file test.py.

test.y_pred_interaction = np.argmax(Y_pred[2], axis=1).reshape((Y_pred[2].shape[0], 1))

Definition at line 299 of file test.py.

test.y_pred_is_antineutrino = np.around(Y_pred[0]).reshape((Y_pred[0].shape[0], 1)).astype(int)

Definition at line 297 of file test.py.

test.y_pred_neutrons = np.argmax(Y_pred[6], axis=1).reshape((Y_pred[6].shape[0], 1))

Definition at line 304 of file test.py.

test.y_pred_pions = np.argmax(Y_pred[4], axis=1).reshape((Y_pred[4].shape[0], 1))

Definition at line 302 of file test.py.

test.y_pred_pizeros = np.argmax(Y_pred[5], axis=1).reshape((Y_pred[5].shape[0], 1))

Definition at line 303 of file test.py.

test.y_pred_protons = np.argmax(Y_pred[3], axis=1).reshape((Y_pred[3].shape[0], 1))

Definition at line 301 of file test.py.

test.y_test_categories = np.array([12 if aux['y_value'] == 13 else aux['y_value'] for aux in test_values]).reshape(y_pred_categories.shape)

Definition at line 214 of file test.py.

test.y_test_flavour = np.zeros(y_test_categories.shape, dtype=int)

Definition at line 215 of file test.py.

test.y_test_interaction = np.array([aux['y_value'][2] for aux in test_values]).reshape(y_pred_interaction.shape)

Definition at line 308 of file test.py.

test.y_test_is_antineutrino = np.array([aux['y_value'][0] for aux in test_values]).reshape(y_pred_is_antineutrino.shape)

Definition at line 306 of file test.py.

test.y_test_neutrons = np.array([aux['y_value'][6] for aux in test_values]).reshape(y_pred_neutrons.shape)

Definition at line 313 of file test.py.

test.y_test_pions = np.array([aux['y_value'][4] for aux in test_values]).reshape(y_pred_pions.shape)

Definition at line 311 of file test.py.

test.y_test_pizeros = np.array([aux['y_value'][5] for aux in test_values]).reshape(y_pred_pizeros.shape)

Definition at line 312 of file test.py.

test.y_test_protons = np.array([aux['y_value'][3] for aux in test_values]).reshape(y_pred_protons.shape)

Definition at line 310 of file test.py.