def generate_fitness_mod_graph(grns, targets, perturbations, file_name): fitness_values = [] mod_values = [] cur_idx = 0 for a_fit_grn in grns: a_np_fit_grn = np.array(a_fit_grn).reshape(10, 10) cur_targets = get_current_targets(cur_idx, target_thresholds, targets) fitness_values.append( fitness.evaluate_grn(a_np_fit_grn, cur_targets, perturbations)) a_grn_plotter = GRNPlotter() mod_values.append(a_grn_plotter.get_modularity_value(a_fit_grn)) cur_idx += 1 fp.save_lists_graph([fitness_values, mod_values], ['Fitness', 'Modularity'], path=working_path, file_name=file_name)
def plot_dist_gen_curve(dist_dict, dpi=300, save_path=None, save_name=None, start_gen=0, end_gen=10000, is_running=False): plt.rcParams.update({'font.size': 22}) dist_list = [] if isinstance(dist_dict, dict): set_idxs = sorted(list([int(x) for x in dist_dict.keys()])) for a_gen in set_idxs[start_gen:end_gen]: if is_running: dist_list.append(np.mean(dist_dict[int(a_gen)])) else: dist_list.append(np.mean(dist_dict[str(a_gen)])) fp.plot_a_list_graph(dist_list, 'Avg dist', dpi=dpi, save_path=save_path, save_name=save_name, marker='x') elif isinstance(dist_dict, list): set_idxs = sorted(list([int(x) for x in dist_dict[0].keys()])) for a_dist_dict in dist_dict: a_dist_list = [] for a_gen in set_idxs[start_gen:end_gen]: if is_running: a_dist_list.append(np.mean(a_dist_dict[int(a_gen)])) else: a_dist_list.append(np.mean(a_dist_dict[str(a_gen)])) dist_list.append(a_dist_list) fp.save_lists_graph(dist_list, ['Symmetry', 'Asymmetry'], path=save_path, file_name=save_name, dpi=dpi, marker='x', left_lim=start_gen)
if level_type == 'high': file_name = target + '-' + selection_type + '-' + level_type + '.png' value_tar = avg_dif_mut_num_fit_h_e stdev_tar = avg_dif_mut_num_std_h_e elif level_type == 'low': file_name = target + '-' + selection_type + '-' + level_type + '.png' value_tar = avg_dif_mut_num_fit_l_e stdev_tar = avg_dif_mut_num_std_l_e elif selection_type == 'mod': if level_type == 'high': file_name = target + '-' + selection_type + '-' + level_type + '.png' value_tar = avg_dif_mut_num_fit_h_m stdev_tar = avg_dif_mut_num_std_h_m elif level_type == 'low': file_name = target + '-' + selection_type + '-' + level_type + '.png' value_tar = avg_dif_mut_num_fit_l_m stdev_tar = avg_dif_mut_num_std_l_m # fp.save_lists_graph([avg_fit_mut_num_fit_h_e, avg_fit_mut_num_fit_l_e, avg_fit_mut_num_fit_h_m, avg_fit_mut_num_fit_l_m], # labels=['Hign Edge Density', 'Low Edge Density', 'High Mod', 'Low Mod'], # ver_lines=None, path='/media/zhenyue-qin/New Volume/Temporary-Location/Untitled Folder', file_name='combined.png', marker='.', colors=None, # dpi=500, to_normalize=False, error_bars=[avg_fit_mut_num_std_h_e, avg_fit_mut_num_std_l_e, avg_fit_mut_num_std_h_m, avg_fit_mut_num_std_l_m], leg_loc=0) fp.save_lists_graph( [value_tar], labels=[label_name], ver_lines=None, path='/media/zhenyue-qin/New Volume/Temporary-Location/Untitled Folder', file_name=file_name, marker='.', colors=None, dpi=500, to_normalize=False, error_bars=[stdev_tar], leg_loc=0)
prop_gen_edges, prop_gen_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( prop_300, True, dir_num=100) tour_gen_edges, tour_gen_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( tour_dir, True, dir_num=100) conv_p_t_gen_edges, conv_p_t_gen_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( prop_to_tour_dir, True, dir_num=100) conv_p_p_gen_edges, conv_p_p_gen_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( prop_to_prop_dir, True, dir_num=100) tour_1_edges, tour_1_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( tour_1_dir, True, dir_num=4) tour_2_edges, tour_2_edges_stds = edge_num_tool.get_avg_edge_num_in_each_generation_of_an_exp( tour_2_dir, True, dir_num=4) elite_edge_lists = edge_num_tool.analyze_edge_nums_for_an_experiment( tour_1_dir, a_type='fit', sample_size=100, eva_type='list', start_gen=0, end_gen=300, edge_type='original') np_mean_elite_edge_lists = np.mean(elite_edge_lists, axis=0) np_std_elite_edge_lists = np.std(elite_edge_lists, axis=0) fp.save_lists_graph([tour_1_edges[:300], tour_2_edges[:300]], error_bars=[tour_1_edges_stds, tour_2_edges_stds]) # fp.save_lists_graph([prop_gen_edges[:99], tour_gen_edges[:99]], dpi=100)
cur_idx = 0 for a_fit_grn in grns: a_np_fit_grn = np.array(a_fit_grn).reshape(10, 10) cur_targets = get_current_targets(cur_idx, target_thresholds, targets) fitness_values.append( fitness.evaluate_grn(a_np_fit_grn, cur_targets, perturbations)) a_grn_plotter = GRNPlotter() mod_values.append(a_grn_plotter.get_modularity_value(a_fit_grn)) cur_idx += 1 fp.save_lists_graph([fitness_values, mod_values], ['Fitness', 'Modularity'], path=working_path, file_name=file_name) mod_fit_list = csv_reader.get_entry_values_of_an_trial(working_path, 'MostModFitness') mod_mod_list = csv_reader.get_entry_values_of_an_trial(working_path, 'MostModularity') fit_fit_list = csv_reader.get_entry_values_of_an_trial(working_path, 'Best') fit_mod_list = csv_reader.get_entry_values_of_an_trial(working_path, 'FittestModularity') fp.save_lists_graph([mod_fit_list, mod_mod_list], ['Fitness', 'Modularity'], path=working_path, file_name='ModTrend.png') fp.save_lists_graph([fit_fit_list, fit_mod_list], ['Fitness', 'Modularity'], path=working_path, file_name='FitTrend.png')
def plot_fit_lines(path_1, labels, save_path, file_name, sample_size=100, gens=2000, to_save=True): csv_file_opener = CSVFileOpener() target_column = None if 'Fitness' in labels[0]: if 'Stoc' in labels[0]: if 'Sym' in labels[0]: if 'Elite' in labels[0]: values = fitness_warehouse.elite_stoc_p00_by_dist_p00_gen[: gens] value_std_1 = fitness_warehouse.elite_stoc_p00_by_dist_p00_stdev[: gens] else: values = fitness_warehouse.stoc_p00_by_dist_p00_gen[:gens] value_std_1 = fitness_warehouse.stoc_p00_by_dist_p00_stdev[: gens] elif 'Asym' in labels[0]: if 'Elite' in labels[0]: values = fitness_warehouse.elite_stoc_p01_by_dist_p01_gen[: gens] value_std_1 = fitness_warehouse.elite_stoc_p01_by_dist_p01_stdev[: gens] else: values = fitness_warehouse.stoc_p01_by_dist_p01_gen[:gens] value_std_1 = fitness_warehouse.stoc_p01_by_dist_p01_stdev[: gens] else: target_column = 'Best' values, value_std_1 = csv_file_opener. \ get_properties_of_each_generation_in_a_whole_experiment_with_stdev(path_1, target_column, sample_size=sample_size) elif 'Modularity' in labels[0]: target_column = 'FittestModularity' values, value_std_1 = csv_file_opener. \ get_mod_of_each_generation_in_a_whole_exp_with_stdev(path_1, target_column, sample_size=sample_size) elif 'Edge' in labels[0]: values, value_std_1 = csv_file_opener. \ get_edge_num_of_each_generation_in_a_whole_exp_with_stdev(path_1, sample_size=sample_size) # values, value_std_1 = csv_file_opener. \ # get_properties_of_each_generation_in_a_whole_experiment_with_stdev(path_1, target_column, # sample_size=sample_size) print('current label: ', labels) print('final value: ', values[-1]) print('value_std_1: ', value_std_1[499]) print('max value: ', np.max(values)) print('min value: ', np.min(values)) print('len of values: ', len(values)) if to_save: if 'Stoc' in labels[0]: the_colors = [1, 0, 2, 3, 4, 5] else: the_colors = None fp.save_lists_graph([values], labels=labels, ver_lines=[500], path=save_path, file_name=file_name, marker='.', colors=the_colors, dpi=500, to_normalize=False, x_gap=20, error_bars=[value_std_1], leg_loc='lower right') return values, labels, value_std_1
file_name=label_key_2 + '.png', sample_size=sample_size, to_save=False) # stat_tool_kil = StatisticsToolkit() # print stat_tool_kil.calculate_statistical_significances(values_1[501:], values_2[501:]) to_save_name = path_key_1 + ' ' + path_key_2 + ' ' + value_type to_save_name = to_save_name.replace(' ', '_') fp.save_lists_graph([values_1[1:2001], values_2[1:2001]], labels=[path_key_1, path_key_2], ver_lines=[500], path=save_path_selection, file_name=to_save_name, marker='.', colors=[0, 1], dpi=500, to_normalize=False, x_gap=20, error_bars=[stdevs_1[1:2001], stdevs_2[1:2001]], leg_loc='upper left') # # fits_avg_1 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_1, 'Median') # # fits_avg_2 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_2, 'Median') # # mod_1 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_1, 'FittestModularity') # mod_2 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_2, 'FittestModularity') # # fp.save_lists_graph([mod_1, mod_2], labels=['Distributional', 'Stochastic'], ver_lines=[500], path=path_1, file_name='avg_mod_comp_esw_new_p01_balanced.png', marker='.', # colors=None, dpi=500, to_normalize=False) #
prefix_path = os.path.expanduser("~") fitness_plotter = GRNCSVReader() path_1 = '/Volumes/Qin-Warehouse/Warehouse-Data/Modularity-Data/Maotai-Project-Symmetry-Breaking/generated-outputs/fixed-record-zhenyue-balanced-combinations-p00' path_2 = '/Volumes/Qin-Warehouse/Warehouse-Data/Modularity-Data/Maotai-Project-Symmetry-Breaking/generated-outputs/record-esw-balanced-combinations-p00' # path_1 = '/Volumes/Qin-Warehouse/Warehouse-Data/Modularity-Data/Maotai-Project-Symmetry-Breaking/generated-outputs/fixed-record-zhenyue-balanced-combinations-elite-p00' # # from GRNPlotter import GRNPlotter # # grn_plotter = GRNPlotter() # mod_1 = grn_plotter.get_avg_module_values_for_each_generation_of_an_experiment(path_1, no_self_edge=True) # # mod_2 = grn_plotter.get_avg_module_values_for_each_generation_of_an_experiment(path_2, no_self_edge=True) # # print('mod 1: ', len(mod_1)) # fp.save_lists_graph([mod_1], labels=['Modularity'], ver_lines=[500], path=path_1, file_name='avg_mod_no_self_edge.png', marker='.', # colors=None, dpi=500, to_normalize=False) sample_size = 100 most_mod_values_1 = fitness_plotter.get_fittest_modularities_of_an_experiment(path_1, 500)[:sample_size] most_mod_values_2 = fitness_plotter.get_fittest_modularities_of_an_experiment(path_1, -1)[:sample_size] mods_1 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_1, 'FittestModularity') mods_2 = csv_file_opener.get_properties_of_each_generation_in_a_whole_experiment(path_1, 'FittestModularity') # # print StatisticsToolkit.calculate_statistical_significances(most_mod_values_1, most_mod_values_2) fp.save_lists_graph([mods_1], labels=['Modularity'], ver_lines=[500], path=path_1, file_name='modularity.png', marker='.', colors=[0], dpi=500, to_normalize=False)