Add graph drawing functionality
This commit is contained in:
parent
f274146d58
commit
0511c5d7d3
15
Graph.py
Normal file
15
Graph.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from graphics import *
|
||||
|
||||
class Graph(object):
|
||||
|
||||
def __init__(self, p_width, p_height, p_name):
|
||||
self.win = GraphWin("perceptron", p_width, p_height)
|
||||
self.win.setCoords(0, 0, 640, 480)
|
||||
self.x_offset = p_width / 2
|
||||
self.y_offset = p_height / 2
|
||||
self.win.setCoords(0, 0, 640, 480)
|
||||
Line(Point(0, p_height / 2), Point(p_width, p_height / 2)).draw(self.win)
|
||||
Line(Point(p_width / 2, 0), Point(p_width / 2, p_height)).draw(self.win)
|
||||
|
||||
def drawLine(self, p_point1, p_point2):
|
||||
Line(p_point1, p_point2).draw(self.win).move(self.x_offset, self.y_offset)
|
7
Main.py
7
Main.py
|
@ -1,10 +1,13 @@
|
|||
from Perceptron import Perceptron
|
||||
from random import Random
|
||||
from Dataset import Dataset
|
||||
from Graph import *
|
||||
|
||||
rand = Random()
|
||||
data = Dataset(open("input.txt").read().split('\n'), open("target.txt").read().split('\n'))
|
||||
learn_rate = 0.01
|
||||
graph = Graph(640, 480, "Perceptron")
|
||||
graph.drawLine(Point(-1000, -1000 + 20), Point(1000, 1000 + 20))
|
||||
|
||||
p = Perceptron()
|
||||
i = data.inputs
|
||||
|
@ -20,8 +23,8 @@ for ind in range(0, 500):
|
|||
print("error: %f" % p.guess(i[key].target, learn_rate))
|
||||
|
||||
for i in range(0, 1000):
|
||||
x = input("Arg1")
|
||||
y = input("Arg2")
|
||||
x = input("Arg1: ")
|
||||
y = input("Arg2: ")
|
||||
p.input(x, y)
|
||||
if p.activation() == 1:
|
||||
print("TRUE")
|
||||
|
|
1001
graphics.py
Normal file
1001
graphics.py
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user