{"id":21488792,"url":"https://github.com/khaledsharif/tsetlinmachine","last_synced_at":"2025-07-15T16:31:00.639Z","repository":{"id":83780061,"uuid":"128676468","full_name":"KhaledSharif/TsetlinMachine","owner":"KhaledSharif","description":"An implementation of the Tsetlin Machine in Rust","archived":false,"fork":false,"pushed_at":"2018-04-15T10:51:29.000Z","size":18,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T07:11:52.326Z","etag":null,"topics":["automata","machine-learning","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KhaledSharif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-08T19:51:38.000Z","updated_at":"2024-11-21T09:14:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"c93a0cb1-b9b0-4bfa-a53f-6d4e8095fbf1","html_url":"https://github.com/KhaledSharif/TsetlinMachine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KhaledSharif/TsetlinMachine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledSharif%2FTsetlinMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledSharif%2FTsetlinMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledSharif%2FTsetlinMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledSharif%2FTsetlinMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KhaledSharif","download_url":"https://codeload.github.com/KhaledSharif/TsetlinMachine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KhaledSharif%2FTsetlinMachine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265445302,"owners_count":23766445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automata","machine-learning","rust"],"created_at":"2024-11-23T14:11:46.807Z","updated_at":"2025-07-15T16:31:00.629Z","avatar_url":"https://github.com/KhaledSharif.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Tsetlin Machine implementation in Rust\n\nA \"Tsetlin Machine\" solves complex pattern recognition problems with easy-to-interpret\npropositional formulas, and is composed of a collective of\n[Tsetlin Automata](https://en.wikipedia.org/wiki/Learning_automata). The idea of\nthe machine was proposed in\n[a paper by Ole-Christoffer Granmo](https://arxiv.org/abs/1804.01508).\n\n## Running the XOR test\n\n\n- Clone this repository using `git clone https://github.com/KhaledSharif/TsetlinMachine.git`\n- Inside the repository root folder, run `cargo test`\n- The test will run the XOR example found in `tests/xor.rs`\n- The test will only pass if the Tsetlin Machine reaches an accuracy greater than 99% on XOR\n\n## Training and testing on MNIST\n\n- Get [the MNIST data from Kaggle](https://www.kaggle.com/c/digit-recognizer/data) in CSV form\n- Create a folder called `mnist` in the same folder that contains `src` and `tests`\n- Copy `train.csv` and `test.csv` into the newly created `mnist` folder\n- Run `cargo run` from the repository root folder\n- Read the code inside `src/main.rs` to get a better understanding\n\n## Example XOR code\n\n```rust\nlet mut tm = tsetlin_machine();\ntm.create(2, 2, 10);\n\nlet mut rng = thread_rng();\nlet mut average_error : f32 = 1.0;\n\nfor e in 0..1000\n{\n    let input_vector = \u0026inputs[e % 4];\n    {\n        let output_vector = tm.activate(input_vector.to_vec());\n        let mut correct = false;\n        if (input_vector[0] == input_vector[1]) \u0026\u0026 (!output_vector[0] \u0026\u0026 output_vector[1])\n        {\n            correct = true;\n        }\n        else if output_vector[0] \u0026\u0026 !output_vector[1]\n        {\n            correct = true;\n        }\n        average_error = 0.99 * average_error + 0.01 * (if !correct {1.0} else {0.0});\n        println!(\"{} {} -\u003e {} {} | {}\", input_vector[0], input_vector[1], output_vector[0], output_vector[1], average_error);\n    }\n    tm.learn(\u0026outputs[e % 4], 4.0, 4.0, \u0026mut rng);\n}\n```\n\n## Example XOR output\n\n```\ntrue true -\u003e false true   | 0.00007643679\nfalse false -\u003e false true | 0.00007567242\nfalse true -\u003e true false  | 0.0000749157\ntrue false -\u003e true false  | 0.00007416654\ntrue true -\u003e false true   | 0.000073424875\n```\n\n## Original implementation\n\nThis repository is [a translation of this repository](https://github.com/222464/TsetlinMachine),\nwhich is an implementation of the Tsetlin Machine in C++.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledsharif%2Ftsetlinmachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhaledsharif%2Ftsetlinmachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhaledsharif%2Ftsetlinmachine/lists"}