-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path2DNoisyXORDemo.py
More file actions
24 lines (18 loc) · 858 Bytes
/
2DNoisyXORDemo.py
File metadata and controls
24 lines (18 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/local/bin/python3
from pyTsetlinMachine.tm import MultiClassConvolutionalTsetlinMachine2D
import numpy as np
from time import time
train_data = np.loadtxt("2DNoisyXORTrainingData.txt")
X_train = train_data[:,0:-1].reshape(train_data.shape[0], 4, 4)
Y_train = train_data[:,-1]
test_data = np.loadtxt("2DNoisyXORTestData.txt")
X_test = test_data[:,0:-1].reshape(test_data.shape[0], 4, 4)
Y_test = test_data[:,-1]
ctm = MultiClassConvolutionalTsetlinMachine2D(40, 60, 3.9, (2, 2), boost_true_positive_feedback=0)
results = np.zeros(0)
for i in range(100):
start = time()
ctm.fit(X_train, Y_train, epochs=5000)
stop = time()
results = np.append(results, 100*(ctm.predict(X_test) == Y_test).mean())
print("#%d Mean Accuracy (%%): %.2f; Std.dev.: %.2f; Training Time: %.1f ms/epoch" % (i+1, np.mean(results), np.std(results), (stop-start)/5.0))