#!/bin/env python

import numpy as np
import matplotlib.pyplot as plt

def dot(x,y):
    ((a, b), (c, d)) = (x, y)
    return a * c + b * d

def plus(x, y):
    ((a, b), (c, d)) = (x, y)
    return (a + c, b + d)

def perceptron(init, data):
    w = init
    err = True
    while err:
        err = False
        for p in data:
            if dot(p,w) < 0:
                err = True
                w = plus(w, p)
                yield w

data = [(-1, 0.001), (1, 0.001)]

x, y = list(zip(*data))
plt.plot(x, y, 'o')
x, y = list(zip(*list(perceptron((0.1,1), data))))
plt.plot(x, y, 'x')

plt.show()
