-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
I am probably doing something wrong but XOR example from PyTsetlinMachineCUDA does not seem to train with this model.
from pathlib import Path
import numpy as np
from PyCoalescedTsetlinMachineCUDA.tm import (
MultiClassTsetlinMachine as MultiClassTsetlinMachine2,
)
train_data = np.loadtxt(
Path.home() / "github/PyTsetlinMachineCUDA/examples/NoisyXORTrainingData.txt"
)
test_data = np.loadtxt(
Path.home() / "github/PyTsetlinMachineCUDA/examples/NoisyXORTestData.txt"
)
X_test = test_data[:, 0:-1]
Y_test = test_data[:, -1]
tm = MultiClassTsetlinMachine2(10, 15, 3.9, boost_true_positive_feedback=0)
print("Starting training...")
for e in range(200):
for i in range(100, len(train_data), 100):
X_train = train_data[i - 100 : i, 0:-1]
Y_train = train_data[i - 100 : i, -1]
tm.fit(X_train, Y_train, epochs=1, incremental=True)
print("Epoch:", e, " Accuracy:", 100 * (tm.predict(X_test) == Y_test).mean())
print(
"Prediction: x1 = 1, x2 = 0, ... -> y = %d"
% (tm.predict(np.array([[1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0]])))
)
print(
"Prediction: x1 = 0, x2 = 1, ... -> y = %d"
% (tm.predict(np.array([[0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0]])))
)
print(
"Prediction: x1 = 0, x2 = 0, ... -> y = %d"
% (tm.predict(np.array([[0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0]])))
)
print(
"Prediction: x1 = 1, x2 = 1, ... -> y = %d"
% (tm.predict(np.array([[1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0]])))
)
The results seem sad:
Starting training...
Epoch: 0 Accuracy: 48.8
Epoch: 1 Accuracy: 49.04
Epoch: 2 Accuracy: 48.980000000000004
Epoch: 3 Accuracy: 49.04
Epoch: 4 Accuracy: 48.64
Epoch: 5 Accuracy: 48.78
Epoch: 6 Accuracy: 48.82
Epoch: 7 Accuracy: 42.66
Epoch: 8 Accuracy: 48.88
Metadata
Metadata
Assignees
Labels
No labels