-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft.py
64 lines (47 loc) · 2.12 KB
/
draft.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
def load_data(input_path, n):
"""TODO: Docstring for load_data.
:returns: TODO
"""
X, y = [], []
all_files = [x for x in os.listdir(input_path) if x[0] != '.']
temp = set([re.sub('(^\.h$)|(^\.cc$)|(^\.c$)', '.cpp', os.path.splitext(x)[1]) \
for x in all_files])
all_extension = {}
for file_name in all_files:
extension = re.sub('(^\.h$)|(^\.cc$)|(^\.c$)', '.cpp', os.path.splitext(file_name)[1])
all_extension.setdefault(extension, operator.indexOf(temp, extension))
with open(input_path + file_name, 'r') as a_file:
label = []
raw_data = [ord(x) for x in a_file.read(n)]
if len(raw_data) < n:
raw_data = raw_data + [32] * (n - len(raw_data))
for index in range(len(temp)):
label.append(0)
label[all_extension[extension]] = 1
X.append(raw_data)
y.append(label)
with open('./parameters/all_extension.txt', 'w') as extension_file:
extension_file.write(json.dumps(all_extension))
X, y = numpy.array(X), numpy.array(y)
return X, y
theta1 = shared(value=params[0])
b1 = shared(value=params[1])
theta2 = shared(value=params[2])
b2 = shared(value=params[3])
neuron = T.nnet.sigmoid(T.dot(X, theta1) + b1)
prediction = T.dot(neuron, theta2) + b2
pred = theano.function([], [prediction])
with open('all_extension.txt', 'w') as extension_file:
extension_file.write(json.dumps(all_extension))
with open('all_keywords.txt', 'w') as keyword_file:
keyword_file.write(json.dumps(all_keywords))
with open('oct_extension.txt', 'w') as oct_extension:
for extension in all_extension:
oct_extension.write(extension + os.linesep)
exec compile('formula = theano.function([z, t_y, '+
''.join(['t_params[%d], ' % (index)
for index in range(len(t_params))])+
't_weight_decay, t_m], '+
'[J, '+''.join(['T.grad(J, t_params[%d]), ' % (index)
for index in range(len(t_params))])+'])',
'', 'exec') in globals(), locals()