def evaluate_pfmce(self, evaluate_emg=True): print "Evaluating performance...." # if not self.mdp: # print "No MDP found" # self.history = [] # return #action_classifier = pickle.load(open('../data/action_classifier.pkl')) history = np.array(self.history) print "raw history shape:", history.shape history = history[5:-6:5, :] # downsampling, cut the first half second print "saved history: ", history.shape if history.shape[0]> 35: history = savgol_filter(history, 31, 3, axis=0) # smoothing np.savetxt('user_data/' + self.user_id, history, delimiter=',') evaluator = Evaluator() emg_l = history[:,0:8] / EMG_WEIGHT emg_u = history[:,18:26] / EMG_WEIGHT ort_l = history[:,14:18] ort_u = history[:,-4:] # plt.figure() # plt.plot(evaluator.ort_l) # plt.figure() # plt.plot(align_signal(evaluator.ort_l, ort_l, has_time=False)) # plt.show(block=True) (diff_emg_l, cost) = dtw_distance(evaluator.emg_l, emg_l) (diff_emg_u, _) = dtw_distance(evaluator.emg_u, emg_u) (diff_ort_l, _) = dtw_distance(evaluator.ort_l, ort_l) (diff_ort_u, _) = dtw_distance(evaluator.ort_u, ort_u) print "difference cost, alignment cost" print (diff_emg_l, cost) print diff_emg_u print diff_ort_l print diff_ort_u if evaluate_emg: EMG_FACTOR = 0.08 else: EMG_FACTOR = 0 ORT_FACTOR = 0.25 TIME_FACTOR = 0.05 performance = 100 * math.exp(-EMG_FACTOR*(diff_emg_l+diff_emg_u) \ - ORT_FACTOR*(diff_ort_l+diff_ort_u) \ - TIME_FACTOR*cost) - 8*self.n_prompts print performance self.score_pub.publish(int(performance)) with open(self.logfile, 'a') as f: f.write('performance score: %f\n' %performance)
def evaluate_pfmce(self, evaluate_emg=True): print "Evaluating performance...." # if not self.mdp: # print "No MDP found" # self.history = [] # return #action_classifier = pickle.load(open('../data/action_classifier.pkl')) history = np.array(self.history) print "raw history shape:", history.shape history = history[5:-6:5, :] # downsampling, cut the first half second print "saved history: ", history.shape if history.shape[0] > 35: history = savgol_filter(history, 31, 3, axis=0) # smoothing np.savetxt('user_data/' + self.user_id, history, delimiter=',') evaluator = Evaluator() emg_l = history[:, 0:8] / EMG_WEIGHT emg_u = history[:, 18:26] / EMG_WEIGHT ort_l = history[:, 14:18] ort_u = history[:, -4:] # plt.figure() # plt.plot(evaluator.ort_l) # plt.figure() # plt.plot(align_signal(evaluator.ort_l, ort_l, has_time=False)) # plt.show(block=True) (diff_emg_l, cost) = dtw_distance(evaluator.emg_l, emg_l) (diff_emg_u, _) = dtw_distance(evaluator.emg_u, emg_u) (diff_ort_l, _) = dtw_distance(evaluator.ort_l, ort_l) (diff_ort_u, _) = dtw_distance(evaluator.ort_u, ort_u) print "difference cost, alignment cost" print(diff_emg_l, cost) print diff_emg_u print diff_ort_l print diff_ort_u if evaluate_emg: EMG_FACTOR = 0.08 else: EMG_FACTOR = 0 ORT_FACTOR = 0.25 TIME_FACTOR = 0.05 performance = 100 * math.exp(-EMG_FACTOR*(diff_emg_l+diff_emg_u) \ - ORT_FACTOR*(diff_ort_l+diff_ort_u) \ - TIME_FACTOR*cost) - 8*self.n_prompts print performance self.score_pub.publish(int(performance)) with open(self.logfile, 'a') as f: f.write('performance score: %f\n' % performance)
def evaluate_pfmce(self, evaluate_emg=True): print "Evaluating performance...." history = np.array(self.history) print "raw history shape:", history.shape #history = history[25:-6:5, :] # downsampling, cut the first half second history = history[5:-6:5, :] # downsampling, cut the first half second print "saved history: ", history.shape if history.shape[0]> 35: history = savgol_filter(history, 31, 3, axis=0) # smoothing np.savetxt('user_data/' + self.user_id, history, delimiter=',') evaluator = Evaluator() emg_l = history[:,0:8] / EMG_WEIGHT emg_u = history[:,18:26] / EMG_WEIGHT ort_l = history[:,14:18] ort_u = history[:,-4:] (diff_emg_l, cost) = dtw_distance(evaluator.emg_l, emg_l) (diff_emg_u, _) = dtw_distance(evaluator.emg_u, emg_u) (diff_ort_l, _) = dtw_distance(evaluator.ort_l, ort_l) (diff_ort_u, _) = dtw_distance(evaluator.ort_u, ort_u) print "difference cost, alignment cost" print (diff_emg_l, cost) print diff_emg_u print diff_ort_l print diff_ort_u if evaluate_emg: EMG_FACTOR = 0.08 else: EMG_FACTOR = 0 ORT_FACTOR = 0.25 TIME_FACTOR = 0.05 performance = 100 * math.exp(-EMG_FACTOR*(diff_emg_l+diff_emg_u) \ - ORT_FACTOR*(diff_ort_l+diff_ort_u) \ - TIME_FACTOR*cost) - 8*self.n_prompts print performance with open(self.logfile, 'a') as f: f.write('performance score: %f\n' %performance)
def evaluate_pfmce(self, evaluate_emg=True): print "Evaluating performance...." history = np.array(self.history) print "raw history shape:", history.shape #history = history[25:-6:5, :] # downsampling, cut the first half second history = history[5:-6:5, :] # downsampling, cut the first half second print "saved history: ", history.shape if history.shape[0] > 35: history = savgol_filter(history, 31, 3, axis=0) # smoothing np.savetxt('user_data/' + self.user_id, history, delimiter=',') evaluator = Evaluator() emg_l = history[:, 0:8] / EMG_WEIGHT emg_u = history[:, 18:26] / EMG_WEIGHT ort_l = history[:, 14:18] ort_u = history[:, -4:] (diff_emg_l, cost) = dtw_distance(evaluator.emg_l, emg_l) (diff_emg_u, _) = dtw_distance(evaluator.emg_u, emg_u) (diff_ort_l, _) = dtw_distance(evaluator.ort_l, ort_l) (diff_ort_u, _) = dtw_distance(evaluator.ort_u, ort_u) print "difference cost, alignment cost" print(diff_emg_l, cost) print diff_emg_u print diff_ort_l print diff_ort_u if evaluate_emg: EMG_FACTOR = 0.08 else: EMG_FACTOR = 0 ORT_FACTOR = 0.25 TIME_FACTOR = 0.05 performance = 100 * math.exp(-EMG_FACTOR*(diff_emg_l+diff_emg_u) \ - ORT_FACTOR*(diff_ort_l+diff_ort_u) \ - TIME_FACTOR*cost) - 8*self.n_prompts print performance with open(self.logfile, 'a') as f: f.write('performance score: %f\n' % performance)