First page Back Continue Last page Overview Graphics

Simple ANN for the „AND“ Function

import numpy as np

class Perceptron:

def __init__(self, input_length, weights=None):

if weights is None:

self.weights = np.ones(input_length) * 0.5

else:

self.weights = weights

@staticmethod

def unit_step_function(x):

if x > 0.5:

return 1

return 0

def __call__(self, in_data):

weighted_input = self.weights * in_data

weighted_sum = weighted_input.sum()

return Perceptron.unit_step_function(weighted_sum)