QuantEcon / book-dp1-public-companion

Dynamic Programming Volume 1
https://quantecon.github.io/book-dp1-public-companion/
BSD 3-Clause "New" or "Revised" License
109 stars 23 forks source link

Chapter 6: Python Code #4

Closed Smit-create closed 1 year ago

Smit-create commented 2 years ago

Plots from inventory_dp

inventory_dp_ts inventory_dp_vs

Smit-create commented 2 years ago

Plots from finite_opt_saving_2: finite_opt_saving_2_1 finite_opt_saving_2_2_OPT finite_opt_saving_2_2_pi finite_opt_saving_2_2_vfi

Smit-create commented 2 years ago

Plots from finite_lq: finite_lq_0 finite_lq_1 finite_lq_time

Smit-create commented 1 year ago

Plots from firm_hiring.py firm_hiring_g firm_hiring_pol firm_hiring_ts

Smit-create commented 1 year ago

A plot from modified_opt_savings: modified_opt_savings_1

Smit-create commented 1 year ago

@jstac This is ready for review. I have added all the code from Chapter 6. Thanks!

jstac commented 1 year ago

Many thanks @Smit-create , this is looking good!

One concern is the first figure above, for inventory dynamics. It looks slightly different to the Julia one in the textbook. I had a quick look at your code and I wasn't sure why that's the case. Could you please compare the two figures and let me know what you think?

Smit-create commented 1 year ago

One concern is the first figure above, for inventory dynamics.

One of the reasons might be differences in the behavior of Geometric random distribution. NumPy generates only positive integers while Julia generates whole numbers:

>>> rand = np.random.default_rng().geometric(0.6, size=20)
>>> np.mean(rand)
1.65
>>> rand
array([1, 2, 1, 1, 3, 1, 1, 2, 2, 1, 6, 1, 1, 2, 1, 1, 1, 1, 2, 2])

Julia:

julia> G = Geometric(0.6)
julia> X = zeros(Int32, 20)
julia> for t in 1:20
           X[t] = rand(G)
       end
julia> mean(X)
0.6
Smit-create commented 1 year ago

Thanks for the review @jstac. Fixed the above issue and the new plot looks like this: inventory_dp_ts

jstac commented 1 year ago

Yep, that's perfect now. Many thanks @Smit-create , great work!