NOte the brain.py uses 1 as the bais input  (not -1 in the notes)

"""

import brain

#  2 inputs 2 layers

# layer 1
#     X1   X2    1      output
#     -1   -1  0.5         Y1
#     1    1   -1.5        Y2

# layer 2
#     Y1  Y2     1
#      1   1    -0.5       output
#

# weight array has the following format
# weight[layer][neuron_out][neuron_in]

brain = brain.FeedForwardBrain(weight=[[[-1.0, -1.0, 0.5], [1.0, 1.0, -1.5]],
                                       [[1.0, 1.0, -0.5]]],
                               func=[brain.step, brain.step])

for x1 in range(2):
    for x2 in range(2):
        input = [x1, x2]
        output = brain.ffwd(input)
        print x1, x2, output
Beispiel #2
0
def createBrain():
    """
    Create a random network of the given size
    """
    return brain.FeedForwardBrain(sz)
                cnt = 0
                best_fit = fit
                best_guess = copy.deepcopy(guess)

        cart.setAngle(math.pi + INIT_ANG)
        cnt += 1

        if not inc or best_guess == None or (cnt % 10 == 0):
            guess = randomWeights(sizes, 1.0)
            #cnt=0
        else:
            scale = random.random() * 0.001
            guess = mutate(best_guess, scale)

        if net == None:
            net = brain.FeedForwardBrain(weight=guess)
        else:
            net.setWeights(guess)

        time = 0
        first = False

    input = copy.deepcopy(cart.getState())
    input[0] = input[0] - math.pi
    out = net.ffwd(input)

    force = (out[0] - 0.5) * force_scale

    # step the car for a single GUI frame
    cart.step(force, dt)