Helpers

Collection of helper functions

source

make_variable_vector

 make_variable_vector (variable, length:int)

Turn a variable into a vector or check that length is consistent.

Type Details
variable can be iterable or float or int
length int length of the vector

For example, when providing a discount factor of 0.9 to all 5 agents, we can simply write

make_variable_vector(0.9, 5)
Array([0.9, 0.9, 0.9, 0.9, 0.9], dtype=float32, weak_type=True)

source

compute_stationarydistribution

 compute_stationarydistribution (Tkk:jax.Array)

Compute stationary distribution for transition matrix Tkk.

Type Details
Tkk Array Transition matrix

For example, let’s create a random transition matrix with dimension 4:

Tkk = np.random.rand(4,4)

A transition matrix contains probabilities, which need to sum up to 1.

Tkk = Tkk / Tkk.sum(-1, keepdims=True)

compute_stationarydistribution should return a 4 by 4 matrix with the stationary distribution in the first column, and the rest filled with a dummy value of -10. This was done to make it work with jax just-in-time-compilation.

compute_stationarydistribution(Tkk).round(1)
Array([[  0.2, -10. , -10. , -10. ],
       [  0.3, -10. , -10. , -10. ],
       [  0.2, -10. , -10. , -10. ],
       [  0.3, -10. , -10. , -10. ]], dtype=float32)