View Single Post
#38
 zsero Junior Member Join Date: Apr 2012 Posts: 6 Re: Perceptron Learning Algorithm

Quote:
 Originally Posted by julien I think it would be interesting to obtain a detailed example with the first few steps used to initialize and train the perceptron. Or a complete example if anybody is willing to share their code. I was unable to implement correctly the perceptron before the deadline, and after spending an additional 5h in this exercise today, I still don't have a proper implementation. Programming is not the issue, I'm a developer, but my issue is how to apply the theory. I feel it's important to successfully code this algorithm, so I can successfully apply the theories we will learn in the next few lectures.
I've written the algorithm just based on the lecture and it worked. Here is the "core" of the algorithm (written in Python / Numpy):

Code:
```w = np.zeros( 3 )
done = False

while not done:
wrongpoints = 0
for p in points:
if np.sign( np.dot(w, p) ) != targetFunction( p ):
w = np.add( w, targetFunction( p ) * p )
wrongpoints += 1
break
if wrongpoints == 0:
done = True```
If anyone is interested in the Python implementation, here is my full code with plotting:
https://gist.github.com/2395395

and the one for the experiments:
https://gist.github.com/2395409