-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
58 lines (49 loc) · 1.36 KB
/
Copy pathdata.py
File metadata and controls
58 lines (49 loc) · 1.36 KB
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
"""データ(xベクトルとyベクトル)を作る
"""
import numpy as np
class Data:
def __init__(self, n = (3, 3), sigma = (1.0, 1.0)):
self.prob = [[0.6, 0.1], [0.1, 0.2]]
self.sigma = sigma
self.n_list= n
self.x_vec = self.createXData()
self.y_vec = self.createYData()
def createXData(self):
random = np.random.rand()
if 0.0 <= random and random < 0.6:
return [0, 0]
if 0.6 <= random and random < 0.7:
return [0, 1]
if 0.7 <= random and random < 0.8:
return [1, 0]
if 0.8 <= random and random < 1.0:
return [1, 1]
def createYData(self):
y_vec = []
for (idx, num) in enumerate(self.n_list):
y_vec.extend([np.random.normal(self.x_vec[idx], self.sigma[idx] ** 2, num)])
return y_vec
def Pr(self, x1, x2):
return self.prob[x1][x2]
def Pr_X1(self, x1):
"""X1の周辺確率を求める
"""
prob = 0
for x2 in range(0, 2):
prob += self.prob[x1][x2]
return prob
def Pr_X2(self, x2):
"""X2の周辺確率を求める
"""
prob = 0
for x1 in range(0, 2):
prob += self.prob[x1][x2]
return prob
def reset(self):
self.x_vec = self.createXData()
self.y_vec = self.createYData()
if __name__ == '__main__':
data = Data()
print(data.y_vec)
data.reset()
print(data.y_vec)