def perclass_wlcss_test(): # classes = [406516, 404516, 406505, 404505, 406519, 404519, 407521, 405506, 406520, 404520, 408512] classes = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57] # classes = [406516, 404516, 406505, 404505, 406519, 404519, 407521, 405506] templates, streams, streams_labels = dl.load_training_dataset( dataset_choice='skoda_mini', classes=classes, template_choice_method='mrt_lcs') streams_labels_sorted_idx = streams_labels.argsort() streams = [streams[i] for i in streams_labels_sorted_idx] streams_labels = streams_labels[streams_labels_sorted_idx] params = [[34, 5, 2], [59, 18, 3], [49, 13, 2], [5, 11, 4], [55, 57, 1], [55, 38, 0], [24, 8, 2], [47, 16, 2], [30, 0, 8], [39, 9, 9]] # params = [[63, 3, 1] for _ in range(len(classes))] thresholds = [500, 994, 907, -698, 962, 405, -643, -74, 859, 480] # thresholds = [374, 228, 104, 279, 519, 394, 247, 73] start_time = time.time() m_wlcss_cuda = WLCSSCuda(templates, streams, np.array(params), False) mss = m_wlcss_cuda.compute_wlcss() m_wlcss_cuda.cuda_freemem() print("Duration: {}".format( time.strftime("%H:%M:%S.%f", time.gmtime(time.time() - start_time)))) fitness_score = ftf.isolated_fitness_function_params( mss, streams_labels, thresholds, classes, parameter_to_optimize='f1') print(fitness_score) pfe.performance_evaluation_isolated(mss, streams_labels, thresholds, classes) plt_creator.plot_isolated_mss( mss, thresholds, 'hci_guided', classes, streams_labels, title="Isolated matching score - Params opt. - {}".format( 'hci_guided')) plt.show()
def __compute_fitness_cuda(self, pop): params = [[ self.__np_to_int(p[0:self.__bits_reward]), self.__np_to_int(p[self.__bits_reward:self.__penalty_idx]), self.__np_to_int(p[self.__penalty_idx:self.__epsilon_idx]) ] for p in pop] thresholds = [[ self.__np_to_int( p[self.__epsilon_idx + (j * self.__bits_thresholds):self.__epsilon_idx + (j + 1) * self.__bits_thresholds]) - self.__scaling_factor for j in range(len(self.__templates)) ] for p in pop] matching_scores = self.__m_wlcss_cuda.compute_wlcss(params) fitness_scores = [ fit_fun.isolated_fitness_function_params( matching_scores[k], self.__streams_labels, thresholds[k], self.__classes, parameter_to_optimize=self.__fitness_function) for k in range(self.__num_individuals) ] return np.array(fitness_scores)
outputconffile.write("Null class extraction: {}\n".format(use_null)) outputconffile.write( "Null class percentage: {}\n".format(null_class_percentage)) outputconffile.write("Use encoding: {}\n".format(encoding)) outputconffile.write("Duration: {}\n".format( time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))) print("Results written") print(output_file_path.replace(".txt", "")) m_wlcss_cuda = WLCSSCuda(best_templates, streams, params, encoding) mss = m_wlcss_cuda.compute_wlcss() m_wlcss_cuda.cuda_freemem() if optimize_thresholds: thresholds = best_thresholds fitness_score = ftf.isolated_fitness_function_params( mss, streams_labels, thresholds, classes, parameter_to_optimize='f1') print(fitness_score) for i, c in enumerate(classes): tmp_labels = np.copy(streams_labels) tmp_labels[tmp_labels != c] = 0 templates_fitness_score = ftf.isolated_fitness_function_templates( mss[:, i], tmp_labels, thresholds[i], parameter_to_optimize=fitness_function) print( "Class: {} - Score: {:4.3f} - Good dist: {:4.3f} - Bad dist: {:4.3f} - Thres: {}" .format(c, templates_fitness_score[0], templates_fitness_score[1], templates_fitness_score[2], thresholds[i]))
if use_evolved_templates: if es_results_file is not None: if use_evolved_thresholds: templates, thresholds = dl.load_evolved_templates( es_results_file, classes, use_evolved_thresholds) else: templates = dl.load_evolved_templates(es_results_file, classes) if isolated_case: m_wlcss_cuda = WLCSSCuda(templates, streams_test, params, encoding) mss = m_wlcss_cuda.compute_wlcss() m_wlcss_cuda.cuda_freemem() print("Perf_F1: {}".format( ftf.isolated_fitness_function_params(mss, test_labels, thresholds, classes, parameter_to_optimize='f1'))) pfe.performance_evaluation_isolated(mss, test_labels, thresholds, classes) plt_creator.plot_isolated_mss( mss, thresholds, dataset_choice, classes, streams_labels=test_labels, title="Dataset: {} - {} - Evolved_templ: {} - Evolved_thres: {}". format(dataset_choice, "Isolated", use_evolved_templates, use_evolved_thresholds)) # plt_creator.plot_gestures(dl.load_dataset(dataset_choice, classes), classes=classes) else: