def interpolate_digits(model, mnist): imgs, labels = mnist.train.next_batch(100) idxs = np.random.randint(0, imgs.shape[0] - 1, 2) mus, _ = model.encode(np.vstack(imgs[i] for i in idxs)) plot.interpolate(model, *mus, name="interpolate_{}->{}".format(*(labels[i] for i in idxs)), outdir=PLOTS_DIR)
def plot_exercise_from_db(exId, exerciseCode, sensorType=ACCELEROMETER_CODE): conn = sqlite3.connect(path + "merged_ankle") c = conn.cursor() c.execute( 'SELECT * FROM {tn} WHERE exercise_id={exid} AND sensor_type={st}'. format(tn=READINGS_TABLE_NAME, st=sensorType, exid=exId)) table = np.array(c.fetchall()) if table.size == 0: return None values = table[:, READING_VALUES] # extract reps reps = table[:, 6] rep_starts = np.zeros([reps.shape[0], 1]) for i in range(0, reps.shape[0] - 1): if reps[i] != reps[i + 1] or i == 0: rep_starts[i] = True # print(rep_starts) sensorReadingData = np.zeros( [np.shape(values)[0], SENSOR_TO_VAR_COUNT[sensorType]]) i = 0 for reading in values: vals = np.array(reading.split(" ")) vals = vals.astype(np.float) sensorReadingData[i] = vals i = i + 1 # print(sensorReadingData[:, 0]) timestamps = table[:, 4].astype("int64") timestamps = timestamps - timestamps[0] plt.figure() plt.suptitle(EXERCISE_CODES_TO_NAME[exerciseCode] + " " + SENSOR_TO_NAME[sensorType] + " " + str(exId), fontsize=13) plt.subplot(3, 1, 1) plt.xticks(np.arange(min(timestamps), max(timestamps) + 1, 1000)) plt.ylabel('x') addRepSeparators(plt, rep_starts, timestamps) plt.plot(timestamps, sensorReadingData[:, 0], 'r-') plt.subplot(3, 1, 2) plt.ylabel('y') plt.xticks(np.arange(min(timestamps), max(timestamps) + 1, 1000)) addRepSeparators(plt, rep_starts, timestamps) # resampling interpol = interpolate(timestamps, sensorReadingData[:, 1]) plt.plot(interpol['x'], interpol['y'], 'b-') # plt.plot(timestamps, sensorReadingData[:, 1], 'b-') # plt.plot(timestamps, smooth(sensorReadingData[:, 1], 40), 'b--') plt.subplot(3, 1, 3) plt.ylabel('z') plt.xticks(np.arange(min(timestamps), max(timestamps) + 1, 1000)) addRepSeparators(plt, rep_starts, timestamps) plt.plot(timestamps, sensorReadingData[:, 2], 'g-') return plt