Skip to content

Commit ab03b90

Browse files
authored
Create xorGates.py
1 parent eb0d217 commit ab03b90

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

xorGates.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import numpy as np
2+
import tensorflow as tf
3+
import keras.backend as k
4+
from keras.models import Sequential
5+
from keras.layers import Dense
6+
from keras.activations import sigmoid
7+
from keras.losses import MSE
8+
from keras.optimizers import SGD
9+
from keras.metrics import binary_accuracy
10+
sess=tf.Session()
11+
k.set_session(sess)
12+
13+
logicand=np.array([[0,0,0],
14+
[0,1,0],
15+
[1,0,0],
16+
[1,1,1]])
17+
18+
19+
logicor=np.array([[0,0,0],
20+
[0,1,1],
21+
[1,0,1],
22+
[1,1,1]])
23+
24+
logicxor=np.array([[0,0,0],
25+
[0,1,1],
26+
[1,0,1],
27+
[1,1,0]])
28+
29+
logicnot=np.array([[0,1],
30+
[1,0]])
31+
# x=logicand[:,:2]
32+
# y=logicand[:,-1]
33+
34+
# x=logicor[:,:2]
35+
# y=logicor[:,-1]
36+
37+
x=logicxor[:,:2]
38+
y=logicxor[:,-1]
39+
40+
# x=logicnot[:,:1]
41+
# y=logicnot[:,-1]
42+
43+
44+
45+
model = Sequential()
46+
model.add(Dense(2,activation=sigmoid,input_dim=2))
47+
model.add(Dense(1,activation=sigmoid))
48+
model.compile(loss=MSE,optimizer=SGD(lr=1))
49+
model.fit(x,y,epochs=1000)
50+
model.save("xorGates.h5")
51+
#print(model.predict(np.array([[,1]])))x
52+
53+
# model = Sequential()
54+
# model.add(Dense(1,activation=sigmoid,input_dim=1))
55+
# model.compile(loss=MSE,optimizer=SGD(lr=1))
56+
# model.fit(x,y,epochs=10000)
57+
# model.save("notGAtes.h5")

0 commit comments

Comments
 (0)