v9.1.1
Menu

Effective Horizon of a Discount Factor

mediumPROMarkov Decision Processes and Bellman EquationsReinforcement LearningRL 1: Foundations

Problem Statement

The effective planning horizon implied by a discount factor is often summarized as 1 / (1 - gamma) — the sum of the geometric discount series sum_{t=0}^inf gamma^t. For gamma == 1 the horizon is infinite; represent that with float('inf').

Implement effective_horizon(gamma) returning a float.

Example

Input
effective_horizon(0.9)
Output
10.0
Reasoning
  • Check if the discount factor γ=0.9\gamma = 0.9 is greater than or equal to 1.01.0 to determine if the horizon is infinite; since 0.9<1.00.9 < 1.0, the horizon is finite.
  • Calculate the denominator of the geometric series sum by subtracting the discount factor from 11: 1.0−0.9=0.11.0 - 0.9 = 0.1.
  • Compute the effective horizon by dividing 11 by this denominator: 1.0/0.1=10.01.0 / 0.1 = 10.0.
  • The final output is 10.0

Constraints

  • 0.0 <= gamma <= 1.0
  • gamma == 1.0 returns float('inf').
  • Otherwise return 1 / (1 - gamma).

Learn this in

More from RL 1: Foundations

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.