A Simple Perceptron Implementation in Python
Zithromax effects
buy Zithromax without a rx overnight shipping
Zithromax online
generic Zithromax uk
where to buy Zithromax
Zithromax shipped by cash on delivery
Zithromax capsule
purchase Zithromax cod overnight delivery
Zithromax cheap no rx required canada
where to buy Zithromax without a prescription
buying Zithromax online without rx
buying Zithromax
buy generic Zithromax online
buy Zithromax 500 mg
achat Zithromax
Zithromax cheap overnight fedex
Zithromax overnight cod
where to buy Zithromax by cod
Zithromax canadian pharmacy
buy cheap Zithromax with dr. prescription
where to buy Zithromax by cod
buy discount Zithromax
buy Zithromax money buy
buy Zithromax canada
buy Zithromax without rx from us pharmacy
purchase online prescription Zithromax
Zithromax
purchasing Zithromax without a script
no rx cod Zithromax
order generic Zithromax
purchase Zithromax online no membership
Zithromax buy online
buy Zithromax 500 mg
purchase Zithromax overnight
purchasing Zithromax with overnight delivery
Zithromax without rx overnight shipping
order online Zithromax without prescription
where to buy Zithromax without a prescription
buy Zithromax with a mastercard
Zithromax ohne rezept
order Zithromax cheap overnight
purchase Zithromax overnight delivery
Zithromax
Zithromax online order
Zithromax apotheke
no rx cod Zithromax
buy in Zithromax uk
Zithromax overdose
buy cheap Zithromax online free consult
Zithromax online
buy Zithromax no prescription
cheap Zithromax by money order
Zithromax buy fedex
order Zithromax online next day delivery
purchase Zithromax online no membership overnight shipping
buy cheap Zithromax on line
Zithromax for sale
purchase Zithromax paypal without prescription
buying Zithromax online without rx
buy Zithromax legally
Zithromax prescription
purchase Zithromax money purchase
Zithromax canada
purchase Zithromax online without prescription
Zithromax no prescription to buy
Zithromax 500 mg
buy Zithromax online overseas
order Zithromax amex online without prescription
buy Zithromax Online
buy Zithromax where
no rx Zithromax with fedex
Zithromax online order
buy Zithromax in mo
Zithromax without prescription overnight shipping
Zithromax rezept
buy Zithromax shipped cod
buy no perscription Zithromax
Zithromax mexico
purchase Zithromax online no membership overnight shipping
no rx Zithromax with fedex
how to order Zithromax online without prescription
purchasing Zithromax online without prescription
order Zithromax pharmacy
order Zithromax without prescription to ship overnight
order buy Zithromax online
Zithromax buy cod
buy Zithromax in mo
where to buy Zithromax
buy Zithromax no prescription
buy Zithromax cheap
buy Zithromax in england
Zithromax fedex
buy cod Zithromax
buy Zithromax with visa
Zithromax suppliers
purchase Zithromax amex online without prescription
order Zithromax without a prescription overnight shipping
Zithromax online prescription
buy Zithromax with a visa
buy Zithromax 500 mg
Zithromax bestellen
buy Zithromax fed ex
online Zithromax
cheap Zithromax no rx
buy Zithromax legally
purchase Zithromax no visa without prescription
fedex Zithromax without priscription
buy Zithromax online overseas
buy Zithromax without prescription
buy Zithromax online
buy no perscription Zithromax
ordering Zithromax online
buy Zithromax paypal without rx
ordering Zithromax online
Zithromax online consultant
Zithromax fedex no prescription
buy Zithromax online no rx
Zithromax with free fedex overnight
purchase Zithromax no visa without prescription
Zithromax prescription order
Zithromax fedex
where to buy generic Zithromax online without a prescription
ordering Zithromax online
buy Zithromax without a rx overnight shipping
Zithromax buy
Zithromax uk
no prescription Zithromax with fedex
buy Zithromax online pills
buy cheap generic Zithromax
order buy Zithromax online
what does Zithromax look like
buy Zithromax without rx needed
buy Zithromax online cod
buy Zithromax pay pal without prescription
order Zithromax cheap overnight
purchase Zithromax money purchase
purchase Zithromax without a prescription online
Zithromax online no rx overnight
uk Zithromax generic
cheapest place to buy Zithromax
During my final term of classes for my degree, we were required to learn how perceptron neural networks function. In my free time I came up with the following Python implementation.
class Perceptron(object): def __init__(self, weights=None, threshold=0.5): self.threshold = threshold self.weights = weights self.verbose = False def output(self, input_vector): if self._total(input_vector) < self.threshold: return 0 else: return 1 def train(self, training_set, alpha=0.1, end_after=100): if self.weights is None: self.weights = [0 for _ in range(len(training_set.keys()[0]))] n = 0 updated = True while(updated): n += 1 updated = False for xv, t in training_set.items(): y = self.output(xv) if(y != t): self._update_weights(alpha, t, y, xv) self._update_threshold(alpha, t, y) updated = True if end_after is not None and n >= end_after: break return n def test(self, training_set): for xv, t in training_set.items(): if(self.output(xv) != t): return False return True def _total(self, input_vector): total = 0 for w,x in zip(self.weights, input_vector): total += (w * x) return total def _update_weights(self, alpha, t, y, xv): for i in range(len(self.weights)): self.weights[i] = (alpha * (t - y) * xv[i]) + self.weights[i] def _update_threshold(self, alpha, t, y): self.threshold = (alpha * (t - y) * -1) + self.threshold
As an example of use, here we are training the perceptron to learn how to compute values from a NAND truth table.
nand_set = { (0,0): 1, (0,1): 1, (1,0): 1, (1,1): 0 } nn = Perceptron() iterations = nn.train(nand_set, alpha=.2) # alpha is the learning rate print "Trained in {0} iterations.".format(iterations) print "Correct?", nn.test(nand_set) print "Weights: {0}, Threshold: {1}".format(nn.weights, nn.threshold)
Output:
Trained in 9 iterations. Correct? True Weights: [-0.40000000000000002, -0.20000000000000001], Threshold: -0.5
Now that we have the weights (-0.4, -0.2) and threshold (-0.5), we can feed those in later without having to train it.
nand_perceptron = Perceptron((-0.4, -0.2), -0.5) print "Correct?", nand_perceptron.test(nand_set)
Output:
Correct? True
This was mostly just a fun little project of mine in order to help my understanding, but if you have any suggestions for improvement, I welcome it!
