Implementation of event-based models for degenerative diseases.
Project description
EBM
This is the python package for implementing Event Based Models for Disease Progression.
Installation
pip install alabebm
Change Log
- 2025-02-26 (V 0.3.4).
- Modified the
shuffle_orderfunction to ensure full derangement, making convergence faster.
- Modified the
- 2025-03-06 (V 0.4.0)
- use
pyproject.tomlinstead - update
conjuage_priors_algo.py, now without using the auxiliary variable ofparticipant_stages. Kept the uncertainties just like insoft_kmeans_algo.py.
- use
- 2025-03-07 (V 0.4.2)
- Compute
new_ln_likelihood_new_theta_phibased onnew_theta_phi_estimates, which is based onstage_likelihoods_posteriorsthat is based on the newly proposed order and previoustheta_phi_estimates. - Update
theta_phi_estimateswithnew_theta_phi_estimatesonly if new order is accepted. - The fallback theta_phi_estimates is the previous parameters rather than theta_phi_default
all_accepted_orders.append(current_order_dict.copy())to make sure the results are not mutated.- Previously I calculated the
new_ln_likelihoodandstage_likelihoods_posteriorsbased on the newly proposed order and previoustheta_phi_estimates, and directly update theta_phi_estimates whether we accept the new order or not. - Previously, I excluded
copy()inall_accepted_orders.append(current_order_dict.copy()), which is inaccurate.
- Compute
- 2025-03-17 (V 0.4.3)
- Added
skipandtitle_detailparameter insave_traceplotfunction.
- Added
- 2025-03-18 (V 0.4.4)
- Add optional horizontal bar indicating upper limit in trace plot.
- 2025-03-18 (V 0.4.7)
- Allowed keeping all cols (
keep_all_cols) in data generation.
- Allowed keeping all cols (
- 2025-03-18 (V 0.4.9)
- copy
data_we_haveand usedata_we_have.loc[:, 'S_n']in soft kmeans algo when preprocessing participant and biomarker data.
- copy
- 2025-03-20 (V 0.5.1)
- In hard kmeans, updated
delta = ln_likelihood - current_ln_likelihood, and in soft kmeans and conjugate priors, made sure I am usingdelta = new_ln_likelihood_new_theta_phi - current_ln_likelihood. - In each iteration, use
theta_phi_estimates = theta_phi_default.copy()first. This means,stage_likelihoods_posteriorsis based on the default theta_phi, not the previous iteration.
- In hard kmeans, updated
- 2025-03-21 (V 0.6.0)
- Integrated all three algorithms to just one file
algorithms/algorithm.py. - Changed the algorithm name of
soft_kmeanstomle(maximum likelihood estimation) - Moved all helper functions from the algorithm script to
utils/data_processing.py.
- Integrated all three algorithms to just one file
- 2025-03-22 (V 0.7.4)
- Current state should include both the current accepted order and its associated theta/phi. When updating theta/phi at the start of each iteration, use the current state's theta/phi (1) in the calculation of stage likelihoods and (2) as the fallback if either of the biomarker's clusters is empty or has only one measurement; (3) as the prior mean and variance.
- Set
conjugate_priorsas the default algorithm.
- 2025-03-22 (V 0.7.5)
- Tried using cluster's mean and var as the prior.
Generate Random Data
from alabebm import generate, get_params_path, get_biomarker_order_path
import os
import json
# Get path to default parameters
params_file = get_params_path()
# Get path to biomarker_order
biomarker_order_json = get_biomarker_order_path()
with open(biomarker_order_json, 'r') as file:
biomarker_order = json.load(file)
generate(
biomarker_order = biomarker_order,
real_theta_phi_file=params_file, # Use default parameters
js = [50, 100],
rs = [0.1, 0.5],
num_of_datasets_per_combination=2,
output_dir='my_data',
seed = None,
prefix = None,
suffix = None,
)
Run MCMC Algorithms
from alabebm import run_ebm
from alabebm.data import get_sample_data_path
import os
print("Current Working Directory:", os.getcwd())
for algorithm in ['soft_kmeans', 'conjugate_priors', 'hard_kmeans']:
results = run_ebm(
data_file=get_sample_data_path('25|50_10.csv'), # Use the path helper
algorithm=algorithm,
n_iter=2000,
n_shuffle=2,
burn_in=1000,
thinning=20,
)
Input data
The input data should have four columns:
- participant: int
- biomarker: str
- measurement: float
- diseased: bool
An example is https://raw.githubusercontent.com/hongtaoh/alabEBM/refs/heads/main/alabEBM/tests/my_data/10%7C100_0.csv
The data should be in a tidy format, i.e.,
- Each variable is a column.
- Each observation is a row.
- Each type of observational unit is a table.
Features
-
Multiple MCMC algorithms:
- Conjugate Priors
- Hard K-means
- Soft K-means
-
Data generation utilities
-
Extensive logging
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alabebm-0.7.5.tar.gz.
File metadata
- Download URL: alabebm-0.7.5.tar.gz
- Upload date:
- Size: 43.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82c72c84d1f079af5a0aa65f5ec022267be2705ad001e17d4c4922db7dfb131c
|
|
| MD5 |
4f6d694242675be8acbe755e44f6f26c
|
|
| BLAKE2b-256 |
2e9f30a805b644da4151bad70e249098642c37e18dbac95e9a2c59f5734d0021
|
File details
Details for the file alabebm-0.7.5-py3-none-any.whl.
File metadata
- Download URL: alabebm-0.7.5-py3-none-any.whl
- Upload date:
- Size: 45.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa2c232d95f393b43fbda322b80e6cd7773a4313f0de03385ab7b1db4d2e446
|
|
| MD5 |
27624a11aa93d4770d783230ede7d27f
|
|
| BLAKE2b-256 |
a718a744bbf93b9c53563b105b5b6657ec0f599eeab15f8c9252407492d071e6
|