In [1]:
import numpy as np

In [7]:
#http://natureofcode.com/book/chapter-10-neural-networks/
#translated into python
class Perceptron(object):
    def __init__(self, weights, lc):
        self.weights = weights
        self.lc = lc
    def createweights(self, n):
        weights = (np.random.rand(n) * 2) - 1
    def feedforward(self, inputs):
        sum_ = 0
        for n in range(len(inputs)):
            sum_ += inputs[n]*weights[n]
            return activate(sum_)
    def activate(self, sum_):
        if sum_ > 0:
            return 1
        else:
            return -1
    def train(self, inputs, expected):
        guess = feedforward(inputs)
        error = desired - guess
        for n in range(len(weights)):
            weights[n] += lc * error * inputs[n]

class Trainer(object):
    def __init__(self, inputs, answer):
        
    
def func(x):
    return 2*x + 1

In [ ]: