Metadata-Version: 2.4
Name: green_tsetlin
Version: 1.1.0
Summary: A fast Tsetlin Machine impl, based on c++
Home-page: https://github.com/ooki/green_tsetlin
Author: Sondre 'Ooki' Glimsdal
Author-email: sondre.glimsdal@gmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/ooki/green_tsetlin/issues
Project-URL: Documentation, https://github.com/ooki/green_tsetlin
Project-URL: Source Code, https://github.com/ooki/green_tsetlin
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10.1
Requires-Dist: scikit-learn>=1.2
Requires-Dist: tqdm>=4.65
Requires-Dist: optuna
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

<p align="center">
  <img src="docs/image/GT_FRONTPAGE_RTD.png" width="400" height="400">
</p>

Green Tsetlin
==============
### **Installation**
Green Tsetlin can be installed by the following:
```bash
pip install green-tsetlin
```

### **Documentation**
The documentation can be found on: https://green-tsetlin.readthedocs.io/  
Below is some short examples of some of the capabilities of green-tsetlin.


### **Tsetlin Machine**
The Tsetlin Machine is the core of Green Tsetlin.
Here a dense (regular) TM:
```python
import green_tsetlin as gt

tm = gt.TsetlinMachine(n_literals=4,
                       n_clauses=5,
                       n_classes=2,
                       s=3.0,
                       threshold=42,
                       literal_budget=4
                       )
```


### **Sparse Tsetlin Machine**
The Tsetlin Machine is the core of Green Tsetlin.
Here a sparse TM:
```python
import green_tsetlin as gt

tm = gt.SparseTsetlinMachine(n_literals=4,
                             n_clauses=5,
                             n_classes=2,
                             s=3.0,
                             threshold=42,
                             literal_budget=4,
                             )
```


### **Trainer**
Use the Trainer to fit a Tsetlin Machine to the data.  
The trainer class is used for both sparse and dense data and TMs.
```python
import green_tsetlin as gt
        

# set n_jobs = 1 to run single threaded
trainer = gt.Trainer(tm, seed=42, n_jobs=1)

trainer.set_train_data(train_x, train_y)
trainer.set_eval_data(eval_x, eval_y)

trainer.train()
```

### **Exporting Tsetlin Machines**
Exporting trained Tsetlin Machines.
```python
.
.
tm.save_state("tsetlin_state.npz")
```


### **Loading exported Tsetlin Machines**
Loading trained Tsetlin Machines to continue training or use for inference.
```python
.
.
tm.load_state("tsetlin_state.npz")
```

### **Inference**
Inference with trained Tsetlin Machines.
```python
.
.
predictor = tm.get_predictor()
predictor.predict(x)
```

### **Green Tsetlin hpsearch**
With the built-in hyperparameter search you can optimize your Tsetlin Machine parameters.
```python
from green_tsetlin.hpsearch import HyperparameterSearch

hyperparam_search = HyperparameterSearch(s_space=(2.0, 20.0),
                                        clause_space=(5, 10),
                                        threshold_space=(3, 20),
                                        max_epoch_per_trial=20,
                                        literal_budget=(1, train_x.shape[1]),
                                        search_or_use_boost_true_positives=(False, True),
                                        seed=42,
                                        n_jobs=5,
                                        k_folds=4,
                                        minimize_literal_budget=False)

hyperparam_search.set_train_data(train_x, train_y)
hyperparam_search.set_eval_data(test_x, test_y)

hyperparam_search.optimize(n_trials=10)
```



