Ejemplo n.º 1
0
def test_stabilise():
    # params = Parameters(seed=3, input_type=InputType.PULSE, cis_count=3,
    params = Parameters(seed=5, input_type=InputType.PULSE, cis_count=3,
                        cue_channels=2, reg_channels=4, out_channels=1)
    world = World(params)
    factory = Factory(world)
    target = DefaultTarget(world, fitness_func2,
                           scoring_method=ScoringMethod.EXPONENTIAL_VEC,
                           strength=.2)
    ntarget = NoisyTarget(world, fitness_func2,
                           scoring_method=ScoringMethod.EXPONENTIAL_VEC,
                           strength=.2, perturb_count=1, perturb_prop=.2)
    select = SelectionModel(world)
    pop = Population(factory, 5000)
    while 1:
        pop.assess(ntarget)
        w, b = pop.worst_and_best()
        print b
        if b == 1.0:
            break
        pop.select(select)
        pop.mutate(.002)

    # Get a network!
    n = pop.get_best()[0]

    print '-->', target.assess(n)
    print '-->', ntarget.assess(n)

    # Get an attractor state
    orig = n.attractors[2][0]
    perturbed = orig.copy()

    # Flip it out of that state
    # See if it goes back in to the attractor
    perturbed.flip(5)
    trans, attr, rates = n.stabilise(perturbed)
    assert orig != attr[0]

    # Push it HARDER
    perturbed.flip(6)
    trans, attr, rates = n.stabilise(perturbed)
    assert orig != attr[0]
Ejemplo n.º 2
0
def test_xor():
    """We should be able to find xor!"""
    params = Parameters(seed=2, cis_count=2, cue_channels=2, reg_channels=1,
                        out_channels=1)
    world = World(params)
    factory = Factory(world)
    target = DefaultTarget(world, fitness_func1)
    select = SelectionModel(world)
    pop = Population(factory, 10000)

    while 1:
        pop.assess(target)
        pop.select(select)
        fits = pop.fitnesses
        max_fit = max(fits)
        if max_fit == 1.0:
            break
        pop.mutate(.05)
Ejemplo n.º 3
0
 def make_initial_population(self, replicate, factory, size):
     p = Population(factory)
     n = factory.create_network()
     p.fill(n, size)
     return p