Perceptron algorithm: implementation