def run_cnn_with_best_params(smell, input_data, conv_layers, filter, kernel, pooling_window, epochs): outfile = get_out_file(smell + "final") write_result( outfile, "conv_layers,filters,kernel,max_pooling_window,epoch,stopped_epoch,auc,accuracy,precision,recall,f1,average_precision,time\n" ) try: config = configuration.CNN_config(conv_layers, filter, kernel, pooling_window, epochs) start_time = time.time() auc, accuracy, precision, recall, f1, average_precision, stopped_epoch = \ cnn(input_data, config, smell, is_final=True) end_time = time.time() elapsed_time = end_time - start_time write_result( outfile, str(conv_layers) + "," + str(filter) + "," + str(kernel) + "," + str(pooling_window) + "," + str(epochs) + "," + str(stopped_epoch) + "," + str(auc) + "," + str(accuracy) + "," + str(precision) + "," + str(recall) + "," + str(f1) + "," + str(average_precision) + "," + str(elapsed_time) + "\n") except ValueError as error: print( "Skipping combination layer: {}, filter: {}, kernel: {}, pooling_window: {}" .format(conv_layers, filter, kernel, pooling_window)) print(error) write_result( outfile, str(conv_layers) + "," + str(filter) + "," + str(kernel) + "," + str(pooling_window) + "," + str(epochs) + ",-1,-1,-1,-1,-1,-1,-1,-1\n")
def main_cnn(smell, data_path, max_encoding_dim=1024): input_data = get_all_data(data_path, smell) filters = [8, 16, 32, 64] kernels = [5, 7, 11] pooling_windows = [2, 3, 4, 5] layers = [1, 2] epochs = 20 outfile = get_out_file(smell, "cnn") write_result(outfile, "conv_layers,filters,kernel,max_pooling_window,epochs,precision,recall,f1,time\n") for layer in layers: for filter in filters: for kernel in kernels: for pooling_window in pooling_windows: config = configuration.CNN_config(layer, filter, kernel, pooling_window, epochs) start_time = time.time() try: optimal_threshold, max_pr, max_re, max_f1 = autoencoder_cnn(input_data, config) except ValueError as error: print(error) optimal_threshold = -1 max_pr = -1 max_re = -1 max_f1 = -1 end_time = time.time() time_taken = end_time - start_time write_result(outfile, str(layer) + "," + str(filter) + "," + str( kernel) + "," + str(pooling_window) + "," + str(epochs) + "," + str(max_pr) + "," + str(max_re) + "," + str(max_f1) + "," + str(time_taken) + "\n")
def main(training_data_path, eval_data_path, smell, skip_iter=-1): input_data = get_all_data(training_data_path, eval_data_path, smell) conv_layers = {1, 2, 3} filters = {8, 16, 32, 64} kernels = {5, 7, 11} pooling_windows = {2, 3, 4, 5} epochs = {50} total_iterations = len(conv_layers) * len(filters) * len(kernels) * len( pooling_windows) * len(epochs) cur_iter = 1 outfile = get_out_file(smell) write_result( outfile, "conv_layers,filters,kernel,max_pooling_window,epoch,stopped_epoch,auc,accuracy,precision,recall,f1,average_precision,time\n" ) for layer in conv_layers: for filter in filters: for kernel in kernels: for pooling_window in pooling_windows: for epoch in epochs: print("** Iteration {0} of {1} **".format( cur_iter, total_iterations)) if cur_iter < skip_iter: cur_iter += 1 continue try: config = configuration.CNN_config( layer, filter, kernel, pooling_window, epoch) start_time = time.time() auc, accuracy, precision, recall, f1, average_precision, stopped_epoch = rq1_cnn_2d.cnn( input_data, config, smell, out_folder=OUT_FOLDER, dim=DIM) end_time = time.time() elapsed_time = end_time - start_time write_result( outfile, str(layer) + "," + str(filter) + "," + str(kernel) + "," + str(pooling_window) + "," + str(epoch) + "," + str(stopped_epoch) + "," + str(auc) + "," + str(accuracy) + "," + str(precision) + "," + str(recall) + "," + str(f1) + "," + str(average_precision) + "," + str(elapsed_time) + "\n") except ValueError as error: print( "Skipping combination layer: {}, filter: {}, kernel: {}, pooling_window: {}" .format(layer, filter, kernel, pooling_window)) print(error) write_result( outfile, str(layer) + "," + str(filter) + "," + str(kernel) + "," + str(pooling_window) + "," + str(epoch) + ",-1,-1,-1,-1,-1,-1,-1,-1\n") cur_iter += 1