-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChawan_03_03.py
57 lines (46 loc) · 1.76 KB
/
Chawan_03_03.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
# Chawan, Varsha Rani
# 1001-553-524
# 2018-10-08
# Assignment-03-03
import numpy as np
import glob
import scipy.misc
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
import os.path
def readImages(file):
#########################################################################
# Logic to read the data file , retrieve the label from filename,
# shuffle and split the data
#########################################################################
data_list = []
outputs = []
directory = file + "/*.png"
for fname in glob.glob(directory):
img = scipy.misc.imread(fname).astype(np.float32)
img = img.flatten()
img = img / 127.5
img = img - 1.0
data_list.append(img)
# key, value = fname.split("//")
key, value = os.path.split(fname)
tmp = int(value[0])
outputs.append(tmp)
data_list = np.array(data_list)
outputs = np.array(outputs)
data_list, outputs = shuffle(data_list, outputs)
X_train, X_test, Y_train, Y_test = train_test_split(data_list, outputs)
return X_train, X_test, Y_train, Y_test
def calculate_ActivationFunction(activation_function, net_value):
############################################
# Calculates the activation function
############################################
if activation_function == "Symmetrical Hard limit":
activation = net_value
activation[activation >= 0] = 1.0
activation[activation < 0] = -1.0
elif activation_function == "Hyperbolic Tangent":
activation = ((np.exp(net_value)) - (np.exp(-net_value))) / ((np.exp(net_value)) + (np.exp(-net_value)))
elif activation_function == "Linear":
activation = net_value
return activation