-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive.py
More file actions
80 lines (62 loc) · 2.26 KB
/
Copy pathlive.py
File metadata and controls
80 lines (62 loc) · 2.26 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import tensorflow as tf
import json
import time
datos = json.load(open('static/datos/LiveCards.json', 'r'))
X = datos['inputs']
Y = datos['outs']
VENTANA = len(X[0])
x_ = tf.placeholder(tf.float32, shape=[len(X), VENTANA], name='X')
y_ = tf.placeholder(tf.float32, shape=[len(Y), 1], name='Y')
capa_0 = tf.Variable(tf.random_uniform([VENTANA, 20], -1, 1), name='capa0')
capa_1 = tf.Variable(tf.random_uniform([20, 10], -1, 1), name='capa1')
capa_2 = tf.Variable(tf.random_uniform([10, 1], -1, 1), name='capa2')
bias_0 = tf.Variable(tf.zeros([20]), name='bias0')
bias_1 = tf.Variable(tf.zeros([10]), name='bias1')
bias_2 = tf.Variable(tf.zeros([1]), name='bias2')
operacion = tf.sigmoid(tf.matmul(x_, capa_0) + bias_0)
operacion1 = tf.sigmoid(tf.matmul(operacion, capa_1) + bias_1)
hipotesis = tf.sigmoid(tf.matmul(operacion1, capa_2) + bias_2)
costo = tf.reduce_mean(((y_ * tf.log(hipotesis)) + ((1 - y_) * tf.log(1.0 - hipotesis))) * -1)
entrenamiento = tf.train.GradientDescentOptimizer(0.1).minimize(costo)
init = tf.global_variables_initializer()
sesion = tf.Session()
sesion.run(init)
x_graf = [i for i in range(250000)]
y_graf = list()
for i in range(250000):
sesion.run(entrenamiento, feed_dict={
x_: X,
y_: Y
})
if i % 1000 == 0:
print('Hipotesis: {}'.format(sesion.run(hipotesis, feed_dict={
x_: X,
y_: Y
})))
# print('Capa 0: {}'.format(sesion.run(capa_0)))
# print('Bias 0: {}'.format(sesion.run(bias_0)))
# print('Capa 1: {}'.format(sesion.run(capa_1)))
# print('Bias 1: {}'.format(sesion.run(bias_1)))
c = sesion.run(costo, feed_dict={
x_: X,
y_: Y
})
y_graf.append(float(c))
print('Costo: {}'.format(c))
print('Epoca: {}'.format(i))
ws = list()
ws.append(sesion.run(capa_0).tolist())
ws.append(sesion.run(capa_1).tolist())
ws.append(sesion.run(capa_2).tolist())
bs = list()
bs.append(sesion.run(bias_0).tolist())
bs.append(sesion.run(bias_1).tolist())
bs.append(sesion.run(bias_2).tolist())
# print(ws)
# print(bs)
json.dump({
'ws': ws,
'bs': bs,
'x': x_graf,
'y': list(y_graf)
}, open('datos/LiveCardsPesos.json', 'w'))