Skip to main content

Library to perform confounded domain adaptation.

Project description

condo-adapter

PyPI version Downloads CC BY-NC-SA 4.0

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:

In Bibtex format:

@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:

pip install condo

Installation from source

After cloning this repo, install the dependencies on the command-line via:

pip install -r requirements.txt

In this directory, run

pip install -e .

Usage

Import ConDo and create the adapter:

import condo
condoer = condo.ConDoAdapter()

Try using it:

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

pytest

Code formatting

The Uncompromising Code Formatter: 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 4.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

condo-0.4.0.tar.gz (26.5 kB view hashes)

Uploaded Source

Built Distribution

condo-0.4.0-py3-none-any.whl (27.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page