-
-
Notifications
You must be signed in to change notification settings - Fork 206
Consolidate distribution classes #1592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…tionality Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
Cursor Agent can help with this pull request. Just |
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR consolidates two distribution classes by merging TimeVaryingDiscreteDistribution
functionality into IndexDistribution
, simplifying the codebase and providing a unified API for handling indexed/time-varying distributions.
Key changes:
- Enhanced
IndexDistribution
with a newdistributions
parameter to directly wrap discrete distributions - Removed the redundant
TimeVaryingDiscreteDistribution
class - Updated all references and imports throughout the codebase to use the consolidated
IndexDistribution
Reviewed Changes
Copilot reviewed 6 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
HARK/distributions/base.py | Consolidated classes by adding distributions parameter to IndexDistribution and removing TimeVaryingDiscreteDistribution |
HARK/distributions/init.py | Removed TimeVaryingDiscreteDistribution from exports |
HARK/simulation/monte_carlo.py | Simplified type checking by removing TimeVaryingDiscreteDistribution references |
HARK/distributions/utils.py | Updated utility function to work with consolidated IndexDistribution |
HARK/core.py | Updated type checking to use only IndexDistribution |
HARK/Calibration/Income/IncomeProcesses.py | Migrated TimeVaryingDiscreteDistribution usage to IndexDistribution |
self.engine = engine | ||
|
||
self.dstns = [] | ||
|
||
# If no engine/conditional were provided, remain empty (should not happen in normal use) | ||
if self.engine is None and not self.conditional: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment suggests a condition that 'should not happen in normal use', but the code allows it. Consider either removing this case handling or throwing an exception if this truly represents an invalid state.
return | |
# If no engine/conditional were provided, this is an invalid state. | |
if self.engine is None and not self.conditional: | |
raise ValueError("MarkovProcess: No engine or conditional parameters provided; this should not happen in normal use.") |
Copilot uses AI. Check for mistakes.
@@ -367,70 +400,6 @@ def draw(self, condition): | |||
these = c == condition | |||
N = np.sum(these) | |||
|
|||
cond = {key: val[c] for (key, val) in self.conditional.items()} | |||
draws[these] = self[c].draw(N) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line cond = {key: val[c] for (key, val) in self.conditional.items()}
was removed but self[c].draw(N)
still depends on the conditional parameters being properly set for index c. This could cause incorrect behavior when drawing from indexed distributions.
Copilot uses AI. Check for mistakes.
Consolidate
TimeVaryingDiscreteDistribution
intoIndexDistribution
Please ensure your pull request adheres to the following guidelines:
Why?
This PR unifies
IndexDistribution
andTimeVaryingDiscreteDistribution
into a single, more versatileIndexDistribution
class. The previous existence of two distinct classes for handling indexed/time-varying distributions led to redundant code and an unnecessarily complex API. This consolidation simplifies the codebase by providing a single, consistent interface for both use cases.Changes:
IndexDistribution
now supports a newdistributions
parameter, allowing it to directly wrap a list of discrete distributions (absorbing the functionality ofTimeVaryingDiscreteDistribution
).TimeVaryingDiscreteDistribution
class has been removed.IndexDistribution
.