Skip to main content

ABC random forests for model choice and parameter estimation, python wrapper

Project description

PyPI abcranger-build

Random forests methodologies for :

Libraries we use :

As a mention, we use our own implementation of LDA and PLS from (Friedman, Hastie, and Tibshirani 2001, 1: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, Durif, et al. 2020).

Python

Installation

pip install pyabcranger

Notebooks examples

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

Terminal 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 rate
  • modelchoice_out.confusion : OOB Confusion matrix of the classifier

Parameter Estimation

Terminal estim param

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 m first axes is defined by the R-squared of the output:

Yvar^m = \frac{\sum_{i=1}^{N}{(\hat{y}^{m}_{i}-\bar{y})^2}}{\sum_{i=1}^{N}{(y_{i}-\hat{y})^2}}

where \hat{y}^{m} is the output Y scored by the pls for the mth component. So, only the n_{comp} first axis are kept, and :

n_{comp} = \underset{Yvar^m \leq{} 0.90*Yvar^M, }{\operatorname{argmax}}

Note that if you specify 0 as --plsmaxvar, an “elbow” heuristic is activiated where the following condition is tested for every computed axis :

\frac{Yvar^{k+1}+Yvar^{k}}{2} \geq 0.99(N-k)\left(Yvar^{k+1}-Yvar^ {k}\right)

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 n_{heur} close enough to the previous n_{comp} 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 (Raynal et al. 2018) 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 prediction
  • estimparam_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 components
  • estimparam_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 (Lakshminarayanan, Roy, and Teh 2014)

References

This have been the subject of a proceedings in JOBIM 2020, PDF and video (in french), (Collin, Estoup, et al. 2020).

Collin, François-David, Ghislain Durif, Louis Raynal, Eric Lombaert, Mathieu Gautier, Renaud Vitalis, Jean Michel Marin, and Arnaud Estoup. 2020. “Extending Approximate Bayesian Computation with Supervised Machine Learning to Infer Demographic History from Genetic Polymorphisms Using DIYABC Random Forest,” July. https://doi.org/10.22541/au.159480722.26357192.

Collin, François-David, Arnaud Estoup, Jean-Michel Marin, and Louis Raynal. 2020. “Bringing ABC inference to the machine learning realm : AbcRanger, an optimized random forests library for ABC.” In JOBIM 2020, 2020:66. JOBIM. Montpellier, France. https://hal.archives-ouvertes.fr/hal-02910067.

Friedman, Jerome, Trevor Hastie, and Robert Tibshirani. 2001. The Elements of Statistical Learning. Vol. 1. 10. Springer series in statistics New York, NY, USA:

Guennebaud, Gaël, Benoît Jacob, and others. 2010. “Eigen V3.” http://eigen.tuxfamily.org.

Lakshminarayanan, Balaji, Daniel M Roy, and Yee Whye Teh. 2014. “Mondrian Forests: Efficient Online Random Forests.” In Advances in Neural Information Processing Systems, 3140–48.

Pudlo, Pierre, Jean-Michel Marin, Arnaud Estoup, Jean-Marie Cornuet, Mathieu Gautier, and Christian P Robert. 2015. “Reliable ABC Model Choice via Random Forests.” Bioinformatics 32 (6): 859–66.

Raynal, Louis, Jean-Michel Marin, Pierre Pudlo, Mathieu Ribatet, Christian P Robert, and Arnaud Estoup. 2018. “ABC random forests for Bayesian parameter inference.” Bioinformatics 35 (10): 1720–28. https://doi.org/10.1093/bioinformatics/bty867.

Wright, Marvin N, and Andreas Ziegler. 2015. “Ranger: A Fast Implementation of Random Forests for High Dimensional Data in c++ and r.” arXiv Preprint arXiv:1508.04409.

[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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyabcranger-0.0.57.tar.gz (54.4 kB view details)

Uploaded Source

Built Distributions

pyabcranger-0.0.57-cp310-cp310-win_amd64.whl (608.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

pyabcranger-0.0.57-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.57-cp310-cp310-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyabcranger-0.0.57-cp39-cp39-win_amd64.whl (608.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyabcranger-0.0.57-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.57-cp39-cp39-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyabcranger-0.0.57-cp38-cp38-win_amd64.whl (608.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyabcranger-0.0.57-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.57-cp38-cp38-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyabcranger-0.0.57-cp37-cp37m-win_amd64.whl (608.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

pyabcranger-0.0.57-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.57-cp37-cp37m-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file pyabcranger-0.0.57.tar.gz.

File metadata

  • Download URL: pyabcranger-0.0.57.tar.gz
  • Upload date:
  • Size: 54.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for pyabcranger-0.0.57.tar.gz
Algorithm Hash digest
SHA256 28a55a083b070b20affe1b12ffaeca8a1f03fc8f6245926d42ad3e1c930f87d3
MD5 0204e3ae14f691eacc2e6276681fb664
BLAKE2b-256 54ed075e4e7fbee6cfcadbc5867f190e62ce503a86639dc6d6bf58d06ded3c80

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c7df58bf9eb02fcff846b682fd38270081eaa3938eb14aa5e115f70512c3d237
MD5 fc530e7f00d5caefdef2f3cc82222bba
BLAKE2b-256 aab6729f0f4778f435f7d91d80ccea39c66f43ab816ad5c708fee1528b0d466b

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 798e4aba6911fa5bf7290f245a4dd7e860d21323c6e4b9de164fa05dede1077e
MD5 1d9bc0bbf0f8c742798233485e7ef6c8
BLAKE2b-256 0c9cb53d9c5281329995420463b4710ddc45fdfe2ed3fb25b1fb0bc63c9e3f97

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3fdf069846c73847a558e1ca2bcc979fb78502631399e216ad63771a3547be50
MD5 c75d0a37c88c4c873a643fec10a0b86b
BLAKE2b-256 0a2156e0459f693de2c33d2ebb2808c9bffd698e47500eef14b0b78ea8d44be9

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bc02d234037badc603f4f9ae638132dc2b7b0f54b16afa10ea7f47a77f8f4767
MD5 bbbb05d26e8cec170e8106122b98eb15
BLAKE2b-256 8e036064e061012da58b29df250b4202c7c4ff4061b33e72d476caadcaaecd0b

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0d0939ebbe58cf74c017f8041879925ec73f0b394a4b7cc85859b043701b2a7
MD5 7b3a1b8d93560b504c0ef4696751c6e4
BLAKE2b-256 1d1b6708c289fa710fe1ad9ed72246a7b5a5f80bf8e171dbf5b9f5a4117a6d1b

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ee79c00f3b566f307a7c2c8c73117b3c2da8564e97ff5f4273aa69b204b4ab41
MD5 58b98e3dbf6a800b54bd304d5cf7895f
BLAKE2b-256 29ac8e5b43c01f7435a640fd2b1049f92606c94cd091ea1a6ea7fbb3bdaa3c02

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f000158d9827428921ae372e0e2489d08852ed9413f4d2574eacce91a7f2533d
MD5 197e6b9100f7bb71a9e08d60d5b3340a
BLAKE2b-256 9bedfaa9d8bf59091fe49f2476e269c0b46f89b8dcc07ffb53cbafb860c43ac7

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9175341fcc403b3d33d7ee9f54c0ee5bcbe802562ae803451c357cf8872679d5
MD5 ff578ef005d5326297b7daaacd424271
BLAKE2b-256 6704ef036163878d488e7696f8c14256d67f30b80ed497f7bb2a2dfeaf4d22fd

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 482da6151d2b611b1074c368325deb73d561fb46142b5b4018f23c8f580325fd
MD5 378267c056e97f638d36d20e549f1e5a
BLAKE2b-256 b99b67d231cc2dedcf298bfb1ed83800b05e71096b5fc8b71aca21a4471b7146

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c596b834991022e8b037c7469403d607a1f493f1a75a77247bc12cc0befd2cf3
MD5 228453f73edc5fd9d03b9477732d5776
BLAKE2b-256 565e1c9bd7aa52699f42b7dfcd6bed77cdede67b3b5e78a6aa81dd35b7f21626

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dfc529bffc86ce0dc49236d250bf5929f1d5b7569b1803017f6c9698f1d0f78e
MD5 950325c67dc20ce72c1864388a931295
BLAKE2b-256 8ab71973a46342115afa3fe227a26959d6a2a995b55a6f9d111b22fd13b6ce48

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.57-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.57-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d83d927cabc757694b9fce088bd1bb510d823923d1c390a0578b4e204dd339c7
MD5 f42dec7210b50b5407e6b9e2373e4703
BLAKE2b-256 3b28a760eeb3321fa55e09776f43d337e0500ff66e0fced872ecc6cf3ec027a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page