-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.py
48 lines (33 loc) · 1.24 KB
/
logic.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 23 16:12:15 2018
@author: mehshan
"""
import numpy as np
table=np.array([[0,0],[0,1],[1,0],[1,1]])
#and
#logic=np.array([[0],[0],[0],[1]])
#or
logic=np.array([[0],[1],[1],[1]])
import keras
from keras.models import Sequential
from keras.layers import Dense
# Initialising the ANN
classifier = Sequential()
# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 3, kernel_initializer = 'uniform', activation = 'relu', input_dim = 2))
# Adding the output layer
classifier.add(Dense(units = 10, kernel_initializer = 'uniform', activation = 'sigmoid'))
# Adding the output layer
classifier.add(Dense(units = 20, kernel_initializer = 'uniform', activation = 'sigmoid'))
# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))
# Compiling the ANN
classifier.compile(loss='binary_crossentropy', metrics=['accuracy'], optimizer='adam')
# Fitting the ANN to the Training set
classifier.fit(table, logic, batch_size = 4, epochs = 3000)
# Part 3 - Making predictions and evaluating the model
# Predicting the Test set results
y_pred = classifier.predict(np.array([[0,0],[0,1],[1,0],[1,1]]))
y_pred = (y_pred > 0.5)