def run_rule_number_experiment_cfg3(): """Experiment with what is the minimum amount of rules possible to get max fitness, with cfg set 3.""" exp_title = "Rule base size 3" varied_param = "chromosome_size" min_number_of_rules = 1 max_number_of_rules = 11 min_chromosome_size = min_number_of_rules * BASE_RULE_SIZE max_chromosome_size = max_number_of_rules * BASE_RULE_SIZE # Increment two rules at a time in the rule inc = BASE_RULE_SIZE exp_settings = dict(BASE_SETTINGS) exp_settings["population_size"] = 900 exp_settings["generations"] = 250 exp_settings["runs"] = 5 exp_settings["mutation_rate_percent"] = 0.4 exp_settings["chromosome_size"] = numpy.arange(min_chromosome_size, max_chromosome_size, inc) fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_mutation_creep_experiment(): """Experiment with changing the creep value""" exp_title = "Mutation creep experiment" varied_param = "indiv_additional_args" arg_sets = [] for creep_val in numpy.arange(0.05, 0.3, 0.05): arg_sets.append([ CONDITION_SIZE, RESULT_SIZE, creep_val, TRAINING_FILE, BASE_TRAIN_FROM_RULE, BASE_TRAIN_TO_RULE, TRAINING_FILE, BASE_TEST_FROM_RULE, BASE_TEST_TO_RULE ]) exp_settings = dict(BASE_SETTINGS) exp_settings["runs"] = 5 exp_settings["indiv_additional_args"] = arg_sets fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_population_size_experiment_with_0_mutation_per(): """Experiment with the affects of changing population size when every other setting is set to base except mutation which is set 0% of the typical range""" exp_title = "Population size parameter when mutation is 0% in range" varied_param = "population_size" num_of_rules = 10 settings = { "runs": 10, "generations": 100, "population_size": numpy.arange(20, 1000, 20), "chromosome_size": num_of_rules * (BASE_CONDITION_SIZE + BASE_RESULT_SIZE), "tournament_size": 2, "single_point_crossover_point": 0.5, "mutation_rate_percent": 0.0, "indiv_class": BinaryRuleSet, "indiv_additional_args": BASE_INDIV_ADD_STD_ARGS } fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, settings, varied_param) return fittest_individual, stats
def run_roulette_experiment(): """Experiment with using roulette wheel selection over tournament""" exp_title = "Using roulette wheel selection" varied_param = "selection_method" exp_settings = dict(BASE_SETTINGS) exp_settings["selection_method"] = ["roulette", "tournament"] fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_tournament_size_experiment(): """Experiment with changing the tournament size""" exp_title = "Tournament size variation" varied_param = "tournament_size" exp_settings = dict(BASE_SETTINGS) exp_settings["tournament_size"] = [2, 3, 4, 5, 6, 7, 8] fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_population_size_experiment_with_base_cfg(): """Experiment with the affects of changing population size when every other setting is set to base""" exp_title = "Population size parameter" varied_param = "population_size" exp_settings = dict(BASE_SETTINGS) exp_settings["population_size"] = numpy.arange(20, 1000, 20) fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_mutation_only_experiment(): """Experiment with the affects of changing mutation rate""" exp_title = "Mutation rate parameter" varied_param = "mutation_rate_percent" # Mutation rate typically between 1/pop size and 1/chromosome length. exp_settings = dict(BASE_SETTINGS) exp_settings["mutation_rate_percent"] = numpy.arange(0.0, 1, 0.1) fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_single_point_crossover_experiment(): """Experiment with the affects of changing the single point crossover""" exp_title = "Single point crossover variation" varied_param = "single_point_crossover_point" exp_settings = dict(BASE_SETTINGS) exp_settings["single_point_crossover_point"] = [ BASE_RULE_SIZE, BASE_RULE_SIZE * 2, BASE_RULE_SIZE * 3, BASE_RULE_SIZE * 4, BASE_RULE_SIZE * 5, BASE_RULE_SIZE * 6, BASE_RULE_SIZE * 7, BASE_RULE_SIZE * 8, BASE_RULE_SIZE * 9 ] fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_population_size_experiment_with_40_mutation_per(): """Experiment with the affects of changing population size when every other setting is set to base except mutation which is set 40% of the typical range""" exp_title = "Population size parameter when mutation is 40% in range" varied_param = "population_size" exp_settings = dict(BASE_SETTINGS) exp_settings["population_size"] = numpy.arange(20, 1000, 20) exp_settings["mutation_rate_percent"] = 0.4 fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_two_point_crossover_experiment(): """Experiment with the affects of changing the two step crossover point""" exp_title = "Two point crossover variation" varied_param = "two_point_crossover_points" exp_settings = dict(BASE_SETTINGS) exp_settings["two_point_crossover_points"] = [ [BASE_RULE_SIZE * 1, BASE_RULE_SIZE * 9], # Crossover rule 2 to rule 9 [BASE_RULE_SIZE * 2, BASE_RULE_SIZE * 8], # Crossover rule 3 to rule 8 [BASE_RULE_SIZE * 3, BASE_RULE_SIZE * 7], # Crossover rule 4 to rule 7 [BASE_RULE_SIZE * 4, BASE_RULE_SIZE * 6], # Crossover rule 5 to rule 6 ] fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_rule_number_experiment_cfg1(): """Experiment with what is the minimum amount of rules possible to get max fitness, with cfg set 1.""" exp_title = "Rule base size 1 cfg P1" varied_param = "chromosome_size" min_number_of_rules = 8 max_number_of_rules = 10 min_chromosome_size = min_number_of_rules * RULE_SIZE max_chromosome_size = max_number_of_rules * RULE_SIZE # Increment two rules at a time in the rule inc = RULE_SIZE mutation_creep = 0.45 args = [ CONDITION_SIZE, RESULT_SIZE, mutation_creep, TRAINING_FILE, BASE_TRAIN_FROM_RULE, BASE_TRAIN_TO_RULE, TRAINING_FILE, BASE_TEST_FROM_RULE, BASE_TEST_TO_RULE ] exp_settings = dict(BASE_SETTINGS) exp_settings["population_size"] = 500 exp_settings["generations"] = 150 exp_settings["runs"] = 3 exp_settings["mutation_rate_percent"] = 0.5 exp_settings["indiv_additional_args"] = args exp_settings["chromosome_size"] = numpy.arange(min_chromosome_size, max_chromosome_size, inc) fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param, test_func=test_rule_set) return fittest_individual, stats
def run_wildcard_experiment(): """Experiment with how using a wildcard makes a difference to fitness""" indiv_add_args_wc_disabled = [ BASE_CONDITION_SIZE, BASE_RESULT_SIZE, TRAINING_FILE, TRAIN_FROM_RULE, TRAIN_TO_RULE, False ] exp_title = "Wildcard Enabled Vs Disabled" varied_param = "indiv_additional_args" exp_settings = dict(BASE_SETTINGS) # Include an arg set where wildcards are enabled ano another where they # are not enabled. exp_settings["indiv_additional_args"] = [ indiv_add_args_wc_disabled, BASE_INDIV_ADD_STD_ARGS ] fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param) return fittest_individual, stats
def run_training_rule_set_size(): exp_title = "Training and test data distribution" varied_param = "indiv_additional_args" arg_sets = [] # What ever rules aren't used for training are used for testing. # Test size = maximum rules in file - training size training_sizes = [600, 800, 1000, 1200, 1400, 1600] # Create an argument set for each training and testing size for training_size in training_sizes: # Training rules will always start from 0 and go up to a set size arg_sets.append([ CONDITION_SIZE, RESULT_SIZE, BASE_MUTATION_CREEP, TRAINING_FILE, BASE_TRAIN_FROM_RULE, training_size, TRAINING_FILE, training_size+1, BASE_TEST_TO_RULE ]) exp_settings = dict(BASE_SETTINGS) exp_settings["indiv_additional_args"] = arg_sets # exp_settings["population_size"] = 400 fittest_individual, best_rule_set_settings, stats = run_varied_setting_experiment( exp_title, exp_settings, varied_param, test_func=test_rule_set) return fittest_individual, stats