|
158 | 158 | "# TODO: Extract a numpy array containing the rows for the fourth snap performed by subject three.\n", |
159 | 159 | "# Hint: You can apply three different boolean filters to whittle down the data set, \n", |
160 | 160 | "# use np.all() to combine the filters into one filter, or use logical and.\n", |
| 161 | + "\n", |
| 162 | + "# Reminder to use the variable snap_id (defined above) when searching for rows that are snaps\n", |
| 163 | + "\n", |
161 | 164 | "s3s4_snap_data = ..." |
162 | 165 | ] |
163 | 166 | }, |
|
197 | 200 | }, |
198 | 201 | "outputs": [], |
199 | 202 | "source": [ |
200 | | - "# TODO: Copy get_descriptor and get_channel_data from lab 2.\n" |
| 203 | + "# TODO: Copy the function get_channel_data from lab 2.\n" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": null, |
| 209 | + "metadata": { |
| 210 | + "tags": [] |
| 211 | + }, |
| 212 | + "outputs": [], |
| 213 | + "source": [ |
| 214 | + "# TODO: Copy the function get_descriptor from lab 2.\n" |
201 | 215 | ] |
202 | 216 | }, |
203 | 217 | { |
|
208 | 222 | }, |
209 | 223 | "outputs": [], |
210 | 224 | "source": [ |
211 | | - "# RMS: sqrt(sum_x x^2)\n", |
212 | | - "def rms(array):\n", |
213 | | - " \"\"\" Calculate the root mean square of each row in array.\n", |
214 | | - " @param array - A 2-dimensional numpy array\n", |
215 | | - " @return A 1-dimensional numpy array containing the RMS of each row in the array.\n", |
| 225 | + "# definition of RMS (Root Mean Squared): sqrt( mean(sum_x x^2) )\n", |
| 226 | + "def rms(in_data):\n", |
| 227 | + " \"\"\" Calculate the root mean square of each row in in_data.\n", |
| 228 | + " @param in_data - A 2-dimensional numpy array\n", |
| 229 | + " @return A 1x number of columns in in_data numpy array containing the RMS of each row in the array.\n", |
216 | 230 | " \"\"\"\n", |
217 | | - " # TODO: Write this function.\n", |
| 231 | + " # TODO: Fill in this function.\n", |
218 | 232 | " # Hint: Use numpy functions to operate on the entire array at once rather than\n", |
219 | 233 | " # iterate through each row.\n", |
220 | 234 | " pass" |
|
229 | 243 | "outputs": [], |
230 | 244 | "source": [ |
231 | 245 | "# Check that the rms function works as expected\n", |
232 | | - "test_array = np.array([[1,2,3], [4,5,6]])\n", |
| 246 | + "test_array = np.array([[1, 2, 3], [4, 5, 6]])\n", |
| 247 | + "\n", |
| 248 | + "# Calculation for first row (reminder, mean is sum of values divided by number of values)\n", |
| 249 | + "first_row_rms = np.sqrt((1 * 1 + 2 * 2 + 3 * 3) / 3)\n", |
| 250 | + "\n", |
233 | 251 | "test_array_rms = rms(test_array)\n", |
234 | | - "assert(np.isclose(test_array_rms[0], 2.1602469))\n", |
| 252 | + "assert(np.isclose(test_array_rms[0], first_row_rms))\n", |
235 | 253 | "assert(np.isclose(test_array_rms[1], 5.06622805))" |
236 | 254 | ] |
237 | 255 | }, |
|
292 | 310 | " pass" |
293 | 311 | ] |
294 | 312 | }, |
| 313 | + { |
| 314 | + "cell_type": "code", |
| 315 | + "execution_count": null, |
| 316 | + "metadata": { |
| 317 | + "tags": [] |
| 318 | + }, |
| 319 | + "outputs": [], |
| 320 | + "source": [ |
| 321 | + "# TODO Write a test function. Call filter_data_set with the values for s3s4_snap_data,\n", |
| 322 | + "# i.e., subject number 3, run number 4, snap data\n", |
| 323 | + "# And check that the resulting data is the same as s3s4_snap_data\n", |
| 324 | + "\n", |
| 325 | + "foo = filter_data_set(full_dataset, 3, 4, snap_id)" |
| 326 | + ] |
| 327 | + }, |
295 | 328 | { |
296 | 329 | "cell_type": "code", |
297 | 330 | "execution_count": null, |
|
362 | 395 | }, |
363 | 396 | "outputs": [], |
364 | 397 | "source": [ |
365 | | - "# Find peak and valley of z axis of the right hand accelerometer in s3s4_snap_data\n", |
| 398 | + "# TODO Find peak and valley of z axis of the right hand accelerometer in s3s4_snap_data\n", |
366 | 399 | "# Hint: You can use get_channel_data to extract just the rh accelerometer channel from s3s4_snap_data.\n", |
367 | 400 | "\n", |
368 | 401 | "s3s4_snap_rh_accelerometer_data = ...\n", |
|
459 | 492 | }, |
460 | 493 | "outputs": [], |
461 | 494 | "source": [ |
462 | | - "# Here, graph the data\n", |
| 495 | + "# Plot size\n", |
463 | 496 | "nrows = 3\n", |
464 | 497 | "ncols = 2\n", |
465 | 498 | "fig, axs = plt.subplots(nrows, ncols, figsize=(6, 8))\n", |
466 | 499 | "\n", |
| 500 | + "# TODO: Make the plot\n", |
467 | 501 | "# Put left hand in the first column, right hand in the second column.\n", |
468 | 502 | "# Hint: To use plot_function with your new \"rms\" data channel, you will need to make a\n", |
469 | 503 | "# dictionary for its descriptor with \"name\" and \"units\" entries.\n", |
| 504 | + "# Note: The time values in the plots in the slides are divided by 1,000\n", |
470 | 505 | "\n", |
471 | | - "fig.tight_layout()" |
| 506 | + "fig.tight_layout()\n", |
| 507 | + "plt.plot()" |
472 | 508 | ] |
473 | 509 | }, |
474 | 510 | { |
|
517 | 553 | }, |
518 | 554 | "outputs": [], |
519 | 555 | "source": [ |
| 556 | + "# TODO Put any additional functions you want here" |
| 557 | + ] |
| 558 | + }, |
| 559 | + { |
| 560 | + "cell_type": "code", |
| 561 | + "execution_count": null, |
| 562 | + "metadata": { |
| 563 | + "tags": [] |
| 564 | + }, |
| 565 | + "outputs": [], |
| 566 | + "source": [ |
| 567 | + "# TODO: Write a function that analyzes the data and returns the id of the one\n", |
| 568 | + "# it guesses\n", |
520 | 569 | "def guess_motion_type(lh_accelerometer_rms, rh_accelerometer_rms):\n", |
521 | 570 | " \"\"\" Guesses the motion that the subject is performing given the RMS of the user's left hand and right hand accelerometers.\n", |
522 | 571 | " @param lh_accelerometer_rms - RMS of the left hand accelerometer\n", |
523 | 572 | " @param rh_accelerometer_rms - RMS of the right hand accelerometer\n", |
524 | 573 | " @return The motion ID of the motion the user was most likely performing.\n", |
525 | 574 | " \"\"\"\n", |
526 | | - " pass" |
| 575 | + " pass\n" |
| 576 | + ] |
| 577 | + }, |
| 578 | + { |
| 579 | + "cell_type": "code", |
| 580 | + "execution_count": null, |
| 581 | + "metadata": { |
| 582 | + "tags": [] |
| 583 | + }, |
| 584 | + "outputs": [], |
| 585 | + "source": [ |
| 586 | + "# TODO: Write some tests here to check that you have the \"right\" answer\n", |
| 587 | + "# i.e., if you give it snap data it should return snap (for at least some of the snap data)" |
527 | 588 | ] |
528 | 589 | }, |
529 | 590 | { |
|
534 | 595 | }, |
535 | 596 | "outputs": [], |
536 | 597 | "source": [ |
537 | | - "# Test code\n", |
| 598 | + "# example test code\n", |
538 | 599 | "s3s4_snap_lh_accelerometer_data = get_channel_data(s3s4_snap_data, index_offset=lh_accelerometer_descriptor[\"index_offset\"], n_dims=lh_accelerometer_descriptor[\"dimensions\"])\n", |
539 | 600 | "\n", |
540 | 601 | "assert(snap_id == guess_motion_type(rms(s3s4_snap_lh_accelerometer_data), rms(s3s4_snap_rh_accelerometer_data)))" |
|
561 | 622 | "source": [ |
562 | 623 | "## Week 3, problem 3: Calculate accuracy of your heuristic\n", |
563 | 624 | "\n", |
564 | | - "You now have a function that guesses the motion type for a given motion, and we have ground truth labels for what motions the subjects are performing. Let's calculate the accuracy of your heuristic.\n", |
| 625 | + "You now have a function that guesses the motion type for a given motion, and we have ground truth labels for what motions the subjects are performing. Let's calculate the accuracy of your heuristic using this function!\n", |
565 | 626 | "\n", |
566 | | - "The data set contains 10 subjects (1 through 10) that perform 10 runs (1 through 10) of each motion type (snap, high five, and clap). You can write nested loops to iterate through each of these and guess the motion type.\n", |
| 627 | + "The data set contains 10 subjects (1 through 10) that perform 10 runs (1 through 10) of each motion type (snap, high five, and clap). You can use three nested for loops (one for participant number, one for run number, one for motion ID) to iterate through each of the motion observations and guess the motion type.\n", |
567 | 628 | "\n", |
568 | 629 | "We expect to see accuracies above 75%, and accuracies above 90% are possible." |
569 | 630 | ] |
|
0 commit comments