Skip to content

Conversation

alanlujan91
Copy link
Member

Consolidate TimeVaryingDiscreteDistribution into IndexDistribution

Please ensure your pull request adheres to the following guidelines:

  • Tests for new functionality/models or Tests to reproduce the bug-fix in code.
  • Updated documentation of features that add new functionality.
  • Update CHANGELOG.md with major/minor changes.

Why?
This PR unifies IndexDistribution and TimeVaryingDiscreteDistribution into a single, more versatile IndexDistribution 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 new distributions parameter, allowing it to directly wrap a list of discrete distributions (absorbing the functionality of TimeVaryingDiscreteDistribution).
  • The TimeVaryingDiscreteDistribution class has been removed.
  • All internal references, imports, type checks, and utility functions across the codebase have been updated to use the enhanced IndexDistribution.

Open in Cursor Open in Web

…tionality

Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
Copy link

cursor bot commented Aug 9, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 2 commits August 9, 2025 01:57
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
@alanlujan91 alanlujan91 marked this pull request as ready for review August 9, 2025 02:10
Co-authored-by: alanlujan91 <alanlujan91@gmail.com>
@alanlujan91 alanlujan91 requested a review from Copilot August 9, 2025 12:27
Copy link
Contributor

@Copilot Copilot AI left a 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 new distributions 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
Copy link
Preview

Copilot AI Aug 9, 2025

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.

Suggested change
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)

Copy link
Preview

Copilot AI Aug 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants