|
1 |
| -# StochasticTree C++ Core |
| 1 | +# StochasticTree |
2 | 2 |
|
3 |
| -[](https://github.com/StochasticTree/stochtree-cpp/actions/workflows/test-multi-platform.yml) |
| 3 | +[](https://github.com/StochasticTree/stochtree-cpp/actions/workflows/cpp-test.yml) |
| 4 | +[](https://github.com/StochasticTree/stochtree-cpp/actions/workflows/python-test.yml) |
| 5 | +[](https://github.com/StochasticTree/stochtree-cpp/actions/workflows/r-test.yml) |
4 | 6 |
|
5 |
| -This repository hosts the "core" C++ code for defining and sampling stochastic tree ensembles (BART, XBART) for various applications. |
6 |
| -The [R](https://github.com/StochasticTree/stochtree-r) and [Python](https://github.com/StochasticTree/stochtree-python) |
7 |
| -packages have been refactored into separate repositories with installation instructions and demo notebooks. |
| 7 | +Software for building stochastic tree ensembles (i.e. BART, XBART) for supervised learning and causal inference. |
| 8 | + |
| 9 | +# Getting Started |
| 10 | + |
| 11 | +`StochasticTree` is composed of a C++ "core" and R / Python interfaces to that core. |
| 12 | +Details on installation and use are available below: |
| 13 | + |
| 14 | +* [Python](#python-package) |
| 15 | +* [R](#r-package) |
| 16 | +* [C++ core](#c-core) |
| 17 | + |
| 18 | +# Python Package |
| 19 | + |
| 20 | +The python package is not yet on PyPI but can be installed from source using pip's [git interface](https://pip.pypa.io/en/stable/topics/vcs-support/). |
| 21 | +To proceed, you will need a working version of [git](https://git-scm.com) and python 3.8 or greater (available from several sources, one of the most |
| 22 | +straightforward being the [anaconda](https://docs.conda.io/projects/conda/en/stable/user-guide/install/index.html) suite). |
| 23 | + |
| 24 | +## Quick start |
| 25 | + |
| 26 | +Without worrying about virtual environments (detailed further below), `stochtree` can be installed from the command line |
| 27 | + |
| 28 | +``` |
| 29 | +pip install numpy scipy pytest pandas scikit-learn pybind11 |
| 30 | +pip install git+https://github.com/StochasticTree/stochtree-cpp.git |
| 31 | +``` |
| 32 | + |
| 33 | +## Virtual environment installation |
| 34 | + |
| 35 | +Often, users prefer to manage different projects (with different package / python version requirements) in virtual environments. |
| 36 | + |
| 37 | +### Conda |
| 38 | + |
| 39 | +Conda provides a straightforward experience in managing python dependencies, avoiding version conflicts / ABI issues / etc. |
| 40 | + |
| 41 | +To build stochtree using a `conda` based workflow, first create and activate a conda environment with the requisite dependencies |
| 42 | + |
| 43 | +```{bash} |
| 44 | +conda create -n stochtree-dev -c conda-forge python=3.10 numpy scipy pytest pandas pybind11 scikit-learn matplotlib seaborn |
| 45 | +conda activate stochtree-dev |
| 46 | +``` |
| 47 | + |
| 48 | +Then, navigate to the main `stochtree-python` project folder (i.e. `cd /path/to/stochtree-python`) and install the package locally via pip |
| 49 | + |
| 50 | +```{bash} |
| 51 | +pip install . |
| 52 | +``` |
| 53 | + |
| 54 | +(*Note*: if you'd also like to run the notebook examples in the `demo/` subfolder, you will also need jupyterlab, seaborn, and matplotlib) |
| 55 | + |
| 56 | +```{bash} |
| 57 | +conda install matplotlib seaborn |
| 58 | +pip install jupyterlab |
| 59 | +``` |
| 60 | + |
| 61 | +### Venv |
| 62 | + |
| 63 | +You could also use venv for environment management. First, navigate to the main `stochtree-python` project folder |
| 64 | +(i.e. `cd /path/to/stochtree-python`) and create and activate a virtual environment as a subfolder of the repo: |
| 65 | + |
| 66 | +```{bash} |
| 67 | +python -m venv venv |
| 68 | +source venv/bin/activate |
| 69 | +``` |
| 70 | + |
| 71 | +Install all of the package (and demo notebook) dependencies |
| 72 | + |
| 73 | +```{bash} |
| 74 | +pip install numpy scipy pytest pandas scikit-learn pybind11 |
| 75 | +``` |
| 76 | + |
| 77 | +Then install stochtree via |
| 78 | + |
| 79 | +```{bash} |
| 80 | +pip install . |
| 81 | +``` |
| 82 | + |
| 83 | +(As above, if you'd like to run the notebook examples in the `demo/` subfolder, you will also need jupyterlab, seaborn, and matplotlib) |
| 84 | + |
| 85 | +```{bash} |
| 86 | +pip install matplotlib seaborn jupyterlab |
| 87 | +``` |
| 88 | + |
| 89 | +# R Package |
| 90 | + |
| 91 | +The package can be installed in R via |
| 92 | + |
| 93 | +``` |
| 94 | +remotes::install_github("StochasticTree/stochtree-cpp") |
| 95 | +``` |
| 96 | + |
| 97 | +# C++ Core |
| 98 | + |
| 99 | +While the C++ core links to both R and Python for a performant, high-level interface, |
| 100 | +the C++ code can be compiled and unit-tested and compiled into a standalone |
| 101 | +[debug program](https://github.com/StochasticTree/stochtree-cpp/tree/main/debug). |
8 | 102 |
|
9 | 103 | ## Compilation
|
10 | 104 |
|
@@ -54,3 +148,24 @@ via `lldb ./build/debugstochtree` (clang) or `gdb ./build/debugstochtree` (gcc).
|
54 | 148 | We test `stochtree-cpp` using the [GoogleTest](https://google.github.io/googletest/) framework.
|
55 | 149 | Unit tests are compiled into a single target as part of the CMake build if the `BUILD_TEST` option is set to `ON`
|
56 | 150 | and the test suite can be run after compilation via `./build/teststochtree`
|
| 151 | + |
| 152 | +## Xcode |
| 153 | + |
| 154 | +While using `gdb` or `lldb` on `debugstochtree` at the command line is very helpful, users may prefer debugging in a full-fledged IDE like xcode. This project's C++ core can be converted to an xcode project from `CMakeLists.txt`, but first you must turn off sanitizers (xcode seems to have its own way of setting this at build time for different configurations, and having injected |
| 155 | +`-fsanitize=address` statically into compiler arguments will cause xcode errors). To do this, modify the `USE_SANITIZER` line in `CMakeLists.txt`: |
| 156 | + |
| 157 | +``` |
| 158 | +option(USE_SANITIZER "Use santizer flags" OFF) |
| 159 | +``` |
| 160 | + |
| 161 | +To generate an XCode project based on the build targets and specifications defined in a `CMakeLists.txt`, navigate to the main project folder (i.e. `cd /path/to/project`) and run the following commands: |
| 162 | + |
| 163 | +```{bash} |
| 164 | +rm -rf xcode/ |
| 165 | +mkdir xcode |
| 166 | +cd xcode |
| 167 | +cmake -G Xcode .. -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ |
| 168 | +cd .. |
| 169 | +``` |
| 170 | + |
| 171 | +Now, if you navigate to the xcode subfolder (in Finder), you should be able to click on a `.xcodeproj` file and the project will open in XCode. |
0 commit comments