Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 30, 2025

This PR fixes a critical issue where setting CRRA = 1.0 (logarithmic utility) in various consumption models would cause a ZeroDivisionError due to division by (1.0 - CRRA) which equals zero.

Problem

Users attempting to use logarithmic utility by setting CRRA = 1.0 would encounter crashes:

from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType
Example = PerfForesightConsumerType()
Example.CRRA = 1.0
Example.solve()  # ZeroDivisionError: float division by zero

The error occurred in expressions like:

MPCnvrs = self.MPC**(-self.CRRA/(1.0-self.CRRA))

Solution

Added special case handling for CRRA == 1.0 using a small epsilon value (CRRA_safe = 1.0 + 1e-8) as suggested by the maintainers. This approach:

  • Prevents division by zero errors
  • Maintains numerical stability
  • Preserves exact behavior for all other CRRA values
  • Includes user warnings about the temporary workaround

Files Modified

  • ConsIndShockModel.py: Fixed 5 problematic expressions in solve_one_period_ConsPF, solve_one_period_ConsIndShock, and solve_one_period_ConsKinkedR
  • ConsPrefShockModel.py: Fixed 4 expressions in preference shock solvers
  • ConsIndShockModelFast.py: Fixed 3 expressions in the fast implementation
  • ConsBequestModel.py: Fixed 2 expressions in bequest model solver
  • ConsGenIncProcessModel.py: Fixed 1 expression in general income process solver
  • test_PerfForesightConsumerType.py: Added test case to prevent regression

Testing

The fix has been thoroughly tested to ensure:

  • CRRA=1.0 no longer causes crashes
  • All other CRRA values work exactly as before
  • Warning messages inform users of the temporary workaround
  • Solution quality remains appropriate

This is an interim fix until proper limit calculation for the logarithmic case is implemented.

Fixes #75.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits July 30, 2025 22:51
- ConsIndShockModelFast.py: Fixed vFuncNvrsSlope and vNvrsP expressions
- ConsBequestModel.py: Fixed vNvrsP_temp and MPCminNvrs expressions
- ConsGenIncProcessModel.py: Fixed MPCminNvrs expression

All fixes use the same epsilon approach (CRRA_safe = 1.0 + 1e-8) for consistency.
@Copilot Copilot AI changed the title [WIP] Perfect foresight model with CRRA = 1 Fix CRRA=1.0 division by zero errors across consumption models Jul 30, 2025
@Copilot Copilot AI requested a review from alanlujan91 July 30, 2025 23:04
Copilot finished work on behalf of alanlujan91 July 30, 2025 23:04
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.

Perfect foresight model with CRRA = 1
2 participants