Skip to content
Merged
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
31 changes: 21 additions & 10 deletions lectures/matsuyama.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.4
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
---
Expand Down Expand Up @@ -38,7 +40,7 @@ In particular, as trade costs fall and international competition increases, inno

Let's start with some imports:

```{code-cell} ipython
```{code-cell} ipython3
import numpy as np
import matplotlib.pyplot as plt
from numba import jit
Expand Down Expand Up @@ -335,7 +337,7 @@ These are the `@jit` statements that you see below (review [this lecture](https:

Here's the main body of code

```{code-cell} python3
```{code-cell} ipython3
@jit(nopython=True)
def _hj(j, nk, s1, s2, θ, δ, ρ):
"""
Expand Down Expand Up @@ -651,9 +653,9 @@ The time series share parameters but differ in their initial condition.

Here's the function

```{code-cell} python3
```{code-cell} ipython3
def plot_timeseries(n1_0, n2_0, s1=0.5, θ=2.5,
δ=0.7, ρ=0.2, ax=None, title=''):
δ=0.7, ρ=0.2, ax=None, title=''):
"""
Plot a single time series with initial conditions
"""
Expand Down Expand Up @@ -735,7 +737,8 @@ Replicate the figure {ref}`shown above <matsrep>` by coloring initial conditions
```{solution-start} matsuyama_ex1
:class: dropdown
```
```{code-cell} python3

```{code-cell} ipython3
def plot_attraction_basis(s1=0.5, θ=2.5, δ=0.7, ρ=0.2, npts=250, ax=None):
if ax is None:
fig, ax = plt.subplots()
Expand Down Expand Up @@ -790,16 +793,21 @@ in real-time. Below we use an interactive plot to do this.

Note, interactive plotting requires the [ipywidgets](https://github.com/jupyter-widgets/ipywidgets) module to be installed and enabled.

```{code-cell} python3
```{note}
This interactive plot is disabled on this static webpage.
In order to use this, we recommend to run this notebook locally.
```

```{code-cell} ipython3
:class: no-execute

def interact_attraction_basis(ρ=0.2, maxiter=250, npts=250):
# Create the figure and axis that we will plot on
fig, ax = plt.subplots(figsize=(12, 10))

# Create model and attraction basis
s1, θ, δ = 0.5, 2.5, 0.75
model = MSGSync(s1, θ, δ, ρ)
ab = model.create_attraction_basis(maxiter=maxiter, npts=npts)

# Color map with colormesh
unitrange = np.linspace(0, 1, npts)
cf = ax.pcolormesh(unitrange, unitrange, ab, cmap="viridis")
Expand All @@ -809,11 +817,14 @@ def interact_attraction_basis(ρ=0.2, maxiter=250, npts=250):
return None
```

```{code-cell} python3
```{code-cell} ipython3
:class: no-execute
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mmcky is this correctly tagged? The build hangs again.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kp992 the correct syntax is

:tags: [no-execute]

Copy link
Contributor

Choose a reason for hiding this comment

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

actually :class: no-execute should work.

I think the future is :tags: [skip-execution]

Let's leave this as is for now. Thanks @kp992


fig = interact(interact_attraction_basis,
ρ=(0.0, 1.0, 0.05),
maxiter=(50, 5000, 50),
npts=(25, 750, 25))
```

```{solution-end}
```
Loading