Metadata-Version: 2.4
Name: gbtsvm
Version: 0.0.3
Summary: Granular Ball Twin Support Vector Machine - scikit-learn compatible implementation
Author-email: Soren A D <sorend@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Requires-Dist: cvxopt>=1.3.0
Requires-Dist: numpy>=1.21.0
Requires-Dist: scikit-learn>=1.0.0
Requires-Dist: scipy>=1.7.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# GBTSVM: Granular Ball Twin Support Vector Machine

A scikit-learn compatible implementation of the Granular Ball Twin Support Vector Machine (GBTSVM).

## Reference

If you use this code, please cite:

> A. Quadir, M. Sajid and M. Tanveer, "Granular Ball Twin Support Vector Machine,"
> in IEEE Transactions on Neural Networks and Learning Systems, vol. 36, no. 7,
> pp. 12444-12453, July 2025, doi: 10.1109/TNNLS.2024.3476391.

Some parts of this implementation are based on:
> Xia, Shuyin, et al. "Gbsvm: Granular-ball support vector machine."
> arXiv preprint arXiv:2210.03120 (2022).

## Installation

```bash
# Install with uv (recommended)
uv sync

# Or install with pip
pip install -e .
```

## Usage

```python
import numpy as np
from gbtsvm import GBTSVMClassifier

# Create sample data
X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [2, 3], [4, 5]])
y = np.array([1, 1, 1, -1, -1, -1])

# Create and fit the classifier
clf = GBTSVMClassifier(c1=0.00001, c2=0.00001)
clf.fit(X, y)

# Make predictions
predictions = clf.predict([[2, 3], [6, 7]])
print(predictions)  # Output: [1, -1]

# Get decision function
decision = clf.decision_function([[2, 3], [6, 7]])
print(decision)  # Positive = class 1, Negative = class -1

# Evaluate accuracy
accuracy = clf.score(X, y)
print(f"Accuracy: {accuracy:.2f}")
```

## Parameters

- `c1` (float): Regularization parameter for first QPP (default: 1.0)
- `c2` (float): Regularization parameter for second QPP (default: 1.0)
- `purity` (float): Purity threshold for granular ball generation (default: 0.925)
- `min_samples` (int): Minimum samples to keep a granular ball (default: 4)
- `eps1` (float): Regularization for numerical stability in first QPP (default: 0.05)
- `eps2` (float): Regularization for numerical stability in second QPP (default: 0.05)

## Development

```bash
# Install with dev dependencies
uv sync --extra dev

# Run tests
make test

# Run linting
make lint

# Run all checks
make check
```

## License

MIT License

## Acknowledgments

This implementation is based on the GBTSVM algorithm described in the papers cited above.
The original code was not available under an open source license, so this is an independent
implementation following the algorithm description in the papers.
