-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTensor.py
68 lines (62 loc) · 1.92 KB
/
Tensor.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
import tensorflow as tf
from tensorflow import keras
from tensorflow.python.keras.layers import Dense, Activation
from tensorflow.python.keras.models import Sequential
import numpy as np
from time import sleep
class Rede_neural(object):
def __init__(self,wids=None):
types=""
if wids == None:
types="m"
else:
types="zeros"
self.model = Sequential()
self.model.add(Dense(64, input_dim=16,kernel_initializer=types,bias_initializer=types))
self.model.add(Activation('hard_sigmoid'))
self.model.add(Dense(4,kernel_initializer=types,bias_initializer=types))
self.model.add(Activation('softmax'))
if wids == None:
self.wids = self.model.get_weights()
else:
self.setWid(wids)
def getWid(self):
return self.wids
def setWid(self,wid):
self.wids = wid
self.model.set_weights(wid)
def predict(self,X):
X = np.matrix(X.flatten())
Y= self.model.predict(X)
return (Y.argmax())
# def mutacao(wid):
# aux = wid
# while (True):
# num = np.random.randint(len(aux))
# if (not hasattr(aux[num], "__len__")):
# aux[num] = np.random.uniform(-1,1)
# break
# aux = aux[num]
# return wid
# y = []
# for x in range(16):
# if x==0:
# y.append(0.0625)
# continue
# y.append(0.0625 +y[-1]);
# y= np.matrix(y)
# #print(y)
# model = Sequential()
# model.add(Dense(32, input_dim=16,kernel_initializer='random_uniform',bias_initializer='random_uniform'))
# model.add(Activation('hard_sigmoid'))
# model.add(Dense(4,kernel_initializer='random_uniform',bias_initializer='random_uniform'))
# model.add(Activation('softmax'))
# wid = model.get_weights()
# x = model.predict(y)
# while True:
# print(model.predict(y))
# wid = mutacao(wid);
# model.set_weights(wid)
# sleep(1)
#print (aux)
#print (wid)