random

Generate MarkovChain and DiscreteDP instances randomly.

quantecon.markov.random.random_discrete_dp(num_states, num_actions, beta=None, k=None, scale=1, sparse=False, sa_pair=False, random_state=None)[source]

Generate a DiscreteDP randomly. The reward values are drawn from the normal distribution with mean 0 and standard deviation scale.

Parameters:
num_statesscalar(int)

Number of states.

num_actionsscalar(int)

Number of actions.

betascalar(float), optional(default=None)

Discount factor. Randomly chosen from [0, 1) if not specified.

kscalar(int), optional(default=None)

Number of possible next states for each state-action pair. Equal to num_states if not specified.

scalescalar(float), optional(default=1)

Standard deviation of the normal distribution for the reward values.

sparsebool, optional(default=False)

Whether to store the transition probability array in sparse matrix form.

sa_pairbool, optional(default=False)

Whether to represent the data in the state-action pairs formulation. (If sparse=True, automatically set True.)

random_stateint or np.random.RandomState/Generator, optional

Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.

Returns:
ddpDiscreteDP

An instance of DiscreteDP.

quantecon.markov.random.random_markov_chain(n, k=None, sparse=False, random_state=None)[source]

Return a randomly sampled MarkovChain instance with n states, where each state has k states with positive transition probability.

Parameters:
nscalar(int)

Number of states.

kscalar(int), optional(default=None)

Number of states that may be reached from each state with positive probability. Set to n if not specified.

sparsebool, optional(default=False)

Whether to store the transition probability matrix in sparse matrix form.

random_stateint or np.random.RandomState/Generator, optional

Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.

Returns:
mcMarkovChain

Examples

>>> mc = qe.markov.random_markov_chain(3, random_state=1234)
>>> mc.P
array([[ 0.19151945,  0.43058932,  0.37789123],
       [ 0.43772774,  0.34763084,  0.21464142],
       [ 0.27259261,  0.5073832 ,  0.22002419]])
>>> mc = qe.markov.random_markov_chain(3, k=2, random_state=1234)
>>> mc.P
array([[ 0.19151945,  0.80848055,  0.        ],
       [ 0.        ,  0.62210877,  0.37789123],
       [ 0.56227226,  0.        ,  0.43772774]])
quantecon.markov.random.random_stochastic_matrix(n, k=None, sparse=False, format='csr', random_state=None)[source]

Return a randomly sampled n x n stochastic matrix with k nonzero entries for each row.

Parameters:
nscalar(int)

Number of states.

kscalar(int), optional(default=None)

Number of nonzero entries in each row of the matrix. Set to n if not specified.

sparsebool, optional(default=False)

Whether to generate the matrix in sparse matrix form.

formatstr, optional(default=’csr’)

Sparse matrix format, str in {‘bsr’, ‘csr’, ‘csc’, ‘coo’, ‘lil’, ‘dia’, ‘dok’}. Relevant only when sparse=True.

random_stateint or np.random.RandomState/Generator, optional

Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.

Returns:
Pnumpy ndarray or scipy sparse matrix (float, ndim=2)

Stochastic matrix.

See also

random_markov_chain

Return a random MarkovChain instance.