def generate_shock(prob, num_agent, num_time, buffer_time, save_dest, seed, init_state): np.random.seed(seed) data_rand = np.random.rand(num_agent, num_time+buffer_time) data_i = np.ones((num_agent, num_time+buffer_time), dtype = int) data_i[:, 0] = init_state calc_trans(data_i, data_rand, prob) data_i = data_i[:, buffer_time:] np.save(save_dest + '.npy' , data_i) split_shock(save_dest, num_agent, num_core)
if __name__ == '__main__': f = open(nd_log_file, 'w') # f.writelines('w, p, rc, dist, mom0, mom1, mom2, mom3\n') f.writelines( 'p, rc, ome, varpi, dist, mom0, mom1, mom2, mom4, mom5, mom7, mom8\n') f.close() ### generate shocks ### np.random.seed(0) data_rand = np.random.rand(num_pop, sim_time) data_i_s = np.ones((num_pop, sim_time), dtype=int) data_i_s[:, 0] = 7 #initial state. it does not matter if simulation is long enough. calc_trans(data_i_s, data_rand, prob) data_i_s = data_i_s[:, 2000:] np.save(path_to_data_i_s + '.npy', data_i_s) split_shock(path_to_data_i_s, 25_000, num_core) del data_rand np.random.seed(2) data_rand = np.random.rand( num_pop, sim_time + 1) #+1 is added since this matters in calculation data_is_o = np.ones((num_pop, sim_time + 1), dtype=int) data_is_o[:, 0] = 0 #initial state. it does not matter if simulation is long enough. calc_trans(data_is_o, data_rand, prob_yo) data_is_o = data_is_o[:, 2000:] np.save(path_to_data_is_o + '.npy', data_is_o) split_shock(path_to_data_is_o, 25_000, num_core)
f.writelines( 'p, rc, ome, varpi, dist, mom0, mom1, mom2, mom4, mom5, mom7\n') f.close() from markov import calc_trans, Stationary num_pop = 100_000 sim_time = 3_000 data_i_s = np.ones((num_pop, sim_time), dtype=int) #need to set initial state for zp data_i_s[:, 0] = 7 # prob = np.load('./input_data/transition_matrix.npy') np.random.seed(0) data_rand = np.random.rand(num_pop, sim_time) calc_trans(data_i_s, data_rand, prob) data_i_s = data_i_s[:, 2000:] np.save(path_to_data_i_s + '.npy', data_i_s) ### check f = open(nd_log_file, 'w') f.writelines( np.array_str(np.bincount(data_i_s[:, 0]) / np.sum(np.bincount(data_i_s[:, 0])), precision=4, suppress_small=True) + '\n') f.writelines( np.array_str(Stationary(prob), precision=4, suppress_small=True) + '\n') f.close()