ABC random forests for model choice and parameter estimation, python wrapper
Project description
Random forests methodologies for :
- ABC model choice [@pudlo2015reliable]
- ABC Bayesian parameter inference [@raynal2016abc]
Libraries we use :
- Ranger [@wright2015ranger] : we use our own fork and have tuned forests to do “online”[1] computations (Growing trees AND making predictions in the same pass, which removes the need of in-memory storage of the whole forest)[2].
- Eigen3 [@eigenweb]
As a mention, we use our own implementation of LDA and PLS from [@friedman2001elements{81, 114}].
There is one set of binaries, which contains a Macos/Linux/Windows (x64 only) binary for each platform. There are available within the “Releases” tab, under “Assets” section (unfold it to see the list).
This is pure command line binary, and they are no prerequisites or library dependencies in order to run it. Just download them and launch them from your terminal software of choice. The usual caveats with command line executable apply there : if you’re not proficient with the command line interface of your platform, please learn some basics or ask someone who might help you in those matters.
The standalone is part of a specialized Population Genetics graphical interface DIYABC-RF, with a (currently under review) submission to MER (Molecular Ecology Resources), [@Collin_2020].
Python
Installation
pip install pyabcranger
Notebooks examples
- On a toy example with
- Population genetics demo, data from [@Collin_2020], available there
Usage
- ABC Random Forest - Model choice or parameter estimation command line options
Usage:
../build/abcranger [OPTION...]
-h, --header arg Header file (default: headerRF.txt)
-r, --reftable arg Reftable file (default: reftableRF.bin)
-b, --statobs arg Statobs file (default: statobsRF.txt)
-o, --output arg Prefix output (modelchoice_out or estimparam_out by
default)
-n, --nref arg Number of samples, 0 means all (default: 0)
-m, --minnodesize arg Minimal node size. 0 means 1 for classification or
5 for regression (default: 0)
-t, --ntree arg Number of trees (default: 500)
-j, --threads arg Number of threads, 0 means all (default: 0)
-s, --seed arg Seed, generated by default (default: 0)
-c, --noisecolumns arg Number of noise columns (default: 5)
--nolinear Disable LDA for model choice or PLS for parameter
estimation
--plsmaxvar arg Percentage of maximum explained Y-variance for
retaining pls axis (default: 0.9)
--chosenscen arg Chosen scenario (mandatory for parameter
estimation)
--noob arg number of oob testing samples (mandatory for
parameter estimation)
--parameter arg name of the parameter of interest (mandatory for
parameter estimation)
-g, --groups arg Groups of models
--help Print help
- If you provide
--chosenscen
,--parameter
and--noob
, parameter estimation mode is selected. - Otherwise by default it’s model choice mode.
- Linear additions are LDA for model choice and PLS for parameter estimation, “–nolinear” options disables them in both case.
Model Choice
Example
Example :
abcranger -t 10000 -j 8
Header, reftable and statobs files should be in the current directory.
Groups
With the option -g
(or --groups
), you may “group” your models in
several groups splitted . For example if you have six models, labeled
from 1 to 6 `-g “1,2,3;4,5,6”
Generated files
Four files are created :
modelchoice_out.ooberror
: OOB Error rate vs number of trees (line number is the number of trees)modelchoice_out.importance
: variables importance (sorted)modelchoice_out.predictions
: votes, prediction and posterior error ratemodelchoice_out.confusion
: OOB Confusion matrix of the classifier
Parameter Estimation
Composite parameters
When specifying the parameter (option --parameter
), one may specify
simple composite parameters as division, addition or multiplication of
two existing parameters. like t/N
or T1+T2
.
A note about PLS heuristic
The --plsmaxvar
option (defaulting at 0.90) fixes the number of
selected pls axes so that we get at least the specified percentage of
maximum explained variance of the output. The explained variance of the
output of the first
axes is defined by the R-squared of the output:
where is the output scored by the pls for the th component. So, only the first axis are kept, and :
Note that if you specify 0 as --plsmaxvar
, an “elbow” heuristic is
activiated where the following condition is tested for every computed
axis :
If this condition is true for a windows of previous axes, sized to 10% of the total possible axis, then we stop the PLS axis computation.
In practice, we find this close enough to the previous for 99%, but it isn’t guaranteed.
The signification of the noob
parameter
The median global/local statistics and confidence intervals (global)
measures for parameter estimation need a number of OOB samples
(--noob
) to be reliable (typlially 30% of the size of the dataset is
sufficient). Be aware than computing the whole set (i.e. assigning
--noob
the same than for --nref
) for weights predictions
[@raynal2016abc] could be very costly, memory and cpu-wise, if your
dataset is large in number of samples, so it could be adviseable to
compute them for only choose a subset of size noob
.
Example (parameter estimation)
Example (working with the dataset in test/data
) :
abcranger -t 1000 -j 8 --parameter ra --chosenscen 1 --noob 50
Header, reftable and statobs files should be in the current directory.
Generated files (parameter estimation)
Five files (or seven if pls activated) are created :
estimparam_out.ooberror
: OOB MSE rate vs number of trees (line number is the number of trees)estimparam_out.importance
: variables importance (sorted)estimparam_out.predictions
: expectation, variance and 0.05, 0.5, 0.95 quantile for predictionestimparam_out.predweights
: csv of the value/weights pairs of the prediction (for density plot)estimparam_out.oobstats
: various statistics on oob (MSE, NMSE, NMAE etc.)
if pls enabled :
estimparam_out.plsvar
: variance explained by number of componentsestimparam_out.plsweights
: variable weight in the first component (sorted by absolute value)
TODO
Input/Output
- Integrate hdf5 (or exdir? msgpack?) routines to save/load reftables/observed stats with associated metadata
- Provide R code to save/load the data
- Provide Python code to save/load the data
C++ standalone
- Merge the two methodologies in a single executable with the (almost) the same options
- (Optional) Possibly move to another options parser (CLI?)
External interfaces
- R package
- Python package
Documentation
- Code documentation
- Document the build
Continuous integration
- Fix travis build. Currently the vcpkg download of eigen3 head is broken.
- osX travis build
- Appveyor win32 build
Long/Mid term TODO
- methodologies parameters auto-tuning
- auto-discovering the optimal number of trees by monitoring OOB error
- auto-limiting number of threads by available memory
- Streamline the two methodologies (model choice and then parameters estimation)
- Write our own tree/rf implementation with better storage efficiency than ranger
- Make functional tests for the two methodologies
- Possible to use mondrian forests for online batches ? See [@lakshminarayanan2014mondrian]
References
This have been the subject of a proceedings in JOBIM 2020, PDF and video (in french), [@collin:hal-02910067].
[1] The term “online” there and in the code has not the usual meaning it has, as coined in “online machine learning”. We still need the entire training data set at once. Our implementation is an “online” one not by the sequential order of the input data, but by the sequential order of computation of the trees in random forests, sequentially computed and then discarded.
[2] We only use the C++ Core of ranger, which is under MIT License, same as ours.
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 Distributions
File details
Details for the file pyabcranger-0.0.48.tar.gz
.
File metadata
- Download URL: pyabcranger-0.0.48.tar.gz
- Upload date:
- Size: 50.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a0c19d269834db8a603faf795794ed4748d7e76f545f0a5442ef449e76ad53e |
|
MD5 | 3fb217e7191d562ac37a60ba6967b52f |
|
BLAKE2b-256 | 51b62ced985757a9d0c7f97ec95b331dc57017005d9f37f673c852ea37b1b3a9 |
File details
Details for the file pyabcranger-0.0.48-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 631.6 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0acd1c5dce2e296e0ffcfc09f1a09c50dc29bf5f45b5410d11d9f9ac88122236 |
|
MD5 | c010085d9d2f30363ec7295b75d7e21d |
|
BLAKE2b-256 | 519acb5265899e99ea812458e6de797fdc8ab7325eb9bad0daf97e7a03701c4d |
File details
Details for the file pyabcranger-0.0.48-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc90d05298e97d92382f8bd73bebf2a7f3dd7e79d58a41564ce10d77b8a581b0 |
|
MD5 | f6e3ef35ed59318f6d369b18e6f813bf |
|
BLAKE2b-256 | 5a1ffb2c3308d20b88c3222a515b1e77706bed3918f2e517ca3166a75d87f0f1 |
File details
Details for the file pyabcranger-0.0.48-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 518.7 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61c84246ffb6ca0c74ff9715f13b5ed8568a7366d82b9b0926b0c2ae5cc31886 |
|
MD5 | 1b2779960ac24855723845a9de723db7 |
|
BLAKE2b-256 | 824f9678344fe0742ede64899c27f8c5a7393e542e8b3f5fe74ee3bddf4141ec |
File details
Details for the file pyabcranger-0.0.48-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 632.1 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7d1aa01a9bffd015ad50169ed23fc2b195ecaf3d259046423bbd73d751006dd |
|
MD5 | d1e891a02414b0cfab55f13dc7905a45 |
|
BLAKE2b-256 | f463ca4e1e74ceec5198463b17a28e0bd73ccfe68fe9dbbc13913eb36069c47b |
File details
Details for the file pyabcranger-0.0.48-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53470c9ca95b1649decb7be77b6d9619dd7400ac7c4aa0574d953c106ea8fd07 |
|
MD5 | 2ea1816316c573781b335cfb85219ff8 |
|
BLAKE2b-256 | a810a8d3a1761c02b48d4a1c653f3ff9afce13664a78ab15b8ec662c920d4254 |
File details
Details for the file pyabcranger-0.0.48-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 516.8 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e30fd66421b3d526faf0901220645fa2cff532ad5df2753af7575b9bcfe8b8 |
|
MD5 | f88db981b6c77d3734617acd0f586632 |
|
BLAKE2b-256 | 4ae6a0f177f32ea59736355097c7f865e2bd4433ac5a0a03eecb60e1418f48bd |
File details
Details for the file pyabcranger-0.0.48-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 632.0 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de5e704744e3af872922cc39ffb536023ff6aa2abe9837e6757ee11889b5c75e |
|
MD5 | d9fc604b638477caf3c8b3f132108f3c |
|
BLAKE2b-256 | 531d0605502eda40f67c925ad5e51598c890fbe02c9393977e117b0bd1f042a7 |
File details
Details for the file pyabcranger-0.0.48-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc28327b552910b805c03e45845c8527667cc934a5d8da25a376ea201f03f84c |
|
MD5 | 8925c840bba388bf63157868d5a3913d |
|
BLAKE2b-256 | 2fe3ed20137150a9889c9804b5add062acd0d3d9be5047206ab853003bd13910 |
File details
Details for the file pyabcranger-0.0.48-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pyabcranger-0.0.48-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 516.8 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ea89ec44b139dc2a51aad0bd311c83d9a86653c98d9877767c761597e419210 |
|
MD5 | 12677994528ee5999c712145ae850c8e |
|
BLAKE2b-256 | c9701ac05875db4f905930db71c0f750dc74f9242a0fc7ec18145376a6f67eda |