コード例 #1
0
ファイル: interface.py プロジェクト: csxeba/NeuralNetworks
def evolve(data):
    """This method evolves a Feed Forward Neural Network for this dataset"""
    # Possible evolvable parameters include:
    # - number of hidden neurons
    # - activation function  # TODO: only sigmoid works atm
    # - number of hidden layers <- hard because num of neurons is evolved separately
    # - learning rate
    # - repeats required for model aquisition (might keep this constant)
    # Unevolvable (or hand-"evolvable") parameters (population Hypers):
    # - max number of Individuals
    # - crossing over rate
    # - mutation rate
    # - max number of offsprings per mating

    inputs = data.neurons_required()[0]
    hiddens_range = (int(inputs / 2), int(inputs * 1.5))
    rate_range = (0.5, 3.0)

    LIMIT = 30
    CROSSING_OVER = 0.2
    MUTATION = 0.1
    FITNESS_F = data.test
    MAX_OFFSPRINGS = 3
    RANGE = (hiddens_range, rate_range)
    BRAIN_MAKER = make_brain

    pop = Population(LIMIT, CROSSING_OVER, MUTATION, FITNESS_F, MAX_OFFSPRINGS, RANGE, BRAIN_MAKER)
    print("Created population for evolution optimization!")
    pop.run(10, 0, 0)
    pop.update(True)
    print("Evolution is done. Best network is stored in the .brain attribute!")

    return pop.individuals[0]
コード例 #2
0
def main():
    pop = Population(LIMIT, SELECTION, CROSSING_OVER, MUTATION, fitness_func,
                     MAX_OFFSPRINGS, RANGE, get_brain)
    print("Population created with size:", len(pop.individuals))
    print("Genomes:", "RATE", "REPEATS", "HIDDENS", sep="\t")
    for ind in pop.individuals:
        print("\t", str(ind.genome).replace(", ", "\t"), sep="\t")
    log = pop.run(epochs=5, verbose=4, log=1)
    return pop, log