def evaluate(self, p, sim, plt): start_time = time.time() while time.time() - start_time < p.T: sim.run(p.dt, progress_bar=False) #sim.run(p.T) self.link.write(self.path + 'duty_cycle_sp', '0') if plt is not None: plt.plot(sim.data[self.p_t], sim.data[self.p_desired]) plt.plot(sim.data[self.p_t], sim.data[self.p_q]) #plt.plot(sim.data[self.p_t], sim.data[self.p_u]) rate = len(sim.data[self.p_t]) / float(p.T) q = sim.data[self.p_q][:,0] d = sim.data[self.p_desired][:,0] t = sim.data[self.p_t][:,0] offset = benchmark.find_offset(q, d) #offset = 1 delay = np.mean(t[offset:]-t[:-offset]) diff = d[:-offset] - q[offset:] N = len(q) / 2 diff = diff[N:] rmse = np.sqrt(np.mean(diff**2)) return dict(rate=rate, delay=delay, rmse=rmse)
def evaluate(self, p, sim, plt): #start_time = time.time() #while time.time() - start_time < p.T: # sim.run(p.dt, progress_bar=False) sim.run(p.T) #q = sim.data[self.p_q][:,0] q = np.array(self.system_state)[:,0] d = np.array(self.system_desired)[:,0] t = np.array(self.system_times) N = len(q) / 2 # find an offset that lines up the data best (this is the delay) offsets = [] for i in range(p.D): #q = sim.data[self.p_q][:,i] q = np.array(self.system_state)[:,i] d = np.array(self.system_desired)[:,i] offset = benchmark.find_offset(q[N:], d[N:]) if offset == 0: offset = 1 offsets.append(offset) offset = int(np.mean(offsets)) delay = np.mean(t[offset:]-t[:-offset]) spinn_dt = np.mean(t[1:]-t[:-1]) if plt is not None: plt.plot(t[offset:], d[:-offset], label='$q_d$') #plt.plot(t[offset:], d[offset:]) t2 = self.system_times plt.plot(t2[offset:], q[offset:], label='$q$') plt.legend(loc='upper left') #plt.plot(np.correlate(d, q, 'full')[len(q):]) diff = np.array(self.system_desired)[:-offset] - np.array(self.system_state)[offset:] diff = diff[N:] rmse = np.sqrt(np.mean(diff.flatten()**2)) return dict(delay=delay, rmse=rmse, spinn_dt=spinn_dt)