You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bff06ac
Browse filesBrowse the repository at this point in the historyBrowse files
ENH: Use sphinx-exercise for Styled Exercises and Solutions (#176)
* [functions]Migrating exercise to use sphinx-exercise
* add sphinx-exercise
* pull out code-cell until supported
* TST: new gated directives
* Enable dropdown via sphinx-togglebutton
* TST: see if sphinx-togglebutton works in sphinx_book_theme
* Restore quantecon-book-theme
* Empty commit to trigger rebuild
* Update all solutions to be hidden by default
* Update for sphinx-exercise
* Migrate to sphinx-exercise
* migrate to sphinx-exercise
* fix numpy syntax issue
* fix broken label
* Enable dropdown toggle for solutions
* Enable dropdown toggle for solutions
* move to use pypi sphinx-exercise==0.4.1
* upgrade sphinx-tojupyter==0.2.1
Co-authored-by: Shu <[email protected]>
@@ -323,17 +324,21 @@ write our own version as an exercise.
323
324
324
325
In particular, write a function `factorial` such that `factorial(n)` returns $n!$
325
326
for any positive integer $n$.
327
+
```
326
328
327
-
### Exercise 2
329
+
```{exercise}
330
+
:label: exercise_2
328
331
329
332
The [binomial random variable](https://en.wikipedia.org/wiki/Binomial_distribution) $Y \sim Bin(n, p)$ represents the number of successes in $n$ binary trials, where each trial succeeds with probability $p$.
330
333
331
334
Without any import besides `from numpy.random import uniform`, write a function
332
335
`binomial_rv` such that `binomial_rv(n, p)` generates one draw of $Y$.
333
336
334
337
Hint: If $U$ is uniform on $(0, 1)$ and $p \in (0,1)$, then the expression `U < p` evaluates to `True` with probability $p$.
338
+
```
335
339
336
-
### Exercise 3
340
+
```{exercise}
341
+
:label: exercise_3
337
342
338
343
First, write a function that returns one realization of the following random device
339
344
@@ -346,12 +351,16 @@ Second, write another function that does the same task except that the second ru
346
351
- If a head occurs `k` or more times within this sequence, pay one dollar.
347
352
348
353
Use no import besides `from numpy.random import uniform`.
354
+
```
349
355
350
356
## Solutions
351
357
352
-
### Exercise 1
358
+
```{solution-start} exercise_1
359
+
:label: solution_1
360
+
:class: dropdown
353
361
354
362
Here's one solution.
363
+
```
355
364
356
365
```{code-cell} python3
357
366
def factorial(n):
@@ -363,7 +372,13 @@ def factorial(n):
363
372
factorial(4)
364
373
```
365
374
366
-
### Exercise 2
375
+
```{solution-end}
376
+
```
377
+
378
+
```{solution-start} exercise_2
379
+
:label: solution_2
380
+
:class: dropdown
381
+
````
367
382
368
383
```{code-cell} python3
369
384
from numpy.random import uniform
@@ -379,9 +394,16 @@ def binomial_rv(n, p):
379
394
binomial_rv(10, 0.5)
380
395
```
381
396
382
-
### Exercise 3
397
+
```{solution-end}
398
+
```
399
+
400
+
401
+
```{solution-start} exercise_3
402
+
:label: solution_3
403
+
:class: dropdown
383
404
384
405
Here's a function for the first random device.
406
+
```
385
407
386
408
```{code-cell} python3
387
409
from numpy.random import uniform
@@ -423,3 +445,5 @@ def draw_new(k): # pays if k successes in a sequence
Copy file name to clipboardExpand all lines: lectures/getting_started.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -468,7 +468,9 @@ Alternatively, if you want an outstanding free text editor and don't mind a seem
468
468
469
469
## Exercises
470
470
471
-
### Exercise 1
471
+
```{exercise}
472
+
:label: gs_ex1
473
+
```
472
474
473
475
If Jupyter is still running, quit by using `Ctrl-C` at the terminal where
474
476
you started it.
@@ -488,8 +490,10 @@ You should now be able to run a standard Jupyter notebook session.
488
490
489
491
This is an alternative way to start the notebook that can also be handy.
490
492
491
-
(gs_ex2)=
492
-
### Exercise 2
493
+
494
+
```{exercise-start}
495
+
:label: gs_ex2
496
+
```
493
497
494
498
```{index} single: Git
495
499
```
@@ -547,3 +551,5 @@ For reading on these and other topics, try
547
551
*[Pro Git Book](http://git-scm.com/book) by Scott Chacon and Ben Straub.
548
552
* One of the thousands of Git tutorials on the Net.
Copy file name to clipboardExpand all lines: lectures/numba.md
+22-7Lines changed: 22 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -475,18 +475,21 @@ When Numba compiles machine code for functions, it treats global variables as co
475
475
476
476
## Exercises
477
477
478
-
(speed_ex1)=
479
-
### Exercise 1
478
+
```{exercise}
479
+
:label: speed_ex1
480
480
481
481
{ref}`Previously <pbe_ex3>` we considered how to approximate $\pi$ by
482
482
Monte Carlo.
483
483
484
484
Use the same idea here, but make the code efficient using Numba.
485
485
486
486
Compare speed with and without Numba when the sample size is large.
487
+
```
488
+
487
489
488
-
(speed_ex2)=
489
-
### Exercise 2
490
+
```{exercise-start}
491
+
:label: speed_ex2
492
+
```
490
493
491
494
In the [Introduction to Quantitative Economics with Python](https://python-intro.quantecon.org) lecture series you can
492
495
learn all about finite-state Markov chains.
@@ -498,7 +501,6 @@ Suppose that the volatility of returns on an asset can be in one of two regimes
498
501
The transition probabilities across states are as follows
0 commit comments