Ejemplo n.º 1
0
def neuro_start(inputs, targets, training):
    #initializes the neural network
    network=neuro.setup_network(inputs)

    #The number of repetitions that you will
    #be training your network with
    training_reps= training

    #trains your neural network
    neuro.train(network, inputs, targets, training_reps)

    total = 0
    correct = 0

    for i in range(1,10):
        for x in range(1,10):
            pred = neuro.predict(network, [i+x])
            #rounds the predicted value to either 0 or 1
            #print '{}  == pred {}'.format(i+x,pred)
            pred = np.round(pred)
            if (i+x)%2 == pred:
                correct+= 1
            total += 1
    percent = (correct/total) * 100
    #print 'with training: {}'.format(training_reps)
    #print 'correct: {}\n total: {} \n {:.2f}%'.format(correct, total, (correct/total) * 100)
    return training_reps, percent, correct, total
Ejemplo n.º 2
0
network = []

data = open('test_cases.csv')
data = data.read()
data = data.split('\n')
data.pop()

for i in data:
    tokens = i.split(',')
    inputs.append([float(tokens[0]), float(tokens[1]), float(tokens[2])])
    targets.append([float(tokens[3])])

network = neuro.setup_network(inputs)
neuro.train(network, inputs, targets, reps)

user_answer = 'y'
while user_answer == 'y':

    r = float(raw_input("Enter a value for red between 0 and 255: ")) / 255
    g = float(raw_input("Enter a value for green between 0 and 255: ")) / 255
    b = float(raw_input("Enter a value for blue between 0 and 255: ")) / 255
    pred = round(neuro.predict(network, [r, g, b]), 2)

    if (pred >= 0.0 and pred < 0.33):
        print("\nThe color is RED!\n")
    elif (pred >= 0.33 and pred < 0.66):
        print("\nThe color is GREEN!\n")
    elif (pred >= 0.66 and pred < 1.0):
        print("\nThe color is BLUE!\n")

    user_answer = raw_input("Again? (y/n): ")
Ejemplo n.º 3
0
targets = [[1], [0], [0], [1], [0], [0], [1], [1], [0], [0], [0], [1], [1],
           [1], [1]]
reps = 1000

inputs = np.float32(inputs) / 255.0

network = []

network = neuro.setup_network(inputs)

neuro.train(network, inputs, targets, reps)

#TAKE INPUT
red_value = input("Enter Red Value: ")
green_value = input("Enter Green Value: ")
blue_value = input("Enter Blue Value: ")

red_value = float(red_value) / 255.0
green_value = float(green_value) / 255.0
blue_value = float(blue_value) / 255.0

color = [red_value, green_value, blue_value]

pred = neuro.predict(network, color)

print("Is it blue?")
if (pred >= float(0.70)):
    print("YES")
else:
    print("NO")
Ejemplo n.º 4
0
neural_counter = 0
naive_counter = 0
tree_counter = 0
static_inputs = list(all_inputs)

for index in range(len(result)):
    test_input = all_inputs.pop(index)
    inputs = all_inputs
    all_inputs = list(static_inputs)
    reps = 50
    network = []
    network = neuro.setup_network(inputs)
    neuro.train(network, inputs, targets, reps)

    pred = neuro.predict(network, test_input)

    if (pred >= 0 and pred < 0.5):
        pred = 0
    elif (pred >= 0.5 and pred < 1.0):
        pred = 1
    else:
        pred = -1

    if (pred == 0):
        party_guess = "Republican"
    elif (pred == 1):
        party_guess = "Democrat"
    else:
        party_guess = "error - out of range"
Ejemplo n.º 5
0
#training targets placed in the same order as their
#corresponding inputs (listed above)
targets = [[0], [0], [0], [1]]

#initializes the neural network
network = neuro.setup_network(inputs)

#The number of repetitions that you will
#be training your network with
training_reps = 100

#trains your neural network
neuro.train(network, inputs, targets, training_reps)

#gets the predicted value for input [0,0]
pred = neuro.predict(network, [0, 0])
#rounds the predicted value to either 0 or 1
pred = int(np.round(pred))

print "0 & 0 =", pred

#the following lines are the same as the lines
#documented above except they are for inputs [0,1], [1,0], and [1,1]
pred = neuro.predict(network, [0, 1])
pred = int(np.round(pred))

print "0 & 1 =", pred

pred = neuro.predict(network, [1, 0])
pred = int(np.round(pred))
Ejemplo n.º 6
0
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
]
testing5 = [
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0,
    1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0,
    0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
]
testing6 = [
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
    0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0
]

pred1 = neuro.predict(network, testing1)
pred2 = neuro.predict(network, testing2)
pred3 = neuro.predict(network, testing3)
pred4 = neuro.predict(network, testing4)
pred5 = neuro.predict(network, testing5)
pred6 = neuro.predict(network, testing6)

print(pred1, pred2, pred3, pred4, pred5, pred6)