Metadata-Version: 2.4
Name: slatex
Version: 0.1.0
Summary: Sparse Lightweight Additive Threshold Ensemble — a small, fast, interpretable classifier for edge devices and TinyML.
Project-URL: Homepage, https://github.com/saikirangogineni/slatex
Project-URL: Repository, https://github.com/saikirangogineni/slatex
Project-URL: Issues, https://github.com/saikirangogineni/slatex/issues
Author-email: Saikiran Gogineni <goginenisaikiran31677@gmail.com>
Maintainer-email: Saikiran Gogineni <goginenisaikiran31677@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Saikiran Gogineni
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: boosting,classifier,edge-ai,explainable-ai,gam,generalized-additive-model,interpretable-ml,machine-learning,sparse-models,tinyml
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Requires-Dist: numpy>=1.21
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: scikit-learn>=1.0; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == 'test'
Requires-Dist: scikit-learn>=1.0; extra == 'test'
Description-Content-Type: text/markdown

# slatex

**Sparse Lightweight Additive Threshold Ensemble** — a small, fast, interpretable
classifier for constrained hardware (edge devices, microcontrollers, TinyML).

SLATE is an additive model (a Generalized Additive Model) built from simple
threshold rules of the form *"1 if a feature is at or below a learned cut, else 0"*.
It is trained by L1-regularized Newton boosting: rules are selected one at a time,
then all active rules are refit together in a corrective pass, while a hard budget
keeps the model tiny.

- **Tiny.** A hard budget caps the number of rules, so a trained model is on the
  order of a kilobyte and inference is a handful of comparisons and adds. The
  fitted model drops its training-time scaffolding, so a pickled/joblib-saved
  estimator is just ~1-2 KB — the same as its live inference footprint.
- **Interpretable.** Because the model is additive, you get exact per-feature shape
  functions and exact Shapley attributions in closed form.
- **Lightweight to install.** Pure NumPy at runtime — no heavy ML stack required.
- **Familiar API.** `fit` / `predict` / `predict_proba`, drops into scikit-learn
  pipelines and grid search. Binary *and* multiclass are supported.

## Installation

```bash
pip install slatex
```

Requires Python 3.9+ and NumPy. To run the test suite you also need
scikit-learn (`pip install "slatex[test]"`).

## Quickstart

```python
import numpy as np
from slatex import SlateClassifier

rng = np.random.RandomState(0)
X = rng.randn(500, 8)
y = (X[:, 0] + 0.5 * X[:, 3] > 0).astype(int)

clf = SlateClassifier(budget=32).fit(X, y)

clf.predict(X[:5])           # class labels
clf.predict_proba(X[:5])     # (n_samples, n_classes) probabilities
clf.score(X, y)              # mean accuracy

print(clf.n_atoms_)          # number of threshold rules used
print(clf.memory_bytes_)     # approximate packed model size in bytes
```

Multiclass works the same way (handled internally via one-vs-rest), and labels
can be any type — integers, strings, etc.:

```python
y = np.array(["low", "mid", "high"])[rng.randint(0, 3, size=500)]
clf = SlateClassifier(budget=24).fit(X, y)
clf.classes_                 # array(['high', 'low', 'mid'], dtype='<U4')
```

## Interpretability

Because SLATE is additive, the contribution of each feature is exact and cheap to
compute.

```python
# Shape function: how feature 0 contributes to the score across a range of values
grid = np.linspace(-3, 3, 50)
contribution = clf.shape_function(feature=0, grid=grid)   # binary
# contribution = clf.shape_function(0, grid, target="high")  # multiclass

# Exact Shapley attributions against a background sample
phi = clf.shapley_values(X[:10], X_background=X)           # (10, n_features)
```

## Hyperparameters

| Parameter | Default | Meaning |
|---|---|---|
| `budget` | 64 | Hard cap on the number of threshold rules per binary model |
| `n_bins` | 32 | Max quantile bins per feature (candidate-cut granularity) |
| `max_iter` | 400 | Max boosting iterations |
| `learning_rate` | 0.5 | Shrinkage on each Newton step |
| `l2` | 2.0 | Newton damping (ridge on the Hessian) |
| `l1` | 1e-3 | Soft-threshold level for pruning weak rules |
| `corrective_every` | 5 | Run a fully-corrective refit pass every *k* iterations |
| `corrective_passes` | 2 | Cyclic passes per corrective phase |
| `tol` | 1e-7 | Stop when the best Newton gain falls below this |

Smaller `budget` → smaller, faster, more interpretable model. Increase `n_bins`
for finer cuts on continuous features.

## scikit-learn compatibility

`SlateClassifier` implements `get_params` / `set_params` and follows the standard
estimator API, so it composes with scikit-learn tools:

```python
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV

pipe = make_pipeline(StandardScaler(), SlateClassifier())
grid = GridSearchCV(pipe, {"slateclassifier__budget": [16, 32, 64]}, cv=3)
grid.fit(X, y)
```

(scikit-learn is optional and only needed if you use these helpers.)

## Notes and requirements

- Inputs must be **finite numeric arrays** (no NaN/inf). Impute or clean first.
- Training is **deterministic**; `random_state` is accepted for API compatibility
  but does not change results.
- This is research-grade software released under the MIT License.

## License

MIT © Saikiran Gogineni
