예제 #1
0
    def setUp(self):

        neuron_sigma = 0.5
        connection_sigma = 0.5
        PS = NumericParamSpec

        self.correct_types = set(
            ['Input', 'Simple', 'Sigmoid', 'Oscillator', 'default'])

        self.correct_sigmoid_spec = GeneSpec("Sigmoid",
                                             PS('bias', -1., 1., neuron_sigma),
                                             PS('gain', 0., 1., neuron_sigma))

        neuron_specs = [
            GeneSpec("Input"),
            self.correct_sigmoid_spec,
            GeneSpec("Simple", PS('bias', -1., 1., neuron_sigma),
                     PS('gain', 0., 1., neuron_sigma)),
            GeneSpec("Oscillator", PS("period", 0., 10., neuron_sigma),
                     PS("phase_offset", 0., 3.14, neuron_sigma),
                     PS("amplitude", 0., 10000., neuron_sigma)),
        ]

        connection_specs = [
            GeneSpec(
                "default",
                PS('weight', mutation_sigma=connection_sigma, mean_value=0.)),
        ]

        self.netspec = NetworkSpec(neuron_specs, connection_specs)
예제 #2
0
def get_extended_mutation_spec(neuron_sigma, connection_sigma):
    neuron_specs = [
        GeneSpec("Input"),
        GeneSpec("Sigmoid", PS('bias', -1., 1., neuron_sigma),
                 PS('gain', 0., 1., neuron_sigma)),
        GeneSpec("Simple", PS('bias', -1., 1., neuron_sigma),
                 PS('gain', 0., 1., neuron_sigma)),
        GeneSpec("Oscillator", PS("period", 0., 10., neuron_sigma),
                 PS("phase_offset", 0., 3.14, neuron_sigma),
                 PS("amplitude", 0., 10000., neuron_sigma)),
        GeneSpec("Bias", PS('bias', -1., 1., neuron_sigma)),
        GeneSpec("DifferentialCPG", PS('bias', -1., 1.)),

        # these neurons (V-Neuron and X-Neuron) are for the nonlinear oscillator CPG model found in Ijspeert (2005):
        GeneSpec("V-Neuron", PS('alpha', 0.05, 10., neuron_sigma),
                 PS('tau', 1., 50., neuron_sigma),
                 PS('energy', 0., 25., neuron_sigma)),
        GeneSpec("X-Neuron", PS('tau', 0.01, 5.)),
    ]

    connection_specs = [
        GeneSpec("default",
                 PS('weight', mutation_sigma=connection_sigma, mean_value=0.)),
    ]

    return NetworkSpec(neuron_specs, connection_specs)
예제 #3
0
    def test_loopback_protection(self):

        genome = self.loopback_test_genome.copy()

        net_spec = NetworkSpec([], [GeneSpec('new_connection')])

        mutator = Mutator(net_spec=net_spec)

        con_added = False
        con_added = mutator.add_connection_mutation(genome)
        # print("---------------- ----------------")
        # print(genome)
        self.assertTrue(con_added, msg="Connection should have been added")

        genome = self.loopback_test_genome.copy()

        mutator = Mutator(net_spec=net_spec,
                          pure_input_types=('input_type_1, input_type_2'))

        con_added = False
        con_added = mutator.add_connection_mutation(genome)
        # print("---------------- ----------------")
        # print(genome)
        self.assertFalse(con_added,
                         msg="Connection should have not been added")
예제 #4
0
def get_mutation_spec(neuron_sigma, connection_sigma):
    neuron_specs = [
        GeneSpec("Input"),
        GeneSpec("Sigmoid", PS('bias', -1., 1., neuron_sigma),
                 PS('gain', 0., 1., neuron_sigma)),
        GeneSpec("Simple", PS('bias', -1., 1., neuron_sigma),
                 PS('gain', 0., 1., neuron_sigma)),
        GeneSpec("Oscillator", PS("period", 0., 10., neuron_sigma),
                 PS("phase_offset", 0., 3.14, neuron_sigma),
                 PS("amplitude", 0., 10000., neuron_sigma)),
    ]

    connection_specs = [
        GeneSpec("default",
                 PS('weight', mutation_sigma=connection_sigma, mean_value=0.)),
    ]

    return NetworkSpec(neuron_specs, connection_specs)
예제 #5
0
def species_sizes(n, num_species):
    return (n // num_species, ) * (num_species - 1) + (n // num_species +
                                                       n % num_species, )


def count_members(species_list):
    return sum(len(species) for species in species_list)


## CREATE GENE SPECS ##
neuron_sigma = 0.25  # mutation sigma value for neuron params
conn_sigma = 10.  # mutation sigma value for connection params

input_neuron_spec = GeneSpec(
    'input',
    PS('layer', gen.const('input')),
)
sigmoid_neuron_spec = GeneSpec(
    'sigmoid',
    PS('layer', gen.const('hidden')),
    PS('bias', gen.uniform(), mut.gauss(neuron_sigma), bounds(-1., 1.)),
    PS('gain', gen.uniform(), mut.gauss(neuron_sigma), bounds(0., 1.)),
)
connection_spec = GeneSpec(
    'connection',
    PS('weight', gen.gauss(0, conn_sigma), mut.gauss(conn_sigma)),
)


def produce_new_generation(pipeline, genome_fitness_list):
    for _ in range(len(genome_fitness_list) - elite_num):
예제 #6
0
    4,  # size of the selection subsample (must be in the range [2, pop_size])
    neuron_param_mut_proba=
    0.5,  # probability to mutate each single neuron in the genome
    connection_param_mut_proba=
    0.5,  # probability to mutate each single connection in the genome
    structural_augmentation_proba=
    0.8,  # probability to augment the topology of a newly created genome 
    structural_removal_proba=
    0.0,  # probability to diminish the topology of a newly created genome
    speciation_threshold=
    0.005  # genomes that are more similar than this value will be considered the same species
)
#### ###### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### #### ####

net_spec = NetworkSpec([
    GeneSpec('input', NPS('layer', ['input'], mutable=False)),
    GeneSpec('sigmoid', PS('bias', -1., 1., neuron_sigma, mutable=True),
             PS('gain', 0, 1., neuron_sigma, mutable=True),
             NPS('layer', ['hidden'], mutable=False))
], [
    GeneSpec(
        'default',
        PS('weight', mutation_sigma=conn_sigma, mean_value=0., mutable=True))
])

mut = Mutator(net_spec, allowed_neuron_types=['sigmoid'])

neat_obj = NEAT(mutator=mut, **conf)

genome = neat_obj.get_init_genome(in1=neuron('input',
                                             protected=True,