update sample course for 19.0

This commit is contained in:
adam j hartz 2023-08-22 17:30:49 -04:00
commit 70d78ec73e
Signed by: hz
GPG key ID: B63A0A59F5C82493
6 changed files with 40 additions and 40 deletions

View file

@ -124,7 +124,7 @@ def handle_submission(submissions, **info):
# okay... here we go...
# first grab the safe interpreter to use during checking
# and the location of the sandbox
sandbox_interpreter = info['csq_python_interpreter']
sandbox_interpreter = info['csq_python_sandbox_interpreter']
id_ = uuid.uuid4().hex
this_sandbox_location = os.path.join(info.get('csq_sandbox_dir', '/tmp/sandbox'), '009checks', id_)

View file

@ -1,6 +1,6 @@
This page briefly describes some pieces of the input syntax for CAT-SOOP pages.
<section>Markdown</section>
<catsoop-section>Markdown</catsoop-section>
Markdown works as expected, plus \$...\$ can be used for $\LaTeX$-style math.
@ -15,7 +15,7 @@ $$-1 + \frac{1}{3} - \frac{1}{5} + \frac{1}{7} - \frac{1}{9} + \cdots = \sum_{n=
Math is rendered with $\KaTeX$ (<https://github.com/Khan/KaTeX>) when possible,
and with MathJax (<https://www.mathjax.org/>) as a fallback.
<section>Python</section>
<catsoop-section>Python</catsoop-section>
Python code can be included within <code>&lt;python&gt;</code> tags. Anything
that is printed within these tags will be rendered to the screen. For example,
@ -31,7 +31,7 @@ can be used to print a single value. For example: @{random.randint(30, 70)}
It is also possible to specify how the value should be formatted. For example:
@%.02f{7}
<section>Images and Hyperlinks</section>
<catsoop-section>Images and Hyperlinks</catsoop-section>
Images and hyperlinks can be included using regular HTML or Markdown syntax:
@ -48,7 +48,7 @@ These kinds of lookups first look for a regular CAT-SOOP page with the given
name. If one isn't found, CAT-SOOP will look in the corresponding `__STATIC__`
directory.
<section>Question</section>
<catsoop-section>Question</catsoop-section>
One of the main uses of CAT-SOOP is to collect and assess responses to questions.
This is handled with the <code>&lt;question&gt;</code> tag, which is decribed

View file

@ -83,10 +83,10 @@ csq_python_sandbox = "python"
#
#if 'localhost' in cs_url_root:
# # locally, just use the system Python install
# csq_python_interpreter = '/usr/bin/python3'
# csq_python_sandbox_interpreter = '/usr/bin/python3'
#else:
# # on the server, use the properly sandboxed python
# csq_python_interpreter = '/home/ubuntu/py3_sandbox/bin/python3'
# csq_python_sandbox_interpreter = '/home/ubuntu/py3_sandbox/bin/python3'
# PERMISSIONS

View file

@ -14,7 +14,7 @@ all the built-in question types. Look at the source of this page
Note that you will need the `'submit'` permission to submit answers to these
questions.
<section>Options Present in All Questions</section>
<catsoop-section>Options Present in All Questions</catsoop-section>
* `csq_prompt`: A piece of text to be displayed before the question's input.
* `csq_name`: A unique identifier (alphanumeric only) for the question. If none is provided, a default value is used.
@ -30,9 +30,9 @@ questions.
* `'legacy'`: Check the response in the same request that submits it. Nice for short checks.
* `'manual'`: No automatic score is assigned. Rather, the submission is logged so it can later be manually graded.
<section>Base Question Types</section>
<catsoop-section>Base Question Types</catsoop-section>
<subsection>smallbox</subsection>
<catsoop-subsection>smallbox</catsoop-subsection>
A small box accepting arbitrary text input.
@ -43,7 +43,7 @@ csq_check_function = lambda sub, sol: sub.lower().strip() == sol.lower()
csq_size = 30 # width of text box
</question>
<subsection>bigbox</subsection>
<catsoop-subsection>bigbox</catsoop-subsection>
A bigger box accepting arbitrary text input. Often used for survey responses.
@ -55,7 +55,7 @@ csq_cols = 50
csq_check_function = lambda sub, sol: 1 # check functions two args
</question>
<subsection>multiplechoice</subsection>
<catsoop-subsection>multiplechoice</catsoop-subsection>
Multiple choice questions come in a few different forms, based on the value of `csq_renderer`. The default mode renders choices as a drop-down menu:
@ -87,9 +87,9 @@ csq_options=['Aloha', 'Guten Tag', 'Auf Wiedersehen', 'Hey', 'Goodbye', 'Tschü
csq_soln = [True, True, False, True, False, False]
</question>
<section>Python-related Questions</section>
<catsoop-section>Python-related Questions</catsoop-section>
<subsection>pythonic</subsection>
<catsoop-subsection>pythonic</catsoop-subsection>
`pythonic` questions expect a single Python expression as input, and a single
Python expression as output.
@ -109,7 +109,7 @@ def csq_check_function(sub, sol):
return 1
</question>
<subsection>pythonliteral</subsection>
<catsoop-subsection>pythonliteral</catsoop-subsection>
`pythonliteral` is like `pythoncode`, except that it expects a single literal
value instead of an abitrary expression. This can be useful for numbers.
@ -120,7 +120,7 @@ csq_soln = 7**0.5
csq_check_function = lambda sub, sol: abs(sub - sol) <= 1e-3
</question>
<subsection>pythoncode</subsection>
<catsoop-subsection>pythoncode</catsoop-subsection>
For larger coding problems (e.g., writing a function or computing a value), the `pythoncode` question
should be used. It is a little more complicated than the other question types.
@ -268,9 +268,9 @@ For a bigger example from 6.145, see the following page (which requires the
* [Linear Regression](CURRENT/linregress)
<section>Symbolic Expressions</section>
<catsoop-section>Symbolic Expressions</catsoop-section>
<subsection>expression</subsection>
<catsoop-subsection>expression</catsoop-subsection>
This question type is used for checking symolic math expressions.
@ -280,7 +280,7 @@ csq_syntax='python'
csq_soln = ['sqrt(e**(j*omega))', 'e**(j*omega / 2)'] # can either be a single string, or a list of multiple correct answers.
</question>
<section>Per-User Randomized Values</section>
<catsoop-section>Per-User Randomized Values</catsoop-section>
Invoking the `csm_tutor.init_random()` function will seed the `random.Random`
object stored in `cs_random` in such a way that the values it produces will be

View file

@ -44,7 +44,7 @@ img1 = fig._show(width='400')
<center><a href="https://www.youtube.com/watch?v=8qjl4lysi_s" target="_blank">Music for this Problem</a></center>
<section>Introduction</section>
<catsoop-section>Introduction</catsoop-section>
In this exercise, we will write a program to compute a 2-dimensional _linear
regression_ for a set of data. In short, we will try to explain the
@ -83,33 +83,33 @@ problems, but for now we'll just focus on _implementing_ a linear regression
As you might guess, this will be a fairly complicated program, and so, as we
have seen before, we will break it down into smaller pieces first.
<section>Primitives</section>
<catsoop-section>Primitives</catsoop-section>
We'll start by defining some primitives:
<subsection>Sample Mean</subsection>
<catsoop-subsection>Sample Mean</catsoop-subsection>
The _sample mean_ of a set of $N$ values $x_0, x_1, \ldots, x_{N-1}$ is given by:
$$\overline{X} = \frac{1}{N}\sum_{i=0}^{N-1} x_i$$
<subsection>Sample Variance</subsection>
<catsoop-subsection>Sample Variance</catsoop-subsection>
The _sample variance_ of a set of $N$ values $x_0, x_1, \ldots, x_{N-1}$ is given by the following (note the two separate forms):
$$\text{Var}(X) = \frac{1}{N-1}\sum_{i=0}^{N-1} (x_i - \overline{X})^2$$
$$\text{Var}(X) = \frac{1}{N-1}\left(\sum_{i=0}^{N-1}(x_i^2) - \frac{1}{N}\left(\sum_{i=0}^{N-1}x_i\right)^2\right)$$
<subsection>Sample Standard Deviation</subsection>
<catsoop-subsection>Sample Standard Deviation</catsoop-subsection>
The _sample standard deviation_ of a set of $N$ values $x_0, x_1, \ldots, x_{N-1}$ is given by:
$$\sigma_X = \sqrt{\text{Var}(X)} = \sqrt{\frac{1}{N-1}\sum_{i=0}^{N-1} (x_i - \overline{X})^2}$$
<subsection>Sample Covariance</subsection>
<catsoop-subsection>Sample Covariance</catsoop-subsection>
The _sample covariance_ of two variables $X$ and $Y$ (an estimate of the true underlying covariance of the two variables), each with $N$ samples, such that $y_i$ is associated with $x_i$, is given by the following (note the two separate forms):
$$\text{cov}(X, Y) = \frac{1}{N-1}\sum_{i=0}^{N-1} (x_i-\overline{X})(y_i-\overline{Y})$$
$$\text{cov}(X, Y) = \frac{1}{N-1}\left(\sum_{i=0}^{N-1}(x_iy_i) - \frac{1}{N}\left(\sum_{i=0}^{N-1}x_i\right)\left(\sum_{i=0}^{N-1}y_i\right)\right)$$
<section>Finding the "Best Fit" Line</section>
<catsoop-section>Finding the "Best Fit" Line</catsoop-section>
We would like to find the values $m$ and $b$ for which $y = mx+b$ best approximates the data we've gathered.
@ -123,9 +123,9 @@ It is possible to solve for these values, and we will use them our
implementation. The next section shows a derivation of the solutions for $m$
and $b$. Understanding the derivation is not crucial for this exercise,
however, and so you are welcome to skip the derivation and move on to
<ref label="results"><a href="{link}">{type} {number}: {title}</a></ref>.
<catsoop-ref label="results"><a href="{link}">{type} {number}: {title}</a></catsoop-ref>.
<subsection>Derivation</subsection>
<catsoop-subsection>Derivation</catsoop-subsection>
Here, we want to find the values of $m$ and $b$ that minimize the sum of squared error (SSE):
@ -139,7 +139,7 @@ $$\frac{\delta}{\delta b}\text{SSE} = \sum_{i=0}^{N-1} -2(y_i - mx_i - b)$$
$$\frac{\delta}{\delta m}\text{SSE} = \sum_{i=0}^{N-1} -2x_i(y_i - mx_i - b)$$
<subsubsection>Solving for b</subsubsection>
<catsoop-subsubsection>Solving for b</catsoop-subsubsection>
Let's start by considering the partial derivative with respect to $b$. We want to find when this expression is 0.
@ -167,7 +167,7 @@ $$\frac{1}{N}\sum_{i=0}^{N-1} y_i - m\left(\frac{1}{N}\sum_{i=0}^{N-1}x_i\right)
Notice that the two expressions on the left have the form of our _sample mean_ equation from above, so we know that this must be:
$$\overline{Y} - m\overline{X} = b$$
<subsubsection>Solving for m</subsubsection>
<catsoop-subsubsection>Solving for m</catsoop-subsubsection>
Now we'll consider the partial derivative with respect to $m$, and again set it equal to zero.
$$\sum_{i=0}^{N-1} -2x_i(y_i - mx_i - b) = 0$$
@ -204,7 +204,7 @@ Recalling the definitions of _sample variance_ and _sample covariance_, we can s
$$\frac{\text{cov}(X, Y)}{\text{Var}(X)} = m$$
<subsection label="results">Results</subsection>
<catsoop-subsection label="results">Results</catsoop-subsection>
The analysis above leads us to the following conclusion:
@ -218,7 +218,7 @@ Here, the first equation tells us that the slope of the "best fit" line is the
ratio of the covariance of $X$ and $Y$ to the variance of $X$. The second
tells us that the line must pass through the point $(\overline{X}, \overline{Y})$.
<section>Pearson's R</section>
<catsoop-section>Pearson's R</catsoop-section>
We will also define the Pearson Correlation Coefficient of two variables $X$ and $Y$ as:
@ -226,7 +226,7 @@ $$r = \frac{\text{cov}(X,Y)}{\sigma_X\sigma_Y}$$
This number $r$, which is between $-1$ and $1$, tells us how strongly, and in what direction, the two variables are correlated: a value of 1 implies total positive linear correlation, 0 implies no linear correlation, and -1 implies total negative linear correlation.
<section>Your Task</section>
<catsoop-section>Your Task</catsoop-section>
Your task in this exercise is to implement several Python functions related to
the discussion above:
@ -259,7 +259,7 @@ In order to keep things organized, you should try to implement these functions
in terms of the others whenever possible!
<section>Submission</section>
<catsoop-section>Submission</catsoop-section>
<question pythoncode>
csq_interface="upload"

View file

@ -1,4 +1,4 @@
<section>Page Specification and Loading</section>
<catsoop-section>Page Specification and Loading</catsoop-section>
CAT-SOOP courses are stored using files on disk. The structure of the web site
mirrors the structure of the directories on disk. Having a directory at
@ -14,7 +14,7 @@ Inside of each page's directory, there should be a file called
[Markdown](COURSE/markdown) and [Questions](COURSE/questions) pages for more
information about how these files are structured).
<subsection>Magic Variables and Inheritance</subsection>
<catsoop-subsection>Magic Variables and Inheritance</catsoop-subsection>
A lot of behavior in CAT-SOOP is defined by the values stored in "magic"
variables with particular names. These variables control various aspects of
@ -41,7 +41,7 @@ So values set in the top-level `preload.py` affect all pages beneath them
particular page's `content.catsoop` affect only that page, and values set in
`question` tags on a page affect only that particular question.
<section>Static Files and Linking</section>
<catsoop-section>Static Files and Linking</catsoop-section>
Static files (i.e., those not generated by a `content.catsoop`) are treated
differently. They should be placed inside a directory called `__STATIC__`
@ -57,9 +57,9 @@ location of the page currently being loaded.
Similarly, from any page within the course, those files could be linked to as
`COURSE/homeworks/week1` and `COURSE/homeworks/an_image.png`, respectively.
<section>Controlling Access to Pages</section>
<catsoop-section>Controlling Access to Pages</catsoop-section>
<subsection>Permissions</subsection>
<catsoop-subsection>Permissions</catsoop-subsection>
Users' roles are determined by the files in the `__USERS__` directory. Each
user should have a file there, named like `username.py`. One way to handle
@ -84,7 +84,7 @@ permissions associated with that role. Take a look at `preload.py`, where such
a mapping is defined. A couple of `__USERS__` files are also included in this
sample course.
<subsection>Release and Due Dates</subsection>
<catsoop-subsection>Release and Due Dates</catsoop-subsection>
`cs_release_date` controls the date at which a page is "released" to a student
(i.e., that it becomes visible to those with the `view` permission). It can