Exemplo n.º 1
0
def generate_example(char_list, char=-1, noise=0):
    if char == -1:
        char = randint(0, 25)

    res = np.zeros((26, 1))
    res[char][0] = 1 - res[char][0]

    # generates random noise from 0 to 3 if noise == -1
    if noise == -1:
        noise = randint(0, 3)

    img = generate_char_img(char_list, char, noise)
    img = img.reshape(126, 1)

    return Example(img, res)
Exemplo n.º 2
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))
Exemplo n.º 3
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))
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
#     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)

print(mj_example[0].result)
val = majorityFunction.output(mj_example[0].result)
print(val)
print(val)
Exemplo n.º 7
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, 4, 4, 1], 0.1)

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

e = [e1, e2, e3, e4]

MAX_LEARN = 10000
example_list = []
for i in range(MAX_LEARN):
    r = randint(0, 3)
    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)
    b = randint(0, 1)
    c = xorAI.output((np.array([[a], [b]])))
Exemplo n.º 8
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, 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 or b == 1)]])))

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 == 1 or b == 1) == int(c[0][0] + 0.5):
        correct = correct + 1

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

print('Correct: {}%'.format(correct / total * 100))