def train(self,X): self.present_input(X) wy,wx = self.winner_coords() self.debug("Winner coords = "+`(wy,wx)`) int_radius = floor(self.radius()) self.debug("Training radius = %.2f" % self.radius()) ymin = max(0,wy-int_radius) ymax = min(wy+int_radius,self.ydim-1) xmin = max(0,wx-int_radius) xmax = min(wx+int_radius,self.xdim-1) self.debug('y range = '+`(ymin,ymax)`) self.debug('x range = '+`(xmin,xmax)`) for y in range(ymin,ymax+1): for x in range(xmin,xmax+1): lattice_dist = sqrt((wx-x)**2 + (wy-y)**2) self.debug("Trying cell %d,%d"%(x,y)) if lattice_dist <= self.radius(): self.debug("Training cell %d,%d"%(x,y)) rate = self.alpha() * gaussian(lattice_dist,self.radius()) self.weights[y,x] += rate * (X - self.weights[y,x]) self.count += 1
def gaussian_activation(self): x = self.dists radii = zeros(self.dists.shape) * 0.0 for u,conn_dict in enumerate(self.connections): neighbors = take(self.weights,conn_dict.keys()) radii[u] = average(matrixnorm(neighbors-self.weights[u])) self.__activation = gaussian(x,radii/2)
def gaussian_activation(self): x = self.dists radii = zeros(self.dists.shape) * 0.0 for u, conn_dict in enumerate(self.connections): neighbors = take(self.weights, conn_dict.keys()) radii[u] = average(matrixnorm(neighbors - self.weights[u])) self.__activation = gaussian(x, radii / 2)
def uniform_gaussian_activation(self): x = self.dists total = 0.0 count = 0 for u,conn_dict in enumerate(self.connections): neighbors = take(self.weights,conn_dict.keys()) total += sum(matrixnorm(neighbors-self.weights[u])) count += len(conn_dict) self.__activation = gaussian(x,(total/count)/2)
def uniform_gaussian_activation(self): x = self.dists total = 0.0 count = 0 for u, conn_dict in enumerate(self.connections): neighbors = take(self.weights, conn_dict.keys()) total += sum(matrixnorm(neighbors - self.weights[u])) count += len(conn_dict) self.__activation = gaussian(x, (total / count) / 2)