def cal_three_mse(r_list, ap_list, seed_list, iteration, use_data, program_num, c_method): result = np.zeros([len(seed_list), len(ap_list), 3]) # [0]:ori-nmf [1]:ori-snmf [2]:nmf-snmf v_original, im_var, im_hol = ipf.read_pgm("/home/ionishi/mnt/workspace/sketchingNMF/face_data/" + use_data) v_list = np.zeros([v_original.shape[0], v_original.shape[1], 3]) # [0]:original [1]:snmf [2]:nmf v_list[:, :, 0] = v_original for ap_i, ap in enumerate(ap_list): for seed_i, seed in enumerate(seed_list): path, file_name = ff.path_and_file_name(r_list[0], ap, iteration, seed, use_data, program_num, c_method, "r,k", directory="matrix") v_list[:, :, 1] = ipf.calculate_v(path, file_name, snmf=True) path, file_name = ff.path_and_file_name(r_list[0], ap_list[-1], iteration, seed, use_data, program_num, c_method, "r,k", directory="matrix") v_list[:, :, 2] = ipf.calculate_v(path, file_name, snmf=False) for i in range(3): result[seed_i, ap_i, (i + 1) % 3] = ipf.mse_calculate(v_list[:, :, i], v_list[:, :, (i + 1) % 3]) return result
r_list, r_list_size, ap_list, ap_list_size, seed_list, seed_list_size = ff.parallel_make_list(tmp[2:]) # r_list_size = len(r_list) # ap_list_size = len(ap_list) # seed_list_size = len(seed_list) os.makedirs(w_path, exist_ok=True) # last 1% of iteration error average ----------------------------------------------------------------------------- NMF_e_result = np.zeros([r_list_size, ap_list_size, seed_list_size]) SNMF_e_result = np.zeros([r_list_size, ap_list_size, seed_list_size]) for r_i, r in enumerate(r_list): for ap_i, ap in enumerate(ap_list): for seed_i, seed in enumerate(seed_list): pr_path, pr_file_name = ff.path_and_file_name(r, ap, ite, seed, use_data, program_num, c_method, "r,k", directory="error") error_M = pd.read_csv(pr_path + pr_file_name + "_error.csv") e_result = error_M.iloc[int(-0.01 * ite):].mean() NMF_e_result[r_i, ap_i, seed_i] = e_result["NMF error"] SNMF_e_result[r_i, ap_i, seed_i] = e_result["SNMF error"] NMF_e_result = np.mean(NMF_e_result, axis=2) SNMF_e_result = np.mean(SNMF_e_result, axis=2) NMF_e_result = np.mean(NMF_e_result, axis=1) df_e_result = pd.DataFrame({"k=" + str(ap_list[0]): SNMF_e_result[0, 0]}, index=["r=" + str(r_list[0])]) for r_i, r in enumerate(r_list[1:]): df_e_result.loc["r=" + str(r)] = SNMF_e_result[r_i + 1, 0] for ap_i, k in enumerate(ap_list[1:]): df_e_result["k=" + str(k)] = SNMF_e_result[:, ap_i + 1] df_e_result["NMF"] = NMF_e_result
use_data, c_method, seed_list)) for wh_seed in seed_list: original_v, im_var, im_hol = ipf.read_pgm( "/home/ionishi/mnt/workspace/sketchingNMF/face_data/" + use_data) error_map = np.zeros([im_var, im_hol, len(image_num_list), 3]) for r in plot_r_list: for ap in plot_ap_list: for im_i, im_num in enumerate(image_num_list): read_path, read_file_name = ff.path_and_file_name( r, ap, ite, wh_seed, use_data, program_num, c_method, "r,k", real_or_not=real_or_not, directory="matrix", space=space) write_path = "/home/ionishi/mnt/workspace/sketchingNMF/{}/{}/{}/{}/Emap_wh_seed={}/" \ .format(use_data, w_program_num, c_method, "error_map", wh_seed) os.makedirs(write_path, exist_ok=True) Emap_nmf_v = ipf.calculate_v(read_path, read_file_name, snmf=False) Emap_snmf_v = ipf.calculate_v(read_path, read_file_name, snmf=True)
os.makedirs(w_path, exist_ok=True) print("start {} {} {} >>>>>".format(w_program_num, use_data, c_method)) # time measurement-------------------------------------------------------------------------------------------------- nmf_t_result = np.zeros([r_list_size, seed_list_size]) snmf_t_result = np.zeros([r_list_size, ap_list_size, seed_list_size]) for r_i, r in enumerate(r_list): for ap_i, ap in enumerate(ap_list): for seed_i, seed in enumerate(seed_list): pr_path, pr_file_name = ff.path_and_file_name(r, ap, ite, seed, use_data, program_num, c_method, "r,k", directory="time", space=space) t_result = pd.read_csv(pr_path + pr_file_name + ".csv") snmf_t_result[r_i, ap_i, seed_i] = t_result["SNMF time"] if ap == ap_list[-1]: nmf_t_result[r_i, seed_i] = t_result["NMF time"] nmf_t_result = np.mean(nmf_t_result, axis=1) snmf_t_result = np.mean(snmf_t_result, axis=2) df_t_result = pd.DataFrame({"k=" + str(ap_list[0]): snmf_t_result[0, 0]}, index=["r=" + str(r_list[0])]) for r_i, r in enumerate(r_list[1:]):