tpcp


Nametpcp JSON
Version 0.33.0 PyPI version JSON
download
home_pagehttps://github.com/mad-lab-fau/tpcp
SummaryPipeline and Dataset helpers for complex algorithm evaluation.
upload_time2024-05-23 12:38:39
maintainerNone
docs_urlNone
authorArne Küderle
requires_python<4.0,>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./docs/_static/logo/tpcp_logo_with_text.png" height="150">

[![PyPI](https://img.shields.io/pypi/v/tpcp)](https://pypi.org/project/tpcp/)
[![Documentation Status](https://readthedocs.org/projects/tpcp/badge/?version=latest)](https://tpcp.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/mad-lab-fau/tpcp/branch/main/graph/badge.svg?token=ZNVT5LNYHO)](https://codecov.io/gh/mad-lab-fau/tpcp)
[![Test and Lint](https://github.com/mad-lab-fau/tpcp/actions/workflows/test-and-lint.yml/badge.svg?branch=main)](https://github.com/mad-lab-fau/tpcp/actions/workflows/test-and-lint.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![PyPI - Downloads](https://img.shields.io/pypi/dm/tpcp)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04953/status.svg)](https://doi.org/10.21105/joss.04953)

# tpcp - Tiny Pipelines for Complex Problems

A generic way to build object-oriented datasets and algorithm pipelines and tools to evaluate them.

Easily install `tpcp` via pip:
```bash
pip install tpcp
```

Or add it to your project with [poetry](https://python-poetry.org/):
```bash
poetry add tpcp
```

## Why?

Evaluating Algorithms - in particular when they contain machine learning - is hard.
Besides understanding required concepts (cross validation, bias, overfitting, ...), you need to implement the required 
steps and make them work together with your algorithms and data.
If you are doing something "regular" like training an SVM on tabular data, amazing libraries like [sklearn](https://scikit-learn.org), 
[tslearn](https://github.com/tslearn-team/tslearn), [pytorch](https://pytorch.org), and many others, have your back.
By using their built-in tools (e.g. `sklearn.evaluation.GridSearchCV`) you prevent implementation errors, and you are
provided with a sensible structure to organize your code that is well understood in the community.

However, often the problems we are trying to solve are not regular.
They are **complex**.
As an example, here is the summary of the method from one of our [recent papers](https://jneuroengrehab.biomedcentral.com/articles/10.1186/s12984-021-00883-7):
- We have continuous multi-dimensional sensor recordings from multiple participants from a hospital visit and multiple days at home
- For each participant we have global metadata (age, diagnosis) and daily annotations
- We want to train a Hidden-Markov-Model that can find events in the data streams
- We need to tune hyper-parameters of the algorithm using a participant-wise cross validation
- We want to evaluate the final performance of the algorithm for the settings trained on the hospital data -> tested on home data and trained on home data -> tested on home data
- Using the same structure we want to evaluate a state-of-the-art algorithm to compare the results

None of the standard frameworks can easily abstract this problem, because here we have none-tabular data, multiple data 
sources per participant, a non-traditional ML algorithm, and a complex train-test split logic.

With `tpcp` we want to provide a flexible framework to approach such complex problems with structure and confidence.

## How?

To make `tpcp` easy to use, we try to focus on a couple of key ideas:

- Datasets are Python classes (think of [`pytorch.datasets`](https://pytorch.org/tutorials/beginner/basics/data_tutorial.html), but more flexible) that can be split, iterated over, and queried.
- Algorithms and Pipelines are Python classes with a simple `run` and `optimize` interface, that can be implemented to fit any problem.
- Everything is a parameter and everything is optimization: In regular ML we differentiate *training* and *hyper-parameter optimization*.
  In `tpcp` we consider everything that modifies parameters or weights as an *optimization*.
  This allows to use the same concepts and code interfaces from simple algorithms that just require a grid search to optimize a parameter to neuronal network pipelines with hyperparameter tuning.
- Provide what is difficult, allow to change everything else:
  `tpcp` implements complicated constructs like cross validation and grid search and, whenever possible, tries to catch obvious errors in your approach.
  However, for the actual algorithm and dataset you are free to do whatever is required to solve your current research question.

## Should you use tpcp?

### Datasets

**Yes** - the object-oriented Datasets have proven themselves to be a really nice and flexible way to encapsulate Datasets with data from multiple modalities.
There is a clear path of integrating lazy-loading, load-cashing, data filtering, or pre-processing on loading.
From our experience, even if you ignore all the other tpcp features, Datasets can greatly simplify how you interact with your data sources and can serve as a self-documenting API for your data.

[Learn more](https://tpcp.readthedocs.io/en/latest/guides/algorithms_pipelines_datasets.html#datasets) 
([Examples](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#datasets))

Other projects using Datasets:
- [gaitmap-datasets](https://github.com/mad-lab-fau/gaitmap-datasets)
- [cold-face-test-analysis](https://github.com/mad-lab-fau/cft-analysis/tree/main/cft_analysis/datasets)
- [carwatch-analysis](https://github.com/mad-lab-fau/carwatch-analysis/tree/main/carwatch_analysis/datasets)
- [mobgap](https://github.com/mobilise-d/mobgap)

### Parameter Optimization and Cross Validation

**Maybe** - All parameter optimization features in tpcp exist to provide a unified API, in case other specific frameworks are too specialised.
In cases where all your algorithms can be abstracted by `sklearn`, `pytorch` (with the `skorch` wrapper), `tensorflow`/`Keras` (with the `scikeras` wrapper), 
or any other framework that provides a nice scikit-learn API, you will get all the features tpcp can provide with much less boilerplate by just using `sklearn` and `optuna` directly.
Even, if you need to implement completely custom algorithms, we would encourage you to see if you can emulate a sklearn-like API to make use of its vast ecosystem.

This will usually work well for all algorithms that can be abstracted by the fit-predict paradigm.
However, for more "traditional" algorithms with no "fit" step or complicated optimizations, the `run` (with optional `self_optimize`) API of tpcp might be a better fit.
So if you are using or developing algorithms across library domains, that don't all work well with a sklearn API, then **Yes**, tpcp is a good choice.

Learn more:
[General Concepts](https://tpcp.readthedocs.io/en/latest/guides/index.html#user-guides),
[Custom Algorithms](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#algorithms), 
[Parameter Optimization](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#parameter-optimization), 
[Cross Validation](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#validation)

Other projects using tpcp features:
- [gaitmap](https://github.com/mad-lab-fau/gaitmap) - uses tpcp as basis for custom class based algorithms
- [gaitmap-bench](https://github.com/mad-lab-fau/gaitmap-bench) - uses all tpcp features (from pipelines to optuna integration) for standardized evaluation of algorithms
- [eargait](https://github.com/mad-lab-fau/eargait) - uses tpcp as basis for custom class based algorithms
- [mobgap](https://github.com/mobilise-d/mobgap) - uses tpcp as basis for custom class based algorithms and to implement reproducible evaluation tools

## Citation

If you use `tpcp` in your research, we would appreciate a citation to our JOSS paper.
This helps us to justify putting time into maintaining and improving the library.

```
Küderle et al., (2023). tpcp: Tiny Pipelines for Complex Problems - 
A set of framework independent helpers for algorithms development and evaluation. 
Journal of Open Source Software, 8(82), 4953,
https://doi.org/10.21105/joss.04953
```

```bibtex
@article{
  Küderle2023, 
  doi = {10.21105/joss.04953},
  url = {https://doi.org/10.21105/joss.04953},
  year = {2023}, publisher = {The Open Journal},
  volume = {8}, number = {82}, pages = {4953},
  author = {Arne Küderle and Robert Richer and Raul C. Sîmpetru and Bjoern M. Eskofier},
  title = {tpcp: Tiny Pipelines for Complex Problems - 
           A set of framework independent helpers for algorithms development and evaluation},
  journal = {Journal of Open Source Software}
}
```

## Contribution

The entire development is managed via [GitHub](https://github.com/mad-lab-fau/tpcp).
If you run into any issues, want to discuss certain decisions, want to contribute features or feature requests, just 
reach out to us by [opening a new issue](https://github.com/mad-lab-fau/tpcp/issues/new/).

## Dev Setup

We are using [poetry](https://python-poetry.org/) to manage dependencies and 
[poethepoet](https://github.com/nat-n/poethepoet) to run and manage dev tasks.

To set up the dev environment *including* the required dependencies for using and developing on `tpcp` run the following
commands: 
```bash
git clone https://github.com/mad-lab-fau/tpcp
cd tpcp
poetry install --all-extras
```

Afterward, you can start to develop and change things.
If you want to run tests, format your code, build the docs, ..., you can run one of the following `poethepoet` commands

```
CONFIGURED TASKS
  format            
  format_unsafe     
  lint              Lint all files with ruff.
  ci_check          Check all potential format and linting issues.
  test              Run Pytest with coverage.
  docs              Build the html docs using Sphinx.
  docs_clean        Remove all old build files and build a clean version of the docs.
  docs_preview      Preview the built html docs.
  version   
```

by calling

```bash
poetry run poe <command name>
````

If you installed `poethepoet` globally, you can skip the `poetry run` part at the beginning.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mad-lab-fau/tpcp",
    "name": "tpcp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Arne K\u00fcderle",
    "author_email": "arne.kuederle@fau.de",
    "download_url": "https://files.pythonhosted.org/packages/98/3a/80e1c9e2533e33d79998b3b912422c1dfdbb1af5d1e872c222428a4ae9d4/tpcp-0.33.0.tar.gz",
    "platform": null,
    "description": "<img src=\"./docs/_static/logo/tpcp_logo_with_text.png\" height=\"150\">\n\n[![PyPI](https://img.shields.io/pypi/v/tpcp)](https://pypi.org/project/tpcp/)\n[![Documentation Status](https://readthedocs.org/projects/tpcp/badge/?version=latest)](https://tpcp.readthedocs.io/en/latest/?badge=latest)\n[![codecov](https://codecov.io/gh/mad-lab-fau/tpcp/branch/main/graph/badge.svg?token=ZNVT5LNYHO)](https://codecov.io/gh/mad-lab-fau/tpcp)\n[![Test and Lint](https://github.com/mad-lab-fau/tpcp/actions/workflows/test-and-lint.yml/badge.svg?branch=main)](https://github.com/mad-lab-fau/tpcp/actions/workflows/test-and-lint.yml)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/tpcp)\n[![DOI](https://joss.theoj.org/papers/10.21105/joss.04953/status.svg)](https://doi.org/10.21105/joss.04953)\n\n# tpcp - Tiny Pipelines for Complex Problems\n\nA generic way to build object-oriented datasets and algorithm pipelines and tools to evaluate them.\n\nEasily install `tpcp` via pip:\n```bash\npip install tpcp\n```\n\nOr add it to your project with [poetry](https://python-poetry.org/):\n```bash\npoetry add tpcp\n```\n\n## Why?\n\nEvaluating Algorithms - in particular when they contain machine learning - is hard.\nBesides understanding required concepts (cross validation, bias, overfitting, ...), you need to implement the required \nsteps and make them work together with your algorithms and data.\nIf you are doing something \"regular\" like training an SVM on tabular data, amazing libraries like [sklearn](https://scikit-learn.org), \n[tslearn](https://github.com/tslearn-team/tslearn), [pytorch](https://pytorch.org), and many others, have your back.\nBy using their built-in tools (e.g. `sklearn.evaluation.GridSearchCV`) you prevent implementation errors, and you are\nprovided with a sensible structure to organize your code that is well understood in the community.\n\nHowever, often the problems we are trying to solve are not regular.\nThey are **complex**.\nAs an example, here is the summary of the method from one of our [recent papers](https://jneuroengrehab.biomedcentral.com/articles/10.1186/s12984-021-00883-7):\n- We have continuous multi-dimensional sensor recordings from multiple participants from a hospital visit and multiple days at home\n- For each participant we have global metadata (age, diagnosis) and daily annotations\n- We want to train a Hidden-Markov-Model that can find events in the data streams\n- We need to tune hyper-parameters of the algorithm using a participant-wise cross validation\n- We want to evaluate the final performance of the algorithm for the settings trained on the hospital data -> tested on home data and trained on home data -> tested on home data\n- Using the same structure we want to evaluate a state-of-the-art algorithm to compare the results\n\nNone of the standard frameworks can easily abstract this problem, because here we have none-tabular data, multiple data \nsources per participant, a non-traditional ML algorithm, and a complex train-test split logic.\n\nWith `tpcp` we want to provide a flexible framework to approach such complex problems with structure and confidence.\n\n## How?\n\nTo make `tpcp` easy to use, we try to focus on a couple of key ideas:\n\n- Datasets are Python classes (think of [`pytorch.datasets`](https://pytorch.org/tutorials/beginner/basics/data_tutorial.html), but more flexible) that can be split, iterated over, and queried.\n- Algorithms and Pipelines are Python classes with a simple `run` and `optimize` interface, that can be implemented to fit any problem.\n- Everything is a parameter and everything is optimization: In regular ML we differentiate *training* and *hyper-parameter optimization*.\n  In `tpcp` we consider everything that modifies parameters or weights as an *optimization*.\n  This allows to use the same concepts and code interfaces from simple algorithms that just require a grid search to optimize a parameter to neuronal network pipelines with hyperparameter tuning.\n- Provide what is difficult, allow to change everything else:\n  `tpcp` implements complicated constructs like cross validation and grid search and, whenever possible, tries to catch obvious errors in your approach.\n  However, for the actual algorithm and dataset you are free to do whatever is required to solve your current research question.\n\n## Should you use tpcp?\n\n### Datasets\n\n**Yes** - the object-oriented Datasets have proven themselves to be a really nice and flexible way to encapsulate Datasets with data from multiple modalities.\nThere is a clear path of integrating lazy-loading, load-cashing, data filtering, or pre-processing on loading.\nFrom our experience, even if you ignore all the other tpcp features, Datasets can greatly simplify how you interact with your data sources and can serve as a self-documenting API for your data.\n\n[Learn more](https://tpcp.readthedocs.io/en/latest/guides/algorithms_pipelines_datasets.html#datasets) \n([Examples](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#datasets))\n\nOther projects using Datasets:\n- [gaitmap-datasets](https://github.com/mad-lab-fau/gaitmap-datasets)\n- [cold-face-test-analysis](https://github.com/mad-lab-fau/cft-analysis/tree/main/cft_analysis/datasets)\n- [carwatch-analysis](https://github.com/mad-lab-fau/carwatch-analysis/tree/main/carwatch_analysis/datasets)\n- [mobgap](https://github.com/mobilise-d/mobgap)\n\n### Parameter Optimization and Cross Validation\n\n**Maybe** - All parameter optimization features in tpcp exist to provide a unified API, in case other specific frameworks are too specialised.\nIn cases where all your algorithms can be abstracted by `sklearn`, `pytorch` (with the `skorch` wrapper), `tensorflow`/`Keras` (with the `scikeras` wrapper), \nor any other framework that provides a nice scikit-learn API, you will get all the features tpcp can provide with much less boilerplate by just using `sklearn` and `optuna` directly.\nEven, if you need to implement completely custom algorithms, we would encourage you to see if you can emulate a sklearn-like API to make use of its vast ecosystem.\n\nThis will usually work well for all algorithms that can be abstracted by the fit-predict paradigm.\nHowever, for more \"traditional\" algorithms with no \"fit\" step or complicated optimizations, the `run` (with optional `self_optimize`) API of tpcp might be a better fit.\nSo if you are using or developing algorithms across library domains, that don't all work well with a sklearn API, then **Yes**, tpcp is a good choice.\n\nLearn more:\n[General Concepts](https://tpcp.readthedocs.io/en/latest/guides/index.html#user-guides),\n[Custom Algorithms](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#algorithms), \n[Parameter Optimization](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#parameter-optimization), \n[Cross Validation](https://tpcp.readthedocs.io/en/latest/auto_examples/index.html#validation)\n\nOther projects using tpcp features:\n- [gaitmap](https://github.com/mad-lab-fau/gaitmap) - uses tpcp as basis for custom class based algorithms\n- [gaitmap-bench](https://github.com/mad-lab-fau/gaitmap-bench) - uses all tpcp features (from pipelines to optuna integration) for standardized evaluation of algorithms\n- [eargait](https://github.com/mad-lab-fau/eargait) - uses tpcp as basis for custom class based algorithms\n- [mobgap](https://github.com/mobilise-d/mobgap) - uses tpcp as basis for custom class based algorithms and to implement reproducible evaluation tools\n\n## Citation\n\nIf you use `tpcp` in your research, we would appreciate a citation to our JOSS paper.\nThis helps us to justify putting time into maintaining and improving the library.\n\n```\nK\u00fcderle et al., (2023). tpcp: Tiny Pipelines for Complex Problems - \nA set of framework independent helpers for algorithms development and evaluation. \nJournal of Open Source Software, 8(82), 4953,\nhttps://doi.org/10.21105/joss.04953\n```\n\n```bibtex\n@article{\n  K\u00fcderle2023, \n  doi = {10.21105/joss.04953},\n  url = {https://doi.org/10.21105/joss.04953},\n  year = {2023}, publisher = {The Open Journal},\n  volume = {8}, number = {82}, pages = {4953},\n  author = {Arne K\u00fcderle and Robert Richer and Raul C. S\u00eempetru and Bjoern M. Eskofier},\n  title = {tpcp: Tiny Pipelines for Complex Problems - \n           A set of framework independent helpers for algorithms development and evaluation},\n  journal = {Journal of Open Source Software}\n}\n```\n\n## Contribution\n\nThe entire development is managed via [GitHub](https://github.com/mad-lab-fau/tpcp).\nIf you run into any issues, want to discuss certain decisions, want to contribute features or feature requests, just \nreach out to us by [opening a new issue](https://github.com/mad-lab-fau/tpcp/issues/new/).\n\n## Dev Setup\n\nWe are using [poetry](https://python-poetry.org/) to manage dependencies and \n[poethepoet](https://github.com/nat-n/poethepoet) to run and manage dev tasks.\n\nTo set up the dev environment *including* the required dependencies for using and developing on `tpcp` run the following\ncommands: \n```bash\ngit clone https://github.com/mad-lab-fau/tpcp\ncd tpcp\npoetry install --all-extras\n```\n\nAfterward, you can start to develop and change things.\nIf you want to run tests, format your code, build the docs, ..., you can run one of the following `poethepoet` commands\n\n```\nCONFIGURED TASKS\n  format            \n  format_unsafe     \n  lint              Lint all files with ruff.\n  ci_check          Check all potential format and linting issues.\n  test              Run Pytest with coverage.\n  docs              Build the html docs using Sphinx.\n  docs_clean        Remove all old build files and build a clean version of the docs.\n  docs_preview      Preview the built html docs.\n  version   \n```\n\nby calling\n\n```bash\npoetry run poe <command name>\n````\n\nIf you installed `poethepoet` globally, you can skip the `poetry run` part at the beginning.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Pipeline and Dataset helpers for complex algorithm evaluation.",
    "version": "0.33.0",
    "project_urls": {
        "Homepage": "https://github.com/mad-lab-fau/tpcp",
        "Repository": "https://github.com/mad-lab-fau/tpcp"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26abf8d08436bb2300ffed92294f5b486945f01196380d52aa411865ab2725a5",
                "md5": "e75a65024bcddc6630ea2509b0b1debb",
                "sha256": "85ecea7748c992cbdbecc97d67fc34c9e7268f9520c476139dbef54fe6f63c39"
            },
            "downloads": -1,
            "filename": "tpcp-0.33.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e75a65024bcddc6630ea2509b0b1debb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 93603,
            "upload_time": "2024-05-23T12:38:37",
            "upload_time_iso_8601": "2024-05-23T12:38:37.118831Z",
            "url": "https://files.pythonhosted.org/packages/26/ab/f8d08436bb2300ffed92294f5b486945f01196380d52aa411865ab2725a5/tpcp-0.33.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "983a80e1c9e2533e33d79998b3b912422c1dfdbb1af5d1e872c222428a4ae9d4",
                "md5": "a4c791cfd6e6b3ad8bddcddd587cfb1e",
                "sha256": "e7908a9089a8121d5dd5ee0a537aaa6307e7090293643b1bedc8b32dbc9be528"
            },
            "downloads": -1,
            "filename": "tpcp-0.33.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a4c791cfd6e6b3ad8bddcddd587cfb1e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 84696,
            "upload_time": "2024-05-23T12:38:39",
            "upload_time_iso_8601": "2024-05-23T12:38:39.401701Z",
            "url": "https://files.pythonhosted.org/packages/98/3a/80e1c9e2533e33d79998b3b912422c1dfdbb1af5d1e872c222428a4ae9d4/tpcp-0.33.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 12:38:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mad-lab-fau",
    "github_project": "tpcp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tpcp"
}
        
Elapsed time: 0.30530s