def setWeights(self, weights): """ Plot the linear regression line for given weights; assuming h_w(x) = weights[0]*x + weights[1]. This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if weights.size >= 2: w = weights[0] b = weights[1] else: w = float(weights) b = 0 # xmin = min(x) # xmax = max(x) # # ymin = w*xmin + b # ymax = w*xmax + b # # point1 = (xmin+self.xShift, ymin+self.yShift) # point2 = (xmax+self.xShift, ymax+self.yShift) (point1, point2) = plotUtil.lineBoxIntersection( w, -1, b, 1 - self.xShift, 1 - self.yShift, self.width - 2 - self.xShift, self.height - 2 - self.yShift) if point1 is not None and point2 is not None: point1 = (point1[0] + self.xShift, point1[1] + self.yShift) point2 = (point2[0] + self.xShift, point2[1] + self.yShift) dx = point2[0] - point1[0] dy = point2[1] - point1[1] if dx == 0: angle = 90 + 180 * dy * 1.0 / abs(dy) else: angle = math.atan(dy * 1.0 / dx) * 180.0 / math.pi if self.line is not None: graphicsUtils.remove_from_screen(self.line) self.line = graphicsUtils.polygon( [self.to_screen(point1), self.to_screen(point2)], LINE_COLOR, filled=0, behind=0) if self.addPacmanToLineStart is True and len(self.agentImages) > 0: # Bring pacman to front of display graphicsUtils._canvas.tag_raise(self.agentImages[0][1][0]) # Put pacman at beginning of line self.movePacman(point1, angle, self.agentImages[0][1]) graphicsUtils.refresh()
def setWeights(self, weights): """ Plot the logistic regression line for given weights This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if weights.size >= 2: w = weights[0] b = weights[1] else: w = float(weights) b = 0 xmin = 1 - self.xShift xmax = self.width - 2 - self.xShift x = np.linspace(xmin, xmax, 30) y = 1.0 / (1 + np.exp(-(w * x + b))) x += self.xShift y += self.yShift if self.line is not None: for obj in self.line: graphicsUtils.remove_from_screen(obj) self.line = [] prevPoint = self.to_screen((x[0], y[0])) for i in xrange(1, len(x)): point = self.to_screen((x[i], y[i])) self.line.append(graphicsUtils.line(prevPoint, point, LINE_COLOR)) prevPoint = point # prevPoint = self.to_screen((x[0],y[0])) # for i in xrange(1,len(x)): # point = self.to_screen((x[i],y[i])) # line.append(graphicsUtils.line(prevPoint, point, LINE_COLOR, filled=0, behind=0) # # prevPoint = point if self.addPacmanToLineStart is True and len(self.agentImages) > 0: # Bring pacman to front of display graphicsUtils._canvas.tag_raise(self.agentImages[0][1][0]) # Put pacman at beginning of line if w >= 0: self.movePacman((x[0] - 0.5, y[0]), Directions.EAST, self.agentImages[0][1]) else: self.movePacman((x[-1] + 0.5, y[-1]), Directions.WEST, self.agentImages[0][1]) graphicsUtils.refresh() graphicsUtils.sleep(1)
def setWeights(self, weights): """ Plot the logistic regression line for given weights This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if weights.size >= 2: w = weights[0] b = weights[1] else: w = float(weights) b = 0 xmin = 1 - self.xShift xmax = self.width-2 - self.xShift x = np.linspace(xmin, xmax,30) y = 1.0/(1+np.exp(-(w*x+b))) x += self.xShift y += self.yShift if self.line is not None: for obj in self.line: graphicsUtils.remove_from_screen(obj) self.line = [] prevPoint = self.to_screen((x[0],y[0])) for i in xrange(1,len(x)): point = self.to_screen((x[i],y[i])) self.line.append(graphicsUtils.line(prevPoint, point, LINE_COLOR)) prevPoint = point # prevPoint = self.to_screen((x[0],y[0])) # for i in xrange(1,len(x)): # point = self.to_screen((x[i],y[i])) # line.append(graphicsUtils.line(prevPoint, point, LINE_COLOR, filled=0, behind=0) # # prevPoint = point if self.addPacmanToLineStart is True and len(self.agentImages) > 0: # Bring pacman to front of display graphicsUtils._canvas.tag_raise(self.agentImages[0][1][0]) # Put pacman at beginning of line if w >= 0: self.movePacman((x[0]-0.5,y[0]), Directions.EAST, self.agentImages[0][1]) else: self.movePacman((x[-1]+0.5,y[-1]), Directions.WEST, self.agentImages[0][1]) graphicsUtils.refresh()
def setWeights(self, weights): """ Plot the linear regression line for given weights; assuming h_w(x) = weights[0]*x + weights[1]. This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if weights.size >= 2: w = weights[0] b = weights[1] else: w = float(weights) b = 0 # xmin = min(x) # xmax = max(x) # # ymin = w*xmin + b # ymax = w*xmax + b # # point1 = (xmin+self.xShift, ymin+self.yShift) # point2 = (xmax+self.xShift, ymax+self.yShift) (point1, point2) = plotUtil.lineBoxIntersection(w, -1, b, 1-self.xShift, 1-self.yShift, self.width-2-self.xShift, self.height-2-self.yShift) if point1 is not None and point2 is not None: point1 = (point1[0]+self.xShift, point1[1]+self.yShift) point2 = (point2[0]+self.xShift, point2[1]+self.yShift) dx = point2[0]-point1[0] dy = point2[1]-point1[1] if dx == 0: angle = 90 + 180*dy*1.0/abs(dy) else: angle = math.atan(dy*1.0/dx)*180.0/math.pi if self.line is not None: graphicsUtils.remove_from_screen(self.line) self.line = graphicsUtils.polygon([self.to_screen(point1), self.to_screen(point2)], LINE_COLOR, filled=0, behind=0) if self.addPacmanToLineStart is True and len(self.agentImages) > 0: # Bring pacman to front of display graphicsUtils._canvas.tag_raise(self.agentImages[0][1][0]) # Put pacman at beginning of line self.movePacman(point1, angle, self.agentImages[0][1]) graphicsUtils.refresh()
def setWeights(self, weights): """ Plot the logistic regression line for given weights This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if self.prev_weights is not None: if np.allclose(self.prev_weights, weights): return False # no line update self.prev_weights = weights.copy() w1 = weights[0] w2 = weights[1] if weights.size >= 3: b = weights[2] else: b = 0 # Line functions # Line where w1*x1 + w2*x2 + b = 0 # x2 = -(w1*x1 + b)/w2 or # x1 = -(w2*x2 + b)/w1 # Figure out where line intersections bounding box around points if w1 == 0 and w2 == 0: return (point1, point2) = plotUtil.lineBoxIntersection( w1, w2, b, 1 - self.xShift, 1 - self.yShift, self.width - 2 - self.xShift, self.height - 2 - self.yShift) if point1 is not None and point2 is not None: point1 = (point1[0] + self.xShift, point1[1] + self.yShift) point2 = (point2[0] + self.xShift, point2[1] + self.yShift) if self.line is not None: graphicsUtils.remove_from_screen(self.line) self.line = graphicsUtils.polygon( [self.to_screen(point1), self.to_screen(point2)], LINE_COLOR, filled=0, behind=0) graphicsUtils.refresh() return True # updated line
def swapImages(self, agentIndex, newState): """ Changes an image from a ghost to a pacman or vis versa (for capture) """ prevState, prevImage = self.agentImages[agentIndex] for item in prevImage: gU.remove_from_screen(item) if newState.isPacman: image = self.drawPacman(newState, agentIndex) self.agentImages[agentIndex] = (newState, image) else: image = self.drawGhost(newState, agentIndex) self.agentImages[agentIndex] = (newState, image) gU.refresh()
def setWeights(self, weights): """ Plot the logistic regression line for given weights This will draw on the existing pacman window with the existing points weights: array or list of 2 values (or if just one value, the bias weight is assumed to be zero). If None, no line is drawn. Default: None """ weights = np.array(weights) if self.prev_weights is not None: if np.allclose(self.prev_weights, weights): return False # no line update self.prev_weights = weights.copy() w1 = weights[0] w2 = weights[1] if weights.size >= 3: b = weights[2] else: b = 0 # Line functions # Line where w1*x1 + w2*x2 + b = 0 # x2 = -(w1*x1 + b)/w2 or # x1 = -(w2*x2 + b)/w1 # Figure out where line intersections bounding box around points if w1 == 0 and w2 == 0: return (point1, point2) = plotUtil.lineBoxIntersection(w1, w2, b, 1-self.xShift, 1-self.yShift, self.width-2-self.xShift, self.height-2-self.yShift) if point1 is not None and point2 is not None: point1 = (point1[0]+self.xShift, point1[1]+self.yShift) point2 = (point2[0]+self.xShift, point2[1]+self.yShift) if self.line is not None: graphicsUtils.remove_from_screen(self.line) self.line = graphicsUtils.polygon([self.to_screen(point1), self.to_screen(point2)], LINE_COLOR, filled=0, behind=0) graphicsUtils.refresh() return True # updated line
def clearExpandedCells(self): if 'expandedCells' in dir(self) and len(self.expandedCells) > 0: for cell in self.expandedCells: gU.remove_from_screen(cell)
def removeCapsule(self, cell, capsuleImages): x, y = cell gU.remove_from_screen(capsuleImages[(x, y)])
def removeFood(self, cell, foodImages): x, y = cell gU.remove_from_screen(foodImages[x][y])
def _remove(obj): parts = Display.partDict[obj] graphicsUtils.remove_from_screen(parts);