def plot_accuracy_gain_per_epoch(data_dict_list, marker_list, marker_labels_list, outdir_path, output_file_name): plt.clf() for i in range(len(data_dict_list)): data_dict = data_dict_list[i] marker = plot_util.get_line_marker_symbol(marker_list[i]) robot_list = data_dict['robot_list'] accuracy_gain_list = data_dict['accuracy_gain_list'] accuracy_gain_std_list = data_dict['accuracy_gain_std_list'] for j in range(len(robot_list)): robot = robot_list[j] color = plot_util.get_robot_color(robot) accuracy_gain = accuracy_gain_list[j] plt.plot(accuracy_gain, marker=marker, color=color) if marker_labels_list is not None: legend_elements = [] for i in range(len(marker_list)): marker = plot_util.get_line_marker_symbol(marker_list[i]) legend_elements.append(Line2D([0], [0], color='black', marker=marker, label=marker_labels_list[i])) plt.legend(handles=legend_elements, bbox_to_anchor=(1.05, 1), loc='upper left') plt.xlabel('epoch') plt.ylabel('accuracy gain') plt.title(output_file_name) plt.savefig(f'{outdir_path}/{output_file_name}.png', bbox_inches='tight') print(f'saved to: {outdir_path}/{output_file_name}.png')
def plot_accuracy_asymptote_values(subplt, seen_bot, bot_list, asymptote_values_list, marker, label_prefix): for i in range(len(bot_list)): robot = bot_list[i] color = plot_util.get_robot_color(robot) accuracy = asymptote_values_list[i] label = f'{label_prefix}_{robot}' # accuracy[0] = baseline # accuracy[1] = comparison baseline = float(accuracy[0]) comparison = float(accuracy[1]) if seen_bot == 1: subplt.plot([baseline], [comparison], ls='', marker=marker, markersize=5, color=color, alpha=0.4, label=label) else: subplt.plot([baseline], [comparison], ls='', marker=marker, markersize=5, color=color, label=label)
def plot_gain_for_robot_list(subplt, seen_bot, bot_list, accuracy_list, gain_list, marker, label_prefix): for i in range(len(bot_list)): robot = bot_list[i] color = plot_util.get_robot_color(robot) accuracy = accuracy_list[i] gain = gain_list[i] label = f'{label_prefix}_{robot}' if seen_bot == 1: subplt.plot(accuracy, gain, ls='', marker=marker, markersize=5, color=color, alpha=0.4, label=label) else: subplt.plot(accuracy, gain, ls='', marker=marker, markersize=5, color=color, label=label)
def plot_layer_weights_distributions(robot_list, weights_dict_list, layer_list, nw_shape_list, outdir_path, out_prefix, compare): for layer in layer_list: plt.clf() for i in range(len(robot_list)): robot = robot_list[i] weights_dict = weights_dict_list[i] shape = nw_shape_list[i] run = 'R1' if compare == 'nwshape': color = weights_analysis.get_shape_color(shape) weights_analysis.plot_layer_weight_distribution(weights_dict, layer, run, 200, color=color, shape=shape) title = f'{robot} weights distribution' elif compare == 'robots': color = plot_util.get_robot_color(robot) weights_analysis.plot_layer_weight_distribution(weights_dict, layer, run, 200, color=color, robot=robot) title = f'{shape} weights distribution' if layer == 'layer_1': plt.legend() plt.ylabel('probability density', fontsize=18) plt.xlabel('$W^{0,1}$ values', fontsize=18) elif layer == 'layer_2': plt.xlabel('$W^{1,2}$ values', fontsize=18) elif layer == 'layer_3': plt.xlabel('$W^{2,3}$ values', fontsize=18) elif layer == 'output': plt.xlabel('$W^{3,4}$ values', fontsize=18) #plt.title(title) plt.savefig(f'{outdir_path}/{out_prefix}_{layer}_weights_distribution.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{out_prefix}_{layer}_weights_distribution.png')
def plot_single_loss_curve(loss_dict): train_type = loss_dict['train_type'] robot_list = loss_dict['robot_list'] loss_list = loss_dict['loss_list'] if train_type == 'multitask': pass else: robot = robot_list[0] loss = loss_list[0] color = plot_util.get_robot_color(robot) if train_type == 'baseline': ls = ':' else: ls = '-' plt.plot(loss, ls=ls, color=color, label=f'{robot}_{train_type}')
def plot_accuracy_per_epoch(data_dict_list, marker_list, marker_labels_list, outdir_path, output_file_name): plt.clf() for i in range(len(data_dict_list)): data_dict = data_dict_list[i] robot_list = data_dict['robot_list'] baseline_accuracy_list = data_dict['baseline_accuracy_list'] baseline_accuracy_std_list = data_dict['baseline_accuracy_std_list'] comparison_accuracy_list = data_dict['comparison_accuracy_list'] comparison_accuracy_std_list = data_dict['comparison_accuracy_std_list'] marker = plot_util.get_line_marker_symbol(marker_list[i]) for j in range(len(robot_list)): robot = robot_list[j] color = plot_util.get_robot_color(robot) baseline = baseline_accuracy_list[j] comparison = comparison_accuracy_list[j] plt.plot(baseline, marker=marker, ls='', color=color, label=f'{robot}_baseline', alpha=0.2) plt.plot(comparison, marker=marker, ls='', color=color, label=f'{robot}_transfer') if marker_labels_list is not None: legend_elements = [] for i in range(len(marker_list)): marker = plot_util.get_line_marker_symbol(marker_list[i]) legend_elements.append(Line2D([0], [0], color='black', marker=marker, label=marker_labels_list[i])) plt.legend(handles=legend_elements, bbox_to_anchor=(1.05, 1), loc='upper left') # plt.legend() plt.xlabel('epoch') plt.ylabel('accuracy') plt.title(f'{output_file_name}') plt.savefig(f'{outdir_path}/{output_file_name}.png', bbox_inches='tight') print(f'saved to: {outdir_path}/{output_file_name}.png')
def plot_for_IROS(mt_dict, mt_list, layer_trf_dict, source_bots_dict, outdir_path, outfile_prefix): transferred_HL_list = ['HL1'] num_robots_list = ['two'] # , 'three', 'four'] data_size_list = ['1k', '100'] # ================= # FOR SPEED UP # ================= for num_robots in num_robots_list: plt.clf() fig, subplts = plt.subplots(1, 2) for HL in transferred_HL_list: for mt_mode in mt_list: if HL in layer_trf_dict[mt_mode]: for source_bots in source_bots_dict[num_robots]: for data_size in data_size_list: data_dict = mt_dict[mt_mode][HL][num_robots][ source_bots][data_size] seen_bot_list = data_dict['seen_bot_list'] seen_bot_accuracy_list = data_dict[ 'seen_bot_accuracy_list'] seen_bot_gain_list = data_dict[ 'seen_bot_gain_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_accuracy_list = data_dict[ 'unseen_bot_accuracy_list'] unseen_bot_gain_list = data_dict[ 'unseen_bot_gain_list'] seen_bot_asymptote_list = data_dict[ 'seen_bot_asymptote_list'] unseen_bot_asymptote_list = data_dict[ 'unseen_bot_asymptote_list'] marker = get_marker_for_HL(HL) label_prefix = f'{data_size}' if num_robots == 'four': if len(seen_bot_list) != 0: plot_gain_for_robot_list( subplts[0], 1, seen_bot_list, seen_bot_accuracy_list, seen_bot_gain_list, marker, label_prefix) plot_accuracy_asymptote_values( subplts[1], 1, seen_bot_list, seen_bot_asymptote_list, marker, label_prefix) else: if len(unseen_bot_list) != 0: plot_gain_for_robot_list( subplts[0], 0, unseen_bot_list, unseen_bot_accuracy_list, unseen_bot_gain_list, marker, label_prefix) plot_accuracy_asymptote_values( subplts[1], 0, unseen_bot_list, unseen_bot_asymptote_list, marker, label_prefix) # Make Legend robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append( Line2D([0], [0], color=color, marker='.', markersize=5, ls='')) legend_labels = robot_list fig.legend(handles=legend_elements, labels=legend_labels, bbox_to_anchor=(0.94, 0.4), borderaxespad=0.1, fontsize=13) # File name file_name = f'{outfile_prefix}_TRF_{num_robots}_source_robots_epochs_gain' # Adjust axes etc subplts[0].set_ylim([0, 13]) subplts[0].set_xlim([79, 98]) subplts[1].set_ylim([0.62, 0.96]) subplts[1].set_xlim([0.62, 0.96]) subplts[0].set_ylabel('# epochs faster', fontsize=18) subplts[0].set_xlabel('accuracy', fontsize=18) subplts[1].set_ylabel('transfer accuracy', fontsize=18) subplts[1].set_xlabel('baseline accuracy', fontsize=18) subplts[0].set_xticks([80, 85, 90, 95]) subplts[0].set_xticklabels(['80', '85', '90', '95'], fontsize=12) subplts[0].set_yticks([0, 2, 4, 6, 8, 10, 12]) subplts[0].set_yticklabels(['0', '2', '4', '6', '8', '10', '12'], fontsize=12) subplts[1].set_yticks([0.65, 0.70, 0.75, 0.8, 0.85, 0.9, 0.95]) subplts[1].set_yticklabels( ['0.65', '0.70', '0.75', '0.80', '0.85', '0.90', '0.95'], fontsize=12) subplts[1].set_xticks([0.65, 0.75, 0.85, 0.95]) subplts[1].set_xticklabels(['0.65', '0.75', '0.85', '0.95'], fontsize=12) subplts[1].plot([0.6, 1], [0.6, 1], ls='-', linewidth=1.2, color='gray', alpha=0.4) plt.tight_layout() plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png')
def make_plots_src_mt_mode_comparison(mt_dict, mt_list, layer_trf_dict, source_bots_dict, outdir_path, outfile_prefix): # #[MT type][transfer layer type][num source robots][source robots][] # for mode in mt_dict.keys(): # mode_dict = mt_dict[mode] # print(f'{mode}: {mode_dict.keys()}') # for hl in mode_dict.keys(): # hl_dict = mode_dict[hl] # print(f' {hl}: {hl_dict.keys()}') # for num in hl_dict.keys(): # robot_dict = hl_dict[num] # print(f' {num}: {robot_dict.keys()}') transferred_HL_list = ['HL1'] num_robots_list = ['two', 'three', 'four'] data_size_list = ['1k', '100'] subplt_index_dict = { '1k': { 'speedup': 0, 'accuracy': 2 }, '100': { 'speedup': 1, 'accuracy': 3 } } # ================= # FOR SPEED UP # ================= for num_robots in num_robots_list: plt.clf() fig, subplts = plt.subplots(1, 4) for HL in transferred_HL_list: for mt_mode in mt_list: if HL in layer_trf_dict[mt_mode]: for source_bots in source_bots_dict[num_robots]: for data_size in data_size_list: data_dict = mt_dict[mt_mode][HL][num_robots][ source_bots][data_size] seen_bot_list = data_dict['seen_bot_list'] seen_bot_accuracy_list = data_dict[ 'seen_bot_accuracy_list'] seen_bot_gain_list = data_dict[ 'seen_bot_gain_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_accuracy_list = data_dict[ 'unseen_bot_accuracy_list'] unseen_bot_gain_list = data_dict[ 'unseen_bot_gain_list'] seen_bot_asymptote_list = data_dict[ 'seen_bot_asymptote_list'] unseen_bot_asymptote_list = data_dict[ 'unseen_bot_asymptote_list'] marker = get_marker_for_HL(HL) label_prefix = f'{data_size}' if num_robots == 'four': if len(seen_bot_list) != 0: subplt_index = subplt_index_dict[ data_size]['speedup'] plot_gain_for_robot_list( subplts[subplt_index], 1, seen_bot_list, seen_bot_accuracy_list, seen_bot_gain_list, marker, label_prefix) subplt_index = subplt_index_dict[ data_size]['accuracy'] plot_accuracy_asymptote_values( subplts[subplt_index], 1, seen_bot_list, seen_bot_asymptote_list, marker, label_prefix) else: if len(unseen_bot_list) != 0: subplt_index = subplt_index_dict[ data_size]['speedup'] plot_gain_for_robot_list( subplts[subplt_index], 0, unseen_bot_list, unseen_bot_accuracy_list, unseen_bot_gain_list, marker, label_prefix) subplt_index = subplt_index_dict[ data_size]['accuracy'] plot_accuracy_asymptote_values( subplts[subplt_index], 0, unseen_bot_list, unseen_bot_asymptote_list, marker, label_prefix) robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] # for hl in transferred_HL_list: # marker = get_marker_for_HL(hl) # legend_elements.append(Line2D([0], [0], color='black', marker=marker, ls='')) for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append( Line2D([0], [0], color=color, marker='.', ls='')) legend_labels = robot_list fig.legend(handles=legend_elements, labels=legend_labels, bbox_to_anchor=(1.0, 0.9), loc='upper left', borderaxespad=0.1) file_name = f'{outfile_prefix}_TRF_{num_robots}_source_robots_epochs_gain' subplts[0].set_ylim([0, 12]) subplts[1].set_ylim([0, 12]) subplts[2].set_ylim([.70, 0.96]) subplts[3].set_ylim([.70, 0.96]) subplts[0].set_xlim([75, 98]) subplts[1].set_xlim([75, 98]) subplts[2].set_xlim([0.50, 0.96]) subplts[3].set_xlim([0.50, 0.96]) subplts[0].set_title('1k speed up') subplts[1].set_title('100 speed up') subplts[2].set_title('1k accuracy') subplts[3].set_title('100 accuracy') fig.suptitle(file_name) subplts[0].set_ylabel('# epochs faster') subplts[2].set_ylabel('transfer accuracy') subplts[0].set_xlabel('accuracy') subplts[1].set_xlabel('accuracy') subplts[2].set_xlabel('baseline') subplts[3].set_xlabel('baseline') #fig.text(0.25, 0.01, 'accuracy', ha='center') subplts[2].plot([0.7, 1], [0.7, 1], ls='-', linewidth=0.5, color='gray', alpha=0.8) subplts[3].plot([0.7, 1], [0.7, 1], ls='-', linewidth=0.5, color='gray', alpha=0.8) plt.subplots_adjust(right=0.9) plt.tight_layout() plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png')
def make_superimposed_and_differences_layer_outputs_bt_first_and_ith_motion(layer_list, robot_list, network_output_list, network_shape_list, outdir_path, outfile_prefix, ith_motion_to_compare, sorted=False): for i in range(len(layer_list)): plt.clf() layer = layer_list[i] differences_list = [] color_list = [] label_list = [] compare_index = ith_motion_to_compare - 1 # ============================= # First make superimposed plots # ----------------------------- for j in range(len(robot_list)): robot = robot_list[j] by_layer_output_list = network_output_list[j] shape = network_shape_list[j] by_layer_output = by_layer_output_list[i] min_motion = by_layer_output[:, 0] max_motion = by_layer_output[:, compare_index] if sorted: min_motion = sort_array_in_descending_order(min_motion) max_motion = sort_array_in_descending_order(max_motion) differences_list.append(max_motion - min_motion) color = plot_util.get_robot_color(robot) color_list.append(color) label_list.append(f'{robot}_differences') label_min = f'{robot}_min_motion' label_max = f'{robot}_motion_{ith_motion_to_compare}' plt.plot(min_motion, ls='', marker='.', color=color, alpha=0.1, label=label_min) plt.plot(max_motion, ls='', marker='.', color=color, label=label_max) title = f'{outfile_prefix}_{layer}_first_and_motion_{ith_motion_to_compare}_comparison' if sorted: outfile_name = f'{title}_sorted' else: outfile_name = title plt.legend() plt.title(title) plt.savefig(f'{outdir_path}/{outfile_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{outfile_name}.png') # ========================== # Then make difference plots # -------------------------- plt.clf() for k in range(len(differences_list)): plt.plot(differences_list[k], ls='', marker='.', color=color_list[k], label=label_list[k]) title = f'{outfile_prefix}_{layer}_first_and_motion_{ith_motion_to_compare}_differences' if sorted: outfile_name = f'{title}_sorted' else: outfile_name = title plt.legend() plt.title(f'{title}_differences') plt.savefig(f'{outdir_path}/{outfile_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{outfile_name}.png')
def get_legend_handles(): legend_elements = [] for robot in comp_robot_list: color = plot_util.get_robot_color(robot) legend_elements.append(Line2D([0], [0], color=color, marker='.', ls='')) return legend_elements
def plot_pseudo_functional_differences_by_layer(robot_list, layer_list, network_output_list, outdir_path, outfile_prefix, sorted=False): def get_legend_handles(): legend_elements = [] for robot in comp_robot_list: color = plot_util.get_robot_color(robot) legend_elements.append(Line2D([0], [0], color=color, marker='.', ls='')) return legend_elements # Compute with respect to Kuka: kuka_output_by_layer = network_output_list[robot_list.index('Kuka')] comp_robot_list = [] comp_robot_layer_neuron_difference_list = [] for robot in robot_list: if robot != 'Kuka': layer_neurons_difference_list = [] comp_robot_output_by_layer = network_output_list[robot_list.index(robot)] for i in range(5): pseudo_function_difference_array = get_pseudo_function_differences(kuka_output_by_layer[i], comp_robot_output_by_layer[i], sort_output=sorted) layer_neurons_difference_list.append(pseudo_function_difference_array) comp_robot_layer_neuron_difference_list.append(layer_neurons_difference_list) comp_robot_list.append(robot) plt.clf() fig, subplts = plt.subplots(3) layer_labels = ['layer_1', 'layer_2', 'layer_3', 'before output', 'output'] for k in range(len(comp_robot_list)): robot = comp_robot_list[k] by_layer_function_differnce = comp_robot_layer_neuron_difference_list[k] color = plot_util.get_robot_color(robot) for m in range(3): layer_neuron_difference = by_layer_function_differnce[m] subplts[m].plot(layer_neuron_difference, ls='', marker='.', markersize=2, color=color) print(comp_robot_list) print(comp_robot_layer_neuron_difference_list[0][4]) print(comp_robot_layer_neuron_difference_list[1][4]) print(comp_robot_layer_neuron_difference_list[2][4]) # Legend legend_elements = get_legend_handles() fig.legend(handles=legend_elements, labels=comp_robot_list, loc='upper right', borderaxespad=0.5, bbox_to_anchor=(0.98, 0.91)) for m in range(3): #subplts[m].set_title(layer_labels[m]) if sorted: if m == 2: subplts[m].set_ylim([0, 20]) else: subplts[m].set_ylim([0, 10]) else: subplts[m].set_ylim([0, 40]) subplts[2].set_xlabel('layer neurons', fontsize=16) fig.text(-0.02, 0.5, 'distance proxy', va='center', rotation='vertical', fontsize=16) subplt_label_x_pos = 0.6 fig.text(subplt_label_x_pos, 0.92, '$\Phi_{1}$: first HL feature', va='center', fontsize=14) fig.text(subplt_label_x_pos, 0.6, '$\Phi_{2}$: second HL feature', va='center', fontsize=14) fig.text(subplt_label_x_pos, 0.3, '$\Phi_{3}$: third HL feature', va='center', fontsize=14) plt.subplots_adjust(right=0.70) fig.tight_layout() title = f'{outfile_prefix}_pseudo_functional_difference' if sorted: outfile_name = f'{title}_sorted' else: outfile_name = title #fig.suptitle(title) plt.savefig(f'{outdir_path}/{outfile_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{outfile_name}.png')
def make_plots_src_mt_mode_comparison(mt_dict, robot_list, layer_trf_dict, source_bots_dict, outdir_path, outfile_prefix): transferred_HL_list = ['HL1', 'HL2', 'HL3'] # ================= # FOR SPEED UP # ================= plt.clf() fig, subplts = plt.subplots(1, 2) for robot in robot_list: for HL in transferred_HL_list: data_dict = mt_dict[robot][HL] seen_bot_list = data_dict['seen_bot_list'] seen_bot_accuracy_list = data_dict['seen_bot_accuracy_list'] seen_bot_gain_list = data_dict['seen_bot_gain_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_accuracy_list = data_dict['unseen_bot_accuracy_list'] unseen_bot_gain_list = data_dict['unseen_bot_gain_list'] unseen_bot_asymptote_list = data_dict['unseen_bot_asymptote_list'] marker = get_marker_for_HL(HL) label_prefix = f'baseline' if len(unseen_bot_list) != 0: plot_gain_for_robot_list(subplts[0], 0, unseen_bot_list, unseen_bot_accuracy_list, unseen_bot_gain_list, marker, label_prefix) plot_accuracy_asymptote_values(subplts[1], 0, unseen_bot_list, unseen_bot_asymptote_list, marker, label_prefix) robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] for hl in transferred_HL_list: marker = get_marker_for_HL(hl) legend_elements.append( Line2D([0], [0], color='black', marker=marker, ls='')) for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append(Line2D([0], [0], color=color, marker='.', ls='')) legend_labels = transferred_HL_list + robot_list fig.legend(handles=legend_elements, labels=legend_labels, bbox_to_anchor=(0.9, 0.8), loc='upper left', borderaxespad=0.1) file_name = f'{outfile_prefix}_TRF_epochs_gain' subplts[0].set_ylim([-5, 40]) subplts[0].set_xlim([78, 98]) subplts[1].set_ylim([0.70, 0.98]) subplts[1].set_xlim([0.70, 0.98]) subplts[0].set_title('speed up') subplts[1].set_title('accuracy gain') subplts[0].set_ylabel('# epochs faster') subplts[0].set_xlabel('accuracy') subplts[1].set_ylabel('transfer accuracy') subplts[1].set_xlabel('baseline accuracy') subplts[0].plot([70, 100], [0, 0], ls='-', linewidth=0.5, color='gray', alpha=0.8) subplts[1].plot([0.7, 1], [0.7, 1], ls='-', linewidth=0.5, color='gray', alpha=0.8) fig.suptitle(file_name) plt.subplots_adjust(right=0.9) plt.tight_layout() plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png') exit(0) # ============================================ # FOR DIFFERENCE IN ASYMPTOTIC ACCURACY VALUES # ============================================ for num_robots in num_robots_list: plt.clf() plt.cla() fig, subplts = plt.subplots(1, 3) for HL in transferred_HL_list: for mt_mode in mt_list: subplt_index = subplt_index_dict[mt_mode] if HL in layer_trf_dict[mt_mode]: for source_bots in source_bots_dict[num_robots]: data_dict = mt_dict[mt_mode][HL][num_robots][ source_bots] seen_bot_list = data_dict['seen_bot_list'] seen_bot_asymptote_list = data_dict[ 'seen_bot_asymptote_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_asymptote_list = data_dict[ 'unseen_bot_asymptote_list'] marker = get_marker_for_HL(HL) label_prefix = f'{mt_mode}' if num_robots == 'four': if len(seen_bot_list) != 0: plot_accuracy_asymptote_values( subplts[subplt_index], 1, seen_bot_list, seen_bot_asymptote_list, marker, label_prefix) else: if len(unseen_bot_list) != 0: plot_accuracy_asymptote_values( subplts[subplt_index], 0, unseen_bot_list, unseen_bot_asymptote_list, marker, label_prefix) robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] for hl in transferred_HL_list: marker = get_marker_for_HL(hl) legend_elements.append( Line2D([0], [0], color='black', marker=marker, ls='')) for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append( Line2D([0], [0], color=color, marker='.', ls='')) legend_labels = transferred_HL_list + robot_list fig.legend(handles=legend_elements, labels=legend_labels, bbox_to_anchor=(0.9, 0.8), loc='upper left', borderaxespad=0.1) file_name = f'{outfile_prefix}_TRF_{num_robots}_source_robots_asympt_accuracy' subplts[0].set_title('MT1SL') subplts[1].set_title('MT2SL') subplts[2].set_title('MT3SL') fig.suptitle(file_name) subplts[0].set_ylabel('transfer accuracy') subplts[1].set_xlabel('baseline accuracy') #fig.text(0.5, 0.04, 'accuracy', ha='center') plt.tight_layout() plt.subplots_adjust(right=0.9) x_lim = [0.96, 0.98] y_lim = [0.96, 0.98] subplts[0].plot(x_lim, y_lim, ls='-', linewidth=0.5, color='gray', alpha=0.8) subplts[1].plot(x_lim, y_lim, ls='-', linewidth=0.5, color='gray', alpha=0.8) subplts[2].plot(x_lim, y_lim, ls='-', linewidth=0.5, color='gray', alpha=0.8) subplts[0].set_xlim(x_lim) subplts[1].set_xlim(x_lim) subplts[2].set_xlim(x_lim) subplts[0].set_ylim(y_lim) subplts[1].set_ylim(y_lim) subplts[2].set_ylim(y_lim) plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png')
def plot_accuracy_gain(list_of_mean_list, list_of_std_list, list_of_robot_list, marker_list, marker_labels_list, out_dir, out_file_name, legend_list=None): # First make x-position dictionary x_pos_dict = {} x_pos = 1 for robot_list in list_of_robot_list: for robot in robot_list: if robot not in x_pos_dict.keys(): x_pos_dict[robot] = x_pos x_pos += 1 x_tick_label_ = [] x_tick_ = [] x_tick_label = [] x_tick = [] for robot, pos in x_pos_dict.items(): x_tick_label_.append(robot) x_tick_.append(pos) sorted_index_x_tick = np.argsort(x_tick_) for ind in sorted_index_x_tick: x_tick.append(x_tick_[ind]) x_tick_label.append(x_tick_label_[ind]) for i in range(len(list_of_mean_list)): mean_list = list_of_mean_list[i] std_list = list_of_std_list[i] robot_list = list_of_robot_list[i] marker = marker_list[i] marker = plot_util.get_line_marker_symbol(marker) for j in range(len(mean_list)): robot = robot_list[j] color = plot_util.get_robot_color(robot) mean = mean_list[j] std = std_list[j] x_position = x_pos_dict[robot] if mean > 0: alpha = 1 else: alpha = 0.2 plt.errorbar(j + 1, mean, std, capsize=2, capthick=1, color='black') if legend_list is None: plt.plot(x_position, mean, marker=marker, markersize=8, color=color, alpha=alpha) else: legend_label = f'{robot}_{legend_list[i]}' plt.plot(x_position, mean, marker=marker, markersize=8, color=color, alpha=alpha, label=legend_label) if legend_list is not None: plt.legend() if marker_labels_list is not None: legend_elements = [] for i in range(len(marker_list)): marker = plot_util.get_line_marker_symbol(marker_list[i]) legend_elements.append( Line2D([0], [0], color='black', marker=marker, label=marker_labels_list[i])) plt.legend(handles=legend_elements, bbox_to_anchor=(1.05, 1), loc='upper left') plt.title(out_file_name) plt.ylabel('accuracy gain') plt.xticks(x_tick, x_tick_label, rotation=90) plt.savefig(f'{out_dir}/{out_file_name}.png', bbox_inches='tight') print(f'saved to: {out_dir}/{out_file_name}.png')
def make_plots_src_mt_mode_comparison(mt_dict, mt_list, layer_trf_dict, source_bots_dict, outdir_path, outfile_prefix): # [MT type][transfer layer type][num source robots][source robots][] two_bots_list = source_bots_dict['two'] three_bots_list = source_bots_dict['three'] four_bots_list = source_bots_dict['four'] MT1SL_trf_layer_list = layer_trf_dict['MT1SL'] MT2SL_trf_layer_list = layer_trf_dict['MT2SL'] MT3SL_trf_layer_list = layer_trf_dict['MT3SL'] trf_layer = 'HL123' # ================= # FOR ACCURACY GAIN # ================= for num_robots in ['two', 'three', 'four']: plt.clf() for mt_mode in mt_list: if trf_layer in layer_trf_dict[mt_mode]: for source_bots in source_bots_dict[num_robots]: data_dict = mt_dict[mt_mode][trf_layer][num_robots][source_bots] seen_bot_list = data_dict['seen_bot_list'] seen_bot_accuracy_list = data_dict['seen_bot_accuracy_list'] seen_bot_gain_list = data_dict['seen_bot_gain_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_accuracy_list = data_dict['unseen_bot_accuracy_list'] unseen_bot_gain_list = data_dict['unseen_bot_gain_list'] marker = get_marker_for_mt_mode(mt_mode) label_prefix = f'{mt_mode}' subplts_title = f'{num_robots}_MT' # if len(seen_bot_list) != 0: # plot_gain_for_robot_list(1, # seen_bot_list, # seen_bot_accuracy_list, # seen_bot_gain_list, # marker, # label_prefix) if len(unseen_bot_list) != 0: plot_gain_for_robot_list(0, unseen_bot_list, unseen_bot_accuracy_list, unseen_bot_gain_list, marker, label_prefix) mt_modes_list = ['MT1SL', 'MT2SL', 'MT3SL'] robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] for mt_mode in mt_modes_list: marker = get_marker_for_mt_mode(mt_mode) legend_elements.append(Line2D([0], [0], color='black', marker=marker, ls='')) for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append(Line2D([0], [0], color=color, marker='.', ls='')) legend_labels = mt_modes_list + robot_list plt.legend(handles=legend_elements, labels=legend_labels, bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.5) file_name = f'{outfile_prefix}_TRF_{trf_layer}_{num_robots}_source_robots_epochs_gain' plt.title(file_name) plt.xlabel('eval accuracy') plt.ylabel('# epoxhs faster to reach given accuracy') plt.plot([70, 100], [0, 0], ls='-', linewidth=0.2, color='gray', alpha=0.8) plt.axis([79, 98, -20, 55]) plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png') # ============================================ # FOR DIFFERENCE IN ASYMPTOTIC ACCURACY VALUES # ============================================ for num_robots in ['two', 'three', 'four']: plt.clf() plt.cla() for mt_mode in mt_list: if trf_layer in layer_trf_dict[mt_mode]: for source_bots in source_bots_dict[num_robots]: data_dict = mt_dict[mt_mode][trf_layer][num_robots][source_bots] seen_bot_list = data_dict['seen_bot_list'] seen_bot_asymptote_list = data_dict['seen_bot_asymptote_list'] unseen_bot_list = data_dict['unseen_bot_list'] unseen_bot_asymptote_list = data_dict['unseen_bot_asymptote_list'] marker = get_marker_for_mt_mode(mt_mode) label_prefix = f'{mt_mode}' # if len(seen_bot_list) != 0: # plot_accuracy_asymptote_values(1, # seen_bot_list, # seen_bot_asymptote_list, # marker, # label_prefix) if len(unseen_bot_list) != 0: plot_accuracy_asymptote_values(0, unseen_bot_list, unseen_bot_asymptote_list, marker, label_prefix) mt_modes_list = ['MT1SL', 'MT2SL', 'MT3SL'] robot_list = ['Kuka', 'Baxter', 'Wam', 'Sawyer'] legend_elements = [] for mt_mode in mt_modes_list: marker = get_marker_for_mt_mode(mt_mode) legend_elements.append(Line2D([0], [0], color='black', marker=marker, ls='')) for robot in robot_list: color = plot_util.get_robot_color(robot) legend_elements.append(Line2D([0], [0], color=color, marker='.', ls='')) legend_labels = mt_modes_list + robot_list low = 0.95 middle = 0.965 high = 0.98 file_name = f'{outfile_prefix}_TRF_{trf_layer}_{num_robots}_source_robots_asympt_accuracy' plt.xticks([low, middle, high], labels=[f'{low}', f'{middle}', f'{high}']) plt.yticks([low, middle, high], labels=[f'{low}', f'{middle}', f'{high}']) plt.xlabel('baseline', fontsize=14) plt.ylabel('transfer', fontsize=14) plt.legend(handles=legend_elements, labels=legend_labels) plt.plot([low, high], [low, high], ls='-', linewidth=0.2, color='gray', alpha=0.8) plt.axis([low, 0.975, low, high]) plt.title(file_name) plt.savefig(f'{outdir_path}/{file_name}.png', bbox_inches='tight') print(f'plot created: {outdir_path}/{file_name}.png')