def get_drawing_coords(self): '''No Args => array return a 2Nx3 (or 2Nx4) array containing the start and stop coordinates for each frustum specified in self.points.''' points =self.getPoints() s = points.shape points = concatenate([points, points],1) points = reshape(points, (-1, s[1]))[1:-1] return points
def record(self, c, f): '''Writes a chromosome and the fitness value to the arraystore. Not thread safe! (self.lockcall(self.record, (c,f)) is thread safe). f should be a tuple (fit, evalconditions) as returned by general_eval. Return value is the new size of the data store''' if self.attrib('EvalConditions'): evc = int(self.attrib('EvalConditions')) evc=zeros((evc, 1)) if f[1] and type(f[1])==type(evc): c=concatenate([[f[0]], f[1], c]) else: c=concatenate([[f[0]], evc, c]) else: c=concatenate([[f[0]], c]) if self._storesize!=c.shape[0]: raise IOError("Attempt to record a parameter set of the wrong length") n=self._store.append(c) #print self._store[n-1] if self.better(f[0], self._best[0]): print "New best %.3f (%s)" % (f[0], str(c)) self._best=(f[0], n-1) return n
def add_point(a, p): if a.shape[1]>len(p): p2 = zeros(a.shape[1], p.dtype.char) p2[:len(p)]=p p=p2 elif a.shape[1]<len(p): a2=zeros((a.shape[0]+1, len(p)), a.dtype.char) a2[:-1,:a.shape[1]]=a a2[-1]=p return a2 return concatenate([a, p[NewAxis, :]])
def setPoints(self, a, append=None): '''a (array), append (bool=False) => None sets self.points to the specified array. If append is true, it adds this array to the existing self.points''' if type(a)!=ArrayType: a=array(a, Float32) if not append or self.points==None or self.points.shape[0]==0: if len(a.shape)==1: a=array([a]) self.points = a.copy() else: if len(a.shape)==2: self.points = concatenate([self.points, a]) else: self.points = add_point(self.points, a)
def init_local_vars(self): self._cached=0 self._size=self._params.size() self._strides=cumproduct(concatenate([[1], self._params._bins])[:-1])