Пример #1
0
from csce420_final_project.NeuralNetwork import NeuralNetwork
from csce420_final_project.NeuralNetwork import Example
import numpy as np
from random import randint

AND_AI = NeuralNetwork([2, 10, 1], 0.1)

MAX_LEARN = 10000
example_list = []
for i in range(MAX_LEARN):
    a = randint(0, 1)
    b = randint(0, 1)
    example_list.append(Example(np.array([[a],[b]]), np.array([[ int(a == 1 and b == 1) ]])))

AND_AI.learn(example_list)

total = 500
correct = 0

for i in range(total):
    a = randint(0, 1)
    b = randint(0, 1)
    c = AND_AI.output((np.array([[a], [b]])))

    if int(a == 1 and b == 1) == int(c[0][0] + 0.5):
        correct = correct + 1

    print('Set [{},{}] -> {} | AI: {} -> {}'.format(a, b, int(a == 1 and b == 1), c, round(c[0,0])))

print('Correct: {}%'.format(correct / total * 100))
Пример #2
0
from csce420_final_project.NeuralNetwork import NeuralNetwork
from csce420_final_project.NeuralNetwork import Example
import numpy as np
from random import randint

xorAI = NeuralNetwork([2, 2, 1], 0.1)

MAX_LEARN = 10000
example_list = []
for i in range(MAX_LEARN):
    a = randint(0, 1)
    b = randint(0, 1)
    example_list.append(
        Example(np.array([[a], [b]]), np.array([[int(a != b)]])))

xorAI.learn(example_list)

total = 500
correct = 0

for i in range(total):
    a = randint(0, 1)
    b = randint(0, 1)
    c = xorAI.output((np.array([[a], [b]])))

    if int(a != b) == int(c[0][0] + 0.5):
        correct = correct + 1

    print('Set [{},{}] -> {} | AI: {}'.format(a, b, int(a != b), c))

print('Correct: {}%'.format(correct / total * 100))
Пример #3
0
from csce420_final_project.NeuralNetwork import NeuralNetwork
from csce420_final_project.NeuralNetwork import Example
import numpy as np
from random import randint

AND2 = NeuralNetwork([2, 1], 0.003)

e1 = Example(np.array([[0], [0]]), np.array([[0]]))
e2 = Example(np.array([[0], [255]]), np.array([[0]]))
e3 = Example(np.array([[255], [0]]), np.array([[0]]))
e4 = Example(np.array([[255], [255]]), np.array([[1]]))

e = [e1, e2, e3, e4]

MAX_LEARN = 100000
example_list = []
for i in range(MAX_LEARN):
    r = randint(0, 3)
    example_list.append(e[r])

AND2.learn(example_list)

total = 500
correct = 0

for i in range(total):
    r = randint(0, 3)
    c = AND2.output(e[r].input)

    if int(round(c[0][0]) == e[r].result[0][0]):
        correct = correct + 1
Пример #4
0
from csce420_final_project.NeuralNetwork import NeuralNetwork
from csce420_final_project.NeuralNetwork import Example
import numpy as np
from random import randint

xorAI = NeuralNetwork([1, 1], 0.1)

e1 = Example(np.array([[-1]]), np.array([[1]]))
e2 = Example(np.array([[1]]), np.array([[-1]]))

e = [e1, e2]

MAX_LEARN = 10000
example_list = []
for i in range(MAX_LEARN):
    r = randint(0, 1)
    example_list.append(e[r])
    # example_list.append(Example(np.array([[a],[b]]), np.array([[ int(a == 1 or b == 1) ]])))

xorAI.learn(example_list)

total = 500
correct = 0

for i in range(total):
    a = randint(0, 1)
    c = xorAI.output(e[a].input)

    # if int(a == 1 or b == 1) == int(c[0][0] + 0.5):
    #     correct = correct + 1
Пример #5
0
# nw = NeuralNetwork([2,2], 0.1)
#
# example = []
# for i in range(4000):
#
#     r = randint(0,1)
#
#     if r == 0:
#         e = Example(np.array([[0],[1]]),np.array([[0.3],[1]]))
#     elif r == 1:
#         e = Example(np.array([[1],[0]]),np.array([[1],[0.3]]))
#
#     example.append( e )

mj_example = []
majorityFunction = NeuralNetwork([1, 1])
for i in range(40000):

    r = randint(0, 1)

    mj_example.append(Example(np.array([[r]]), np.array([[r]])))

majorityFunction.learn(mj_example)

for i in range(30):
    print('------')
    print(i)
    r = randint(0, 1)
    solution = majorityFunction.output(np.array([[r]]))
    print(r)
    print(solution)
Пример #6
0
    for ex in examples:
        ai_out = ai.output(ex.input)
        ai_char = result_to_char(ai_out)
        correct_ans = result_to_char(ex.result)

        if ai_char == correct_ans:
            correct = correct + 1

    return correct / len(examples) * 100


########################################################################################################################

# Majority Function test
if TEST_MAJORITY:
    AND_AI = NeuralNetwork([2, 10, 1], 0.1)

    MAX_LEARN = 10000
    example_list = []
    for i in range(MAX_LEARN):
        a = randint(0, 1)
        b = randint(0, 1)
        example_list.append(
            Example(np.array([[a], [b]]), np.array([[int(a == 1
                                                         and b == 1)]])))

    AND_AI.learn(example_list)

    total = 500
    correct = 0