-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_gen_data_mu.py
73 lines (57 loc) · 2.01 KB
/
simple_gen_data_mu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
"""periodic boundary condition"""
K = 10; L = 15
class Particle_Class:
def __init__(self,i,x,mu,n):
self.id = i
self.x=x
self.mu = mu
self.n = n
def set_x(self,x):
self.x = x
def get_x(self):
return self.x
def set_n(self,n):
self.n = n
def get_n(self):
return self.n
def get_mu(self):
return self.mu
def init_particles():
global particles
#------ location -------#
location = np.arange(L)
np.random.shuffle(location)
location = np.sort( np.copy(location[:K]) ) #ex. 0,1,2,3,4,5 -> 0,2,3,5
#------ transfer coefficient -------#
trans_coeff = np.random.uniform(0,1,K)
trans_coeff = np.copy(trans_coeff) / np.sum(trans_coeff)
for i in range(K):
vacancy_i = ( location[(i+1)%K]-location[i] + L ) % L - 1
particles.append( Particle_Class( i, location[i], trans_coeff[i], vacancy_i ) )
def update():
global particles,f_vacancy
for i in range(K):
if( np.random.uniform() < particles[i].get_mu() ):
f_vacancy.write( str(1)+" " )
else:
f_vacancy.write( str(0)+" " )
f_vacancy.write("\n")
if __name__ == "__main__":
particles = []
init_particles()
sample_size = 10000
#fname_location = "location_K"+str(K)+"_L"+str(L)+"_N"+str(sample_size)+"_every_T1step.dat"
fname_vacancy = "simple_vacancy_K"+str(K)+"_L"+str(L)+"_N"+str(sample_size)+"_every_T1step.dat"
fname_trans_coeff = "simple_trans_coeff_K"+str(K)+"_L"+str(L)+"_N"+str(sample_size)+"_every_T1step.dat"
#f_location = open(fname_location,"w")
f_vacancy = open(fname_vacancy,"w")
f_trans_coeff = open(fname_trans_coeff,"w")
for i in range(K):f_trans_coeff.write( str(particles[i].mu) + " " )
f_trans_coeff.close()
t_wait = 10
for t in range(sample_size*t_wait):
update()
f_vacancy.close()