def compute_ergodic(self): r''' Computes the ergodic distribution over the unemployment and employment states Returns --------- pibar(1d-array) : the ergodic distribution of P ''' return quantecon.mc_compute_stationary(self.P)
graph_mat = np.zeros((14,14),dtype=float) for line in f: tmp = (re.findall('\w', line)) graph_mat[idxdict[tmp[0]],idxdict[tmp[1]]] = 1 return graph_mat gmat = graph_from_file(filepath) #normalize graph by number of links to form Markov matrix n = gmat.shape[0] gmat = gmat/np.reshape(np.repeat(gmat.sum(axis=1).T,n,axis=0),(n,n)) #solve for stationary distribution pstat = qe.mc_compute_stationary(gmat) # Ex 3 def approx_markov(rho, sigma_u, m=3, n=7): sigma_y = np.sqrt((sigma_u**2)/(1.-rho**2)) x_arr = np.linspace(start=-m*sigma_y,stop=m*sigma_y,num=n) F = stats.norm(scale=sigma_u**2).cdf s = x_arr[1]-x_arr[0] P_arr = np.empty((n,n),dtype=float) for i in range(0,n): for j in range(0,n): if j==0: P_arr[i][j] = F(x_arr[0]-rho*x_arr[i]+s/2) elif j==n-1:
P = ((0.971, 0.029, 0.000), (0.145, 0.778, 0.077), (0.000, 0.508, 0.492)) P = np.array(P) psi = (0.0, 0.2, 0.8) # Initial condition fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_zlim(0, 1) ax.set_xticks((0.25, 0.5, 0.75)) ax.set_yticks((0.25, 0.5, 0.75)) ax.set_zticks((0.25, 0.5, 0.75)) x_vals, y_vals, z_vals = [], [], [] for t in range(20): x_vals.append(psi[0]) y_vals.append(psi[1]) z_vals.append(psi[2]) psi = np.dot(psi, P) ax.scatter(x_vals, y_vals, z_vals, c='r', s=60) psi_star = mc_compute_stationary(P)[0] ax.scatter(psi_star[0], psi_star[1], psi_star[2], c='k', s=60) plt.show()