############################################################################ # Copyright (C) 2006 by Bruk Habtu # # bruk@themightyowl.com # # # # This program is free software; you can redistribute it and#or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the # # Free Software Foundation, Inc., # # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ class brain: def __init__(self): self.inputs = [] self.hidden = [] self.outputs = [] class neuron: def __init__(self, threshhold ): self.output = None #the node to output to self.threshhold = threshhold #threshhold self.w = [] #inputs self.active = 0 #0 means not active def setOutput(self, neuron, weight): self.output = neuron self.output.addInput(self, weight) def addInput(self, neuron, weight) self.w.append((neuron,weight)) def processInputs(self): sum = 0 for n,w in self.w: sum += (n.active * w) if sum => self.threshhold: self.active = 1 else: self.active = 0