Skip to content

Commit 612db81

Browse files
committed
Updated documentation significantly, and addressed two issues in the issue section and added test cases for them
1 parent 2ae077a commit 612db81

18 files changed

+842
-559
lines changed

pymaclab/dsge/solvers/modsolvers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,9 @@ def solve(self):
11961196
self.solab2()
11971197

11981198
def sim(self,tlen,sntup=None):
1199+
# Deals with 0-tuples
1200+
if type(sntup) != type((1,2,3)) and type(sntup) == type('abc'):
1201+
sntup = (sntup,)
11991202
# Add 1000 observations, as they will be thrown away
12001203
# Add one more observation to start first-order vector
12011204
exoli = [x[1] for x in self.vardic['exo']['var']]
@@ -2440,6 +2443,9 @@ def solve(self):
24402443
self.F = np.matrix(F)
24412444

24422445
def sim(self,tlen,sntup=None,shockvec=None):
2446+
# Deals with 0-tuples
2447+
if type(sntup) != type((1,2,3)) and type(sntup) == type('abc'):
2448+
sntup = (sntup,)
24432449
# Add 1000 observations, as they will be thrown away
24442450
# Add one more observation to start first-order vector
24452451
exoli = [x[1] for x in self.vardic['exo']['var']]

pymaclab/filters/bkfilter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
import numpy as np
33

44
def bkfilter(data=None,up=6,dn=32,kkl=12):
5-
if type(data) != type(np.array([1,2,3])):
6-
data = np.array(data)
5+
if type(data) == type(np.matlib.matrix([1,2,3])) and len(data.shape) == 2:
6+
if data.shape[0] < data.shape[1]: data = data.__array__().T
7+
else: data = data.__array__()
8+
elif type(data) != type(np.array([1,2,3])):
9+
data = np.array([x for x in data])
10+
elif type(data) == type(np.array([1,2,3])):
11+
if len(data.shape) == 2 and data.shape[0] < data.shape[1]:
12+
data = data.reshape(data.shape[1])
13+
elif len(data.shape) == 2 and data.shape[0] > data.shape[1]:
14+
data = data.reshape(data.shape[0])
715
tlen = len(data)
816
return bkf(data,up,dn,kkl,tlen)

pymaclab/filters/cffilter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
from pymaclab.filters._cffilter import cffilter as cff
22
import numpy as np
33

4-
def cffilter(data=None,low=6,high=32,drift=True):
4+
def cffilter(data=None,low=6,high=32,drift=True):
5+
if type(data) == type(np.matlib.matrix([1,2,3])) and len(data.shape) == 2:
6+
if data.shape[0] < data.shape[1]: data = data.__array__().T
7+
else: data = data.__array__()
8+
elif type(data) != type(np.array([1,2,3])):
9+
data = np.array([x for x in data])
10+
elif type(data) == type(np.array([1,2,3])):
11+
if len(data.shape) == 2 and data.shape[0] < data.shape[1]:
12+
data = data.reshape(data.shape[1])
13+
elif len(data.shape) == 2 and data.shape[0] > data.shape[1]:
14+
data = data.reshape(data.shape[0])
515
return cff(data,low=low,high=high,drift=drift)

pymaclab/filters/hpfilter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
import numpy as np
33

44
def hpfilter(data=None,lam=1600):
5-
if type(data) != type(np.array([1,2,3])):
6-
data = np.array(data)
5+
if type(data) == type(np.matlib.matrix([1,2,3])) and len(data.shape) == 2:
6+
if data.shape[0] < data.shape[1]: data = data.__array__().T
7+
else: data = data.__array__()
8+
elif type(data) != type(np.array([1,2,3])):
9+
data = np.array([x for x in data])
10+
elif type(data) == type(np.array([1,2,3])):
11+
if len(data.shape) == 2 and data.shape[0] < data.shape[1]:
12+
data = data.reshape(data.shape[1])
13+
elif len(data.shape) == 2 and data.shape[0] > data.shape[1]:
14+
data = data.reshape(data.shape[0])
715
tlen = len(data)
816
wdata = np.zeros((tlen,3))
917
lam = 1600

pymaclab/modfiles/templates/wheezy_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
@if type(sigma) != type(True):
162162
Sigma = [@sigma.__str__().replace('[','').replace(']',';')[:-2] ];
163163
@end
164-
@else:
164+
@if type(sigma) == type(False):
165165
None
166166
@end
167167

pymaclab/tests/pymaclab_tests/filters_tests/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pymaclab as pm
2+
import pymaclab.modfiles.models as models
3+
import pymaclab.filters as filters
4+
5+
6+
def test_filters():
7+
rbc = pm.newMOD(models.stable.rbc1_num,mesg=True)
8+
rbc.modsolvers.forkleind.solve()
9+
# Also test here the one-element shock array at work
10+
rbc.modsolvers.forkleind.sim(250,('productivity'))
11+
12+
# Use consumption and test the filtering options
13+
14+
# First turn this into a ordinary Python list and test it
15+
consmat = rbc.modsolvers.forkleind.insim[1][0]
16+
consmat2 = consmat.reshape(consmat.shape[1],consmat.shape[0])
17+
consarr = consmat.__array__()
18+
consarr2 = consarr.flatten()
19+
consli = [x for x in rbc.modsolvers.forkleind.insim[1][0].__array__()[0]]
20+
21+
datli = []
22+
datli.append(consmat)
23+
datli.append(consmat2)
24+
datli.append(consarr)
25+
datli.append(consarr2)
26+
datli.append(consli)
27+
28+
for datar in datli:
29+
cons_cycle = filters.hpfilter(data=datar)[0]
30+
cons_cycle2 = filters.bkfilter(data=datar)
31+
cons_cycle3 = filters.cffilter(data=datar)[0]

pymaclab/tests/pymaclab_tests/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def configuration(parent_package='',top_path=None):
55
config = Configuration('pymaclab_tests', parent_package, top_path)
66
config.add_subpackage('dsge_tests')
77
config.add_subpackage('modfiles_tests')
8+
config.add_subpackage('filters_tests')
89
return config
910

1011
if __name__ == '__main__':
19.9 KB
Loading

pymaclab_sphinx/docs/index.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,19 @@ Series of Brief Tutorials
9696

9797
1) :doc:`Basic DSGE tutorial <tutorial/started_tutorial>`
9898
Brief tutorial on how to use PyMacLab to work with DSGE models.
99-
2) :doc:`PyMacLab DSGE instance tutorial <tutorial/dsge_instance_tutorial>`
99+
2) :doc:`DSGE model file tutorial <tutorial/modfile_tutorial>`
100+
Brief tutorial describing the structure of a DSGE model file.
101+
3) :doc:`PyMacLab DSGE instance tutorial <tutorial/dsge_instance_tutorial>`
100102
Succinct tutorial facilitating the understanding of the DSGE OOP data structure in PyMacLab.
101-
3) :doc:`PyMacLab DSGE instance updater tutorial <tutorial/dsge_instance_updater_tutorial>`
103+
4) :doc:`PyMacLab DSGE instance updater tutorial <tutorial/dsge_instance_updater_tutorial>`
102104
Tutorial on how to use DSGE model instance's intelligent runtime update features.
103-
4) :doc:`PyMacLab DSGE steady state solver tutorial <tutorial/steady_solver_tutorial>`
105+
5) :doc:`PyMacLab DSGE steady state solver tutorial <tutorial/steady_solver_tutorial>`
104106
This section illustrates various options available to solve DSGE models' steady state.
105-
5) :doc:`PyMacLab DSGE dynamic solver tutorial <tutorial/dynamic_solver_tutorial>`
107+
6) :doc:`PyMacLab DSGE dynamic solver tutorial <tutorial/dynamic_solver_tutorial>`
106108
This section finally shows how dynamic solution to the PyMacLab DSGE models are obtained.
107-
6) :doc:`PyMacLab DSGE simulation and plotting tutorial <tutorial/simirf_plotting_tutorial>`
109+
7) :doc:`PyMacLab DSGE simulation and plotting tutorial <tutorial/simirf_plotting_tutorial>`
108110
Short tutorial on using convenience functions for simulations, IRFs and plotting.
109-
7) :doc:`Description of all template DSGE models <tutorial/started_allmodels>`
111+
8) :doc:`Description of all template DSGE models <tutorial/started_allmodels>`
110112
Detailed description of all of the template DSGE models which come supplied with PyMacLab.
111113

112114

pymaclab_sphinx/docs/pymaclab_biblio.bib

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,15 @@ @Book{Lan:2009
101101
isbn = {3540739157, 9783540739159},
102102
edition = {3rd},
103103
publisher = {Springer Publishing Company, Incorporated},
104-
}
104+
}
105+
106+
@Article{CoeReyWin:2011,
107+
author={Nicolas Coeurdacier and Helene Rey and Pablo Winant},
108+
title={The Risky Steady State},
109+
journal={American Economic Review},
110+
year=2011,
111+
volume={101},
112+
number={3},
113+
pages={398-401},
114+
month={May}
115+
}

pymaclab_sphinx/docs/tutorial/dsge_instance_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\newpage
66

7-
Tutorial 2 - The PyMacLab DSGE instance
7+
Tutorial 3 - The PyMacLab DSGE instance
88
=======================================
99

1010
Introduction

pymaclab_sphinx/docs/tutorial/dsge_instance_updater_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\newpage
66

7-
Tutorial 3 - The Python DSGE instance updater methods
7+
Tutorial 4 - The Python DSGE instance updater methods
88
=====================================================
99

1010
Introduction

pymaclab_sphinx/docs/tutorial/dynamic_solver_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\newpage
66

7-
Tutorial 5 - Dynamic Solution Methods
7+
Tutorial 6 - Dynamic Solution Methods
88
=====================================
99

1010
Introduction

0 commit comments

Comments
 (0)