Skip to content

Commit e3e289a

Browse files
authored
Fix qe.lss bug (#137)
1 parent 54e007c commit e3e289a

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

lectures/additive_functionals.md

+23-22
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ jupytext:
33
text_representation:
44
extension: .md
55
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.14.5
68
kernelspec:
7-
display_name: Python 3
9+
display_name: Python 3 (ipykernel)
810
language: python
911
name: python3
1012
---
@@ -29,10 +31,9 @@ kernelspec:
2931

3032
In addition to what's in Anaconda, this lecture will need the following libraries:
3133

32-
```{code-cell} ipython
33-
---
34-
tags: [hide-output]
35-
---
34+
```{code-cell} ipython3
35+
:tags: [hide-output]
36+
3637
!pip install --upgrade quantecon
3738
```
3839

@@ -72,7 +73,7 @@ More details about these concepts and algorithms can be found in Hansen {cite
7273

7374
Let's start with some imports:
7475

75-
```{code-cell} ipython
76+
```{code-cell} ipython3
7677
import numpy as np
7778
import scipy as sp
7879
import scipy.linalg as la
@@ -243,7 +244,8 @@ This system also constructs the components of the decompositions of $y_t$ and of
243244
All of these objects are computed using the code below
244245

245246
(amf_lss)=
246-
```{code-cell} python3
247+
248+
```{code-cell} ipython3
247249
class AMF_LSS_VAR:
248250
"""
249251
This class transforms an additive (multiplicative)
@@ -348,7 +350,7 @@ class AMF_LSS_VAR:
348350
# Build LSS type
349351
x0 = np.hstack([1, 0, nx0r, ny0r, ny0r])
350352
S0 = np.zeros((len(x0), len(x0)))
351-
lss = qe.lss.LinearStateSpace(Abar, Bbar, Gbar, Hbar, mu_0=x0, Sigma_0=S0)
353+
lss = qe.LinearStateSpace(Abar, Bbar, Gbar, Hbar, mu_0=x0, Sigma_0=S0)
352354
353355
return lss
354356
@@ -400,10 +402,9 @@ class AMF_LSS_VAR:
400402

401403
The code below adds some functions that generate plots for instances of the `AMF_LSS_VAR` {ref}`class <amf_lss>`.
402404

403-
```{code-cell} python3
404-
---
405-
tags: [collapse-20]
406-
---
405+
```{code-cell} ipython3
406+
:tags: [collapse-20]
407+
407408
def plot_given_paths(amf, T, ypath, mpath, spath, tpath,
408409
mbounds, sbounds, horline=0, show_trend=True):
409410
@@ -682,7 +683,8 @@ def plot_martingales(amf, T, npaths=25):
682683
For now, we just plot $y_t$ and $x_t$, postponing until later a description of exactly how we compute them.
683684

684685
(addfunc_egcode)=
685-
```{code-cell} python3
686+
687+
```{code-cell} ipython3
686688
ϕ_1, ϕ_2, ϕ_3, ϕ_4 = 0.5, -0.2, 0, 0.5
687689
σ = 0.01
688690
ν = 0.01 # Growth rate
@@ -860,7 +862,7 @@ Let's use this code (embedded above) to explore the {ref}`example process descri
860862
If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call
861863
you will generate (modulo randomness) the plot
862864

863-
```{code-cell} python3
865+
```{code-cell} ipython3
864866
plot_additive(amf, T)
865867
plt.show()
866868
```
@@ -916,7 +918,7 @@ Let's plot this multiplicative functional for our example.
916918
If you run {ref}`the code that first simulated that example <addfunc_egcode>` again and then the method call in the cell below you'll
917919
obtain the graph in the next cell.
918920

919-
```{code-cell} python3
921+
```{code-cell} ipython3
920922
plot_multiplicative(amf, T)
921923
plt.show()
922924
```
@@ -950,7 +952,7 @@ The second is a **peculiar property** noted and proved by Hansen and Sargent {ci
950952

951953
The following simulation of many paths of $\widetilde M_t$ illustrates both properties
952954

953-
```{code-cell} python3
955+
```{code-cell} ipython3
954956
np.random.seed(10021987)
955957
plot_martingales(amf, 12000)
956958
plt.show()
@@ -994,7 +996,7 @@ Let's write a program to simulate sample paths of $\{ x_t, y_{t} \}_{t=0}^{\inft
994996

995997
We'll do this by formulating the additive functional as a linear state space model and putting the [LinearStateSpace](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/lss.py) class to work.
996998

997-
```{code-cell} python3
999+
```{code-cell} ipython3
9981000
class AMF_LSS_VAR:
9991001
"""
10001002
This class is written to transform a scalar additive functional
@@ -1051,7 +1053,7 @@ class AMF_LSS_VAR:
10511053
# Build LSS type
10521054
x0 = np.hstack([1, 0, 0, 0, 0])
10531055
S0 = np.zeros((5, 5))
1054-
lss = qe.lss.LinearStateSpace(Abar, Bbar, Gbar, Hbar,
1056+
lss = qe.LinearStateSpace(Abar, Bbar, Gbar, Hbar,
10551057
mu_0=x0, Sigma_0=S0)
10561058
10571059
return lss
@@ -1103,7 +1105,7 @@ The heavy lifting is done inside the `AMF_LSS_VAR` class.
11031105

11041106
The following code adds some simple functions that make it straightforward to generate sample paths from an instance of `AMF_LSS_VAR`.
11051107

1106-
```{code-cell} python3
1108+
```{code-cell} ipython3
11071109
def simulate_xy(amf, T):
11081110
"Simulate individual paths."
11091111
foo, bar = amf.lss.simulate(T)
@@ -1149,7 +1151,7 @@ def population_means(amf, T=150):
11491151
Now that we have these functions in our toolkit, let's apply them to run some
11501152
simulations.
11511153

1152-
```{code-cell} python3
1154+
```{code-cell} ipython3
11531155
def simulate_martingale_components(amf, T=1000, I=5000):
11541156
# Get the multiplicative decomposition
11551157
ν, H, g = amf.multiplicative_decomp()
@@ -1204,7 +1206,7 @@ This is peculiar, so make sure you are careful in working with the log normal di
12041206

12051207
Here is some code that tackles these tasks
12061208

1207-
```{code-cell} python3
1209+
```{code-cell} ipython3
12081210
def Mtilde_t_density(amf, t, xmin=1e-8, xmax=5.0, npts=5000):
12091211
12101212
# Pull out the multiplicative decomposition
@@ -1270,4 +1272,3 @@ A **likelihood ratio process** is a multiplicative martingale with mean unity
12701272

12711273
Likelihood ratio processes exhibit the peculiar property that naturally also appears
12721274
[here](https://python.quantecon.org/likelihood_ratio_process.html).
1273-

0 commit comments

Comments
 (0)