forked from Acce1erat0rS/tf_learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMLP_placeholder.py
124 lines (99 loc) · 3.03 KB
/
MLP_placeholder.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
#coding=utf-8
import numpy as np
import tensorflow as tf
from tensorflow.contrib import rnn
import random
import ProgressBar as pb
hop = 71
timestep_size = 71 # Hours of looking ahead
output_parameters = 3 # Number of predicting parameters
num_stations = 3 # Number of monitoring stations
training_epochs = 200 # Number of training Epochs
total_batch = 12288 # Number of training instance
data_dir = "./dev_data/"
def process(x):
if x == '?':
return 0.0
else:
return float(x)
dataset = []
split = 200
leap = 6
length = 16
lr = 0.0001
hidden_size = 256
layer_num = 3
# from UNIX time 1395691200
# to UNIX time 1448564400
# Read from the file of the training set
data = []
target_set = []
# defines how many hours is used to predict
# --------------------------------------------
# Data Preparation
# --------------------------------------------
print("Processing target set")
start = 1395691200
end = 1448564400
cur_start = start
cur_end = start+hop*3600
count = 0
bar = pb.ProgressBar(total=(end-start)/3600)
while(cur_end < end-(120+288)*3600):
bar.move()
count += 1
if(count % 100 == 0):
bar.log('Preparing : ' + str(cur_end) + ' till 1448564400')
buff = []
for i in range(hop):
hour = []
f1 = open(data_dir+(str)(cur_start+i*3600), 'rb')
for line in f1.readlines():
ls = line.split('#')
hour = hour+(map(float, ls[4:16]))
f1.close()
buff.append(hour)
data.append(buff)
f1 = open(data_dir+(str)(cur_start+120*3600), 'rb')
for line in f1.readlines():
ls = line.split("#")
target_set.append(map(float, ls[7:10]))
break
cur_start = cur_start+3600
cur_end = cur_end+3600
print(len(target_set))
np_data = np.asarray(data)
np_target = np.asarray(target_set)
print("Target shape :", np_target.shape)
print("Data shape : :", np_data.shape)
X = np_data
y = np_target
training_set = np.array(X[1920:])
training_target = np.array(y[1920:])
val_set = np.array(X[:1920])
val_target = np.array(y[:1920])
sess = tf.InteractiveSession()
batch_size = tf.placeholder(tf.int32)
_X = tf.placeholder( ) # TODO:Add here
y = tf.placeholder( ) # TODO: Add here
# TODO: --------------------------------------------
# TODO: Construct MLP computation graph
# TODO: --------------------------------------------
# TODO: --------------------------------------------
# TODO: Construct Training Algo
# TODO: --------------------------------------------
cost =
accuracy =
optimizer =
# TODO:--------------------------------------------
# TODO: Start Training
# TODO:--------------------------------------------
avg_cost = 0
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(training_epochs):
for i in range(total_batch):
_, c = sess.run([optimizer, cost],
feed_dict={_X: training_set,
y:training_target})
avg_cost += c / total_batch