def data_acquisition(self,num_of_data_set,rep_data): print 'Training Started' features=[] labels=[] for i in range(num_of_data_set): action = np.random.rand(1, 3) action[0, 0] = (2 * action[0, 0] - 1.0) * 1.0 action[0, 1] = (2 * action[0, 1] - 1.0) * 0.5 action[0, 2] = (2 * action[0, 2] - 1.0) * 0.25 print 'Training for dataset', (i+1) real_robot_action = rospy.ServiceProxy('real_robot', RobotAction) req = RobotActionRequest() req.reset = True resp =real_robot_action(req) for j in range(rep_data): #print 'Rep set',(j+1) f=np.append(np.array(resp.robot_state),action) features.append(f) req = RobotActionRequest() req.reset = False req.action = action.reshape((3)) resp = real_robot_action(req) labels.append(resp.robot_state) features=np.asarray(features) labels=np.asarray(labels) print features print "Acquisition Completed" return features,labels
def get_data(n): # get data set real_robot_action = rospy.ServiceProxy('real_robot', RobotAction) feature = [] label = [] #print(resp_real) #print('------') for k in range(n): req = RobotActionRequest() req.reset = True resp_real = real_robot_action(req) action = numpy.random.rand(1, 3) action[0, 0] = (2 * action[0, 0] - 1.0) * 1.0 action[0, 1] = (2 * action[0, 1] - 1.0) * 0.5 action[0, 2] = (2 * action[0, 2] - 1.0) * 0.25 robsta = resp_real.robot_state robsta = numpy.array(robsta) sfeature = [ robsta[0], robsta[1], robsta[2], robsta[3], robsta[4], robsta[5], action[0, 0], action[0, 1], action[0, 2] ] for i in range(200): #print(sfeature) req = RobotActionRequest() req.reset = False req.action = action.reshape((3)) resp_real = real_robot_action(req) #print(resp_real.robot_state) #print(action) feature.append(sfeature) print(resp_real) label.append(numpy.array(resp_real.robot_state)) #print(label) #rospy.spin() return feature, label
def get_new_state(self, action, k): req = RobotActionRequest() req.reset = True resp = self.robot_new_state(req) for i in range(self.num_steps): req = RobotActionRequest() req.reset = False req.action = action.reshape((3)) resp = self.robot_new_state(req) self.train_data_matrix[k, i, 6:9] = action.reshape((3)) self.train_data_matrix[k, i, 9:15] = resp.robot_state time.sleep(0.01) self.train_data_matrix[k, 1:self.num_steps, 0:6] = self.train_data_matrix[k, 0:self.num_steps - 1, 9:15]
def single_test(self, action): req = RobotActionRequest() req.reset = True # send request to reset resp = self.get_action(req) for i in range(self.num_steps): req = RobotActionRequest() req.reset = False req.action = action # get training data self.features.append((np.append(resp.robot_state, req.action)).tolist()) # send request to move real_robot resp = self.get_action(req) self.labels.append(resp.robot_state)
def single_test(self, action): req = RobotActionRequest() req.reset = True resp = self.real_robot_action(req) resp = self.fake_robot_action(req) for i in range(self.num_steps): req = RobotActionRequest() req.reset = False req.action = action.reshape((3)) resp_real = self.real_robot_action(req) message = RobotState() message.robot_name = str('real_robot') message.robot_state = resp_real.robot_state self.pub.publish(message) resp_fake = self.fake_robot_action(req) message = RobotState() message.robot_name = str('fake_robot') message.robot_state = resp_fake.robot_state self.pub.publish(message) #time.sleep(0.01) return self.score_state(resp_real.robot_state, resp_fake.robot_state)
def perturb(self, action): req_real = RobotActionRequest() req_real.reset = True # send request to reset real_robot config resp_real = self.real_robot_action(req_real) collect_interval = 1 # how many steps we skip # apply a constant action for j in range(self.perturb_steps): # create a new request req_real = RobotActionRequest() req_real.reset = False req_real.action = action is_collected = j % collect_interval == 0 if is_collected: # collect feature self.features.append( np.append(resp_real.robot_state, req_real.action).tolist()) # send request to move real_robot resp_real = self.real_robot_action(req_real) if is_collected: # collect label self.labels.append(resp_real.robot_state)
def training_data(self): #get the data to train fake robot n = 0 for k in range(0, self.num_random_tests): action = np.random.rand(1, 3) action[0, 0] = (2 * action[0, 0] - 1.0) * 1.0 action[0, 1] = (2 * action[0, 1] - 1.0) * 0.5 action[0, 2] = (2 * action[0, 2] - 1.0) * 0.25 req_real = RobotActionRequest() req_real.reset = True resp = self.real_robot_action(req_real) self.data_fea[k * self.num_steps, 0:6] = np.array(resp.robot_state) print(k) for i in range(self.num_steps): req_real = RobotActionRequest() req_real.reset = False req_real.action = action.reshape((3)) resp_real = self.real_robot_action(req_real) self.data_fea[n, 6:9] = req_real.action self.label[n] = resp_real.robot_state n += 1 self.data_fea[n, 0:6] = resp_real.robot_state print('trainning finished') self.data_fea = np.delete(self.data_fea, -1, axis=0)