fuzzy-rank-ensemble-torch 0.1.1
A torch based package for fuzzy rank based ensembles
Requires Python: >=3.10

# Fuzzy-Rank-Ensemble-Torch

[![GitHub Release](https://img.shields.io/github/v/release/Digiratory/fuzzy-rank-ensemble-torch)](https://github.com/Digiratory/fuzzy-rank-ensemble-torch/releases)
[![GitHub License](https://img.shields.io/github/license/Digiratory/fuzzy-rank-ensemble-torch)](https://github.com/Digiratory/fuzzy-rank-ensemble-torch/blob/main/LICENSE)
[![PyPI - Version](https://img.shields.io/pypi/v/fuzzy-rank-ensemble-torch)](https://pypi.org/project/fuzzy-rank-ensemble-torch/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/fuzzy-rank-ensemble-torch)](https://pypi.org/project/fuzzy-rank-ensemble-torch/)
[![Python Version](https://img.shields.io/pypi/pyversions/fuzzy-rank-ensemble-torch)](https://pypi.org/project/fuzzy-rank-ensemble-torch/)

A PyTorch-based implementation of a Fuzzy Rank-based Ensemble compatible with the MONAI framework for medical image segmentation and classification tasks.

The code is based on our papers:

* "[A fuzzy rank-based ensemble of CNN models for MRI segmentation](https://www.sciencedirect.com/science/article/abs/pii/S1746809424014009)" published in Elseiver Biomedical Signal Processing and Control journal.
* "[A Fuzzy Rank-based Ensemble of CNN Models for Classification of Cervical Cytology](https://www.nature.com/articles/s41598-021-93783-8)" published in Nature-Scientific Reports journal.

## Installation

### Basic Installation

```bash
pip install fuzzy-rank-ensemble-torch
```

### With MONAI Support

```bash
pip install fuzzy-rank-ensemble-torch[monai]
```

### Development Installation

```bash
git clone https://github.com/Digiratory/fuzzy-rank-ensemble-torch.git
cd fuzzy-rank-ensemble-torch
pip install -e .
```

## Usage

### Pure PyTorch Implementation

```python
import torch
from fuzzy_rank_ensemble_torch import fuzzy_rank_ensemble

# Initialize prediction tensors from different models
# Shape: [Batch, Class Index]

# Inception v3 model predictions
inception_v3_pred = torch.tensor([[0.261, 0.315, 0.102, 0.286]])

# Xception model predictions
xception_pred = torch.tensor([[0.402, 0.347, 0.201, 0.050]])

# DenseNet-169 model predictions
densenet_169_pred = torch.tensor([[0.357, 0.467, 0.131, 0.045]])

# Apply fuzzy rank ensemble
result = fuzzy_rank_ensemble([inception_v3_pred, xception_pred, densenet_169_pred])
print(f"Ensemble Result: {result}")
```

### MONAI Integration

```python
import torch
from fuzzy_rank_ensemble_torch.monai import FuzzyRankBasedEnsemble

# Initialize models and predictions (same as above)
# ...

# Create ensemble instance
ens = FuzzyRankBasedEnsemble()

# Apply ensemble to predictions
result = ens([inception_v3_pred, xception_pred, densenet_169_pred])

# Verify result matches expected output
expected = torch.tensor([[1-0.4587, 1-0.4264, 1-0.5948, 1-0.5883]])
assert torch.allclose(result, expected, rtol=1e-03)
```

Also, you can use dictionary-based wrapper `FuzzyRankBasedEnsembled`.

## Citation

If you use this software in your research, please cite our work:

```bibtex
@article{10.1016/j.bspc.2024.107342,
  title     = {A fuzzy rank-based ensemble of CNN models for MRI segmentation},
  journal   = {Biomedical Signal Processing and Control},
  volume    = {102},
  pages     = {107342},
  year      = {2025},
  issn      = {1746-8094},
  doi       = {10.1016/j.bspc.2024.107342},
  url       = {https://www.sciencedirect.com/science/article/pii/S1746809424014009},
  author    = {Valenkova, Daria and Lyanova, Asya and Sinitca, Aleksandr and Sarkar, Ram and Kaplun, Dmitrii},
}
```

```bibtex
@article{manna2021fuzzy,
  title        = {A fuzzy rank-based ensemble of CNN models for classification of cervical cytology},
  author       = {Manna, Ankur and Kundu, Rohit and Kaplun, Dmitrii and Sinitca, Aleksandr and Sarkar, Ram},
  journal      = {Scientific Reports},
  volume       = {11},
  number       = {1},
  pages        = {1--18},
  year         = {2021},
  doi          = {10.1038/s41598-021-93783-8},
  publisher    = {Nature Publishing Group}
}
```

## Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

## License

This project is licensed under the Apache-2.0 license - see the [LICENSE](LICENSE) file for details.