Ejemplo n.º 1
0
        public static void Save_Experiment_Settings <T>(
            string this_experiment__output_folder,
            string experiment_name,
            MEL__Algorithm <T> map_elites
            )
            where T : MEL__Individual
        {
            string experiment_description_file_path =
                Path.Combine(this_experiment__output_folder,
                             "experiment_settings.txt"
                             );

            string text_to_write = "experiment name: " + experiment_name + "\n";

            text_to_write += map_elites.Get_Settings_Description();

            IO_Utilities.Append_To_File(
                experiment_description_file_path,
                text_to_write
                );
        }
Ejemplo n.º 2
0
        public static void Save_Feature_Tables_CSV <T>(
            string this_experiment__output_folder,
            int random_seed,
            int current_iteration,
            MEL__Algorithm <T> map_elites
            )
            where T : MEL__Individual
        {
            // data analysis tables - folder paths
            string individual_exists__csv_folder = Path.Combine(
                this_experiment__output_folder, "CSV_0_A_individual_exists");
            string fitness__csv_folder = Path.Combine(
                this_experiment__output_folder, "CSV_0_B_fitness");
            string selections_per_location__csv_folder = Path.Combine(
                this_experiment__output_folder, "CSV_1_A_selections_per_location");
            string offspring_survivals_per_location__csv_folder = Path.Combine(
                this_experiment__output_folder, "CSV_1_B_offspring_survivals_per_location");

            IO_Utilities.CreateFolder(individual_exists__csv_folder);
            IO_Utilities.CreateFolder(fitness__csv_folder);
            IO_Utilities.CreateFolder(selections_per_location__csv_folder);
            IO_Utilities.CreateFolder(offspring_survivals_per_location__csv_folder);

            /////////////////////////////////////////////////////////////////////////
            // SAVE CSV FILES...
            ////////////////////////////////////////////////////////////////////////

            string individual_exists_table__csv__file_path =
                Path.Combine(individual_exists__csv_folder,
                             "individual_exists_table__"
                             + "seed_" + random_seed.ToString()
                             + "__iter_" + current_iteration.ToString()
                             + ".csv"
                             );

            IO_Utilities.Append_To_File(
                individual_exists_table__csv__file_path,
                map_elites.state.individual_exists.To_CSV_0_1()
                );

            string fitness_table__csv__file_path =
                Path.Combine(fitness__csv_folder,
                             "fitness_table__"
                             + "seed_" + random_seed.ToString()
                             + "__iter_" + current_iteration.ToString()
                             + ".csv"
                             );

            IO_Utilities.Append_To_File(
                fitness_table__csv__file_path,
                map_elites.Q_ST_Fitness_Table().To_CSV()
                );


            string selections_per_location__csv__file_path =
                Path.Combine(selections_per_location__csv_folder,
                             "selections_per_location__"
                             + "seed_" + random_seed.ToString()
                             + "__iter_" + current_iteration.ToString()
                             + ".csv"
                             );

            IO_Utilities.Append_To_File(
                selections_per_location__csv__file_path,
                map_elites.state.selections__per__location.To_CSV()
                );

            string offspring_survivals_per_location__csv__file_path =
                Path.Combine(offspring_survivals_per_location__csv_folder,
                             "offspring_survivals_per_location__"
                             + "seed_" + random_seed.ToString()
                             + "__iter_" + current_iteration.ToString()
                             + ".csv"
                             );

            IO_Utilities.Append_To_File(
                offspring_survivals_per_location__csv__file_path,
                map_elites.state.offspring_survivals__per__location.To_CSV()
                );
        }
Ejemplo n.º 3
0
        public static void Run_Experiment <T>(
            string experiment_name,
            List <int> random_seeds, // implies number of repetitions...
            MEL__Operator_Settings <T> operator_settings,
            MEL__Evaluation_Settings <T> eval_settings,
            MEL__Parent_Selection_Method <T> selection_method,
            int initial_population,
            int total_num_iterations,
            List <int> iterations_for_feature_tables_csv,
            List <int> iterations_for_feature_tables_png,
            List <int> iterations_for_data_logging,
            List <int> iterations_for_console_logging
            )
            where T : MEL__Individual
        {
            // prepare paths etc...
            string general_output_folder = Path.Combine(
                Directory.GetCurrentDirectory(),
                "output"
                );

            if (IO_Utilities.Folder_Exists(general_output_folder) == false)
            {
                // create the general output folder
                IO_Utilities.CreateFolder(general_output_folder);
            }
            string this_experiment__output_folder = Path.Combine(
                general_output_folder,
                experiment_name + "___" + DateTime.UtcNow.Ticks.ToString()
                );

            if (IO_Utilities.Folder_Exists(this_experiment__output_folder) == false)
            {
                // create this experiment's folder
                IO_Utilities.CreateFolder(this_experiment__output_folder);
            }

            string data_logging_file_path = Path.Combine(
                this_experiment__output_folder,
                experiment_name + "_data.csv"
                );

            if (IO_Utilities.File_Exists(data_logging_file_path) == false)
            {
                IO_Utilities.Create_File(data_logging_file_path, false, false);
            }

            // create and save the data header...
            string data_header = Map_Elites__Data_Header();

            IO_Utilities.Append_To_File(data_logging_file_path, data_header);

            MEL__Algorithm <T> map_elites = new MEL__Algorithm <T>(
                operator_settings,
                eval_settings,
                selection_method
                );

            Save_Experiment_Settings(
                this_experiment__output_folder,
                experiment_name,
                map_elites
                );

            foreach (var random_seed in random_seeds)
            {
                // initialize the random numbers generator...
                Random randomness_provider = new Random(random_seed);

                map_elites = new MEL__Algorithm <T>(
                    operator_settings,
                    eval_settings,
                    selection_method
                    );

                // generate the initial population
                map_elites.Generate_Initial_Population(randomness_provider, initial_population);

                // save the data at this stage, before any operation...
                Save_Feature_Tables_CSV(
                    this_experiment__output_folder,
                    random_seed,
                    0,
                    map_elites
                    );
                Save_Feature_Tables_PNG(
                    this_experiment__output_folder: this_experiment__output_folder,
                    random_seed: random_seed,
                    current_iteration: 0,
                    map_elites: map_elites,
                    min_fitness: 0.0,
                    max_fitness: 1.0
                    );
                string data_row = Map_Elites__Data_Row(random_seed, 0, map_elites);
                IO_Utilities.Append_To_File(data_logging_file_path, data_row);

                Console_Log(experiment_name, random_seed, 0);

                for (int current_iteration = 1; current_iteration <= total_num_iterations; current_iteration++)
                {
                    // advance algorithm
                    map_elites.Select_And_Mutate_Individual(randomness_provider);

                    // perhaps, save data
                    if (iterations_for_feature_tables_csv.Contains(current_iteration))
                    {
                        Save_Feature_Tables_CSV(
                            this_experiment__output_folder,
                            random_seed,
                            current_iteration,
                            map_elites
                            );
                    }
                    if (iterations_for_feature_tables_png.Contains(current_iteration))
                    {
                        Save_Feature_Tables_PNG(
                            this_experiment__output_folder: this_experiment__output_folder,
                            random_seed: random_seed,
                            current_iteration: current_iteration,
                            map_elites: map_elites,
                            min_fitness: 0.0,
                            max_fitness: 1.0
                            );
                    }
                    if (iterations_for_data_logging.Contains(current_iteration))
                    {
                        data_row = Map_Elites__Data_Row(random_seed, current_iteration, map_elites);
                        IO_Utilities.Append_To_File(data_logging_file_path, data_row);
                    }
                    if (iterations_for_console_logging.Contains(current_iteration))
                    {
                        Console_Log(experiment_name, random_seed, current_iteration);
                    }
                }
            }
        }