Last active
October 19, 2015 12:57
-
-
Save bbengfort/11212093 to your computer and use it in GitHub Desktop.
Plotting 3D points for a perceptron to determine linear separability as well as a tiny computation for that neural network (studies for evolutionary computing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
pts0 = [ | |
(0, 0, 0), | |
(0, 1, 1), | |
(1, 0, 1), | |
(1, 1, 0), | |
] | |
pts1 = [ | |
(0, 0, 1), | |
(0, 1, 0), | |
(1, 0, 0), | |
(1, 1, 1), | |
] | |
fig = plt.figure() | |
axe = Axes3D(fig) | |
axe.scatter([pt[0] for pt in pts0], [pt[1] for pt in pts0], [pt[2] for pt in pts0], color='r', marker='o') | |
axe.scatter([pt[0] for pt in pts1], [pt[1] for pt in pts1], [pt[2] for pt in pts1], color='b', marker='^') | |
#axe.plot((1,1,1), 'r--') | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
theta = 0.0 | |
weights = [0.0, 0.0, 0.0] | |
eta = 1.0 | |
E = [1, 0, 0], 1 | |
D = [0, 1, 1], 0 | |
H = [1, 1, 1], 1 | |
def update(avec, target): | |
global theta | |
global weights | |
global eta | |
print "avec = %s" % avec | |
print "weights = %s" % weights | |
inr = sum(map(lambda a,b: a*b, avec, weights)) | |
print "inr = %0.3f" % inr | |
ar = 1 if inr >= theta else 0 | |
print "ar = %i" % ar | |
if ar != target: | |
for i in xrange(len(weights)): | |
weights[i] = weights[i] + (eta * (target - ar) * avec[i]) | |
theta = theta - (eta * (target - ar)) | |
print "theta = %0.3f" % theta | |
print "weights = %s" % weights | |
update(*E) | |
update(*D) | |
update(*H) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment