Skip to content

Commit 503300a

Browse files
committed
New download for spring 2025, first draft
1 parent cbdd149 commit 503300a

29 files changed

Lines changed: 764 additions & 878 deletions

‎Week_0_python/Intro_assignment.ipynb‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,14 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 2,
40-
"metadata": {},
41-
"outputs": [],
42-
"source": [
43-
"# Safety check - if you did not install numpy or otter-grader correctly this should do it for you\n",
44-
"# If you have installed everything already, it should spit out a bunch of \"requirement already satisfied\" messages\n",
45-
"import sys\n",
46-
"!{sys.executable} -m pip install numpy\n",
47-
"!{sys.executable} -m pip install otter-grader"
48-
]
49-
},
50-
{
51-
"cell_type": "code",
52-
"execution_count": 3,
39+
"execution_count": null,
5340
"metadata": {},
5441
"outputs": [],
5542
"source": [
5643
"# Doing the imports for you\n",
44+
"# Note, if this fails try running a_start_here_libraries.ipynb first\n",
45+
"# If you've done that, then make sure that the kernel you've selected for both is the same\n",
46+
"# If that doesn't work, find a TA.\n",
5747
"import numpy as np\n",
5848
"import json as json"
5949
]
@@ -89,7 +79,7 @@
8979
"data_file_name = ...\n",
9080
"\n",
9181
"# This is what the autograder will check\n",
92-
"assert data_file_name == \"data1.csv\"\n"
82+
"assert data_file_name == \"data1.csv\""
9383
]
9484
},
9585
{
@@ -292,7 +282,7 @@
292282
"\n",
293283
"# List of names (creates a set)\n",
294284
"worked_with_names = {\"not filled out\"}\n",
295-
"# List of URLS SP5 (creates a set)\n",
285+
"# List of URLS I25 (creates a set)\n",
296286
"websites = {\"not filled out\"}\n",
297287
"# Approximate number of hours, including lab/in-class time\n",
298288
"hours = -1.5"
@@ -318,7 +308,12 @@
318308
"\n",
319309
"Read me!!! This last cell will always have hand-in instructions. They're pretty boring (most of the time) but around week 5 you'll need to do more than just hand in this .ipynb. It is your responsibility to check if the Gradescope autograder ran correctly.\n",
320310
"\n",
321-
"- Hit Clear All Outputs, then 'Run All' to make sure that your code executes from top to bottom from scratch. If you hand in a file without doing this we will deduct points (i.e., if the little numbers to the left of the cell do not start with 1...)\n",
311+
"- Hit clear all outputs (this removes all the outputs)\n",
312+
"- Hit Restart (say yes when it asks if it's ok to blow everything away)\n",
313+
"- Hit 'Run All' to make sure that your code executes from top to bottom from scratch. \n",
314+
"\n",
315+
"If you hand in a file without doing this we will deduct points (the little numbers to the left of the first cell should be 1 and all cells executed)\n",
316+
"\n",
322317
"- Make sure the file has saved (there is no little black dot to the right of the file name in the top bar)\n",
323318
"- Submit this .ipynb file to Gradescope. Do NOT submit the tutorial files - Gradescope expects 1, and only 1, file with an .ipynb extension.\n",
324319
"- Go get a cup of coffee (or tea or whatever). Come back and check that your autograder score is 5/5\n",
@@ -332,7 +327,7 @@
332327
],
333328
"metadata": {
334329
"kernelspec": {
335-
"display_name": "Python 3",
330+
"display_name": "base",
336331
"language": "python",
337332
"name": "python3"
338333
},
@@ -346,7 +341,7 @@
346341
"name": "python",
347342
"nbconvert_exporter": "python",
348343
"pygments_lexer": "ipython3",
349-
"version": "3.12.7"
344+
"version": "3.11.7"
350345
},
351346
"otter": {
352347
"OK_FORMAT": true,
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"deletable": false,
8+
"editable": false
9+
},
10+
"outputs": [],
11+
"source": [
12+
"# Initialize Otter\n",
13+
"import otter\n",
14+
"grader = otter.Notebook(\"a_start_here_libraries.ipynb\")"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"## Ensuring the libararies are installed correctly\n",
22+
"\n",
23+
"Use this JN to check that all your libraries are installed correctly, and to install any that are not.\n",
24+
"\n",
25+
"First thing to note: See the \"Select Kernel\" in the upper-right hand corner? This needs to be set to the Python version you setup in the instructions:\n",
26+
"\n",
27+
"https://docs.google.com/document/d/1Cp4uuRHMWHfKTAbYAV14y2tMWslmj_-bv_xo3CxYGAo/edit?usp=sharing\n",
28+
"\n",
29+
"Presumably, if you are reading this, than you have already set up VSCode and done the library installs in the above document. \n",
30+
"\n",
31+
"Note: If you are using this file to \"fix\" library problems, first make sure that whatever you've selected in \"Select Kernel\" is the same for both JNs. \n"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"# These are all the imports you'll need in the class; if you get a \"library not found\" then see the following cells for installing them\n",
41+
"\n",
42+
"# Note: You may get a pop-up that says \"ipykernel needed, install y/n\". Say yes. That's the library that lets you run cells in a JN.\n",
43+
"# For Mac users with Apple silicon: That install will likely Fail - you will need to follow the instructions to over-ride the\n",
44+
"# system checks (at least as-of spring 2025). Go back to the install doc (above) and follow the instructions for how to do that.\n",
45+
"# If you've already done it, then chances are that when you did Select Kernel you did not pick the same kernel as the one you\n",
46+
"# did the homebrew install with. Double check that they are the same by typing \"python3 --version\" into a terminal - that one\n",
47+
"# should be the same as the one you picked for Select Kernel\n",
48+
"import otter\n",
49+
"import numpy\n",
50+
"import matplotlib\n",
51+
"import scipy\n",
52+
"import json"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"If all of the above imports worked, then you're done! If not, you can use the following cell to force-install the missing libraries\n",
60+
"\n",
61+
"This may take awhile, btw"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"import sys\n",
71+
"!{sys.executable} -m pip install otter-grader\n",
72+
"!{sys.executable} -m pip install numpy\n",
73+
"!{sys.executable} -m pip install matplotlib\n",
74+
"!{sys.executable} -m pip install scipy\n",
75+
"!{sys.executable} -m pip install json"
76+
]
77+
},
78+
{
79+
"cell_type": "markdown",
80+
"metadata": {
81+
"deletable": false,
82+
"editable": false
83+
},
84+
"source": [
85+
"## Submission\n",
86+
"\n",
87+
"Make sure you have run all cells in your notebook in order before running the cell below, so that all images/graphs appear in the output. The cell below will generate a zip file for you to submit. **Please save before exporting!**"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {
94+
"deletable": false,
95+
"editable": false
96+
},
97+
"outputs": [],
98+
"source": [
99+
"# Save your notebook first, then run this cell to export your submission.\n",
100+
"grader.export(run_tests=True)"
101+
]
102+
},
103+
{
104+
"cell_type": "markdown",
105+
"metadata": {},
106+
"source": [
107+
" "
108+
]
109+
}
110+
],
111+
"metadata": {
112+
"kernelspec": {
113+
"display_name": "base",
114+
"language": "python",
115+
"name": "python3"
116+
},
117+
"language_info": {
118+
"codemirror_mode": {
119+
"name": "ipython",
120+
"version": 3
121+
},
122+
"file_extension": ".py",
123+
"mimetype": "text/x-python",
124+
"name": "python",
125+
"nbconvert_exporter": "python",
126+
"pygments_lexer": "ipython3",
127+
"version": "3.11.7"
128+
},
129+
"otter": {
130+
"OK_FORMAT": true,
131+
"tests": {}
132+
}
133+
},
134+
"nbformat": 4,
135+
"nbformat_minor": 2
136+
}

‎Week_1_data_structures/HW_1_numpy_and_plotting.ipynb‎

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
"# TODO: Extract a numpy array containing the rows for the fourth snap performed by subject three.\n",
159159
"# Hint: You can apply three different boolean filters to whittle down the data set, \n",
160160
"# 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",
161164
"s3s4_snap_data = ..."
162165
]
163166
},
@@ -197,7 +200,18 @@
197200
},
198201
"outputs": [],
199202
"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"
201215
]
202216
},
203217
{
@@ -208,13 +222,13 @@
208222
},
209223
"outputs": [],
210224
"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",
216230
" \"\"\"\n",
217-
" # TODO: Write this function.\n",
231+
" # TODO: Fill in this function.\n",
218232
" # Hint: Use numpy functions to operate on the entire array at once rather than\n",
219233
" # iterate through each row.\n",
220234
" pass"
@@ -229,9 +243,13 @@
229243
"outputs": [],
230244
"source": [
231245
"# 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",
233251
"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",
235253
"assert(np.isclose(test_array_rms[1], 5.06622805))"
236254
]
237255
},
@@ -292,6 +310,21 @@
292310
" pass"
293311
]
294312
},
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+
},
295328
{
296329
"cell_type": "code",
297330
"execution_count": null,
@@ -362,7 +395,7 @@
362395
},
363396
"outputs": [],
364397
"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",
366399
"# Hint: You can use get_channel_data to extract just the rh accelerometer channel from s3s4_snap_data.\n",
367400
"\n",
368401
"s3s4_snap_rh_accelerometer_data = ...\n",
@@ -459,16 +492,19 @@
459492
},
460493
"outputs": [],
461494
"source": [
462-
"# Here, graph the data\n",
495+
"# Plot size\n",
463496
"nrows = 3\n",
464497
"ncols = 2\n",
465498
"fig, axs = plt.subplots(nrows, ncols, figsize=(6, 8))\n",
466499
"\n",
500+
"# TODO: Make the plot\n",
467501
"# Put left hand in the first column, right hand in the second column.\n",
468502
"# Hint: To use plot_function with your new \"rms\" data channel, you will need to make a\n",
469503
"# 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",
470505
"\n",
471-
"fig.tight_layout()"
506+
"fig.tight_layout()\n",
507+
"plt.plot()"
472508
]
473509
},
474510
{
@@ -517,13 +553,38 @@
517553
},
518554
"outputs": [],
519555
"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",
520569
"def guess_motion_type(lh_accelerometer_rms, rh_accelerometer_rms):\n",
521570
" \"\"\" Guesses the motion that the subject is performing given the RMS of the user's left hand and right hand accelerometers.\n",
522571
" @param lh_accelerometer_rms - RMS of the left hand accelerometer\n",
523572
" @param rh_accelerometer_rms - RMS of the right hand accelerometer\n",
524573
" @return The motion ID of the motion the user was most likely performing.\n",
525574
" \"\"\"\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)"
527588
]
528589
},
529590
{
@@ -534,7 +595,7 @@
534595
},
535596
"outputs": [],
536597
"source": [
537-
"# Test code\n",
598+
"# example test code\n",
538599
"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",
539600
"\n",
540601
"assert(snap_id == guess_motion_type(rms(s3s4_snap_lh_accelerometer_data), rms(s3s4_snap_rh_accelerometer_data)))"
@@ -561,9 +622,9 @@
561622
"source": [
562623
"## Week 3, problem 3: Calculate accuracy of your heuristic\n",
563624
"\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",
565626
"\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",
567628
"\n",
568629
"We expect to see accuracies above 75%, and accuracies above 90% are possible."
569630
]

0 commit comments

Comments
 (0)