Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XOR example from PyTsetlinMachineCUDA does not train #1

Open
ricpruss opened this issue Aug 25, 2021 · 1 comment
Open

XOR example from PyTsetlinMachineCUDA does not train #1

ricpruss opened this issue Aug 25, 2021 · 1 comment

Comments

@ricpruss
Copy link

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

@olegranmo
Copy link
Member

olegranmo commented Sep 22, 2021

Hi @ricpruss! Our Coalesced TM implementation has clause weighting turned on by default while the original XOR demo assumes standard clauses without weighting (default in the other implementations). For the Coalesced TM implementations it is currently not possible to turn the weighting off, however, we are working on addressing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants