Skip to content

Commit

Permalink
DiscreteDP: Allow beta=1
Browse files Browse the repository at this point in the history
  • Loading branch information
oyamad committed Mar 18, 2016
1 parent b0cb89a commit 3bdc97e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions quantecon/markov/ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"""
from __future__ import division
import warnings
import numpy as np
import scipy.sparse as sp

Expand Down Expand Up @@ -165,7 +166,7 @@ class DiscreteDP(object):
Transition probability array.
beta : scalar(float)
Discount factor. Must be 0 <= beta < 1.
Discount factor. Must be in [0, 1].
s_indices : array_like(int, ndim=1), optional(default=None)
Array containing the indices of the states.
Expand All @@ -190,6 +191,13 @@ class DiscreteDP(object):
max_iter : scalar(int), default=250
Default value for the maximum number of iterations.
Notes
-----
DiscreteDP accepts beta=1 for convenience. In this case, infinite
horizon solution methods are disabled, and the instance is then seen
as merely an object carrying the Bellman operator, which may be used
for backward induction for finite horizon problems.
Examples
--------
Consider the following example, taken from Puterman (2005), Section
Expand Down Expand Up @@ -401,8 +409,12 @@ def s_wise_max(vals, out=None, out_argmax=None):
# Check that for every state, at least one action is feasible
self._check_action_feasibility()

if not (0 <= beta < 1):
raise ValueError('beta must be in [0, 1)')
if not (0 <= beta <= 1):
raise ValueError('beta must be in [0, 1]')
if beta == 1:
msg = 'infinite horizon solution methods are disabled with beta=1'
warnings.warn(msg)
self._error_msg_no_discounting = 'method invalid for beta=1'
self.beta = beta

self.epsilon = 1e-3
Expand Down Expand Up @@ -561,6 +573,9 @@ def evaluate_policy(self, sigma):
Value vector of `sigma`, of length n.
"""
if self.beta == 1:
raise NotImplementedError(self._error_msg_no_discounting)

# Solve (I - beta * Q_sigma) v = R_sigma for v
R_sigma, Q_sigma = self.RQ_sigma(sigma)
b = R_sigma
Expand Down Expand Up @@ -678,6 +693,9 @@ def value_iteration(self, v_init=None, epsilon=None, max_iter=None):
`solve` method.
"""
if self.beta == 1:
raise NotImplementedError(self._error_msg_no_discounting)

if max_iter is None:
max_iter = self.max_iter
if epsilon is None:
Expand Down Expand Up @@ -718,6 +736,9 @@ def policy_iteration(self, v_init=None, max_iter=None):
`solve` method.
"""
if self.beta == 1:
raise NotImplementedError(self._error_msg_no_discounting)

if max_iter is None:
max_iter = self.max_iter

Expand Down Expand Up @@ -755,6 +776,9 @@ def modified_policy_iteration(self, v_init=None, epsilon=None,
the `solve` method.
"""
if self.beta == 1:
raise NotImplementedError(self._error_msg_no_discounting)

if max_iter is None:
max_iter = self.max_iter
if epsilon is None:
Expand Down

0 comments on commit 3bdc97e

Please sign in to comment.