Repository navigation
ENH: Add state_values to DiscreteDP - #832
Conversation
|
@HG-Cheng Thank you for the contribution! Main comments
Other commentsPlease do not include changes in the files |
…e accidental files
|
"Hi @oyamad, thanks for the detailed review and guidance! I completely understand. I will remove action_values and num_actions to keep this PR focused on state_values only, and we can leave the state-action pair discussion for the future. I will pass state_values=state_values to MarkovChain in controlled_mc as suggested. Apologies for the accidental inclusion of .vscode/settings.json and _matrix_eqn.py! They leaked in from my local workspace and another task. I will remove them from this branch right away. I'll push the updated commits shortly!" |
# Conflicts: # quantecon/markov/ddp.py
|
Thanks again for the review. I've updated the PR to keep it focused on I also synced the branch with the latest |
oyamad
left a comment
There was a problem hiding this comment.
Thanks @HG-Cheng! One main request: please follow what is done in MarkovChain:
- Implement
state_valuesas a@propertywith a validating setter (storing toself._state_values), and have__init__delegate to it byself.state_values = state_values, as inMarkovChain.__init__. - You might also use
MarkovChain's error messages and setter docstring verbatim (e.g.,'state_values must be an array_like of length n').
|
Thanks for the review, @oyamad! I've updated
The focused tests and the full local test suite pass ( Could you please take another look when convenient? Thanks! |
* DOC: Correct the state_values docstring in MarkovChain The attribute does not default to integers 0 through n-1; it is None when unset, in which case the states are represented by their indices (as the Attributes entry and the simulate docstring already state). Co-Authored-By: Claude Fable 5 <[email protected]> * ENH: Refine DiscreteDP state_values; record in DPSolveResult Refine the state_values support added in #832: * Correct the docstring: the attribute is None when unset (in which case the states are represented by their indices), and the values may be 2-dimensional (row per state). * Record state_values in DPSolveResult. * Reorganize the tests into a class covering both formulations, 2-dimensional values, the solution pipeline, and carry-over by to_sa_pair_form/to_product_form. Cf. #248 Co-Authored-By: Claude Fable 5 <[email protected]> * ENH: Add action_values to DiscreteDP Add an action_values keyword argument to DiscreteDP, symmetric to state_values. The values play no role in the solution algorithms. DPSolveResult records action_values, and gains a sigma_values property returning the optimal policy decoded to action values, i.e., action_values[sigma] (sigma itself if action_values is None). The semantics follow the "universal action set" approach (approach 2 of QuantEcon/QuantEcon.jl#94 (comment); cf. QuantEcon/QuantEcon.jl#402): action_values labels a common action set A with A(s) a subset of A for each state s. In the state-action pairs formulation, its length defines the number of actions and may exceed a_indices.max() + 1, so a universal action set strictly containing the union of the feasible sets is representable in both formulations. to_sa_pair_form/to_product_form carry action_values unchanged, with to_product_form restoring the full number of columns, so actions feasible at no state survive the round trip. Cf. #248 Co-Authored-By: Claude Fable 5 <[email protected]> * ENH: Add util.index_dict Add `index_dict`, which builds a Numba typed dict mapping each value in an array of unique values (scalars or rows) to its index, usable both from the interpreter and inside jitted functions. This is the value-to-index translation layer for building DiscreteDP instances in value space (with `state_values`/`action_values` attached), and for the interface proposed in #228. Notable: Numba typed dicts hash floats by bit pattern, so -0.0 and 0.0 are distinct keys (unlike Python dicts); -0.0 is therefore rejected at build time. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
This PR partially addresses #248 by adding
state_valuessupport toDiscreteDP.Changes:
state_valuesargument toDiscreteDP.state_valuesconsistently withMarkovChain.state_valueswhen converting between product andstate-action-pair formulations.
state_valuesto theMarkovChainreturned bycontrolled_mc.conversion.
action_valuesandnum_actionsare intentionally left out of this PR,following the review discussion.