ENH: Add action_values to DiscreteDP; add util.index_dict - #940
Merged
Conversation
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds human-readable action values to DiscreteDP and introduces a Numba-compatible value-to-index utility.
Changes:
- Propagates state/action values through DP conversions and solve results.
- Adds
sigma_valuesfor decoded optimal policies. - Adds and documents
index_dict, with comprehensive tests.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
quantecon/markov/ddp.py |
Implements action values and result propagation. |
quantecon/markov/core.py |
Clarifies state-value documentation. |
quantecon/markov/tests/test_ddp.py |
Tests state/action value behavior. |
quantecon/util/indexing.py |
Implements index_dict. |
quantecon/util/tests/test_indexing.py |
Tests indexing behavior and validation. |
quantecon/util/__init__.py |
Exports index_dict. |
quantecon/__init__.py |
Exposes index_dict publicly. |
docs/source/util/indexing.rst |
Adds utility API documentation. |
docs/source/util.rst |
Includes the indexing documentation page. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 <noreply@anthropic.com>
oyamad
force-pushed
the
ddp-state-action-values
branch
from
August 16, 2026 07:45
e3ff6aa to
2dd0aef
Compare
Contributor
|
thanks @oyamad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
action_valuestoDiscreteDP, building on ENH: Add state_values to DiscreteDP #832 which addedstate_valuesindex_dictwhich builds a Numba typed dict (so usable within a jitted function) mapping each value in an array of unique values to its indexDefinition of the set of actions
I proposed to defer the decision in #832 (comment), but of the two approaches as described in QuantEcon/QuantEcon.jl#94 (comment) I am proposing Approach 2 here: Universal action set
AwithA(s) \subset Afor eachs; the union of allA(s)s may be a proper subset ofA.n x mreward matrixRshares one action axis for all states, so each actionais the same action at every state: thus simply,self._num_actions = self.R.shape[1].action_valuesif supplied defines the number of actions, soself._num_actions = values.shape[0](wherevalues = np.asarray(action_values)); otherwise,self._num_actions = self.a_indices.max() + 1.Example
Old Aiyagari code:
This PR:
AI assisted with Claude Code Fable 5