-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadtr.py
executable file
·66 lines (63 loc) · 1.32 KB
/
readtr.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
import numpy as np
import random
s=0.98
def read(st=0,en=62):
f=open("fetr1.txt","r")
a=[]
for lin in f:
a.append(lin.strip().split(" "))
b=[]
c=[]
for i in xrange(st*55,en*55):
b.append([])
for j in xrange(1,len(a[i])):
b[i-st*55].append(float(a[i][j])/255.0)
c.append(int(float(a[i][0]))-st)
d=np.array(b,dtype=np.float32)
e=np.array(c,dtype=int)
fir=[]
firl=[]
fit=[]
fitl=[]
for i in xrange(len(e)):
if(random.random()<s):
fir.append(d[i])
firl.append(e[i])
else:
fit.append(d[i])
fitl.append(e[i])
fi=[fir,firl]
ti=[fit,fitl]
f.close()
return(fi,ti)
def readnn(st=0,en=62):
a,b=read(st,en)
ti=[np.reshape(x, (len(a[0][0]), 1)) for x in a[0]]
tr=[vectorized_result(y,(en-st)) for y in a[1]]
te=[np.reshape(x, (len(a[0][0]), 1)) for x in b[0]]
trd= zip(ti,tr)
tsd= zip(te,b[1])
return(trd,tsd)
def vectorized_result(j,i):
e = np.zeros((i, 1))
e[j] = 1.0
return e
def read2(st=0,en=62):
f=open("fetr1.txt","r")
a=[]
for lin in f:
a.append(lin.strip().split(" "))
b=[]
for i in xrange(st*55,en*55):
b.append([])
for j in xrange(len(a[i])):
b[i-st*55].append(float(a[i][j]))
tr=[]
ts=[]
for i in xrange(len(b)):
if(random.random()<s):
tr.append(b[i])
else:
ts.append(b[i])
f.close()
return(tr,ts)