Skip to content

Commit a85cfcb

Browse files
committed
Updated regression testing framework and added python regression tests
1 parent 73bd635 commit a85cfcb

File tree

11 files changed

+1125
-0
lines changed

11 files changed

+1125
-0
lines changed

tools/regression/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ For this reason, the "regression testing" setup is somewhat informal. It is desi
1010

1111
## Usage
1212

13+
The primary scripts for running the regression tests are located in the `tools/regression/bart` and `tools/regression/bcf` directories. Here, there are scripts that run each models on a variety of datasets and combine and summarize their results (RMSE, coverage, runtime).
14+
15+
This section documents how to run the end-to-end regression test suite for both the R and Python packages of `stochtree`. For more information on the individual tests, see the following section for documentation on the data generating processes tested and the test script parameters.
16+
1317
### R Package
1418

1519
To run the regression tests for the R package, first navigate to the `stochtree` repository in your terminal and then run:
@@ -27,3 +31,111 @@ Rscript tools/regression/bcf/regression_test_analysis_bcf.R
2731
```
2832

2933
This can be compared against any previously saved results. We are currently figuring out a solution for hosting previous regression results, so for now, you will need to manually save and compare outputs of the tests locally before and after after making your changes.
34+
35+
### Python Package
36+
37+
To run the regression tests for the Python package, first navigate to the `stochtree` repository in your terminal and then run:
38+
39+
```bash
40+
python tools/regression/bart/regression_test_dispatch_bart.py
41+
python tools/regression/bcf/regression_test_dispatch_bcf.py
42+
```
43+
44+
Then, to combine and analyze the results, run:
45+
46+
```bash
47+
python tools/regression/bart/regression_test_analysis_bart.py
48+
python tools/regression/bcf/regression_test_analysis_bcf.py
49+
```
50+
51+
## Individual Regression Tests
52+
53+
### BART
54+
55+
#### Data-generating processes (DGPs):
56+
57+
1. **DGP 1**: Basic BART without basis or random effects
58+
2. **DGP 2**: BART with basis but no random effects
59+
3. **DGP 3**: BART with random effects but no basis
60+
4. **DGP 4**: BART with both basis and random effects
61+
62+
#### Script
63+
64+
The individual regression tests are dispatched by a `tools/regression/bart/regression_test_dispatch_bart` script for R or Python, both of which accept the following (options) command line arguments:
65+
66+
- `n_iter`: Number of iterations (default: 5)
67+
- `n`: Sample size (default: 1000)
68+
- `p`: Number of covariates (default: 5)
69+
- `num_gfr`: Number of GFR iterations (default: 10)
70+
- `num_mcmc`: Number of MCMC iterations (default: 100)
71+
- `dgp_num`: Data generating process number 1-4 (default: 1)
72+
- `snr`: Signal-to-noise ratio (default: 2.0)
73+
- `test_set_pct`: Test set percentage (default: 0.2)
74+
- `num_threads`: Number of threads, -1 for all available (default: -1)
75+
76+
Run this script in python:
77+
78+
```bash
79+
python tools/regression/bart/individual_regression_test_bart.py [n_iter] [n] [p] [num_gfr] [num_mcmc] [dgp_num] [snr] [test_set_pct] [num_threads]
80+
```
81+
82+
or in R:
83+
84+
```bash
85+
Rscript tools/regression/bart/individual_regression_test_bart.R [n_iter] [n] [p] [num_gfr] [num_mcmc] [dgp_num] [snr] [test_set_pct] [num_threads]
86+
```
87+
88+
#### Output
89+
90+
BART results are saved to CSV files in the `tools/regression/bart/stochtree_bart_python_results/` or `tools/regression/bart/stochtree_bart_r_results/` directory with filenames that encode the parameter values. Each file contains:
91+
92+
- Parameter values (n, p, num_gfr, num_mcmc, dgp_num, snr, test_set_pct, num_threads)
93+
- Iteration number
94+
- RMSE on test set
95+
- Coverage of 95% prediction intervals
96+
- Runtime in seconds
97+
98+
### BCF
99+
100+
#### Data-generating processes (DGPs):
101+
102+
1. **DGP 1**: Basic BCF without random effects
103+
2. **DGP 2**: BCF with multivariate treatment but no random effects
104+
3. **DGP 3**: BCF with random effects but univariate treatment
105+
4. **DGP 4**: BCF with both multivariate treatment and random effects
106+
107+
#### Script
108+
109+
The individual regression tests are dispatched by a `tools/regression/bcf/regression_test_dispatch_bcf` script for R or Python, both of which accept the following (options) command line arguments:
110+
111+
- `n_iter`: Number of iterations (default: 5)
112+
- `n`: Sample size (default: 1000)
113+
- `p`: Number of covariates (default: 5)
114+
- `num_gfr`: Number of GFR iterations (default: 10)
115+
- `num_mcmc`: Number of MCMC iterations (default: 100)
116+
- `dgp_num`: Data generating process number 1-4 (default: 1)
117+
- `snr`: Signal-to-noise ratio (default: 2.0)
118+
- `test_set_pct`: Test set percentage (default: 0.2)
119+
- `num_threads`: Number of threads, -1 for all available (default: -1)
120+
121+
Run this script in python:
122+
123+
```bash
124+
python tools/regression/bcf/individual_regression_test_bcf.py [n_iter] [n] [p] [num_gfr] [num_mcmc] [dgp_num] [snr] [test_set_pct] [num_threads]
125+
```
126+
127+
or in R:
128+
129+
```bash
130+
Rscript tools/regression/bcf/individual_regression_test_bcf.R [n_iter] [n] [p] [num_gfr] [num_mcmc] [dgp_num] [snr] [test_set_pct] [num_threads]
131+
```
132+
133+
#### Outputs
134+
135+
BCF results are saved to CSV files in the `tools/regression/bcf/stochtree_bcf_python_results/` or `tools/regression/bcf/stochtree_bcf_r_results/` directory with filenames that encode the parameter values. Each file contains:
136+
137+
- Parameter values (n, p, num_gfr, num_mcmc, dgp_num, snr, test_set_pct, num_threads)
138+
- Iteration number
139+
- Outcome RMSE and coverage
140+
- Treatment effect RMSE and coverage
141+
- Runtime in seconds

0 commit comments

Comments
 (0)