forked from yanshengli/DBN_Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal_8.py
157 lines (152 loc) · 4.83 KB
/
normal_8.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
__author__ = 'LiGe'
#encoding:utf-8
import numpy as np
#归一化train数据
def txt2mat_train():
f=open("train.txt",'r')
datas=f.readlines()
train_mat=list()
train_label=list()
for data in datas:
data=data.strip()
if len(data)>0:
data=data.split(',')
row=list()
for j in range(0,len(data)-1):
row.append(float(data[j]))
if len(row)!=8:
print row
train_mat.append(row)
if data[-1]=='1':
train_label.append([1,0])
else:
train_label.append([0,1])
#print train_mat
train_np=np.array(train_mat)
train_label_np=np.array(train_label)
for i in range(0,train_np.shape[1]):
max=train_np[:,i].max()
min=train_np[:,i].min()
#print max,min
print '_______________________________________'+str(i)+'__________________'
for j in range(0,train_np.shape[0]):
normal_value='%0.4f'%((train_np[j,i]-min)/(max-min))
print normal_value
if i==0:
if float(normal_value) > 0.5:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==1:
if float(normal_value) < 0.0001:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==2:
if float(normal_value)>0.05:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==3:
if float(normal_value)>0.02:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==4:
if float(normal_value)>0.4:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==5:
if float(normal_value)<0.02:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==6:
if float(normal_value)>0.80:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==7:
if float(normal_value)>0.09:
train_np[j,i]=1
else:
train_np[j,i]=0
print train_np
#print train_label_np
return train_np,train_label_np
#归一化测试数据
def txt2mat_text():
f=open("test.txt",'r')
datas=f.readlines()
train_mat=list()
train_label=list()
for data in datas:
data=data.strip()
if len(data)>0:
data=data.split(',')
row=list()
for j in range(0,len(data)-1):
row.append(float(data[j]))
if len(row)!=8:
print row
train_mat.append(row)
if data[-1]=='1':
train_label.append([1,0])
else:
train_label.append([0,1])
#print train_mat
train_np=np.array(train_mat)
train_label_np=np.array(train_label)
for i in range(0,train_np.shape[1]):
max=train_np[:,i].max()
min=train_np[:,i].min()
#print max,min
for j in range(0,train_np.shape[0]):
normal_value='%0.4f'%((train_np[j,i]-min)/(max-min))
print normal_value
if i==0:
if float(normal_value) > 0.5:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==1:
if float(normal_value) < 0.0001:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==2:
if float(normal_value)>0.05:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==3:
if float(normal_value)>0.02:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==4:
if float(normal_value)>0.4:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==5:
if float(normal_value)<0.02:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==6:
if float(normal_value)>0.80:
train_np[j,i]=1
else:
train_np[j,i]=0
if i==7:
if float(normal_value)>0.09:
train_np[j,i]=1
else:
train_np[j,i]=0
#print train_np
#print train_label_np
return train_np,train_label_np
if __name__=='__main__':
txt2mat_train()