Python에서 U 분포 생성

4109 단어 PythonU 분포
서적:'데이터가 보이지 않는 손 착용 센서가 보여주는 인간, 조직, 사회의 법칙'에 기재된 U분포를 만들어 보려고 파이톤으로 프로그래밍을 했습니다.
2017.2.12 코드 오류를 수정했습니다.
책에 관한 상세한 내용은 나의 블로그에도 기록되어 있다.
[Link] http://kansetsulight.seesaa.net

코드


import numpy as np
import matplotlib.pyplot as plt
nindex = []
n = 0
nxxx = 0
nyyy = 0
x = np.random.rand(1000)*100
y = np.random.rand(1000)*100
while n < 1000:
if x[n] < 10:
nxxx = 1
elif x[n] < 20:
nxxx = 2
elif x[n] < 30:
nxxx = 3
elif x[n] < 40:
nxxx = 4
elif x[n] < 50:
nxxx = 5
elif x[n] < 60:
nxxx = 6
elif x[n] < 70:
nxxx = 7
elif x[n] < 80:
nxxx = 8
elif x[n] < 90:
nxxx = 9
elif x[n] <= 100:
nxxx = 10
if y[n] < 10:
nyyy = 1
elif y[n] < 20:
nyyy = 2
elif y[n] < 30:
nyyy = 3
elif y[n] < 40:
nyyy = 4
elif y[n] < 50:
nyyy = 5
elif y[n] < 60:
nyyy = 6
elif y[n] < 70:
nyyy = 7
elif y[n] < 80:
nyyy = 8
elif y[n] < 90:
nyyy = 9
elif y[n] <= 100:
nyyy = 10
nindex.append([nxxx, nyyy])
n = n + 1
nxxx = 0
nyyy = 0
ite = 0
chk = 0
while ite < 1e4:
chk1 = 0
while chk1 == 0:
x_strt = np.random.randint(1,11)
y_strt = np.random.randint(1,11)
chk1 = nindex.count([x_strt,y_strt])
strt = nindex.index([x_strt,y_strt])
print 'index of start: ',strt
print 'index of start: ',nindex[strt]
print 'x_strt, y_strt: ',x_strt, y_strt
chk2 = 0
while chk2 == 0:
x_dest = np.random.randint(1,11)
y_dest = np.random.randint(1,11)
chk2 = nindex.count([x_dest,y_dest])
print chk2
dest = nindex.index([x_dest,y_dest])
x[strt] = float(x_dest*10)-np.random.uniform(0,10)
y[strt] = float(y_dest*10)-np.random.uniform(0,10)
print 'dest x,y index: ', x_dest,' ', y_dest
print 'dest crd: ',x[strt],y[strt]
print

Update for nindex


nindex[strt] = nindex[dest]
ite = ite + 1
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.scatter(x,y,s=1)
ax.set_title('random plot')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.grid(True)
plt.savefig('testfig')
plt.show()
코드는 GiitHub에도 UP이 있습니다.
[Link] https://github.com/yama89/U-distribution1.0

결실

< 1step後 >
아직 균등하네.<10step後>
변한 게 없어요.<100step後>
이것도 너무(완전?)안 변해.<1000step後>
나는 마침내 편차가 생겼다고 생각한다.<2000step後>
이거 입었어.
편차가 뚜렷하다.<10000step後>
이것이 바로 U분포다.
이걸 뭘로 활용하고 싶은데?
내 생각엔

좋은 웹페이지 즐겨찾기