# condo-adapter
[![PyPI version](https://badge.fury.io/py/condo.svg)](https://badge.fury.io/py/condo.svg)
[![Downloads](https://pepy.tech/badge/condo)](https://pepy.tech/project/condo)
[![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa]
ConDo Adapter performs Confounded Domain Adaptation, which corrects for
batch effects while conditioning on confounding variables.
We hope it sparks joy as you clean up your data!
### Using and citing this toolbox
If you use this toolbox in your research and find it useful, please cite ConDo
using the following reference to our [arXiv preprint](https://arxiv.org/abs/2203.12720):
In Bibtex format:
```bibtex
@misc{https://doi.org/10.48550/arxiv.2203.12720,
doi = {10.48550/ARXIV.2203.12720},
url = {https://arxiv.org/abs/2203.12720},
author = {McCarter, Calvin},
title = {Towards Backwards-Compatible Data with Confounded Domain Adaptation},
publisher = {arXiv},
year = {2022},
}
```
## Installation
### Installation from pip
You can install the toolbox through PyPI with:
```console
pip install condo
```
Note: If you have issues with importing `torchmin`, you may need to install from source, as shown below. Or you can try re-installing [pytorch-minimize](https://github.com/rfeinman/pytorch-minimize) from source.
### Installation from source
After cloning this repo, install the dependencies on the command-line via:
```console
pip install -r requirements.txt
```
In this directory, run
```console
pip install -e .
```
## Usage
Import ConDo and create the adapter:
```python
import condo
condoer = condo.ConDoAdapter()
```
Try using it:
```python
import numpy as np
X_T = np.sort(np.random.uniform(0, 8, size=(100, 1)))
X_S = np.sort(np.random.uniform(4, 8, size=(100, 1)))
Y_T = np.random.normal(4 * X_T + 1, 1 * X_T + 1)
Y_Strue = np.random.normal(4 * X_S + 1, 1 * X_S + 1)
Y_S = 5 * Y_Strue + 2
condoer.fit(Y_S, Y_T, X_S, X_T)
Y_S2T = condoer.transform(Y_S)
print(f"before ConDo: {np.mean((Y_S - Y_Strue) ** 2):.3f}")
print(f"after ConDo: {np.mean((Y_S2T - Y_Strue) ** 2):.3f}")
```
More thorough examples are provided in the examples directory.
## Development
### Testing
In this directory run
```console
pytest
```
### Code formatting
The Uncompromising Code Formatter: [Black](https://github.com/psf/black)
```black {source_file_or_directory}```
Install it into pre-commit hook to always commit well-formatted code:
```pre-commit install```
## License Information
This work is licensed under a
[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].
[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]
[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg
Raw data
{
"_id": null,
"home_page": "http://github.com/calvinmccarter/condo-adapter",
"name": "condo",
"maintainer": "Calvin McCarter",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "mccarter.calvin@gmail.com",
"keywords": "confounding, domain adaptation, batch correction",
"author": "Calvin McCarter",
"author_email": "mccarter.calvin@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5f/47/2232458e943dcd04eeca1307481aa33ea3892a549f25309698a7b93bb388/condo-0.8.0.tar.gz",
"platform": null,
"description": "# condo-adapter\n\n[![PyPI version](https://badge.fury.io/py/condo.svg)](https://badge.fury.io/py/condo.svg)\n[![Downloads](https://pepy.tech/badge/condo)](https://pepy.tech/project/condo)\n[![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa]\n\nConDo Adapter performs Confounded Domain Adaptation, which corrects for\nbatch effects while conditioning on confounding variables.\nWe hope it sparks joy as you clean up your data!\n\n### Using and citing this toolbox\n\nIf you use this toolbox in your research and find it useful, please cite ConDo\nusing the following reference to our [arXiv preprint](https://arxiv.org/abs/2203.12720):\n\nIn Bibtex format:\n\n```bibtex\n@misc{https://doi.org/10.48550/arxiv.2203.12720,\n doi = {10.48550/ARXIV.2203.12720},\n url = {https://arxiv.org/abs/2203.12720},\n author = {McCarter, Calvin},\n title = {Towards Backwards-Compatible Data with Confounded Domain Adaptation},\n publisher = {arXiv},\n year = {2022},\n}\n```\n\n## Installation\n\n### Installation from pip\n\nYou can install the toolbox through PyPI with:\n\n```console\npip install condo\n```\n\nNote: If you have issues with importing `torchmin`, you may need to install from source, as shown below. Or you can try re-installing [pytorch-minimize](https://github.com/rfeinman/pytorch-minimize) from source. \n\n### Installation from source\n\nAfter cloning this repo, install the dependencies on the command-line via:\n\n```console\npip install -r requirements.txt\n```\n\nIn this directory, run\n\n```console\npip install -e .\n```\n\n## Usage\n\nImport ConDo and create the adapter:\n```python\nimport condo\ncondoer = condo.ConDoAdapter()\n```\n\nTry using it:\n```python\nimport numpy as np\nX_T = np.sort(np.random.uniform(0, 8, size=(100, 1)))\nX_S = np.sort(np.random.uniform(4, 8, size=(100, 1)))\nY_T = np.random.normal(4 * X_T + 1, 1 * X_T + 1)\nY_Strue = np.random.normal(4 * X_S + 1, 1 * X_S + 1)\nY_S = 5 * Y_Strue + 2\ncondoer.fit(Y_S, Y_T, X_S, X_T)\nY_S2T = condoer.transform(Y_S)\nprint(f\"before ConDo: {np.mean((Y_S - Y_Strue) ** 2):.3f}\")\nprint(f\"after ConDo: {np.mean((Y_S2T - Y_Strue) ** 2):.3f}\")\n```\n\nMore thorough examples are provided in the examples directory.\n\n## Development\n\n### Testing\nIn this directory run\n```console\npytest\n```\n\n### Code formatting\nThe Uncompromising Code Formatter: [Black](https://github.com/psf/black) \n```black {source_file_or_directory}``` \n\nInstall it into pre-commit hook to always commit well-formatted code: \n```pre-commit install```\n\n## License Information\n\nThis work is licensed under a\n[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].\n\n[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]\n\n[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/\n[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png\n[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg\n\n\n",
"bugtrack_url": null,
"license": "by-nc-sa-4.0",
"summary": "Confounded domain adaptation",
"version": "0.8.0",
"project_urls": {
"Homepage": "http://github.com/calvinmccarter/condo-adapter"
},
"split_keywords": [
"confounding",
" domain adaptation",
" batch correction"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "66f1cbad3062d54135d39c097fac94c3d38249b71edef44fca634af13e5fd7bd",
"md5": "3d4f2e54a83e97ac2f2cbb28ba480cfe",
"sha256": "4034d24ddeb458aecd1cb0a6e9280ea01b4da433162f841f92c878a7f16cf0ed"
},
"downloads": -1,
"filename": "condo-0.8.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3d4f2e54a83e97ac2f2cbb28ba480cfe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 28619,
"upload_time": "2024-08-25T20:49:44",
"upload_time_iso_8601": "2024-08-25T20:49:44.333713Z",
"url": "https://files.pythonhosted.org/packages/66/f1/cbad3062d54135d39c097fac94c3d38249b71edef44fca634af13e5fd7bd/condo-0.8.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5f472232458e943dcd04eeca1307481aa33ea3892a549f25309698a7b93bb388",
"md5": "8b242c5d2730819613c347e6c09f2409",
"sha256": "79e5be350484a1c8e99e8e277284d46c0a020896fe68a7a0528c208d712bf68b"
},
"downloads": -1,
"filename": "condo-0.8.0.tar.gz",
"has_sig": false,
"md5_digest": "8b242c5d2730819613c347e6c09f2409",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 23341,
"upload_time": "2024-08-25T20:49:45",
"upload_time_iso_8601": "2024-08-25T20:49:45.943219Z",
"url": "https://files.pythonhosted.org/packages/5f/47/2232458e943dcd04eeca1307481aa33ea3892a549f25309698a7b93bb388/condo-0.8.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-25 20:49:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "calvinmccarter",
"github_project": "condo-adapter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "miceforest",
"specs": [
[
"==",
"5.7.0"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.18.1"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.0"
]
]
},
{
"name": "pre-commit",
"specs": [
[
">=",
"2.2.0"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"5.4.1"
]
]
},
{
"name": "pytorch-minimize",
"specs": [
[
">=",
"0.0.2"
]
]
},
{
"name": "scipy",
"specs": [
[
"==",
"1.7.1"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"1.0"
]
]
},
{
"name": "torch",
"specs": [
[
">=",
"1.4.0"
]
]
}
],
"lcname": "condo"
}