<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.extremist.software/index.php?action=history&amp;feed=atom&amp;title=User%3AElgreengeeto%2FPython_Linear_Perceptron</id>
	<title>User:Elgreengeeto/Python Linear Perceptron - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.extremist.software/index.php?action=history&amp;feed=atom&amp;title=User%3AElgreengeeto%2FPython_Linear_Perceptron"/>
	<link rel="alternate" type="text/html" href="https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;action=history"/>
	<updated>2026-04-08T17:42:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.13</generator>
	<entry>
		<id>https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=10091&amp;oldid=prev</id>
		<title>SpammerHellDontDelete at 03:47, 2 March 2010</title>
		<link rel="alternate" type="text/html" href="https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=10091&amp;oldid=prev"/>
		<updated>2010-03-02T03:47:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:47, 1 March 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l3&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#same-lengthed arrays&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#same-lengthed arrays&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;def dot_product(a, b):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;def dot_product(a, b):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    sum &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;= 0&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;    &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;return &lt;/ins&gt;sum&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(x*y for x,y in zip&lt;/ins&gt;(a&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;,b)&lt;/ins&gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;   i = 0&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;   while i &amp;lt; len&lt;/del&gt;(a)&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;       sum += a[i] * b[i]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;       i += 1&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;   return sum&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;class Perceptron:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;class Perceptron:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>SpammerHellDontDelete</name></author>
	</entry>
	<entry>
		<id>https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=4951&amp;oldid=prev</id>
		<title>SpammerHellDontDelete at 03:39, 7 May 2009</title>
		<link rel="alternate" type="text/html" href="https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=4951&amp;oldid=prev"/>
		<updated>2009-05-07T03:39:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:39, 6 May 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pre&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#a dot product is the sum of the products of aligned-elements from two&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#a dot product is the sum of the products of aligned-elements from two&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#same-lengthed arrays&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#same-lengthed arrays&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l63&quot;&gt;Line 63:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		train(data, subject)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		train(data, subject)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	print &amp;quot;final bias weight: %s, final input weights: %s&amp;quot; % (subject.bias_weight, subject.weights)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	print &amp;quot;final bias weight: %s, final input weights: %s&amp;quot; % (subject.bias_weight, subject.weights)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/pre&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>SpammerHellDontDelete</name></author>
	</entry>
	<entry>
		<id>https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=4950&amp;oldid=prev</id>
		<title>SpammerHellDontDelete: New page: #a dot product is the sum of the products of aligned-elements from two #same-lengthed arrays def dot_product(a, b):    sum = 0    i = 0    while i &lt; len(a):        sum += a[i] * b[i]      ...</title>
		<link rel="alternate" type="text/html" href="https://wiki.extremist.software/index.php?title=User:Elgreengeeto/Python_Linear_Perceptron&amp;diff=4950&amp;oldid=prev"/>
		<updated>2009-05-07T03:38:55Z</updated>

		<summary type="html">&lt;p&gt;New page: #a dot product is the sum of the products of aligned-elements from two #same-lengthed arrays def dot_product(a, b):    sum = 0    i = 0    while i &amp;lt; len(a):        sum += a[i] * b[i]      ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;#a dot product is the sum of the products of aligned-elements from two&lt;br /&gt;
#same-lengthed arrays&lt;br /&gt;
def dot_product(a, b):&lt;br /&gt;
   sum = 0&lt;br /&gt;
   i = 0&lt;br /&gt;
   while i &amp;lt; len(a):&lt;br /&gt;
       sum += a[i] * b[i]&lt;br /&gt;
       i += 1&lt;br /&gt;
   return sum&lt;br /&gt;
&lt;br /&gt;
class Perceptron:&lt;br /&gt;
&lt;br /&gt;
	#percieve based on a list of inputs&lt;br /&gt;
	def percieve(self, inputs):&lt;br /&gt;
		#if there is not a list of weights, make one of = length to list of inputs&lt;br /&gt;
		if len(self.weights) &amp;lt; len(inputs):&lt;br /&gt;
			for ip in inputs:&lt;br /&gt;
				self.weights.append(self.defualt_weight)&lt;br /&gt;
		#get the dot product of those inputs with the bias and the input&amp;#039;s weights with the bias&amp;#039;s weight&lt;br /&gt;
		sum = dot_product(inputs + [self.bias], self.weights + [self.bias_weight])&lt;br /&gt;
		return sum&lt;br /&gt;
&lt;br /&gt;
	#learn method compares output of percieve() to the expected output and adjusts weights by plus or minus&lt;br /&gt;
	#the learn rate which is incrementally decreased by a factor of 0.99&lt;br /&gt;
	def learn(self, inputs, expected):&lt;br /&gt;
		if self.learn_rate &amp;lt; 0.001:&lt;br /&gt;
			return&lt;br /&gt;
		self.learn_rate = self.learn_rate * 0.999&lt;br /&gt;
		print &amp;quot;learn rate is %s&amp;quot; % (self.learn_rate)&lt;br /&gt;
		train_step = (expected - self.percieve(inputs)) * self.learn_rate&lt;br /&gt;
		self.bias_weight += self.bias_weight * train_step&lt;br /&gt;
		print &amp;quot;bias weight is: %s&amp;quot; % (self.bias_weight)&lt;br /&gt;
		for i in xrange(len(inputs)):&lt;br /&gt;
			self.weights[i] += inputs[i] * train_step&lt;br /&gt;
			print &amp;quot;input %s weight is: %s&amp;quot; % (i, self.weights[i])&lt;br /&gt;
&lt;br /&gt;
	#this defines how a Perceptron object represents itself in the interpreter&lt;br /&gt;
	def __str__(self):&lt;br /&gt;
		return &amp;quot;Weights: %s. Threshhold: %s. Learn rate: %s.&amp;quot; % (self.weights, self.threshhold, self.learn_rate)&lt;br /&gt;
	#same as above&lt;br /&gt;
	__repr__ = __str__&lt;br /&gt;
	&lt;br /&gt;
	#defines initial values for a new Perceptron object&lt;br /&gt;
	def __init__(self):&lt;br /&gt;
		self.bias = 1.0	&lt;br /&gt;
		self.bias_weight = 0.0&lt;br /&gt;
		self.defualt_weight = 0.0&lt;br /&gt;
		self.weights = []&lt;br /&gt;
		self.learn_rate = 1&lt;br /&gt;
&lt;br /&gt;
#trains a perceptron according to data&lt;br /&gt;
def train(data, perceptron):&lt;br /&gt;
	for case in data:&lt;br /&gt;
		perceptron.learn(case[0],case[1])&lt;br /&gt;
&lt;br /&gt;
#define a dataset to try and train a perceptron&lt;br /&gt;
data = [[[1.0],2.0],[[2.0],4.0],[[3.0],6.0]]&lt;br /&gt;
&lt;br /&gt;
#do the damned thing&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
	subject = Perceptron()&lt;br /&gt;
	for i in range(100000):&lt;br /&gt;
		train(data, subject)&lt;br /&gt;
	print &amp;quot;final bias weight: %s, final input weights: %s&amp;quot; % (subject.bias_weight, subject.weights)&lt;/div&gt;</summary>
		<author><name>SpammerHellDontDelete</name></author>
	</entry>
</feed>