Exemplo n.º 1
0
	def test_bool_gene_copy_constructor(self):
		g = BoolGene(True)
		c_copy = BoolGene(g)
		self.assertEqual(c_copy.data, True)

		# test copy does not depend on original
		g.data = False
		self.assertEqual(c_copy.data, True)
Exemplo n.º 2
0
    def __init__(self, fitness_calc):
        Individual.__init__(self, fitness_calc)
        self.length = 18  # number of parameters

        num_hidden_layers = IntGene(
            current=1, min=1, max=3)  # the default tuple length is 1 (100,)
        hidden_layer_sizes = TupleGene(current=(100, ),
                                       size=num_hidden_layers,
                                       gene_list=[
                                           IntGene(100, 1, 200),
                                           IntGene(0, 0, 200),
                                           IntGene(0, 0, 200)
                                       ])
        activation = ListGene(current='relu',
                              values=['relu', 'identity', 'logistic', 'tanh'])
        solver = ListGene(current='adam', values=['adam', 'lbfgs', 'sgd'])
        alpha = FloatGene(current=0.0001, std=0.01, min=0.00001, max=1)
        batch_size = ListGene(current='auto', values=['auto', 10, 100, 1000])
        learning_rate = ListGene(current='constant',
                                 values=['constant', 'invscaling', 'adaptive'])
        max_iter = IntGene(current=200, min=50, max=5000)
        tol = FloatGene(current=1e-4, std=0.01, min=1e-6, max=1e-1)
        learning_rate_init = FloatGene(current=0.001,
                                       std=0.01,
                                       min=0.0001,
                                       max=1)
        power_t = FloatGene(current=0.5, std=0.1, min=0.0001, max=1)
        warm_start = BoolGene(current=False)
        momentum = FloatGene(current=0.9, std=0.25, min=0, max=1)
        nesterovs_momentum = BoolGene(current=True)
        early_stopping = BoolGene(current=False)
        validation_fraction = FloatGene(current=0.1, std=0.25, min=0, max=1)
        beta_1 = FloatGene(current=0.9, std=0.25, min=0, max=1)
        beta_2 = FloatGene(current=0.999, std=0.25, min=0, max=1)
        epsilon = FloatGene(current=1e-8, std=1e-3, min=1e-10, max=1e-2)

        self.genes = {'hidden_layer_sizes': hidden_layer_sizes, \
             'activation': activation, \
             'solver': solver, \
             'alpha': alpha, \
             'batch_size': batch_size, \
             'learning_rate': learning_rate, \
             'max_iter': max_iter, \
             'tol': tol, \
             'learning_rate_init': learning_rate_init, \
             'power_t': power_t, \
             'warm_start': warm_start, \
             'momentum': momentum, \
             'nesterovs_momentum': nesterovs_momentum, \
             'early_stopping': early_stopping, \
             'validation_fraction': validation_fraction, \
             'beta_1': beta_1, \
             'beta_2': beta_2, \
             'epsilon': epsilon}
Exemplo n.º 3
0
	def test_bool_gene_mutation(self):
		g = BoolGene()
		self.assertFalse(g.data)
		g.mute()
		self.assertTrue(g.data)

		g = BoolGene(True)
		self.assertTrue(g.data)
		g.mute()
		self.assertFalse(g.data)