def get_true_values(self): true_values = [] in_front = peak.isWallInFront(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) true_values.append([in_front]) on_left = peak.isWallOnLeft(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) on_right = peak.isWallOnRight(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) true_values.append([on_left, on_right]) return true_values
def get_true_values(self): true_values = [] in_front = peak.isWallInFront(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) true_values.append([in_front]) on_left = peak.isWallOnLeft(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) on_right = peak.isWallOnRight(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) true_values.append([on_left, on_right]) is_behind = peak.isWallBehind(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) wall_adjacent = peak.isWallAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_to_adjacent = peak.distanceToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_left = peak.distanceLeftToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_right = peak.distanceRightToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_back = peak.distanceBehindToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) wall_left_forward = peak.wallLeftForward(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) return true_values
def update_ui(self, action): """Re-draws the UI Args: action (int): the action taken this time-step. """ # Create a voronoi image if self.state: frame = self.state['visionData'] if self.show_display: voronoi = voronoi_from_pixels( pixels=frame, dimensions=(WIDTH, HEIGHT), pixelsOfInterest=self.network.layers[0]. function_approximation.pointsOfInterest) # cv2.imshow('My Image', voronoi) # cv2.waitKey(0) if self.state is False: # todo: should be None for first val, not bool. did_touch = False else: did_touch = self.state['touchData'] # find the ground truth of the predictions. in_front = peak.isWallInFront(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) on_left = peak.isWallOnLeft(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) on_right = peak.isWallOnRight(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) is_behind = peak.isWallBehind(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) wall_adjacent = peak.isWallAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_to_adjacent = peak.distanceToAdjacent( self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_left = peak.distanceLeftToAdjacent( self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_right = peak.distanceRightToAdjacent( self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) distance_back = peak.distanceBehindToAdjacent( self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) wall_left_forward = peak.wallLeftForward(self.state['x'], self.state['y'], self.state['yaw'], self.grid_world) # get the most recent predictions touch_prediction = self.network.layers[0].last_prediction[0] turn_left_and_touch_prediction = self.network.layers[ 1].last_prediction[0] # turn_left_and_touch_prediction = 0 turn_right_and_touch_prediction = self.network.layers[ 1].last_prediction[1] # turn_right_and_touch_prediction = 0 # unimplemented, so zero... touch_behind_prediction = 0 is_wall_adjacent_prediction = 0 distance_to_adjacent_prediction = 0 distance_left_prediction = 0 distance_right_prediction = 0 distance_back_prediction = 0 wall_left_forward_prediction = 0 game_image = Image.frombytes('RGB', (WIDTH, HEIGHT), bytes(frame)) if self.show_display: if self.action_count > self.steps_before_updating_display: self.display.update( voronoiImage=voronoi, gameImage=game_image, numberOfSteps=self.action_count, currentTouchPrediction=touch_prediction, wallInFront=in_front, didTouch=did_touch, turnLeftAndTouchPrediction= turn_left_and_touch_prediction, wallOnLeft=on_left, turnRightAndTouchPrediction= turn_right_and_touch_prediction, touchBehindPrediction=touch_behind_prediction, wallBehind=is_behind, touchAdjacentPrediction=is_wall_adjacent_prediction, wallAdjacent=wall_adjacent, wallOnRight=on_right, distanceToAdjacent=distance_to_adjacent, distanceToAdjacentPrediction= distance_to_adjacent_prediction, distanceToLeft=distance_left, distanceToLeftPrediction=distance_left_prediction, distanceToRight=distance_right, distanceToRightPrediction=distance_right_prediction, distanceBack=distance_back, distanceBackPrediction=distance_back_prediction, wallLeftForward=wall_left_forward, wallLeftForwardPrediction=wall_left_forward_prediction, action=action)
def updateUI(self): # Create a voronoi image frameError = False try: frame = self.state['visionData'] except: frameError = True print("Error gettnig frame") if not frameError: # rgb = self.s if self.showDisplay: voronoi = voronoi_from_pixels(pixels=frame, dimensions=(WIDTH, HEIGHT), pixelsOfInterest=self.stateRepresentation.pointsOfInterest) # cv2.imshow('My Image', voronoi) # cv2.waitKey(0) if self.state == False: didTouch = False else: didTouch = self.state['touchData'] inFront = peak.isWallInFront(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) touchPrediction = self.gvfs['T'].prediction(self.phi) gameImage = Image.frombytes('RGB', (WIDTH, HEIGHT), bytes(frame)) ''' #For debugging previousInFront = peak.isWallInFront(self.oldState['x'], self.oldState['y'], self.oldState['yaw'], self.gridWorld) previousTouchPrediction = self.gvfs['T'].prediction(self.oldPhi) if not previousInFront and previousTouchPrediction > 0.0: print("Bad first learning. ") print("Last action: " + self.action) msg = self.oldState.observations[0].text observations = json.loads(msg) # and parse the JSON yaw = observations.get(u'Yaw', 0) x = observations.get(u'XPos', 0) z = observations.get(u'ZPos', 0) print("From: " + str(yaw) + ", " + str(x) + ", " + str(z)) msg = self.state.observations[0].text observations = json.loads(msg) # and parse the JSON yaw = observations.get(u'Yaw', 0) x = observations.get(u'XPos', 0) z = observations.get(u'ZPos', 0) print("To: " + str(yaw) + ", " + str(x) + ", " + str(z)) ph = self.stateRepresentation.getPhi(previousPhi = self.oldPhi, state=self.state, previousAction=self.action, simplePhi = USE_SIMPLE_PHI) idx = np.nonzero(ph)[0][0] numNonZeros = len(np.nonzero(ph)[0]) print("idx: " + str(idx) + ", nonZeros: " + str(numNonZeros)) print("Observations since last:" + str(self.state.number_of_observations_since_last_state)) print("") ''' onLeft = peak.isWallOnLeft(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) turnLeftAndTouchPrediction = self.gvfs['TL'].prediction(self.phi) onRight = peak.isWallOnRight(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) turnRightAndtouchPrediction = self.gvfs['TR'].prediction(self.phi) isBehind = peak.isWallBehind(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) touchBehindPrediction = self.gvfs['TB'].prediction(self.phi) wallAdjacent = peak.isWallAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) isWallAdjacentPrediction = self.gvfs['TA'].prediction(self.phi) distanceToAdjacent = peak.distanceToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) distanceToAdjacentPrediction = self.gvfs['DTA'].prediction(self.phi) distanceLeft = peak.distanceLeftToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) distanceLeftPrediction = self.gvfs['DTL'].prediction(self.phi) distanceRight = peak.distanceRightToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) distanceRightPrediction = self.gvfs['DTR'].prediction(self.phi) distanceBack = peak.distanceBehindToAdjacent(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) distanceBackPrediction = self.gvfs['DTB'].prediction(self.phi) wallLeftForward =peak.wallLeftForward(self.state['x'], self.state['y'], self.state['yaw'], self.gridWorld) wallLeftForwardPrediction = self.gvfs['WLF'].prediction(self.phi) if self.showDisplay: if self.actionCount > self.stepsBeforeUpdatingDisplay: self.display.update(voronoiImage=voronoi, gameImage = gameImage, numberOfSteps=self.actionCount, currentTouchPrediction=touchPrediction, wallInFront=inFront, didTouch=didTouch, turnLeftAndTouchPrediction=turnLeftAndTouchPrediction, wallOnLeft=onLeft, turnRightAndTouchPrediction=turnRightAndtouchPrediction, touchBehindPrediction = touchBehindPrediction, wallBehind = isBehind, touchAdjacentPrediction=isWallAdjacentPrediction, wallAdjacent=wallAdjacent, wallOnRight=onRight, distanceToAdjacent = distanceToAdjacent, distanceToAdjacentPrediction = distanceToAdjacentPrediction, distanceToLeft = distanceLeft, distanceToLeftPrediction = distanceLeftPrediction, distanceToRight = distanceRight, distanceToRightPrediction = distanceRightPrediction, distanceBack = distanceBack, distanceBackPrediction = distanceBackPrediction, wallLeftForward = wallLeftForward, wallLeftForwardPrediction = wallLeftForwardPrediction )