From 130c23e69de027052bbf807c52030422f98aef7a Mon Sep 17 00:00:00 2001 From: Zejin Shi Date: Fri, 24 Feb 2017 14:20:26 +0900 Subject: [PATCH 1/4] fix unknown sections --- quantecon/cartesian.py | 16 ++++++++-------- quantecon/game_theory/normal_form_game.py | 4 ++-- quantecon/gridtools.py | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/quantecon/cartesian.py b/quantecon/cartesian.py index c1bfba45d..69634c05b 100644 --- a/quantecon/cartesian.py +++ b/quantecon/cartesian.py @@ -13,13 +13,13 @@ def cartesian(nodes, order='C'): '''Cartesian product of a list of arrays - Parameters: - ----------- + Parameters + ---------- nodes: (list of 1d-arrays) order: ('C' or 'F') order in which the product is enumerated - Returns: - -------- + Returns + ------- out: (2d-array) each line corresponds to one point of the product space ''' @@ -50,15 +50,15 @@ def cartesian(nodes, order='C'): def mlinspace(a, b, nums, order='C'): '''Constructs a regular cartesian grid - Parameters: - ----------- + Parameters + ---------- a: (1d-array) lower bounds in each dimension b: (1d-array) upper bounds in each dimension nums: (1d-array) number of nodes along each dimension order: ('C' or 'F') order in which the product is enumerated - Returns: - -------- + Returns + ------- out: (2d-array) each line corresponds to one point of the product space ''' diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index 0d3a444d5..97d222b2d 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -703,8 +703,8 @@ def best_response_2p(payoff_matrix, opponent_mixed_action, tol=1e-8): tol : scalar(float), optional(default=None) Tolerance level used in determining best responses. - Return - ------ + Returns + ------- scalar(int) Best response action. diff --git a/quantecon/gridtools.py b/quantecon/gridtools.py index f29b48b56..9bec7ae3e 100644 --- a/quantecon/gridtools.py +++ b/quantecon/gridtools.py @@ -12,13 +12,13 @@ def cartesian(nodes, order='C'): '''Cartesian product of a list of arrays - Parameters: - ----------- + Parameters + ---------- nodes: (list of 1d-arrays) order: ('C' or 'F') order in which the product is enumerated - Returns: - -------- + Returns + ------- out: (2d-array) each line corresponds to one point of the product space ''' @@ -49,15 +49,15 @@ def cartesian(nodes, order='C'): def mlinspace(a, b, nums, order='C'): '''Constructs a regular cartesian grid - Parameters: - ----------- + Parameters + ---------- a: (1d-array) lower bounds in each dimension b: (1d-array) upper bounds in each dimension nums: (1d-array) number of nodes along each dimension order: ('C' or 'F') order in which the product is enumerated - Returns: - -------- + Returns + ------- out: (2d-array) each line corresponds to one point of the product space ''' From 5fb39d018afb0189fcf8dfbdce04c922ae379775 Mon Sep 17 00:00:00 2001 From: Zejin Shi Date: Wed, 15 Mar 2017 17:39:03 +0900 Subject: [PATCH 2/4] Fix block quotes --- quantecon/compute_fp.py | 6 +++--- quantecon/game_theory/mclennan_tourky.py | 3 +-- quantecon/game_theory/normal_form_game.py | 19 +++++++------------ quantecon/game_theory/random.py | 6 ++---- quantecon/markov/core.py | 12 ++++-------- quantecon/markov/ddp.py | 8 ++++---- quantecon/markov/random.py | 15 ++++++--------- quantecon/random/utilities.py | 6 ++---- 8 files changed, 29 insertions(+), 46 deletions(-) diff --git a/quantecon/compute_fp.py b/quantecon/compute_fp.py index 83369d12d..866885d32 100644 --- a/quantecon/compute_fp.py +++ b/quantecon/compute_fp.py @@ -86,9 +86,9 @@ def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=2, print_skip : scalar(int), optional(default=5) How many iterations to apply between print messages (effective only when `verbose=2`) - method : str in {'iteration', 'imitation_game'}, - optional(default='iteration') - Method of computing an approximate fixed point + method : str, optional(default='iteration') + str in {'iteration', 'imitation_game'}. Method of computing + an approximate fixed point args, kwargs : Other arguments and keyword arguments that are passed directly to the function T each time it is called diff --git a/quantecon/game_theory/mclennan_tourky.py b/quantecon/game_theory/mclennan_tourky.py index 9b9bceba3..aec85734e 100644 --- a/quantecon/game_theory/mclennan_tourky.py +++ b/quantecon/game_theory/mclennan_tourky.py @@ -25,8 +25,7 @@ def mclennan_tourky(g, init=None, epsilon=1e-3, max_iter=200, g : NormalFormGame NormalFormGame instance. - init : array_like(int or array_like(float, ndim=1)), - optional(default=None) + init : array_like(int or array_like(float, ndim=1)), optional Initial action profile, an array of N objects, where each object must be an iteger (pure action) or an array of floats (mixed action). If None, default to an array of zeros (the zero-th diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index 97d222b2d..de5b2b9d7 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -276,8 +276,7 @@ def best_response(self, opponents_actions, tie_breaking='smallest', Parameters ---------- - opponents_actions : array_like(int or array_like(float)) or - array_like(int, ndim=1) or scalar(int) + opponents_actions : scalar(int) or array_like A profile of N-1 opponents' actions. If N=2, then it must be a 1-dimensional array of floats (in which case it is treated as the opponent's mixed action) or a scalar of integer (in @@ -286,10 +285,9 @@ def best_response(self, opponents_actions, tie_breaking='smallest', object must be an integer (pure action) or an array of floats (mixed action). - tie_breaking : {'smallest', 'random', False}, - optional(default='smallest') - Control how, or whether, to break a tie (see Returns for - details). + tie_breaking : str, optional(default='smallest') + str in {'smallest', 'random', False}. Control how, or + whether, to break a tie (see Returns for details). payoff_perturbation : array_like(float), optional(default=None) Array of length equal to the number of actions of the player @@ -300,8 +298,7 @@ def best_response(self, opponents_actions, tie_breaking='smallest', Tolerance level used in determining best responses. If None, default to the value of the `tol` attribute. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState @@ -350,8 +347,7 @@ def random_choice(self, actions=None, random_state=None): actions : array_like(int), optional(default=None) An array of integers representing pure actions. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState @@ -389,8 +385,7 @@ class NormalFormGame(object): Parameters ---------- - data : array_like(Player) or array_like(int, ndim=1) or - array_like(float, ndim=2 or N+1) + data : array_like of Player, int (ndim=1), or float (ndim=2 or N+1) Data to initialize a NormalFormGame. `data` may be an array of Players, in which case the shapes of the Players' payoff arrays must be consistent. If `data` is an array of N integers, then diff --git a/quantecon/game_theory/random.py b/quantecon/game_theory/random.py index 2c4397105..f83a1f2c4 100644 --- a/quantecon/game_theory/random.py +++ b/quantecon/game_theory/random.py @@ -22,8 +22,7 @@ def random_game(nums_actions, random_state=None): nums_actions : tuple(int) Tuple of the numbers of actions, one for each player. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is @@ -63,8 +62,7 @@ def covariance_game(nums_actions, rho, random_state=None): Covariance of a pair of payoff values. Must be in [-1/(N-1), 1], where N is the number of players. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is diff --git a/quantecon/markov/core.py b/quantecon/markov/core.py index 782d09a42..10e2d35d0 100644 --- a/quantecon/markov/core.py +++ b/quantecon/markov/core.py @@ -458,16 +458,14 @@ def simulate_indices(self, ts_length, init=None, num_reps=None, ts_length : scalar(int) Length of each simulation. - init : scalar(int) or array_like(int, ndim=1), - optional(default=None) + init : int or array_like(int, ndim=1), optional Initial state(s). If None, the initial state is randomly drawn. num_reps : scalar(int), optional(default=None) Number of repetitions of simulation. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState @@ -558,8 +556,7 @@ def simulate(self, ts_length, init=None, num_reps=None, random_state=None): num_reps : scalar(int), optional(default=None) Number of repetitions of simulation. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState @@ -700,8 +697,7 @@ def mc_sample_path(P, init=0, sample_size=1000, random_state=None): sample_size : scalar(int), optional(default=1000) The length of the sample path. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is diff --git a/quantecon/markov/ddp.py b/quantecon/markov/ddp.py index aaa638d7c..2087dd41b 100644 --- a/quantecon/markov/ddp.py +++ b/quantecon/markov/ddp.py @@ -639,10 +639,10 @@ def solve(self, method='policy_iteration', Parameters ---------- - method : str in {'value_iteration', 'vi', 'policy_iteration', - 'pi', 'modified_policy_iteration', 'mpi'}, - optinal(default='policy_iteration') - Solution method. + method : str, optinal(default='policy_iteration') + Solution method, str in {'value_iteration', 'vi', + 'policy_iteration', 'pi', 'modified_policy_iteration', + 'mpi'}. v_init : array_like(float, ndim=1), optional(default=None) Initial value function, of length n. If None, `v_init` is diff --git a/quantecon/markov/random.py b/quantecon/markov/random.py index 55af34ed8..f7a8c2ea7 100644 --- a/quantecon/markov/random.py +++ b/quantecon/markov/random.py @@ -35,8 +35,7 @@ def random_markov_chain(n, k=None, sparse=False, random_state=None): Whether to store the transition probability matrix in sparse matrix form. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is @@ -84,12 +83,11 @@ def random_stochastic_matrix(n, k=None, sparse=False, format='csr', sparse : bool, optional(default=False) Whether to generate the matrix in sparse matrix form. - format : str in {'bsr', 'csr', 'csc', 'coo', 'lil', 'dia', 'dok'}, - optional(default='csr') - Sparse matrix format. Relevant only when sparse=True. + format : str, optional(default='csr') + Sparse matrix format, str in {'bsr', 'csr', 'csc', 'coo', 'lil', + 'dia', 'dok'}. Relevant only when sparse=True. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is @@ -183,8 +181,7 @@ def random_discrete_dp(num_states, num_actions, beta=None, Whether to represent the data in the state-action pairs formulation. (If `sparse=True`, automatically set `True`.) - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is diff --git a/quantecon/random/utilities.py b/quantecon/random/utilities.py index abd1d72b1..e34c9fd5e 100644 --- a/quantecon/random/utilities.py +++ b/quantecon/random/utilities.py @@ -22,8 +22,7 @@ def probvec(m, k, random_state=None, parallel=True): k : scalar(int) Dimension of each probability vectors. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is @@ -112,8 +111,7 @@ def sample_without_replacement(n, k, num_trials=None, random_state=None): num_trials : scalar(int), optional(default=None) Number of trials. - random_state : scalar(int) or np.random.RandomState, - optional(default=None) + random_state : int or np.random.RandomState, optional Random seed (integer) or np.random.RandomState instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is From 8817a972bb26cf8725d82ba53cb71f80db2c176c Mon Sep 17 00:00:00 2001 From: Zejin Shi Date: Wed, 15 Mar 2017 17:40:22 +0900 Subject: [PATCH 3/4] Fix inline * --- quantecon/markov/ddp.py | 12 ++++++------ quantecon/quad.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/quantecon/markov/ddp.py b/quantecon/markov/ddp.py index 2087dd41b..b6176e886 100644 --- a/quantecon/markov/ddp.py +++ b/quantecon/markov/ddp.py @@ -134,8 +134,8 @@ class DiscreteDP(object): * discount factor beta, where `R[s, a]` is the reward for action `a` when the state is - `s` and `Q[s, a, s']` is the probability that the state in the - next period is `s'` when the current state is `s` and the action + `s` and `Q[s, a, s_next]` is the probability that the state in the + next period is `s_next` when the current state is `s` and the action chosen is `a`. 2. `DiscreteDP(R, Q, beta, s_indices, a_indices)` @@ -151,8 +151,8 @@ class DiscreteDP(object): where the pairs (`s_indices[0]`, `a_indices[0]`), ..., (`s_indices[L-1]`, `a_indices[L-1]`) enumerate feasible state-action pairs, and `R[i]` is the reward for action - `a_indices[i]` when the state is `s_indices[i]` and `Q[i, s']` is - the probability that the state in the next period is `s'` when + `a_indices[i]` when the state is `s_indices[i]` and `Q[i, s_next]` is + the probability that the state in the next period is `s_next` when the current state is `s_indices[i]` and the action chosen is `a_indices[i]`. With this formulation, `Q` may be represented by a scipy.sparse matrix. @@ -213,7 +213,7 @@ class DiscreteDP(object): r(0, 0) = 5, r(0, 1) =10, r(1, 0) = -1 - * Transition probabilities q(s'|s, a): + * Transition probabilities q(s_next|s, a): q(0|0, 0) = 0.5, q(1|0, 0) = 0.5, q(0|0, 1) = 0, q(1|0, 1) = 1, @@ -648,7 +648,7 @@ def solve(self, method='policy_iteration', Initial value function, of length n. If None, `v_init` is set such that v_init(s) = max_a r(s, a) for value iteration and policy iteration; for modified policy iteration, - v_init(s) = min_(s', a) r(s', a)/(1 - beta) to guarantee + v_init(s) = min_(s_next, a) r(s_next, a)/(1 - beta) to guarantee convergence. epsilon : scalar(float), optional(default=None) diff --git a/quantecon/quad.py b/quantecon/quad.py index 83c2dc653..aced4d8cd 100644 --- a/quantecon/quad.py +++ b/quantecon/quad.py @@ -464,7 +464,7 @@ def quadrect(f, n, a, b, kind='lege', *args, **kwargs): that accepts as its first argument a matrix representing points along each dimension (each dimension is a column). Other arguments that need to be passed to the function are caught by - *args and **kwargs + `*args` and `**kwargs` n : int or array_like(float) A length-d iterable of the number of nodes in each dimension From d69f1562698ae1d6a1b354f4dfe1c62586b2ddcd Mon Sep 17 00:00:00 2001 From: Zejin Shi Date: Fri, 17 Mar 2017 19:12:25 +0900 Subject: [PATCH 4/4] Update docs. --- quantecon/game_theory/normal_form_game.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index de5b2b9d7..4db9504e1 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -277,13 +277,15 @@ def best_response(self, opponents_actions, tie_breaking='smallest', Parameters ---------- opponents_actions : scalar(int) or array_like - A profile of N-1 opponents' actions. If N=2, then it must be - a 1-dimensional array of floats (in which case it is treated - as the opponent's mixed action) or a scalar of integer (in - which case it is treated as the opponent's pure action). If - N>2, then it must be an array of N-1 objects, where each - object must be an integer (pure action) or an array of - floats (mixed action). + A profile of N-1 opponents' actions, represented by either + scalar(int), array_like(float), array_like(int), or + array_like(array_like(float)). If N=2, then it must be a + scalar of integer (in which case it is treated as the + opponent's pure action) or a 1-dimensional array of floats + (in which case it is treated as the opponent's mixed + action). If N>2, then it must be an array of N-1 objects, + where each object must be an integer (pure action) or an + array of floats (mixed action). tie_breaking : str, optional(default='smallest') str in {'smallest', 'random', False}. Control how, or