Skip to content

Commit 31a3263

Browse files
Copilotmmcky
andcommitted
Replace interpolation package with numpy alternatives in AMSS lecture
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent 4a54475 commit 31a3263

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lectures/_static/downloads/amss_environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies:
1616
- matplotlib
1717
- networkx
1818
- sphinx=2.4.4
19-
- interpolation
2019
- seaborn
2120
- pip:
2221
- sphinxcontrib-jupyter

lectures/amss.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ In addition to what's in Anaconda, this lecture will need the following librarie
2727
tags: [hide-output]
2828
---
2929
!pip install --upgrade quantecon
30-
!pip install interpolation
3130
```
3231

3332
## Overview
@@ -38,10 +37,28 @@ Let's start with following imports:
3837
import numpy as np
3938
import matplotlib.pyplot as plt
4039
from scipy.optimize import root
41-
from interpolation.splines import eval_linear, UCGrid, nodes
4240
from quantecon import optimize, MarkovChain
4341
from numba import njit, prange, float64
4442
from numba.experimental import jitclass
43+
44+
# NumPy-based replacements for interpolation package functions
45+
def UCGrid(bounds):
46+
"""Uniform coordinate grid."""
47+
return (bounds,)
48+
49+
def nodes(x_grid):
50+
"""Extract grid nodes."""
51+
x_min, x_max, x_num = x_grid[0]
52+
grid_points = np.linspace(x_min, x_max, int(x_num))
53+
return grid_points.reshape(-1, 1)
54+
55+
@njit
56+
def eval_linear(x_grid, y_values, x_points):
57+
"""Linear interpolation using numpy."""
58+
x_min, x_max, x_num = x_grid[0]
59+
grid_points = np.linspace(x_min, x_max, int(x_num))
60+
result = np.interp(x_points, grid_points, y_values)
61+
return result[0]
4562
```
4663

4764
In {doc}`an earlier lecture <opt_tax_recur>`, we described a model of

0 commit comments

Comments
 (0)