# dynamic_opt.py
"""Volume 2: Dynamic Optimization.
"""
import numpy as np
# Problem 1
def graph_policy(policy, b, u):
"""Plot the utility gained over time.
Return the total utility gained with the policy given.
Parameters:
policy (ndarray): Policy vector.
b (float): Discount factor. 0 < beta < 1.
u (function): Utility function.
Returns:
total_utility (float): Total utility gained from the policy given.
"""
raise NotImplementedError("Problem 1 Incomplete")
# Problem 2
def consumption(N, u=lambda x: np.sqrt(x)):
"""Create the consumption matrix for the given parameters.
Parameters:
N (int): Number of pieces given, where each piece of cake is the
same size.
u (function): Utility function.
Returns:
C ((N+1,N+1) ndarray): Consumption matrix.
"""
raise NotImplementedError("Problem 2 Incomplete")
# Problems 3-5
def eat_cake(T, N, B, u=lambda x: np.sqrt(x)):
"""Create the value and policy matrices for the given parameters.
Parameters:
T (int): Time at which to end (T+1 intervals).
N (int): Number of pieces given, where each piece of cake is the
same size.
B (float): Discount factor, where 0 < B < 1.
u (function): Utility function.
Returns:
A ((N+1,T+1) ndarray): The matrix where the (ij)th entry is the
value of having w_i cake at time j.
P ((N+1,T+1) ndarray): The matrix where the (ij)th entry is the
number of pieces to consume given i pieces at time j.
"""
raise NotImplementedError("Problems 3-5 Incomplete")
# Problem 6
def find_policy(T, N, B, u=lambda x: np.sqrt(x)):
"""Find the most optimal route to take assuming that we start with all of
the pieces. Show a graph of the optimal policy using graph_policy().
Parameters:
T (int): Time at which to end (T+1 intervals).
N (int): Number of pieces given, where each piece of cake is the same size.
B (float): Discount factor, where 0 < B < 1.
u (function): Utility function.
Returns:
maximum_utility (float): The total utility gained from the
optimal policy.
optimal_policy ((N,) nd array): The matrix describing the optimal
percentage to consume at each time.
"""
raise NotImplementedError("Problem 6 Incomplete")