Example #1
0
Creates the network with 6 neurons on hidden layer and 2 on output layer
"""
net = nl.net.newff([[-180,180],[-180,180]],[6,2])


"""
Creates the input data that will be used to train the network
"""
data = np.array([fuzzy_ia.angle_dmn, fuzzy_ia.angle_dmn]).reshape(360,2)


"""
Set the target function to the fuzzy function plus some random gaussian noise
"""
target_function = lambda x: fuzzy_ia.next_action(int(d[0]+0.2*np.random.randn()),
                                                 int(d[1]+0.2*np.random.randn()),
                                                 None)


"""
Creates the desired output
"""
target = [ target_function(d) for d in data  ]


"""
Trains the network using gd with a learning rate of 0.01, for 500 epochs or 0.01 MSE
ref: https://pythonhosted.org/neurolab/lib.html#neurolab.train.train_gd
"""
net.train(data, target, show=15)
Example #2
0
import math
import neurolab as nl
import fuzzy_ia
"""
Creates the network with 6 neurons on hidden layer and 2 on output layer
"""
net = nl.net.newff([[-180, 180], [-180, 180]], [6, 2])
"""
Creates the input data that will be used to train the network
"""
data = np.array([fuzzy_ia.angle_dmn, fuzzy_ia.angle_dmn]).reshape(360, 2)
"""
Set the target function to the fuzzy function plus some random gaussian noise
"""
target_function = lambda x: fuzzy_ia.next_action(
    int(d[0] + 0.2 * np.random.randn()), int(d[1] + 0.2 * np.random.randn()),
    None)
"""
Creates the desired output
"""
target = [target_function(d) for d in data]
"""
Trains the network using gd with a learning rate of 0.01, for 500 epochs or 0.01 MSE
ref: https://pythonhosted.org/neurolab/lib.html#neurolab.train.train_gd
"""
net.train(data, target, show=15)
"""
Creates the function that will feed foward the learnt weights
"""

Example #3
0
    """
    Writes output to a file
    """
    with open('output.csv', 'w') as f:
        csvwriter = csv.writer(f)
        csvwriter.writerow(data)


host, port, choice = parse_host_port()
print("Iniciando conexão com o host %s, na porta %s" %  (host,port))

sc = SoccerClient()
sc.connect(host, port)

IA = {
    'fuzzy': lambda t, b, s: fuzzy_ia.next_action(t, b, s),
    'spin': lambda t, b, s: (2., -2.),
    'str8': lambda t, b, s: (0., 0.),
    'crazy': lambda t, b, s: (1., 1.),
    'neural': lambda t, b, s: neural_ia.next_action(t, b, s)
}

def print_info(l, r):
    print("raw_target_angle: %f raw_ball_angle: %f" %
          (sc.get_target_angle(), sc.get_ball_angle()))
    print("target_angle: %d ball_angle: %d left: %f right: %f" %
          (target_angle(), ball_angle(), l, r))
    print("left: [%s], right: [%s]" % (int_repr(l), int_repr(r)))
    print("target: [%s], ball: [%s]" % (angle_repr(target_angle()),
          angle_repr(ball_angle())))