Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lectures/about_py.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ popularity of a single Python deep learning library

```{figure} /_static/lecture_specific/about_py/pytorch_vs_matlab.png
```
Pytorch is just one of several Python libraries for deep learning and AI.
PyTorch is just one of several Python libraries for deep learning and AI.



Expand Down Expand Up @@ -349,7 +349,7 @@ We will discuss the details later in the lecture series, where we cover NumPy in
While NumPy is still the king of array processing in Python, there are now
important competitors.

Libraries such as [JAX](https://github.com/jax-ml/jax), [Pytorch](https://pytorch.org/), and [CuPy](https://cupy.dev/) also have
Libraries such as [JAX](https://github.com/jax-ml/jax), [PyTorch](https://pytorch.org/), and [CuPy](https://cupy.dev/) also have
built in array types and array operations that can be very fast and efficient.

In fact these libraries are better at exploiting parallelization and fast hardware, as
Expand Down
6 changes: 3 additions & 3 deletions lectures/autodiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ Let's generate some simulated data:
```{code-cell} ipython3
n = 100
key = jax.random.key(1234)
x = jax.random.uniform(key, (n,))
key, x_key, ϵ_key = jax.random.split(key, 3)
x = jax.random.uniform(x_key, (n,))

α, β, σ = 0.5, 1.0, 0.1 # Set the true intercept and slope.
key, subkey = jax.random.split(key)
ϵ = jax.random.normal(subkey, (n,))
ϵ = jax.random.normal(ϵ_key, (n,))

y = α * x + β + σ * ϵ
```
Expand Down
8 changes: 6 additions & 2 deletions lectures/numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,11 @@ class DiscreteRV:
def __init__(self, q, seed=None):
"""
The argument q is a NumPy array, or array like, nonnegative and sums
to 1
to 1.

The argument seed sets the seed for the underlying random number

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstac what is your view on docstrings in lectures. Should they fully document a function interface (like in a library) or be a concise one sentence description?

generator; with the default seed=None, draws are not reproducible
across runs.
"""
self.q = q
self.Q = cumsum(q)
Expand Down Expand Up @@ -1431,7 +1435,7 @@ print(A)

**Part2**: Move on to replicate the result of the following broadcasting operation. Meanwhile, compare the speeds of broadcasting and the `for` loop you implement.

For this part of the exercise you can use the `tic`/`toc` functions from the `quantecon` library to time the execution.
For this part of the exercise you can use the `qe.Timer()` context manager from the `quantecon` library to time the execution.

Let's make sure this library is installed.

Expand Down
3 changes: 2 additions & 1 deletion lectures/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Let's start with Series.
We begin by creating a series of four random observations

```{code-cell} ipython3
s = pd.Series(np.random.randn(4), name='daily returns')
rng = np.random.default_rng()
s = pd.Series(rng.standard_normal(4), name='daily returns')
s
```

Expand Down
6 changes: 3 additions & 3 deletions lectures/pandas_panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ countries and assign it to `realwage`.
The dataset can be accessed with the following link:

```{code-cell} ipython3
url1 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/realwage.csv'
url1 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/realwage.csv'
```

```{code-cell} ipython3
Expand Down Expand Up @@ -197,7 +197,7 @@ function.
The dataset can be accessed with the following link:

```{code-cell} ipython3
url2 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/countries.csv'
url2 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/countries.csv'
```

```{code-cell} ipython3
Expand Down Expand Up @@ -506,7 +506,7 @@ in Europe by age and sex from [Eurostat](https://ec.europa.eu/eurostat/data/data
The dataset can be accessed with the following link:

```{code-cell} ipython3
url3 = 'https://github.com/QuantEcon/data-lectures/raw/main/lectures/employ.csv'
url3 = 'https://raw.githubusercontent.com/QuantEcon/data-lectures/main/lectures/employ.csv'
```

Reading in the CSV file returns a panel dataset in long format. Use `.pivot_table()` to construct
Expand Down
19 changes: 10 additions & 9 deletions lectures/polars.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Let's start with Series.
We begin by creating a series of four random observations

```{code-cell} ipython3
s = pl.Series(name='daily returns', values=np.random.randn(4))
rng = np.random.default_rng()
s = pl.Series(name='daily returns', values=rng.standard_normal(4))
s
```

Expand Down Expand Up @@ -114,7 +115,7 @@ For example, to associate ticker symbols with returns:
```{code-cell} ipython3
df = pl.DataFrame({
'company': ['AMZN', 'AAPL', 'MSFT', 'GOOG'],
'daily returns': np.random.randn(4)
'daily returns': rng.standard_normal(4)
})
df
```
Expand Down Expand Up @@ -463,13 +464,13 @@ a grouped weighted average.

```{code-cell} ipython3
n = 5_000_000
np.random.seed(42)
rng = np.random.default_rng(42)

groups = np.random.choice(['A', 'B', 'C', 'D'], n)
values = np.random.randn(n)
weights = np.random.rand(n)
extra1 = np.random.randn(n)
extra2 = np.random.randn(n)
groups = rng.choice(['A', 'B', 'C', 'D'], n)
values = rng.standard_normal(n)
weights = rng.random(n)
extra1 = rng.standard_normal(n)
extra2 = rng.standard_normal(n)

big_pd = pd.DataFrame({
'group': groups, 'value': values,
Expand Down Expand Up @@ -685,7 +686,7 @@ Calculate percentage changes using Polars expressions:

```{code-cell} ipython3
price_change = ticker.select([
((pl.col(tick).last() / pl.col(tick).first() - 1) * 100)
((pl.col(tick).drop_nulls().last() / pl.col(tick).drop_nulls().first() - 1) * 100)
.alias(tick)
for tick in ticker_list.keys()
]).transpose(
Expand Down
9 changes: 6 additions & 3 deletions lectures/python_by_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,22 @@ Then it's harder for readers to know where `sqrt` came from, should they wish to

### Random Draws

Returning to our program that plots white noise, the remaining three lines
Returning to our program that plots white noise, the remaining four lines
after the import statements are

```{code-cell} ipython
rng = np.random.default_rng()
ϵ_values = rng.standard_normal(100)
plt.plot(ϵ_values)
plt.show()
```

The first line generates 100 (quasi) independent standard normals and stores
The first line creates a random number generator `rng`.

The second line generates 100 (quasi) independent standard normals and stores
them in `ϵ_values`.

The next two lines genererate the plot.
The last two lines generate the plot.

We can and will look at various ways to configure and improve this plot below.

Expand Down
Loading