コード例 #1
0
def test_double_evolution():
    p = problems.DoubleFrequency()
    g = grns.ClassicGRN()
    config.POPULATION_SIZE = 30
    g.random(p.nin, p.nout, 5)
    random_fitness = p.eval(g)
    evo = evolution.Evolution(p)
    best_fit, best_ind = evo.run(5)
    print(random_fitness, ", ", best_fit)
    assert best_fit > random_fitness
コード例 #2
0
def test_evolution_boston():
    config.POPULATION_SIZE = 5
    config.INITIALIZATION_DUPLICATION = 2
    config.START_SPECIES_THRESHOLD = 0.05
    config.MIN_SPECIES_SIZE = 1
    p = problems.Boston()
    newgrn = lambda: grns.DiffGRN()
    grneat = evolution.Evolution(p, newgrn)
    best_fit, _ = grneat.run(2)
    assert best_fit >= 0.0
    assert best_fit <= 1.0
コード例 #3
0
log_file = os.path.join(log_dir, 'fits_' + args.id + '.log')
grn_dir = os.path.join(args.root_dir, 'grns')
data_dir = os.path.join(args.root_dir, 'data')
log_file = os.path.join(log_dir, 'fits_' + args.id + '.log')

p = eval('problems.' + args.problem)
p = p(args.env, args.nin, args.nout, args.ep_max)

print("..Init GRN..")
newgrn = grns.ClassicGRN()  #DiffGRN()
newgrn2 = lambda: grns.ClassicGRN()  #DiffGRN()
if args.evo:
    print("..Evolv GRN..")
    grneat = evolution.Evolution(p,
                                 newgrn2,
                                 run_id=args.id,
                                 grn_dir=grn_dir,
                                 log_dir=log_dir)
    grneat.run(args.gens)
else:
    for i in range(1):
        print("..Init GRN", i, "..")
        #grn = grns.ClassicGRN()
        if args.grn_file:
            print("..Load GRN..")
            with open(grn_dir + "/grns_" + str(args.id) + ".log", 'r') as f:
                grns = f.readlines()
                #print("\t ", grns[-1])
                newgrn.from_str(grns[-1])
        else:
            print("..Gen Random GRN..")
コード例 #4
0
                    help='Log directory',
                    default='logs')

args = parser.parse_args()

log_file = os.path.join(args.log_dir, 'fits_' + args.id + '.log')
pclass = eval("problems." + args.problem)
np.random.seed(args.seed)
p = pclass(log_file, args.seed, args.learn, args.env, args.steps, args.warmup)

newgrn = lambda: grns.DiffGRN()

if args.evo:
    grneat = evolution.Evolution(p,
                                 newgrn,
                                 args.id,
                                 grn_dir=args.grn_dir,
                                 log_dir=args.log_dir)
    if args.grn_file:
        with open(args.grn_file, 'r') as f:
            pcount = 0
            for g in f.readlines():
                if pcount < len(grneat.population.offspring):
                    grn = newgrn()
                    grn.from_str(g)
                    ind = evolution.Individual(grn)
                    grneat.population.offspring[pcount] = ind
                    pcount += 1
    grneat.run(args.gens)
else:
    if args.grn_file: