Plot predictions
This commit is contained in:
parent
77380e3ef3
commit
ba994ccead
40
Main.py
40
Main.py
|
@ -4,7 +4,7 @@ from Dataset import Dataset
|
||||||
from Graph import *
|
from Graph import *
|
||||||
|
|
||||||
graph = Graph(640, 480, "Perceptron")
|
graph = Graph(640, 480, "Perceptron")
|
||||||
graph.drawLine(Point(-1000, -1000 + 20), Point(1000, 1000 + 20))
|
graph.drawLine(Point(-1000, -1000 + 100), Point(1000, 1000 + 100))
|
||||||
|
|
||||||
rand = Random()
|
rand = Random()
|
||||||
data = Dataset(open("input.txt").read().split('\n'), open("target.txt").read().split('\n'))
|
data = Dataset(open("input.txt").read().split('\n'), open("target.txt").read().split('\n'))
|
||||||
|
@ -13,39 +13,51 @@ learn_rate = 0.01
|
||||||
p = Perceptron()
|
p = Perceptron()
|
||||||
i = data.inputs
|
i = data.inputs
|
||||||
|
|
||||||
|
|
||||||
def line_perceptron():
|
def line_perceptron():
|
||||||
p.add_input("1", 1, rand.uniform(-1, 1))
|
p.add_input("1", 1, rand.uniform(-1, 1))
|
||||||
p.add_input("2", 1, rand.uniform(-1, 1))
|
p.add_input("2", 1, rand.uniform(-1, 1))
|
||||||
|
p.add_input("bias", 1, rand.uniform(-1, 1))
|
||||||
|
|
||||||
def answer(p_x, p_y):
|
def answer(p_x, p_y):
|
||||||
if p_y > calc_y(p_x):
|
if p_y > calc_y(p_x)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def calc_y(p_x):
|
def calc_y(p_x):
|
||||||
return p_x + 2
|
return p_x + 100
|
||||||
|
|
||||||
for ind in range(0, 1000):
|
for ind in range(0, 100):
|
||||||
x = rand.randint(-640 / 2, 640 / 2)
|
x = rand.randint(-1000, 1000)
|
||||||
y = rand.randint(-480 / 2, 480 / 2)
|
y = rand.randint(-1000, 1000)
|
||||||
print(x, y)
|
print(x, y)
|
||||||
p.input(x, y)
|
p.input(x, y)
|
||||||
print("error: %f" % p.guess(answer(x, y), learn_rate))
|
z = answer(x, y)
|
||||||
|
print("error: %f" % p.guess(z, learn_rate))
|
||||||
|
|
||||||
for i in range(0, 1000):
|
'''for i in range(0, 1000):
|
||||||
x = int(input("x: "))
|
x = int(input("x: "))
|
||||||
|
if x == 9001:
|
||||||
|
break
|
||||||
y = int(input("y: "))
|
y = int(input("y: "))
|
||||||
p.input(x, y)
|
p.input(x, y)
|
||||||
if p.activation() == 1:
|
if p.activation() == 1:
|
||||||
graph.win.plot(x, y, "green")
|
graph.drawCircle(Point(x, y), 4, "green")
|
||||||
print("TRUE")
|
|
||||||
else:
|
else:
|
||||||
graph.win.plot(x, y, "red")
|
graph.drawCircle(Point(x, y), 4, "red")'''
|
||||||
print("FALSE")
|
|
||||||
|
|
||||||
|
for i in range(0, 1000000):
|
||||||
|
x = int(input())
|
||||||
|
y = int(input())
|
||||||
|
if i == 500:
|
||||||
|
y = 8
|
||||||
|
p.input(x, y)
|
||||||
|
if p.activation() == 1:
|
||||||
|
graph.drawCircle(Point(x, y), 4, "green")
|
||||||
|
else:
|
||||||
|
graph.drawCircle(Point(x, y), 4, "red")
|
||||||
|
|
||||||
|
input()
|
||||||
|
|
||||||
def and_perceptron():
|
def and_perceptron():
|
||||||
p.add_input("1", 1, rand.uniform(-1, 1))
|
p.add_input("1", 1, rand.uniform(-1, 1))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user