Metadata-Version: 2.4
Name: genDWD
Version: 0.1.0
Summary: Generalized Distance Weighted Discrimination (DWD) with sGS-ADDM
Author: Thoriq Al Mahdi
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# genDWD: Generalized Distance Weighted Discrimination

**genDWD** is a high-performance Python implementation of the Generalized Distance Weighted Discrimination (DWD) algorithm. 

While **Support Vector Machines (SVM)** are widely used, they often suffer from the "data piling" phenomenon in **HDLLS (High-Dimension, Low Large Sample)** settings, where many data points project onto the same location on the decision boundary, leading to poor generalization. DWD was specifically developed to overcome this by accounting for the relative distance of all data points, providing better robustness in high-dimensional spaces.

Originally formulated for binary classification, this implementation extends the algorithm's utility by featuring built-in **Multiclass classification** support, enabling its application to complex, real-world datasets with multiple categories. It is designed to handle these tasks efficiently using the sGS-ADMM framework for large-scale optimization.

---

## Core Research Basis

This implementation is strictly constructed based on the numerical procedures described in the following scientific paper:

> **"Fast algorithms for large scale generalized distance weighted discrimination"**
>
> â€” *Xin Yee Lam, J.S. Marron, Defeng Sun, and Kim-Chuan Toh (September 5, 2018)*

## Key Features

- **Automatic Detection**: Automatically switches between Binary and Multiclass (One-vs-One) logic.
- **Adaptive Solvers**: Dynamically selects between Cholesky, SMW, or PSQMR based on $n$ and $d$.
- **sGS-ADMM Framework**: Ensures fast convergence using Symmetric Gauss-Seidel ADMM.
- **Penalty Tuning**: Automatic $C$ parameter calculation using median inter-class distance.

## Quick Start

1. Install the package:
```bash
pip install genDWD
```

## Implementation Guide

To use the `genDWD` class in your project, follow the instructions below. The model follows the standard `.fit()` and `.predict()` pattern.

### 1. Basic Initialization
You can customize the model during initialization. The parameter `C='auto'` is recommended as it calculates the penalty based on the dataset's geometry.

```python
from gendwd import genDWD

model = genDWD(C='auto')
```

### 2. Model Training and Prediction

The model follows the familiar `.fit()` and `.predict()` workflow. It automatically handles both binary and multiclass data.

#### Training the Model
To train the model, pass your feature matrix `X` and label vector `y`. The algorithm will automatically detect if it should use a binary or multiclass (One-vs-One) strategy.

```python
import numpy as np

# Sample Data: 100 samples, 10 features
X_train = np.random.randn(100, 10)
# Labels can be integers, strings, or floats
y_train = np.random.choice(['Class_A', 'Class_B'], size=100)

# Train the model
model.fit(X_train, y_train)

# New data for prediction
X_new = np.random.randn(5, 10)

# Get predicted class labels
predictions = model.predict(X_new)

print(f"Predicted Labels: {predictions}")
```
