Example #1
0
def post_evaluation_multimodal(metrics, file, filename, list_of_demonstrations,
                               feat_fname):

    mutual_information_1 = []
    normalized_mutual_information_1 = []
    adjusted_mutual_information_1 = []
    homogeneity_1 = []
    precision_1_micro = []
    recall_1_micro = []
    precision_1_macro = []
    recall_1_macro = []
    precision_1_weighted = []
    recall_1_weighted = []

    mutual_information_2 = []
    normalized_mutual_information_2 = []
    adjusted_mutual_information_2 = []
    homogeneity_2 = []
    precision_2_micro = []
    recall_2_micro = []
    precision_2_macro = []
    recall_2_macro = []
    precision_2_weighted = []
    recall_2_weighted = []

    silhoutte_level_1_global = []
    silhoutte_level_1_weighted = []
    dunn1_level_1 = []
    dunn2_level_1 = []
    dunn3_level_1 = []

    silhoutte_level_2_global = []
    silhoutte_level_2_weighted = []
    dunn1_level_2 = []
    dunn2_level_2 = []
    dunn3_level_2 = []

    list_of_frms = {}

    for elem in metrics:
        precision_1_micro.append(elem[0]["precision_micro"])
        precision_2_micro.append(elem[1]["precision_micro"])

        precision_1_macro.append(elem[0]["precision_macro"])
        precision_2_macro.append(elem[1]["precision_macro"])

        precision_1_weighted.append(elem[0]["precision_weighted"])
        precision_2_weighted.append(elem[1]["precision_weighted"])

        recall_1_micro.append(elem[0]["recall_micro"])
        recall_2_micro.append(elem[1]["recall_micro"])

        recall_1_macro.append(elem[0]["recall_macro"])
        recall_2_macro.append(elem[1]["recall_macro"])

        recall_1_weighted.append(elem[0]["recall_weighted"])
        recall_2_weighted.append(elem[1]["recall_weighted"])

        mutual_information_1.append(elem[0]["mutual_info_score"])
        mutual_information_2.append(elem[1]["mutual_info_score"])

        normalized_mutual_information_1.append(
            elem[0]["normalized_mutual_info_score"])
        normalized_mutual_information_2.append(
            elem[1]["normalized_mutual_info_score"])

        adjusted_mutual_information_1.append(
            elem[0]["adjusted_mutual_info_score"])
        adjusted_mutual_information_2.append(
            elem[1]["adjusted_mutual_info_score"])

        homogeneity_1.append(elem[0]["homogeneity_score"])
        homogeneity_2.append(elem[1]["homogeneity_score"])

        silhoutte_level_1_global.append(elem[2]["level1"])
        dunn1_level_1.append(elem[3]["level1"])
        dunn2_level_1.append(elem[4]["level1"])
        dunn3_level_1.append(elem[5]["level1"])

        silhoutte_level_2_global += elem[6]
        dunn1_level_2 += elem[7]
        dunn2_level_2 += elem[8]
        dunn3_level_2 += elem[9]

        viz = elem[10]

        for demonstration in viz.keys():
            utils.dict_insert_list(demonstration, viz[demonstration],
                                   list_of_frms)

        silhoutte_level_1_weighted.append(elem[11]["level1"])
        silhoutte_level_2_weighted += elem[12]

    utils.print_and_write_2("precision_1_micro", np.mean(precision_1_micro),
                            np.std(precision_1_micro), file)
    utils.print_and_write_2("precision_2_micro", np.mean(precision_2_micro),
                            np.std(precision_2_micro), file)

    utils.print_and_write_2("precision_1_macro", np.mean(precision_1_macro),
                            np.std(precision_1_macro), file)
    utils.print_and_write_2("precision_2_macro", np.mean(precision_2_macro),
                            np.std(precision_2_macro), file)

    utils.print_and_write_2("precision_1_weighted",
                            np.mean(precision_1_weighted),
                            np.std(precision_1_weighted), file)
    utils.print_and_write_2("precision_2_weighted",
                            np.mean(precision_2_weighted),
                            np.std(precision_2_weighted), file)

    utils.print_and_write_2("recall_1_micro", np.mean(recall_1_micro),
                            np.std(recall_1_micro), file)
    utils.print_and_write_2("recall_2_micro", np.mean(recall_2_micro),
                            np.std(recall_2_micro), file)

    utils.print_and_write_2("recall_1_macro", np.mean(recall_1_macro),
                            np.std(recall_1_macro), file)
    utils.print_and_write_2("recall_2_macro", np.mean(recall_2_macro),
                            np.std(recall_2_macro), file)

    utils.print_and_write_2("recall_1_weighted", np.mean(recall_1_weighted),
                            np.std(recall_1_weighted), file)
    utils.print_and_write_2("recall_2_weighted", np.mean(recall_2_weighted),
                            np.std(recall_2_weighted), file)

    utils.print_and_write_2("mutual_info_1", np.mean(mutual_information_1),
                            np.std(mutual_information_1), file)
    utils.print_and_write_2("mutual_info_2", np.mean(mutual_information_2),
                            np.std(mutual_information_2), file)

    utils.print_and_write_2("normalized_mutual_info_1",
                            np.mean(normalized_mutual_information_1),
                            np.std(normalized_mutual_information_1), file)
    utils.print_and_write_2("normalized_mutual_info_2",
                            np.mean(normalized_mutual_information_2),
                            np.std(normalized_mutual_information_2), file)

    utils.print_and_write_2("adjusted_mutual_info_1",
                            np.mean(adjusted_mutual_information_1),
                            np.std(adjusted_mutual_information_1), file)
    utils.print_and_write_2("adjusted_mutual_info_2",
                            np.mean(adjusted_mutual_information_2),
                            np.std(adjusted_mutual_information_2), file)

    utils.print_and_write_2("homogeneity_1", np.mean(homogeneity_1),
                            np.std(homogeneity_1), file)
    utils.print_and_write_2("homogeneity_2", np.mean(homogeneity_2),
                            np.std(homogeneity_2), file)

    utils.print_and_write_2("silhoutte_level_1_global",
                            np.mean(silhoutte_level_1_global),
                            np.std(silhoutte_level_1_global), file)
    utils.print_and_write_2("silhoutte_level_2_global",
                            np.mean(silhoutte_level_2_global),
                            np.std(silhoutte_level_2_global), file)

    utils.print_and_write_2("silhoutte_level_1_weighted",
                            np.mean(silhoutte_level_1_weighted),
                            np.std(silhoutte_level_1_weighted), file)
    utils.print_and_write_2("silhoutte_level_2_weighted",
                            np.mean(silhoutte_level_2_weighted),
                            np.std(silhoutte_level_2_weighted), file)

    utils.print_and_write_2("dunn1_level1", np.mean(dunn1_level_1),
                            np.std(dunn1_level_1), file)
    utils.print_and_write_2("dunn2_level1", np.mean(dunn2_level_1),
                            np.std(dunn2_level_1), file)
    utils.print_and_write_2("dunn3_level1", np.mean(dunn3_level_1),
                            np.std(dunn3_level_1), file)

    utils.print_and_write_2("dunn1_level2", np.mean(dunn1_level_2),
                            np.std(dunn1_level_2), file)
    utils.print_and_write_2("dunn2_level2", np.mean(dunn2_level_2),
                            np.std(dunn2_level_2), file)
    utils.print_and_write_2("dunn3_level2", np.mean(dunn3_level_2),
                            np.std(dunn3_level_2), file)

    list_of_dtw_values = []
    list_of_norm_dtw_values = []
    list_of_lengths = []

    data_cache = {}

    for demonstration in list_of_demonstrations:
        try:
            list_of_frms_demonstration = list_of_frms[demonstration]

            data = {}

            for i in range(len(list_of_frms_demonstration)):
                data[i] = [elem[0] for elem in list_of_frms_demonstration[i]]

            dtw_score, normalized_dtw_score, length, labels_manual_d, colors_manual_d, labels_automatic_d, colors_automatic_d = broken_barh.plot_broken_barh(
                demonstration, data, constants.PATH_TO_CLUSTERING_RESULTS +
                demonstration + "_" + filename + ".jpg",
                constants.N_COMPONENTS_TIME_ZW)

            list_of_dtw_values.append(dtw_score)
            list_of_norm_dtw_values.append(normalized_dtw_score)
            list_of_lengths.append(length)

            # Inserting manual and annotations labels into data struct before dumping as pickle file
            cache_entry = {}
            cache_entry['changepoints'] = list_of_frms_demonstration
            cache_entry['plot_labels_manual'] = labels_manual_d
            cache_entry['plot_colors_manual'] = colors_manual_d
            cache_entry['plot_labels_automatic'] = labels_automatic_d
            cache_entry['plot_colors_automatic'] = colors_automatic_d
            data_cache[demonstration] = cache_entry

        except:
            print demonstration
            continue

    utils.print_and_write_2("dtw_score", np.mean(list_of_dtw_values),
                            np.std(list_of_dtw_values), file)
    utils.print_and_write_2("dtw_score_normalized",
                            np.mean(list_of_norm_dtw_values),
                            np.std(list_of_norm_dtw_values), file)
    utils.print_and_write(str(list_of_lengths), file)

    pickle.dump(
        data_cache,
        open(constants.PATH_TO_CLUSTERING_RESULTS + filename + "_.p", "wb"))
Example #2
0
def post_evaluation_multimodal(metrics, file, filename, list_of_demonstrations, feat_fname):

	mutual_information_1 = []
	normalized_mutual_information_1 = []
	adjusted_mutual_information_1 = []
	homogeneity_1 = []
	precision_1_micro = []
	recall_1_micro = []
	precision_1_macro = []
	recall_1_macro = []
	precision_1_weighted = []
	recall_1_weighted = []

	mutual_information_2 = []
	normalized_mutual_information_2 = []
	adjusted_mutual_information_2 = []
	homogeneity_2 = []
	precision_2_micro = []
	recall_2_micro = []
	precision_2_macro = []
	recall_2_macro = []
	precision_2_weighted = []
	recall_2_weighted = []

	silhoutte_level_1_global = []
	silhoutte_level_1_weighted = []
	dunn1_level_1 = []
	dunn2_level_1 = []
	dunn3_level_1 = []

	silhoutte_level_2_global = []
	silhoutte_level_2_weighted = []
	dunn1_level_2 = []
	dunn2_level_2 = []
	dunn3_level_2 = []

	list_of_frms = {}

	for elem in metrics:
		precision_1_micro.append(elem[0]["precision_micro"])
		precision_2_micro.append(elem[1]["precision_micro"])

		precision_1_macro.append(elem[0]["precision_macro"])
		precision_2_macro.append(elem[1]["precision_macro"])

		precision_1_weighted.append(elem[0]["precision_weighted"])
		precision_2_weighted.append(elem[1]["precision_weighted"])

		recall_1_micro.append(elem[0]["recall_micro"])
		recall_2_micro.append(elem[1]["recall_micro"])

		recall_1_macro.append(elem[0]["recall_macro"])
		recall_2_macro.append(elem[1]["recall_macro"])

		recall_1_weighted.append(elem[0]["recall_weighted"])
		recall_2_weighted.append(elem[1]["recall_weighted"])

		mutual_information_1.append(elem[0]["mutual_info_score"])
		mutual_information_2.append(elem[1]["mutual_info_score"])

		normalized_mutual_information_1.append(elem[0]["normalized_mutual_info_score"])
		normalized_mutual_information_2.append(elem[1]["normalized_mutual_info_score"])

		adjusted_mutual_information_1.append(elem[0]["adjusted_mutual_info_score"])
		adjusted_mutual_information_2.append(elem[1]["adjusted_mutual_info_score"])

		homogeneity_1.append(elem[0]["homogeneity_score"])
		homogeneity_2.append(elem[1]["homogeneity_score"])

		silhoutte_level_1_global.append(elem[2]["level1"])
		dunn1_level_1.append(elem[3]["level1"])
		dunn2_level_1.append(elem[4]["level1"])
		dunn3_level_1.append(elem[5]["level1"])

		silhoutte_level_2_global += elem[6]
		dunn1_level_2 += elem[7]
		dunn2_level_2 += elem[8]
		dunn3_level_2 += elem[9]

		viz = elem[10]

		for demonstration in viz.keys():
			utils.dict_insert_list(demonstration, viz[demonstration], list_of_frms)

		silhoutte_level_1_weighted.append(elem[11]["level1"])
		silhoutte_level_2_weighted += elem[12]

	utils.print_and_write_2("precision_1_micro", np.mean(precision_1_micro), np.std(precision_1_micro), file)
	utils.print_and_write_2("precision_2_micro", np.mean(precision_2_micro), np.std(precision_2_micro), file)

	utils.print_and_write_2("precision_1_macro", np.mean(precision_1_macro), np.std(precision_1_macro), file)
	utils.print_and_write_2("precision_2_macro", np.mean(precision_2_macro), np.std(precision_2_macro), file)

	utils.print_and_write_2("precision_1_weighted", np.mean(precision_1_weighted), np.std(precision_1_weighted), file)
	utils.print_and_write_2("precision_2_weighted", np.mean(precision_2_weighted), np.std(precision_2_weighted), file)

	utils.print_and_write_2("recall_1_micro", np.mean(recall_1_micro), np.std(recall_1_micro), file)
	utils.print_and_write_2("recall_2_micro", np.mean(recall_2_micro), np.std(recall_2_micro), file)

	utils.print_and_write_2("recall_1_macro", np.mean(recall_1_macro), np.std(recall_1_macro), file)
	utils.print_and_write_2("recall_2_macro", np.mean(recall_2_macro), np.std(recall_2_macro), file)

	utils.print_and_write_2("recall_1_weighted", np.mean(recall_1_weighted), np.std(recall_1_weighted), file)
	utils.print_and_write_2("recall_2_weighted", np.mean(recall_2_weighted), np.std(recall_2_weighted), file)

	utils.print_and_write_2("mutual_info_1", np.mean(mutual_information_1), np.std(mutual_information_1), file)
	utils.print_and_write_2("mutual_info_2", np.mean(mutual_information_2), np.std(mutual_information_2), file)

	utils.print_and_write_2("normalized_mutual_info_1", np.mean(normalized_mutual_information_1), np.std(normalized_mutual_information_1), file)
	utils.print_and_write_2("normalized_mutual_info_2", np.mean(normalized_mutual_information_2), np.std(normalized_mutual_information_2), file)

	utils.print_and_write_2("adjusted_mutual_info_1", np.mean(adjusted_mutual_information_1), np.std(adjusted_mutual_information_1), file)
	utils.print_and_write_2("adjusted_mutual_info_2", np.mean(adjusted_mutual_information_2), np.std(adjusted_mutual_information_2), file)

	utils.print_and_write_2("homogeneity_1", np.mean(homogeneity_1), np.std(homogeneity_1), file)
	utils.print_and_write_2("homogeneity_2", np.mean(homogeneity_2), np.std(homogeneity_2), file)

	utils.print_and_write_2("silhoutte_level_1_global", np.mean(silhoutte_level_1_global), np.std(silhoutte_level_1_global), file)
	utils.print_and_write_2("silhoutte_level_2_global", np.mean(silhoutte_level_2_global), np.std(silhoutte_level_2_global), file)

	utils.print_and_write_2("silhoutte_level_1_weighted", np.mean(silhoutte_level_1_weighted), np.std(silhoutte_level_1_weighted), file)
	utils.print_and_write_2("silhoutte_level_2_weighted", np.mean(silhoutte_level_2_weighted), np.std(silhoutte_level_2_weighted), file)

	utils.print_and_write_2("dunn1_level1", np.mean(dunn1_level_1), np.std(dunn1_level_1), file)
	utils.print_and_write_2("dunn2_level1", np.mean(dunn2_level_1), np.std(dunn2_level_1), file)
	utils.print_and_write_2("dunn3_level1", np.mean(dunn3_level_1), np.std(dunn3_level_1), file)

	utils.print_and_write_2("dunn1_level2", np.mean(dunn1_level_2), np.std(dunn1_level_2), file)
	utils.print_and_write_2("dunn2_level2", np.mean(dunn2_level_2), np.std(dunn2_level_2), file)
	utils.print_and_write_2("dunn3_level2", np.mean(dunn3_level_2), np.std(dunn3_level_2), file)

	list_of_dtw_values = []
	list_of_norm_dtw_values = []
	list_of_lengths = []

	data_cache = {}

	for demonstration in list_of_demonstrations:
		try:
			list_of_frms_demonstration = list_of_frms[demonstration]

			data = {}

			for i in range(len(list_of_frms_demonstration)):
				data[i] = [elem[0] for elem in list_of_frms_demonstration[i]]

			dtw_score, normalized_dtw_score, length, labels_manual_d, colors_manual_d, labels_automatic_d, colors_automatic_d  = broken_barh.plot_broken_barh(demonstration, data,
				constants.PATH_TO_CLUSTERING_RESULTS + demonstration +"_" + filename + ".jpg", constants.N_COMPONENTS_TIME_ZW)

			list_of_dtw_values.append(dtw_score)
			list_of_norm_dtw_values.append(normalized_dtw_score)
			list_of_lengths.append(length)

			# Inserting manual and annotations labels into data struct before dumping as pickle file
			cache_entry = {}
			cache_entry['changepoints'] = list_of_frms_demonstration
			cache_entry['plot_labels_manual'] = labels_manual_d
			cache_entry['plot_colors_manual'] = colors_manual_d
			cache_entry['plot_labels_automatic'] = labels_automatic_d
			cache_entry['plot_colors_automatic'] = colors_automatic_d
			data_cache[demonstration] = cache_entry

		except:
			print demonstration
			continue

	utils.print_and_write_2("dtw_score", np.mean(list_of_dtw_values), np.std(list_of_dtw_values), file)
	utils.print_and_write_2("dtw_score_normalized", np.mean(list_of_norm_dtw_values), np.std(list_of_norm_dtw_values), file)
	utils.print_and_write(str(list_of_lengths), file)

	pickle.dump(data_cache, open(constants.PATH_TO_CLUSTERING_RESULTS + filename + "_.p", "wb"))
def post_evaluation(metrics, file, fname, vision_mode):

	mutual_information_1 = []
	normalized_mutual_information_1 = []
	adjusted_mutual_information_1 = []
	homogeneity_1 = []
	precision_1_micro = []
	recall_1_micro = []
	precision_1_macro = []
	recall_1_macro = []
	precision_1_weighted = []
	recall_1_weighted = []
	silhouette_scores_global = []
	silhouette_scores_weighted = []

	dunn1_level_1 = []
	dunn2_level_1 = []
	dunn3_level_1 = []

	list_of_frms = {}

	for elem in metrics:

		mutual_information_1.append(elem[0]["mutual_info_score"])
		normalized_mutual_information_1.append(elem[0]["normalized_mutual_info_score"])
		adjusted_mutual_information_1.append(elem[0]["adjusted_mutual_info_score"])
		homogeneity_1.append(elem[0]["homogeneity_score"])

		silhouette_scores_global.append(elem[1])
		silhouette_scores_weighted.append(elem[6])

		dunn1_level_1.append(elem[2]["level1"])
		dunn2_level_1.append(elem[3]["level1"])
		dunn3_level_1.append(elem[4]["level1"])

		precision_1_micro.append(elem[0]["precision_micro"])
		precision_1_macro.append(elem[0]["precision_macro"])
		precision_1_weighted.append(elem[0]["precision_weighted"])

		recall_1_micro.append(elem[0]["recall_micro"])
		recall_1_macro.append(elem[0]["recall_macro"])
		recall_1_weighted.append(elem[0]["recall_weighted"])

		viz = elem[5]
		for demonstration in viz.keys():
			utils.dict_insert_list(demonstration, viz[demonstration], list_of_frms)

	utils.print_and_write_2("precision_1_micro", np.mean(precision_1_micro), np.std(precision_1_micro), file)
	utils.print_and_write_2("precision_1_macro", np.mean(precision_1_macro), np.std(precision_1_macro), file)
	utils.print_and_write_2("precision_1_weighted", np.mean(precision_1_weighted), np.std(precision_1_weighted), file)

	utils.print_and_write_2("recall_1_micro", np.mean(recall_1_micro), np.std(recall_1_micro), file)
	utils.print_and_write_2("recall_1_macro", np.mean(recall_1_macro), np.std(recall_1_macro), file)
	utils.print_and_write_2("recall_1_weighted", np.mean(recall_1_weighted), np.std(recall_1_weighted), file)

	utils.print_and_write_2("mutual_info", np.mean(mutual_information_1), np.std(mutual_information_1), file)
	utils.print_and_write_2("normalized_mutual_info", np.mean(normalized_mutual_information_1), np.std(normalized_mutual_information_1), file)
	utils.print_and_write_2("adjusted_mutual_info", np.mean(adjusted_mutual_information_1), np.std(adjusted_mutual_information_1), file)
	utils.print_and_write_2("silhouette_scores_global", np.mean(silhouette_scores_global), np.std(silhouette_scores_global), file)
	utils.print_and_write_2("silhouette_scores_weighted", np.mean(silhouette_scores_weighted), np.std(silhouette_scores_weighted), file)

	utils.print_and_write_2("homogeneity", np.mean(homogeneity_1), np.std(homogeneity_1), file)

	utils.print_and_write_2("dunn1", np.mean(dunn1_level_1), np.std(dunn1_level_1), file)
	utils.print_and_write_2("dunn2", np.mean(dunn2_level_1), np.std(dunn2_level_1), file)
	utils.print_and_write_2("dunn3", np.mean(dunn3_level_1), np.std(dunn3_level_1), file)

	list_of_dtw_values = []
	list_of_norm_dtw_values = []
	list_of_lengths = []

	if vision_mode:
		T = constants.N_COMPONENTS_TIME_Z
	else:
		T = constants.N_COMPONENTS_TIME_W

	pickle.dump(list_of_frms, open(constants.PATH_TO_CLUSTERING_RESULTS + fname + "_.p", "wb"))

	for demonstration in list_of_demonstrations:
		try:
			list_of_frms_demonstration = list_of_frms[demonstration]

			data = {}

			for i in range(len(list_of_frms_demonstration)):
				data[i] = [elem[0] for elem in list_of_frms_demonstration[i]]

			dtw_score, normalized_dtw_score, length = broken_barh.plot_broken_barh(demonstration, data,
				constants.PATH_TO_CLUSTERING_RESULTS + demonstration +"_" + fname + ".jpg", T)
			list_of_dtw_values.append(dtw_score)
			list_of_norm_dtw_values.append(normalized_dtw_score)
			list_of_lengths.append(length)
		except:
			print demonstration
			pass

	utils.print_and_write_2("dtw_score", np.mean(list_of_dtw_values), np.std(list_of_dtw_values), file)
	utils.print_and_write_2("dtw_score_normalized", np.mean(list_of_norm_dtw_values), np.std(list_of_norm_dtw_values), file)
	utils.print_and_write(str(list_of_lengths), file)