def __init__(self,size):
     '''
     Constructor
     '''
     self.size=size
     self.outputPattern=zeros(self.size)
     self.connectionWeights=zeros((self.size, self.size))
     self.network=Network(self.size)
Beispiel #2
0
 def __init__(self,size):
     '''
     Constructor
     '''
     self.numCities=size
     self.networkSize=size*size
     self.outputRoute=zeros(self.numCities)
     self.distances=zeros((self.numCities, self.numCities))
     self.network=Network(self.networkSize)
     self.connectionWeights=zeros((self.networkSize,self.networkSize))
 def testIterate(self):
     network = Network(10)
     initialStates = random.randint(2, size=10)
     arr = random.random_integers(-2000, 2000, size=(10, 10)) 
     synapsis = (arr + arr.T) / 2.0 - diag(diag(arr))
     network.loadInitialState(initialStates)
     network.loadConnectionMatrix(synapsis)
     network.iterate()
     pass
class AssociativeMemory(object):
    '''
    classdocs
    '''

    def __init__(self,size):
        '''
        Constructor
        '''
        self.size=size
        self.outputPattern=zeros(self.size)
        self.connectionWeights=zeros((self.size, self.size))
        self.network=Network(self.size)
        
    def learn(self,patterns):
        for i in range(0,self.size):
            for j in range(0,self.size):
                if i==j:
                    self.connectionWeights[i,j]=0
                else:
                    partial=zeros(len(patterns))
                    for x in range (0,len(patterns)):
                        partial[x]=(2*patterns[x][i]-1)*(2*patterns[x][j]-1)
                    self.connectionWeights[i,j]=sum(partial) 
        print self.connectionWeights
        
    def recall(self,pattern):
        self.network.loadInitialState(pattern)
        self.network.loadConnectionMatrix(self.connectionWeights)
        self.network.iterate()
           
        
Beispiel #5
0
class TSP(object):
    '''
    classdocs
    '''


    def __init__(self,size):
        '''
        Constructor
        '''
        self.numCities=size
        self.networkSize=size*size
        self.outputRoute=zeros(self.numCities)
        self.distances=zeros((self.numCities, self.numCities))
        self.network=Network(self.networkSize)
        self.connectionWeights=zeros((self.networkSize,self.networkSize))
     
    def delta(self,a,b):
        if a==b:
            return 1
        else: 
            return 0  
        
    def iterate(self):
        initialStates = random.randint(-1, 1, size=self.networkSize )
        self.network.loadInitialState(initialStates)
        self.network.loadConnectionMatrix(self.connectionWeights)
        self.network.iterate()
        self.outputRoute=self.network.neuronStates
        print "\nRoute:"
        print self.outputRoute
        
    def learn(self,distances):
        A=1
        B=1
        C=0.5
        for x in range(0,self.numCities):
            for y in range(0,self.numCities):
                for i in range(0,self.numCities):
                    for j in range(0,self.numCities): 
                        self.connectionWeights[x+i,y+j]=-A*self.delta(x,y)*(1-self.delta(i,j))-B*self.delta(i,j)*(1-self.delta(x,y))-C*self.delta(x,y)*(self.delta(j,i)+self.delta(j,i-1))
        print self.connectionWeights
 def testUpdate(self):
     network = Network(4)
     network.update()
     pass