parser.add_argument("--situation", "-s", required=True, help="Situation") args = parser.parse_args() csv_dir = './../csv_files/latent_vectors/' + args.situation + "/" if os.path.exists(csv_dir + args.output_dir) is False: print("対象のファイルが見つかりません。") exit() original_data_path = csv_dir + args.old_dir + "/latent_vectors.csv" parents_index_path = csv_dir + args.output_dir + "/parents_index.csv" children_index_path = csv_dir + args.output_dir + "/children_index.csv" children_path = csv_dir + args.output_dir + "/children.csv" original_data = functions.read_csv(original_data_path) parents_index = functions.read_csv(parents_index_path) parents_index = functions.transform_to_int(parents_index) parents_index = parents_index[0] children_index = functions.read_csv(children_index_path) children_index = functions.transform_to_int(children_index) children_index = children_index[0] children = functions.read_csv(children_path) children = functions.transform_to_float(children) new_data = functions.replace(original_data, children, parents_index, children_index) # 新しい潜在ベクトル群をcsvファイルに書き込む functions.write_csv(csv_dir + args.output_dir + "/latent_vectors.csv", new_data)
write_filename = 'MGGimprove/children' # 実行回数 num_execute = int(5000/300) # 潜在空間の次元数 num_dimentions = 100 # 局所解ファイル solutions_file = 'pre_experiment/mock_solutions_100' # 評価結果のファイル result_file = 'MGGimprove/evaluation_result' # 局所解ファイルの読み込み solutions_data = functions.read_csv(solutions_file) del solutions_data[0] solutions_data = functions.transform_to_float(solutions_data) # 局所解とバイアスに分ける solutions, bias = functions.divide_solutions_bias(solutions_data) # 評価値の結果のリスト evaluations_result = [] for num_experiment in range(1, 101): print(num_experiment) # 対象のデータの読み込み data = functions.read_csv(read_filename) del data[0] data = functions.transform_to_float(data) # before_index = functions.get_result(data, functions.get_evaluations_list(data, solutions, bias), num_experiment, functions.get_best_solution_index(bias), solutions)[2] # 次の世代の作成
parser.add_argument("--output_dir", "-o", required=True, help="Directory to output generated csv files to") parser.add_argument("--situation", "-s", required=True, help="Situation") parser.add_argument("--num_parent", "-p", default=4, type=int, help="Number of parents") parser.add_argument("--num_children", "-c", default=16, type=int, help="Number of children") args = parser.parse_args() csv_dir = './../csv_files/latent_vectors/' + args.situation + "/" if os.path.exists(csv_dir + args.output_dir) is True: exit() if os.path.exists(csv_dir + args.output_dir) is False: os.mkdir(csv_dir + args.output_dir) input_path = csv_dir + args.input_dir + '/latent_vectors.csv' latent_vectors = functions.read_csv(input_path) latent_vectors = functions.transform_to_float(latent_vectors) latent_vectors = np.array(latent_vectors) num_vectors = len(latent_vectors) parents_index = functions.make_random_list(num_vectors, args.num_parent) parent_vectors = np.zeros((args.num_parent, len(latent_vectors[0]))) for index in range(len(parents_index)): parent_vectors[index] = np.copy(latent_vectors[parents_index[index]]) children = functions.make_children(parent_vectors, args.num_children) # 親に使ったベクトルのインデックスのcsvファイルを作成 functions.write_csv_for_vector(csv_dir + args.output_dir + "/parents_index.csv", parents_index) # 親に使ったベクトルのcsvファイルを作成 functions.write_csv(csv_dir + args.output_dir + "/parents.csv", parent_vectors)