Skip to content

Commit 1c61b5f

Browse files
Merge pull request #4 from DiogoRibeiro7/feat/first_commit
feat: implement THMM data generator and finalize full model suite
2 parents b8d44a0 + 0d57884 commit 1c61b5f

File tree

21 files changed

+587
-18
lines changed

21 files changed

+587
-18
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.9"
21+
22+
- name: Install Poetry
23+
run: |
24+
curl -sSL https://install.python-poetry.org | python3 -
25+
echo "$HOME/.local/bin" >> $GITHUB_PATH
26+
27+
- name: Install dependencies
28+
run: poetry install
29+
30+
- name: Run tests
31+
run: poetry run pytest

.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Poetry virtualenvs
7+
.env
8+
.venv
9+
poetry.lock
10+
11+
# Installer logs
12+
pip-log.txt
13+
pip-delete-this-directory.txt
14+
15+
# Unit test / coverage reports
16+
htmlcov/
17+
.tox/
18+
.nox/
19+
.coverage
20+
.cache
21+
nosetests.xml
22+
coverage.xml
23+
*.cover
24+
*.py,cover
25+
26+
# Pytest
27+
.pytest_cache/
28+
29+
# Jupyter Notebook checkpoints
30+
.ipynb_checkpoints
31+
32+
# PyCharm
33+
.idea/
34+
35+
# VSCode
36+
.vscode/
37+
38+
# MacOS
39+
.DS_Store
40+
41+
# System files
42+
Thumbs.db
43+
ehthumbs.db
44+
45+
# Build artifacts
46+
build/
47+
dist/
48+
*.egg-info/
49+
50+
# Temporary
51+
*.log
52+
*.tmp

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 [Diogo Ribeiro]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
1-
# private_repo_template
1+
# gen_surv
2+
3+
**gen_surv** is a Python package for simulating survival data under a variety of models, inspired by the R package [`genSurv`](https://cran.r-project.org/package=genSurv). It supports data generation for:
4+
5+
- Cox Proportional Hazards Models (CPHM)
6+
- Continuous-Time Markov Models (CMM)
7+
- Time-Dependent Covariate Models (TDCM)
8+
- Time-Homogeneous Hidden Markov Models (THMM)
9+
10+
---
11+
12+
## 📦 Installation
13+
14+
```bash
15+
poetry install
16+
```
17+
## ✨ Features
18+
19+
- Consistent interface across models
20+
- Censoring support (`uniform` or `exponential`)
21+
- Easy integration with `pandas` and `NumPy`
22+
- Suitable for benchmarking survival algorithms and teaching
23+
24+
## 🧪 Example
25+
26+
```python
27+
from gen_surv.cphm import gen_cphm
28+
29+
df = gen_cphm(
30+
n=100,
31+
model_cens="uniform",
32+
cens_par=1.0,
33+
beta=0.5,
34+
covar=2.0
35+
)
36+
print(df.head())
37+
```
38+
39+
## 🔧 Available Generators
40+
41+
| Function | Description |
42+
|--------------|--------------------------------------------|
43+
| `gen_cphm()` | Cox Proportional Hazards Model |
44+
| `gen_cmm()` | Continuous-Time Multi-State Markov Model |
45+
| `gen_tdcm()` | Time-Dependent Covariate Model |
46+
| `gen_thmm()` | Time-Homogeneous Markov Model |
47+
248

349
```text
50+
genSurvPy/
451
gen_surv/
5-
├── gen_surv/
6-
│ ├── __init__.py
7-
│ ├── cphm.py ← put CPHM logic here
8-
│ ├── validate.py ← validation functions here
9-
│ ├── censoring.py ← censoring functions here
10-
│ └── utils.py ← for any shared tools
11-
├── tests/
12-
│ ├── __init__.py
13-
│ └── test_cphm.py ← tests for CPHM
14-
├── pyproject.toml
15-
└── README.md ← rename README.rst if you prefer
16-
LICENSE
17-
```
52+
├── cphm.py
53+
├── cmm.py
54+
├── tdcm.py
55+
├── thmm.py
56+
├── censoring.py
57+
├── validate.py
58+
examples/
59+
├── run_cphm.py
60+
├── run_cmm.py
61+
├── run_tdcm.py
62+
├── run_thmm.py
63+
└── utils.py # optional for shared config (e.g. seeding)
64+
```
65+
66+
## 🧠 License
67+
68+
MIT License. See [LICENSE](LICENSE) for details.

gen_surv-stubs/gen_surv/__init__.pyi

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import numpy as np
2+
3+
def runifcens(size: int, cens_par: float) -> np.ndarray: ...
4+
def rexpocens(size: int, cens_par: float) -> np.ndarray: ...

gen_surv-stubs/gen_surv/cmm.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens
2+
from gen_surv.validate import validate_gen_cmm_inputs as validate_gen_cmm_inputs
3+
4+
def generate_event_times(z1: float, beta: list, rate: list) -> dict: ...
5+
def gen_cmm(n, model_cens, cens_par, beta, covar, rate): ...

gen_surv-stubs/gen_surv/cphm.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pandas as pd
2+
from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens
3+
from gen_surv.validate import validate_gen_cphm_inputs as validate_gen_cphm_inputs
4+
5+
def generate_cphm_data(n, rfunc, cens_par, beta, covariate_range): ...
6+
def gen_cphm(n: int, model_cens: str, cens_par: float, beta: float, covar: float) -> pd.DataFrame: ...

gen_surv-stubs/gen_surv/tdcm.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens
2+
from gen_surv.validate import validate_gen_tdcm_inputs as validate_gen_tdcm_inputs
3+
4+
def generate_censored_observations(n, dist_par, model_cens, cens_par, beta, lam, b): ...
5+
def gen_tdcm(n, dist, corr, dist_par, model_cens, cens_par, beta, lam): ...

gen_surv-stubs/gen_surv/thmm.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens
2+
from gen_surv.validate import validate_gen_thmm_inputs as validate_gen_thmm_inputs
3+
4+
def calculate_transitions(z1: float, cens_par: float, beta: list, rate: list, rfunc) -> dict: ...
5+
def gen_thmm(n, model_cens, cens_par, beta, covar, rate): ...

0 commit comments

Comments
 (0)