Skip to content

Commit 9106058

Browse files
docs: rewrite README (#51)
1 parent 533f118 commit 9106058

File tree

21 files changed

+831
-254
lines changed

21 files changed

+831
-254
lines changed

.github/workflows/docs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Documentation Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
docs:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.11'
17+
- name: Install Poetry
18+
run: pip install poetry
19+
- name: Install dependencies
20+
run: poetry install --with docs
21+
- name: Build documentation
22+
run: poetry run sphinx-build -W -b html docs/source docs/build
23+
- name: Upload artifacts
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: documentation
27+
path: docs/build/

.readthedocs.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ build:
44
os: ubuntu-22.04
55
tools:
66
python: "3.11"
7+
jobs:
8+
post_create_environment:
9+
- pip install poetry
10+
post_install:
11+
- poetry config virtualenvs.create false
12+
- poetry install --with docs
713

814
python:
915
install:
10-
- requirements: docs/requirements.txt
16+
- method: pip
17+
path: .
1118

1219
sphinx:
1320
configuration: docs/source/conf.py
21+
fail_on_warning: false
22+
23+
formats:
24+
- pdf
25+
- epub

README.md

Lines changed: 61 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,97 @@
11
# gen_surv
22

3-
![Coverage](https://codecov.io/gh/DiogoRibeiro7/genSurvPy/branch/main/graph/badge.svg)
4-
[![Docs](https://readthedocs.org/projects/gensurvpy/badge/?version=stable)](https://gensurvpy.readthedocs.io/en/stable/)
5-
![PyPI](https://img.shields.io/pypi/v/gen_surv)
6-
![Tests](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/test.yml/badge.svg)
7-
![Python](https://img.shields.io/pypi/pyversions/gen_surv)
3+
[![Coverage](https://codecov.io/gh/DiogoRibeiro7/genSurvPy/branch/main/graph/badge.svg)](https://app.codecov.io/gh/DiogoRibeiro7/genSurvPy)
4+
[![Docs](https://readthedocs.org/projects/gensurvpy/badge/?version=latest)](https://gensurvpy.readthedocs.io/en/latest/)
5+
[![PyPI](https://img.shields.io/pypi/v/gen_surv)](https://pypi.org/project/gen-surv/)
6+
[![Tests](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/test.yml/badge.svg)](https://github.com/DiogoRibeiro7/genSurvPy/actions/workflows/test.yml)
7+
[![Python](https://img.shields.io/pypi/pyversions/gen_surv)](https://pypi.org/project/gen-surv/)
88

9-
10-
**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:
11-
12-
- Cox Proportional Hazards Models (CPHM)
13-
- Continuous-Time Markov Models (CMM)
14-
- Time-Dependent Covariate Models (TDCM)
15-
- Time-Homogeneous Hidden Markov Models (THMM)
9+
**gen_surv** is a Python package for simulating survival data under a variety of statistical models. It is inspired by the R package [genSurv](https://cran.r-project.org/package=genSurv) and provides a unified interface for generating realistic survival datasets.
1610

1711
---
1812

19-
## 📦 Installation
13+
## Features
2014

21-
```bash
22-
poetry install
23-
```
24-
This package requires **Python 3.10** or later.
25-
## ✨ Features
26-
27-
- Consistent interface across models
28-
- Censoring support (`uniform` or `exponential`)
29-
- Easy integration with `pandas` and `NumPy`
30-
- Suitable for benchmarking survival algorithms and teaching
31-
- Accelerated Failure Time (Log-Normal) model generator
15+
- Cox proportional hazards model (CPHM)
16+
- Accelerated failure time models (log-normal, log-logistic)
17+
- Continuous-time multi-state Markov model (CMM)
18+
- Time-dependent covariate model (TDCM)
19+
- Time-homogeneous hidden Markov model (THMM)
3220
- Mixture cure and piecewise exponential models
3321
- Competing risks generators (constant and Weibull hazards)
34-
- Command-line interface powered by `Typer`
35-
- Export utilities for CSV, JSON, and Feather formats
22+
- Command-line interface and export utilities
3623

37-
## 🧪 Example
24+
## Installation
3825

39-
```python
40-
from gen_surv import generate
26+
Install the latest release from PyPI:
4127

42-
# CPHM
43-
generate(model="cphm", n=100, model_cens="uniform", cens_par=1.0, beta=0.5, covariate_range=2.0)
44-
45-
# AFT Log-Normal
46-
generate(model="aft_ln", n=100, beta=[0.5, -0.3], sigma=1.0, model_cens="exponential", cens_par=3.0)
47-
48-
# CMM
49-
generate(model="cmm", n=100, model_cens="exponential", cens_par=2.0,
50-
qmat=[[0, 0.1], [0.05, 0]], p0=[1.0, 0.0])
51-
52-
# TDCM
53-
generate(model="tdcm", n=100, dist="weibull", corr=0.5,
54-
dist_par=[1, 2, 1, 2], model_cens="uniform", cens_par=1.0,
55-
beta=[0.1, 0.2, 0.3], lam=1.0)
56-
57-
# THMM
58-
generate(model="thmm", n=100, qmat=[[0, 0.2, 0], [0.1, 0, 0.1], [0, 0.3, 0]],
59-
emission_pars={"mu": [0.0, 1.0, 2.0], "sigma": [0.5, 0.5, 0.5]},
60-
p0=[1.0, 0.0, 0.0], model_cens="exponential", cens_par=3.0)
61-
62-
# Mixture Cure
63-
generate(model="mixture_cure", n=100, cure_fraction=0.3, seed=42)
64-
65-
# Piecewise Exponential
66-
generate(
67-
model="piecewise_exponential",
68-
n=100,
69-
breakpoints=[1.0, 3.0],
70-
hazard_rates=[0.2, 0.5, 1.0],
71-
seed=0
72-
)
28+
```bash
29+
pip install gen-surv
7330
```
7431

75-
## ⌨️ Command-Line Usage
76-
77-
Install the package and use ``python -m gen_surv`` to generate datasets without
78-
writing Python code:
32+
To develop locally with all extras:
7933

8034
```bash
81-
python -m gen_surv dataset aft_ln --n 100 > data.csv
35+
git clone https://github.com/DiogoRibeiro7/genSurvPy.git
36+
cd genSurvPy
37+
poetry install
8238
```
8339

84-
## 🔧 API Overview
85-
86-
| Function | Description |
87-
|----------|-------------|
88-
| `generate()` | Unified interface that calls any generator |
89-
| `gen_cphm()` | Cox Proportional Hazards Model |
90-
| `gen_cmm()` | Continuous-Time Multi-State Markov Model |
91-
| `gen_tdcm()` | Time-Dependent Covariate Model |
92-
| `gen_thmm()` | Time-Homogeneous Markov Model |
93-
| `gen_aft_log_normal()` | Accelerated Failure Time Log-Normal |
94-
| `gen_aft_log_logistic()` | AFT model with log-logistic baseline |
95-
| `gen_competing_risks()` | Competing risks with constant hazards |
96-
| `gen_competing_risks_weibull()` | Competing risks with Weibull hazards |
97-
| `gen_mixture_cure()` | Mixture cure model |
98-
| `cure_fraction_estimate()` | Estimate cure fraction |
99-
| `gen_piecewise_exponential()` | Piecewise exponential model |
100-
| `sample_bivariate_distribution()` | Sample correlated Weibull or exponential times |
101-
| `runifcens()` | Generate uniform censoring times |
102-
| `rexpocens()` | Generate exponential censoring times |
103-
| `export_dataset()` | Save a dataset to CSV, JSON or Feather |
104-
105-
106-
```text
107-
genSurvPy/
108-
├── gen_surv/ # Pacote principal
109-
│ ├── __main__.py # Interface CLI via python -m
110-
│ ├── cphm.py
111-
│ ├── cmm.py
112-
│ ├── tdcm.py
113-
│ ├── thmm.py
114-
│ ├── censoring.py
115-
│ ├── bivariate.py
116-
│ ├── validate.py
117-
│ └── interface.py
118-
├── tests/ # Testes automatizados
119-
│ ├── test_cphm.py
120-
│ ├── test_cmm.py
121-
│ ├── test_tdcm.py
122-
│ ├── test_thmm.py
123-
├── examples/ # Exemplos de uso
124-
│ ├── run_aft.py
125-
│ ├── run_cmm.py
126-
│ ├── run_cphm.py
127-
│ ├── run_tdcm.py
128-
│ └── run_thmm.py
129-
├── docs/ # Documentação Sphinx
130-
│ ├── source/
131-
│ └── ...
132-
├── scripts/ # Utilidades diversas
133-
│ └── check_version_match.py
134-
├── tasks.py # Tarefas automatizadas com Invoke
135-
├── TODO.md # Roadmap de desenvolvimento
136-
├── pyproject.toml # Configurado com Poetry
137-
├── README.md
138-
├── LICENCE
139-
└── .gitignore
140-
```
40+
## Quick Example
14141

142-
## 🧠 License
42+
```python
43+
from gen_surv import generate
14344

144-
MIT License. See [LICENCE](LICENCE) for details.
45+
# basic Cox proportional hazards data
46+
sim = generate(model="cphm", n=100, beta=0.5, covar=2.0,
47+
model_cens="uniform", cens_par=1.0)
48+
```
14549

50+
See the [usage guide](docs/source/getting_started.md) for more examples.
14651

147-
## 🔖 Release Process
52+
## Supported Models
14853

149-
This project uses Git tags to manage releases. A GitHub Actions workflow
150-
(`version-check.yml`) verifies that the version declared in `pyproject.toml`
151-
matches the latest Git tag. If they diverge, the workflow fails and prompts a
152-
correction before merging. Run `python scripts/check_version_match.py` locally
153-
before creating a tag to catch issues early.
54+
| Model | Description |
55+
|----------------------|-----------------------------------------|
56+
| **CPHM** | Cox proportional hazards |
57+
| **AFT** | Accelerated failure time (log-normal, log-logistic) |
58+
| **CMM** | Continuous-time multi-state Markov |
59+
| **TDCM** | Time-dependent covariates |
60+
| **THMM** | Time-homogeneous hidden Markov |
61+
| **Competing Risks** | Multiple event types with cause-specific hazards |
62+
| **Mixture Cure** | Models long-term survivors |
63+
| **Piecewise Exponential** | Flexible baseline hazard via intervals |
15464

155-
## 🌟 Code of Conduct
65+
More details on each algorithm are available in the [Algorithms](docs/source/algorithms.md) page and the [theory guide](docs/source/theory.md).
15666

157-
Please read our [Code of Conduct](CODE_OF_CONDUCT.md) to learn about the
158-
expectations for participants in this project.
67+
## Command-Line Usage
15968

160-
## 🤝 Contributing
69+
Datasets can be generated without writing Python code:
70+
71+
```bash
72+
python -m gen_surv dataset cphm --n 1000 -o survival.csv
73+
```
16174

162-
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on setting up your environment, running tests, and submitting pull requests.
75+
## Documentation
16376

164-
## 🔧 Development Tasks
77+
Full documentation is hosted on [Read the Docs](https://gensurvpy.readthedocs.io/en/latest/). It includes installation instructions, tutorials, API references and a bibliography.
16578

166-
Common project commands are defined in [`tasks.py`](tasks.py) and can be executed with [Invoke](https://www.pyinvoke.org/):
79+
To build the docs locally:
16780

16881
```bash
169-
poetry run inv -l # list available tasks
170-
poetry run inv test # run the test suite
82+
cd docs
83+
make html
17184
```
17285

173-
## 📑 Citation
86+
Open `build/html/index.html` in your browser to view the result.
87+
88+
## License
89+
90+
This project is licensed under the MIT License. See [LICENCE](LICENCE) for details.
17491

175-
If you use **gen_surv** in your work, please cite it using the metadata in
176-
[`CITATION.cff`](CITATION.cff). Many reference managers can import this file
177-
directly.
92+
## Citation
93+
94+
If you use **gen_surv** in your research, please cite the project using the metadata in [CITATION.cff](CITATION.cff).
17895

17996
## Author
18097

@@ -183,3 +100,4 @@ directly.
183100
- ORCID: <https://orcid.org/0009-0001-2022-7072>
184101
- Professional email: <[email protected]>
185102
- Personal email: <[email protected]>
103+

docs/requirements.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
sphinx
2-
myst-parser
1+
sphinx>=6.0
2+
myst-parser>=1.0.0,<4.0.0
3+
sphinx-rtd-theme
4+
sphinx-autodoc-typehints
5+
sphinx-copybutton
6+
sphinx-design

docs/source/_static/custom.css

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Custom styling for gen_surv documentation */
2+
3+
/* Improve code block appearance */
4+
.highlight {
5+
background: #f8f9fa;
6+
border: 1px solid #e9ecef;
7+
border-radius: 4px;
8+
padding: 10px;
9+
margin: 10px 0;
10+
}
11+
12+
/* Style admonitions */
13+
.admonition {
14+
border-radius: 6px;
15+
margin: 1em 0;
16+
padding: 1em;
17+
}
18+
19+
.admonition.tip {
20+
border-left: 4px solid #28a745;
21+
background-color: #d4edda;
22+
}
23+
24+
.admonition.note {
25+
border-left: 4px solid #007bff;
26+
background-color: #cce5ff;
27+
}
28+
29+
.admonition.warning {
30+
border-left: 4px solid #ffc107;
31+
background-color: #fff3cd;
32+
}
33+
34+
/* Table styling */
35+
table.docutils {
36+
border-collapse: collapse;
37+
margin: 1em 0;
38+
width: 100%;
39+
}
40+
41+
table.docutils th,
42+
table.docutils td {
43+
border: 1px solid #ddd;
44+
padding: 8px;
45+
text-align: left;
46+
}
47+
48+
table.docutils th {
49+
background-color: #f8f9fa;
50+
font-weight: bold;
51+
}
52+
53+
/* Math styling */
54+
.math {
55+
font-size: 1.1em;
56+
}

0 commit comments

Comments
 (0)