QuantEcon / QuantEcon.notebooks

Jupyter notebooks contributed by QuantEcon developers, users and the community
BSD 3-Clause "New" or "Revised" License
122 stars 105 forks source link

ddp_ex_MF_7_6_4_jl #61

Closed akihirosasaki closed 6 years ago

akihirosasaki commented 6 years ago

julia translation ddp_ex_MF_7_6_4_py

sglyon commented 6 years ago

Does this routine work with a_indices containing elements equal to 0? I would think this would cause out of bounds indexing errors

oyamad commented 6 years ago

@sglyon Good point.

Now looking into the ddp code, a_indices is actually not used as action "indices" (apart from your newly added conversion routines in the Python version), but rather it can be used as action "values" (as long as they are sorted). (Apparently I wasn't really understanding the logic when I was writing the initial Python version...)

There are two alternatives:

  1. Rename a_indices to a_values. For to_product_form, raise an error if not np.array_equal(self.a_values, np.arange(self.a_values.max()).
  2. Leave a_indices as is, and (implicitly or explicitly) let the advanced user use it as action values.

(I would vote for alternative 2, as it involves no costs...)

sglyon commented 6 years ago

Hmm, are you certain that they aren't used as indices? From these lines it looks like the Julia version uses them as indices when constructing a sparse matrix

oyamad commented 6 years ago

You are right (and in these lines in the Python version). But these lines are not reached if _has_sorted_sa_indices is true (so the qualification "as long as they are sorted").