def generate_random_ftne_configuration(maximum_iterations=100, maximum_number_of_layers=5, maximum_neurons_per_layer=5): configuration = {} configuration['stopping_criterion'] = MaxGenerationsCriterion(random.randint(1, maximum_iterations)) #=========================================================================== # configuration['stopping_criterion'] = MaxGenerationsCriterion(DEFAULT_NUMBER_OF_ITERATIONS) #=========================================================================== configuration['population_size'] = DEFAULT_POPULATION_SIZE # Jan: [create_network_from_topology(topology) for topology in [[1], [2], [2, 2], [3, 3, 3], [5, 5, 5]]] number_of_layers = random.randint(1, maximum_number_of_layers) neurons_per_layer = [random.randint(1, maximum_neurons_per_layer) for i in range(number_of_layers)] configuration['topology'] = create_network_from_topology(neurons_per_layer) # Jan: [SelectionOperatorTournament(5)] tournament_size = random.randint(1, configuration['population_size']) configuration['selection_operator'] = SelectionOperatorTournament(tournament_size) # Jan: [MutationOperatorGaussian(0.01), MutationOperatorGaussian(0.1)] standard_deviation = random.uniform(0.001, 5) configuration['mutation_operator'] = MutationOperatorGaussian(standard_deviation) # Jan: [CrossoverOperatorArithmetic()] configuration['crossover_operator'] = CrossoverOperatorArithmetic() # Jan: [0.25, 0.5] configuration['mutation_rate'] = random.uniform(0.001, 1) # Jan: [0.01, 0.1] configuration['crossover_rate'] = random.uniform(0.001, 1) return configuration
def setUp(self): self.training, self.validation, self.testing = load_samples( 'r_music', 0) topology = create_network_from_topology([2, 2]) self.sga = SimpleGeneticAlgorithm(100, MaxGenerationsCriterion(200), topology, SelectionOperatorTournament(5), MutationOperatorGaussian(0.05), CrossoverOperatorArithmetic(), 0.01, 0.5)
def test_benchmark_sga(self): print('Test BenchmarkSGA()...') topology = create_network_from_topology([2, 2]) algorithm = BenchmarkSGA(10, MaxGenerationsCriterion(10), topology, SelectionOperatorTournament(5), MutationOperatorGaussian(0.1), CrossoverOperatorArithmetic(), 0.01, 0.25) X = get_input_variables(self.training).as_matrix() y = get_target_variable(self.training).as_matrix() log = algorithm.fit(X, y, RootMeanSquaredError, verbose=True) self.assertTrue(expr=log) print()
'node_delete_prob': [0.1], 'weight_mutate_rate': [0.25], 'weight_mutate_power': [0.25] } _SGA_PARAMETERS = { 'stopping_criterion': [MaxGenerationsCriterion(_BASE_PARAMETERS.get('number_generations'))], 'population_size': [_BASE_PARAMETERS.get('population_size')], 'topology': [ create_network_from_topology(topology) for topology in [[1], [2], [2, 2], [3, 3, 3], [5, 5, 5]] ], 'selection_operator': [SelectionOperatorTournament(5)], 'mutation_operator': [MutationOperatorGaussian(0.01), MutationOperatorGaussian(0.1)], 'crossover_operator': [CrossoverOperatorArithmetic()], 'mutation_rate': [0.25, 0.5], 'crossover_rate': [0.01, 0.1] } _SVM_PARAMETERS = { 'C': [c / 10 for c in range(1, 11)], 'kernel': ['linear', 'poly', 'rbf', 'sigmoid'], 'epsilon': [e / 10 for e in range(1, 6)], 'degree': [d for d in range(1, 5)], 'gamma': [g / 10 for g in range(1, 6)], 'coef0': [co / 10 for co in range(1, 6)], 'probability': [True] }