pyplasmode 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyplasmode-1.0.0/.gitignore +14 -0
- pyplasmode-1.0.0/CHANGELOG.md +18 -0
- pyplasmode-1.0.0/CITATION.cff +20 -0
- pyplasmode-1.0.0/CONTRIBUTING.md +48 -0
- pyplasmode-1.0.0/LICENSE +29 -0
- pyplasmode-1.0.0/PKG-INFO +142 -0
- pyplasmode-1.0.0/README.md +116 -0
- pyplasmode-1.0.0/THIRD_PARTY_NOTICES.md +9 -0
- pyplasmode-1.0.0/docs/api.md +48 -0
- pyplasmode-1.0.0/docs/assets/concepts/README.md +10 -0
- pyplasmode-1.0.0/docs/assets/concepts/plasmode-workflow.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/concepts/plasmode-workflow.png +0 -0
- pyplasmode-1.0.0/docs/assets/concepts/signal-recovery.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/concepts/signal-recovery.png +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/correlated-recovery.csv +25 -0
- pyplasmode-1.0.0/docs/assets/patterns/correlated-recovery.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/correlated-recovery.png +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/correlated-recovery.svg +693 -0
- pyplasmode-1.0.0/docs/assets/patterns/feature-correlations.csv +37 -0
- pyplasmode-1.0.0/docs/assets/patterns/outcome-calibration.json +217 -0
- pyplasmode-1.0.0/docs/assets/patterns/outcome-families.csv +910 -0
- pyplasmode-1.0.0/docs/assets/patterns/outcome-families.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/outcome-families.png +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/outcome-families.svg +581 -0
- pyplasmode-1.0.0/docs/assets/patterns/signal-shapes.csv +10087 -0
- pyplasmode-1.0.0/docs/assets/patterns/signal-shapes.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/signal-shapes.png +0 -0
- pyplasmode-1.0.0/docs/assets/patterns/signal-shapes.svg +11193 -0
- pyplasmode-1.0.0/docs/assets/validation/external-conformance.csv +6 -0
- pyplasmode-1.0.0/docs/assets/validation/null-control.csv +101 -0
- pyplasmode-1.0.0/docs/assets/validation/outcome-reproducibility.csv +6 -0
- pyplasmode-1.0.0/docs/assets/validation/truth-recovery.csv +3 -0
- pyplasmode-1.0.0/docs/assets/validation/validation.pdf +0 -0
- pyplasmode-1.0.0/docs/assets/validation/validation.png +0 -0
- pyplasmode-1.0.0/docs/assets/validation/validation.svg +529 -0
- pyplasmode-1.0.0/docs/evaluation.md +176 -0
- pyplasmode-1.0.0/docs/gallery.md +81 -0
- pyplasmode-1.0.0/docs/index.md +52 -0
- pyplasmode-1.0.0/docs/methods.md +97 -0
- pyplasmode-1.0.0/docs/outcomes.md +169 -0
- pyplasmode-1.0.0/docs/privacy-and-limitations.md +22 -0
- pyplasmode-1.0.0/docs/references.md +30 -0
- pyplasmode-1.0.0/docs/structures-and-extensions.md +35 -0
- pyplasmode-1.0.0/docs/truths.md +66 -0
- pyplasmode-1.0.0/docs/tutorial.md +140 -0
- pyplasmode-1.0.0/docs/validation.md +84 -0
- pyplasmode-1.0.0/examples/custom_signal.py +40 -0
- pyplasmode-1.0.0/examples/pattern_gallery.py +195 -0
- pyplasmode-1.0.0/examples/quickstart.py +48 -0
- pyplasmode-1.0.0/examples/recovery.py +34 -0
- pyplasmode-1.0.0/examples/survival.py +46 -0
- pyplasmode-1.0.0/examples/validation_vignette.py +332 -0
- pyplasmode-1.0.0/mkdocs.yml +33 -0
- pyplasmode-1.0.0/pyproject.toml +113 -0
- pyplasmode-1.0.0/src/pyplasmode/__init__.py +178 -0
- pyplasmode-1.0.0/src/pyplasmode/_validation.py +29 -0
- pyplasmode-1.0.0/src/pyplasmode/data.py +221 -0
- pyplasmode-1.0.0/src/pyplasmode/evaluate.py +392 -0
- pyplasmode-1.0.0/src/pyplasmode/generate.py +349 -0
- pyplasmode-1.0.0/src/pyplasmode/nominations.py +623 -0
- pyplasmode-1.0.0/src/pyplasmode/outcomes.py +709 -0
- pyplasmode-1.0.0/src/pyplasmode/py.typed +0 -0
- pyplasmode-1.0.0/src/pyplasmode/results.py +172 -0
- pyplasmode-1.0.0/src/pyplasmode/structures.py +123 -0
- pyplasmode-1.0.0/src/pyplasmode/truth.py +510 -0
- pyplasmode-1.0.0/tests/__init__.py +1 -0
- pyplasmode-1.0.0/tests/integration/__init__.py +1 -0
- pyplasmode-1.0.0/tests/integration/test_documented_workflows.py +27 -0
- pyplasmode-1.0.0/tests/integration/test_fractional_recovery.py +78 -0
- pyplasmode-1.0.0/tests/integration/test_generate_evaluate.py +191 -0
- pyplasmode-1.0.0/tests/integration/test_outcome_composition.py +62 -0
- pyplasmode-1.0.0/tests/integration/test_pattern_gallery.py +73 -0
- pyplasmode-1.0.0/tests/statistical/__init__.py +1 -0
- pyplasmode-1.0.0/tests/statistical/test_evaluate.py +48 -0
- pyplasmode-1.0.0/tests/statistical/test_matched_recovery.py +296 -0
- pyplasmode-1.0.0/tests/statistical/test_outcomes.py +176 -0
- pyplasmode-1.0.0/tests/statistical/test_resampling.py +20 -0
- pyplasmode-1.0.0/tests/unit/__init__.py +1 -0
- pyplasmode-1.0.0/tests/unit/test_data.py +89 -0
- pyplasmode-1.0.0/tests/unit/test_evaluate.py +206 -0
- pyplasmode-1.0.0/tests/unit/test_nominations.py +92 -0
- pyplasmode-1.0.0/tests/unit/test_outcomes.py +61 -0
- pyplasmode-1.0.0/tests/unit/test_public_contracts.py +188 -0
- pyplasmode-1.0.0/tests/unit/test_structures.py +32 -0
- pyplasmode-1.0.0/tests/unit/test_truth.py +129 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
First public release. PyPlasmode provides outcome generation, feature-recovery evaluation,
|
|
6
|
+
worked examples and reference validation for biomarker benchmarking.
|
|
7
|
+
|
|
8
|
+
### Included in this release
|
|
9
|
+
|
|
10
|
+
- Empirical complete-row resampling and source-partitioned generation.
|
|
11
|
+
- Null, sparse, correlated-group, module, interaction and custom signals.
|
|
12
|
+
- Five outcome families calibrated in observable units.
|
|
13
|
+
- Recovery, prediction, panel, reconstruction and rank-stability evaluation.
|
|
14
|
+
- API documentation, worked examples, validation figures and cross-platform CI.
|
|
15
|
+
- A visual gallery of signal shapes, correlated-feature recovery and outcome families,
|
|
16
|
+
with editable vector figures and an executable source-data example.
|
|
17
|
+
- Python 3.12-3.14 and scikit-learn 1.6 through the current 1.x series.
|
|
18
|
+
- BSD 3-Clause licensing.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use PyPlasmode in your research, please cite this software using the metadata below."
|
|
3
|
+
title: "PyPlasmode"
|
|
4
|
+
type: software
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
repository-code: "https://github.com/BradSegal/PyPlasmode"
|
|
7
|
+
license: BSD-3-Clause
|
|
8
|
+
authors:
|
|
9
|
+
- family-names: Segal
|
|
10
|
+
given-names: Bradley
|
|
11
|
+
- family-names: Fieggen
|
|
12
|
+
given-names: Joshua
|
|
13
|
+
- family-names: Simond
|
|
14
|
+
given-names: Greg
|
|
15
|
+
- family-names: Belgrave
|
|
16
|
+
given-names: Danielle
|
|
17
|
+
- family-names: Clifton
|
|
18
|
+
given-names: David
|
|
19
|
+
- family-names: Clifton
|
|
20
|
+
given-names: Lei
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Contributions to generators, evaluation functions, documentation and examples are welcome.
|
|
4
|
+
For a new signal or outcome family, describe the intended use and mathematical definition
|
|
5
|
+
in an issue before implementing it.
|
|
6
|
+
|
|
7
|
+
From a checkout, install a supported Python version (3.12-3.14) and uv, then run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv sync --extra validation --group docs
|
|
11
|
+
uv run pytest
|
|
12
|
+
uv run ruff check .
|
|
13
|
+
uv run ruff format --check .
|
|
14
|
+
uv run mypy src/pyplasmode
|
|
15
|
+
uv run mkdocs build --strict
|
|
16
|
+
uv run python -m build
|
|
17
|
+
uv run twine check --strict dist/*
|
|
18
|
+
uv run check-wheel-contents dist/*.whl
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Run `python examples/validation_vignette.py --output validation-output` to regenerate the
|
|
22
|
+
synthetic validation figures and tables. The `validation` extra is included in the setup above.
|
|
23
|
+
|
|
24
|
+
The local uv lock records your development environment. Supported dependency ranges are
|
|
25
|
+
listed in `pyproject.toml`.
|
|
26
|
+
|
|
27
|
+
## Changes and support
|
|
28
|
+
|
|
29
|
+
Use the repository's issue tracker for bug reports, questions and feature proposals. For a bug,
|
|
30
|
+
include dependency versions, the expected result and a small synthetic reproducer. Keep
|
|
31
|
+
participant data and credentials out of reports. Send security-sensitive reports privately
|
|
32
|
+
to the repository maintainer.
|
|
33
|
+
|
|
34
|
+
Add a focused regression test for bug fixes. Generator changes also need checks of their
|
|
35
|
+
distributional properties, including null signals and a reference calculation or estimator.
|
|
36
|
+
Integration tests exercise complete user workflows; the examples show how to combine the
|
|
37
|
+
library with model fitting, tuning and explanation tools.
|
|
38
|
+
|
|
39
|
+
## Releases and compatibility
|
|
40
|
+
|
|
41
|
+
Record public changes in the changelog. Incompatible API or statistical-definition changes
|
|
42
|
+
increment the major version; compatible additions increment the minor version, and fixes
|
|
43
|
+
increment the patch version. Explain corrections that affect numerical results in the release notes.
|
|
44
|
+
Record random seeds and dependency versions when sharing reproducible analyses.
|
|
45
|
+
|
|
46
|
+
The CI matrix covers minimum numerical dependencies on Python 3.12 and current dependencies
|
|
47
|
+
on supported Python versions, with Linux, Windows and macOS jobs. Test dependency changes
|
|
48
|
+
against this matrix. Build release artifacts from the tagged version after CI passes.
|
pyplasmode-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, PyPlasmode contributors
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyplasmode
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Simulate biomarker signals and evaluate prediction and feature recovery.
|
|
5
|
+
Project-URL: Repository, https://github.com/BradSegal/PyPlasmode
|
|
6
|
+
Project-URL: Documentation, https://github.com/BradSegal/PyPlasmode/tree/main/docs
|
|
7
|
+
Project-URL: Issues, https://github.com/BradSegal/PyPlasmode/issues
|
|
8
|
+
License-Expression: BSD-3-Clause
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
18
|
+
Requires-Python: <3.15,>=3.12
|
|
19
|
+
Requires-Dist: numpy<3,>=2.0
|
|
20
|
+
Requires-Dist: scikit-learn<2,>=1.6
|
|
21
|
+
Requires-Dist: scipy<2,>=1.14
|
|
22
|
+
Provides-Extra: validation
|
|
23
|
+
Requires-Dist: matplotlib<4,>=3.10; extra == 'validation'
|
|
24
|
+
Requires-Dist: statsmodels<0.16,>=0.14; extra == 'validation'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# PyPlasmode
|
|
28
|
+
|
|
29
|
+
PyPlasmode benchmarks the reliability of biomarker discovery. A model can predict disease
|
|
30
|
+
accurately while selecting proteins that only track the underlying signal. To evaluate its
|
|
31
|
+
explanations, you need a comparison in which the relevant features are known. PyPlasmode
|
|
32
|
+
creates that comparison by generating outcomes from specified effects within your measurements.
|
|
33
|
+
|
|
34
|
+
Use it with your existing modelling workflow: generate a dataset, fit and tune your models,
|
|
35
|
+
then evaluate their predictions, feature rankings or selected panels.
|
|
36
|
+
|
|
37
|
+
[](docs/methods.md)
|
|
38
|
+
|
|
39
|
+
The same generated dataset supports two comparisons: predictions against outcomes, and
|
|
40
|
+
selected features against the signal that generated them.
|
|
41
|
+
|
|
42
|
+
Explore the [visual gallery](docs/gallery.md) for signal patterns, correlated-feature recovery
|
|
43
|
+
and the five outcome families.
|
|
44
|
+
|
|
45
|
+
The [biomarker tutorial](docs/tutorial.md) follows a complete example from correlated
|
|
46
|
+
measurements through model fitting, attribution and recovery above chance.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
Requires Python 3.12-3.14. Install from GitHub:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python -m pip install "git+https://github.com/BradSegal/PyPlasmode.git@v1.0.0"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The runtime dependencies are NumPy, SciPy and scikit-learn. To include the reference
|
|
57
|
+
validation and survival examples, install the validation extra:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m pip install "PyPlasmode[validation] @ git+https://github.com/BradSegal/PyPlasmode.git@v1.0.0"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Ten-minute example
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import numpy as np
|
|
67
|
+
from sklearn.linear_model import LogisticRegression
|
|
68
|
+
import pyplasmode as ppm
|
|
69
|
+
|
|
70
|
+
rng = np.random.default_rng(1)
|
|
71
|
+
population = ppm.Population(
|
|
72
|
+
rng.normal(size=(2_000, 100)),
|
|
73
|
+
tuple(f"protein_{index}" for index in range(100)),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
partition = ppm.partition_population(
|
|
77
|
+
population,
|
|
78
|
+
training_fraction=0.6,
|
|
79
|
+
validation_fraction=0.2,
|
|
80
|
+
seed=7,
|
|
81
|
+
)
|
|
82
|
+
samples = ppm.generate_partitioned(
|
|
83
|
+
partition,
|
|
84
|
+
truth=ppm.SparseTruth(features=("protein_3", "protein_17", "protein_42")),
|
|
85
|
+
outcome=ppm.BinaryOutcome(probability=0.15, odds_ratio=2.0),
|
|
86
|
+
sample_sizes=ppm.PartitionSampleSizes(1_200, 400, 400),
|
|
87
|
+
sampling_method="without_replacement",
|
|
88
|
+
seed=42,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
train, test = samples.training, samples.evaluation
|
|
92
|
+
model = LogisticRegression(max_iter=1_000).fit(train.X, train.outcome.values)
|
|
93
|
+
ranking = tuple(train.feature_ids[index] for index in np.argsort(-np.abs(model.coef_[0])))
|
|
94
|
+
|
|
95
|
+
recovery = ppm.evaluate_ranking(ranking, train.truth, depths=(10, 20, 50))
|
|
96
|
+
prediction = ppm.evaluate_prediction(
|
|
97
|
+
test.outcome.values,
|
|
98
|
+
model.predict_proba(test.X)[:, 1],
|
|
99
|
+
metric="roc_auc",
|
|
100
|
+
)
|
|
101
|
+
print(recovery.at_depth[0].recall)
|
|
102
|
+
print(prediction.value)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Recall measures how many of the three generating features appear in the model's top ten;
|
|
106
|
+
AUC measures prediction on held-out participants. Repeat the comparison with different seeds
|
|
107
|
+
to estimate average performance and its Monte Carlo uncertainty.
|
|
108
|
+
|
|
109
|
+
Source participants are split before resampling, keeping training, validation and test
|
|
110
|
+
rows separate. This example uses a fixed model; the validation sample is available for
|
|
111
|
+
hyperparameter tuning. See [Methods](docs/methods.md) for the generation process.
|
|
112
|
+
|
|
113
|
+
## What can be varied
|
|
114
|
+
|
|
115
|
+
- **Signal:** null, sparse features, correlated groups, distributed modules, pairwise
|
|
116
|
+
interactions or a custom function.
|
|
117
|
+
- **Outcome:** binary probability, continuous mean and spread, count rate, ordinal category
|
|
118
|
+
probabilities or cumulative event risks at native-time horizons.
|
|
119
|
+
- **Evaluation:** feature and group recovery, weighted-module and graph-region coverage,
|
|
120
|
+
signal reconstruction, prediction accuracy, panel performance and ranking stability.
|
|
121
|
+
Additional functions handle tied scores, incomplete selections and matched chance references.
|
|
122
|
+
|
|
123
|
+
Start with [Methods](docs/methods.md), then choose a [signal](docs/truths.md) and
|
|
124
|
+
[outcome](docs/outcomes.md). The [evaluation guide](docs/evaluation.md) defines each result.
|
|
125
|
+
The [validation example](docs/validation.md) checks the generators and recovery metrics against
|
|
126
|
+
known values and reference estimators.
|
|
127
|
+
|
|
128
|
+
The executable [quickstart](https://github.com/BradSegal/PyPlasmode/blob/main/examples/quickstart.py),
|
|
129
|
+
[survival example](https://github.com/BradSegal/PyPlasmode/blob/main/examples/survival.py)
|
|
130
|
+
and [custom signal](https://github.com/BradSegal/PyPlasmode/blob/main/examples/custom_signal.py)
|
|
131
|
+
use synthetic inputs. The [documentation](https://github.com/BradSegal/PyPlasmode/tree/main/docs)
|
|
132
|
+
includes the generation methods, evaluation definitions and API reference.
|
|
133
|
+
|
|
134
|
+
## Working with empirical data
|
|
135
|
+
|
|
136
|
+
Resampling preserves the source data's feature relationships and missingness patterns.
|
|
137
|
+
It can reproduce individual records, so generated datasets require the same privacy protections
|
|
138
|
+
as their source. See [Data handling](docs/privacy-and-limitations.md).
|
|
139
|
+
|
|
140
|
+
## Licence
|
|
141
|
+
|
|
142
|
+
PyPlasmode uses the [BSD 3-Clause License](LICENSE).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# PyPlasmode
|
|
2
|
+
|
|
3
|
+
PyPlasmode benchmarks the reliability of biomarker discovery. A model can predict disease
|
|
4
|
+
accurately while selecting proteins that only track the underlying signal. To evaluate its
|
|
5
|
+
explanations, you need a comparison in which the relevant features are known. PyPlasmode
|
|
6
|
+
creates that comparison by generating outcomes from specified effects within your measurements.
|
|
7
|
+
|
|
8
|
+
Use it with your existing modelling workflow: generate a dataset, fit and tune your models,
|
|
9
|
+
then evaluate their predictions, feature rankings or selected panels.
|
|
10
|
+
|
|
11
|
+
[](docs/methods.md)
|
|
12
|
+
|
|
13
|
+
The same generated dataset supports two comparisons: predictions against outcomes, and
|
|
14
|
+
selected features against the signal that generated them.
|
|
15
|
+
|
|
16
|
+
Explore the [visual gallery](docs/gallery.md) for signal patterns, correlated-feature recovery
|
|
17
|
+
and the five outcome families.
|
|
18
|
+
|
|
19
|
+
The [biomarker tutorial](docs/tutorial.md) follows a complete example from correlated
|
|
20
|
+
measurements through model fitting, attribution and recovery above chance.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Requires Python 3.12-3.14. Install from GitHub:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m pip install "git+https://github.com/BradSegal/PyPlasmode.git@v1.0.0"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The runtime dependencies are NumPy, SciPy and scikit-learn. To include the reference
|
|
31
|
+
validation and survival examples, install the validation extra:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install "PyPlasmode[validation] @ git+https://github.com/BradSegal/PyPlasmode.git@v1.0.0"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Ten-minute example
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import numpy as np
|
|
41
|
+
from sklearn.linear_model import LogisticRegression
|
|
42
|
+
import pyplasmode as ppm
|
|
43
|
+
|
|
44
|
+
rng = np.random.default_rng(1)
|
|
45
|
+
population = ppm.Population(
|
|
46
|
+
rng.normal(size=(2_000, 100)),
|
|
47
|
+
tuple(f"protein_{index}" for index in range(100)),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
partition = ppm.partition_population(
|
|
51
|
+
population,
|
|
52
|
+
training_fraction=0.6,
|
|
53
|
+
validation_fraction=0.2,
|
|
54
|
+
seed=7,
|
|
55
|
+
)
|
|
56
|
+
samples = ppm.generate_partitioned(
|
|
57
|
+
partition,
|
|
58
|
+
truth=ppm.SparseTruth(features=("protein_3", "protein_17", "protein_42")),
|
|
59
|
+
outcome=ppm.BinaryOutcome(probability=0.15, odds_ratio=2.0),
|
|
60
|
+
sample_sizes=ppm.PartitionSampleSizes(1_200, 400, 400),
|
|
61
|
+
sampling_method="without_replacement",
|
|
62
|
+
seed=42,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
train, test = samples.training, samples.evaluation
|
|
66
|
+
model = LogisticRegression(max_iter=1_000).fit(train.X, train.outcome.values)
|
|
67
|
+
ranking = tuple(train.feature_ids[index] for index in np.argsort(-np.abs(model.coef_[0])))
|
|
68
|
+
|
|
69
|
+
recovery = ppm.evaluate_ranking(ranking, train.truth, depths=(10, 20, 50))
|
|
70
|
+
prediction = ppm.evaluate_prediction(
|
|
71
|
+
test.outcome.values,
|
|
72
|
+
model.predict_proba(test.X)[:, 1],
|
|
73
|
+
metric="roc_auc",
|
|
74
|
+
)
|
|
75
|
+
print(recovery.at_depth[0].recall)
|
|
76
|
+
print(prediction.value)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Recall measures how many of the three generating features appear in the model's top ten;
|
|
80
|
+
AUC measures prediction on held-out participants. Repeat the comparison with different seeds
|
|
81
|
+
to estimate average performance and its Monte Carlo uncertainty.
|
|
82
|
+
|
|
83
|
+
Source participants are split before resampling, keeping training, validation and test
|
|
84
|
+
rows separate. This example uses a fixed model; the validation sample is available for
|
|
85
|
+
hyperparameter tuning. See [Methods](docs/methods.md) for the generation process.
|
|
86
|
+
|
|
87
|
+
## What can be varied
|
|
88
|
+
|
|
89
|
+
- **Signal:** null, sparse features, correlated groups, distributed modules, pairwise
|
|
90
|
+
interactions or a custom function.
|
|
91
|
+
- **Outcome:** binary probability, continuous mean and spread, count rate, ordinal category
|
|
92
|
+
probabilities or cumulative event risks at native-time horizons.
|
|
93
|
+
- **Evaluation:** feature and group recovery, weighted-module and graph-region coverage,
|
|
94
|
+
signal reconstruction, prediction accuracy, panel performance and ranking stability.
|
|
95
|
+
Additional functions handle tied scores, incomplete selections and matched chance references.
|
|
96
|
+
|
|
97
|
+
Start with [Methods](docs/methods.md), then choose a [signal](docs/truths.md) and
|
|
98
|
+
[outcome](docs/outcomes.md). The [evaluation guide](docs/evaluation.md) defines each result.
|
|
99
|
+
The [validation example](docs/validation.md) checks the generators and recovery metrics against
|
|
100
|
+
known values and reference estimators.
|
|
101
|
+
|
|
102
|
+
The executable [quickstart](https://github.com/BradSegal/PyPlasmode/blob/main/examples/quickstart.py),
|
|
103
|
+
[survival example](https://github.com/BradSegal/PyPlasmode/blob/main/examples/survival.py)
|
|
104
|
+
and [custom signal](https://github.com/BradSegal/PyPlasmode/blob/main/examples/custom_signal.py)
|
|
105
|
+
use synthetic inputs. The [documentation](https://github.com/BradSegal/PyPlasmode/tree/main/docs)
|
|
106
|
+
includes the generation methods, evaluation definitions and API reference.
|
|
107
|
+
|
|
108
|
+
## Working with empirical data
|
|
109
|
+
|
|
110
|
+
Resampling preserves the source data's feature relationships and missingness patterns.
|
|
111
|
+
It can reproduce individual records, so generated datasets require the same privacy protections
|
|
112
|
+
as their source. See [Data handling](docs/privacy-and-limitations.md).
|
|
113
|
+
|
|
114
|
+
## Licence
|
|
115
|
+
|
|
116
|
+
PyPlasmode uses the [BSD 3-Clause License](LICENSE).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
PyPlasmode depends on NumPy, SciPy and scikit-learn. These dependencies are not vendored in
|
|
4
|
+
the PyPlasmode source distribution or wheel and remain subject to their own licences. Their
|
|
5
|
+
installed versions can be recorded with `python -m pip freeze`. The source distribution
|
|
6
|
+
declares supported ranges rather than shipping an experiment-specific lock file.
|
|
7
|
+
|
|
8
|
+
The BSD 3-Clause License for PyPlasmode does not relicense empirical input data, generated
|
|
9
|
+
row-level plasmodes or third-party software.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
The common entry points are exported from `pyplasmode`. Matrices have shape
|
|
4
|
+
`(participants, features)`; `feature_ids` supplies one unique string per column.
|
|
5
|
+
Generated arrays are read-only. Convert result dataclasses to plain records with
|
|
6
|
+
`dataclasses.asdict` for your reporting workflow.
|
|
7
|
+
|
|
8
|
+
Use `generate` for one sample or `partition_population` followed by
|
|
9
|
+
`generate_partitioned` for source-disjoint development and evaluation. Access
|
|
10
|
+
`outcome.values` for binary, continuous and count outcomes, `outcome.codes` for
|
|
11
|
+
ordinal outcomes, and `outcome.time` plus `outcome.event` for survival outcomes.
|
|
12
|
+
Survival times are in days; latent event and censoring times beyond administrative
|
|
13
|
+
follow-up are represented by infinity.
|
|
14
|
+
|
|
15
|
+
The rendered reference includes signatures, types and result fields. See the
|
|
16
|
+
methods and evaluation guides for the scientific definitions.
|
|
17
|
+
|
|
18
|
+
## Populations and sampling
|
|
19
|
+
|
|
20
|
+
::: pyplasmode.data
|
|
21
|
+
|
|
22
|
+
## Generation
|
|
23
|
+
|
|
24
|
+
::: pyplasmode.generate
|
|
25
|
+
|
|
26
|
+
## Truth specifications
|
|
27
|
+
|
|
28
|
+
::: pyplasmode.truth
|
|
29
|
+
|
|
30
|
+
## Outcome specifications and results
|
|
31
|
+
|
|
32
|
+
::: pyplasmode.outcomes
|
|
33
|
+
|
|
34
|
+
## Feature sets and graphs
|
|
35
|
+
|
|
36
|
+
::: pyplasmode.structures
|
|
37
|
+
|
|
38
|
+
## Ranking and prediction evaluation
|
|
39
|
+
|
|
40
|
+
::: pyplasmode.evaluate
|
|
41
|
+
|
|
42
|
+
## Fractional nominations and matched references
|
|
43
|
+
|
|
44
|
+
::: pyplasmode.nominations
|
|
45
|
+
|
|
46
|
+
## Evaluation results
|
|
47
|
+
|
|
48
|
+
::: pyplasmode.results
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Concept diagrams
|
|
2
|
+
|
|
3
|
+
Bradley Segal supplied these diagrams for the PyPlasmode documentation and manuscript.
|
|
4
|
+
The original vector PDFs are preserved; PNG copies provide browser previews.
|
|
5
|
+
|
|
6
|
+
- `plasmode-workflow.pdf`: supplied as `Biomarkers (2).pdf`.
|
|
7
|
+
- `signal-recovery.pdf`: supplied as `Biomarkers (3).pdf`.
|
|
8
|
+
|
|
9
|
+
The captions in the documentation explain the simulated disease score and distinguish
|
|
10
|
+
true contributors from proteins selected by a fitted model.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
panel,order,depth,recovery
|
|
2
|
+
b,Generator first,1,1.0
|
|
3
|
+
c,Generator first,1,1.0
|
|
4
|
+
b,Generator first,2,1.0
|
|
5
|
+
c,Generator first,2,1.0
|
|
6
|
+
b,Generator first,3,1.0
|
|
7
|
+
c,Generator first,3,1.0
|
|
8
|
+
b,Generator first,4,1.0
|
|
9
|
+
c,Generator first,4,1.0
|
|
10
|
+
b,Generator first,5,1.0
|
|
11
|
+
c,Generator first,5,1.0
|
|
12
|
+
b,Generator first,6,1.0
|
|
13
|
+
c,Generator first,6,1.0
|
|
14
|
+
b,Substitute first,1,0.0
|
|
15
|
+
c,Substitute first,1,1.0
|
|
16
|
+
b,Substitute first,2,0.0
|
|
17
|
+
c,Substitute first,2,1.0
|
|
18
|
+
b,Substitute first,3,0.0
|
|
19
|
+
c,Substitute first,3,1.0
|
|
20
|
+
b,Substitute first,4,0.0
|
|
21
|
+
c,Substitute first,4,1.0
|
|
22
|
+
b,Substitute first,5,0.0
|
|
23
|
+
c,Substitute first,5,1.0
|
|
24
|
+
b,Substitute first,6,1.0
|
|
25
|
+
c,Substitute first,6,1.0
|
|
Binary file
|
|
Binary file
|