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.50.tar.gz (53.0 kB view details)

Uploaded Source

Built Distributions

pyabcranger-0.0.50-cp39-cp39-win_amd64.whl (649.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyabcranger-0.0.50-cp39-cp39-macosx_10_9_x86_64.whl (547.8 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyabcranger-0.0.50-cp38-cp38-win_amd64.whl (649.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyabcranger-0.0.50-cp38-cp38-macosx_10_9_x86_64.whl (547.8 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyabcranger-0.0.50-cp37-cp37m-win_amd64.whl (650.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

pyabcranger-0.0.50-cp37-cp37m-macosx_10_9_x86_64.whl (546.0 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pyabcranger-0.0.50-cp36-cp36m-win_amd64.whl (650.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

pyabcranger-0.0.50-cp36-cp36m-macosx_10_9_x86_64.whl (546.0 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50.tar.gz
Algorithm Hash digest
SHA256 c5471afbb59e3e94c65e39c5c83c707c57a060c4798fd81bb098158c24a85556
MD5 d58c90cabe1df4b0e5cc08a5b3d6c0bd
BLAKE2b-256 e6aab658de0de95c248ab893ef5afd8590a7dd9188c5f23e1e2eebfffb402929

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 649.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 15ad79be1672a547409deaa11136ae28bb0668e47967470d5006c7bb191e0f7b
MD5 0163e1e1514c0be26748051f469a4ea2
BLAKE2b-256 ad312fd9f56bf7185c94d2291637914c26864741b68da2bb43de6cf9a892ae95

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 488c520deb0295cd7feb26073eae20c6d4843aafcf8746c3a77c99b71183c498
MD5 cb58c170319cd3419ada7d8ddded52c0
BLAKE2b-256 34f23d2914fb11341aec38a320d9b10e8e150a6b66dc01868f7a11d0a8c9a3c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 547.8 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2e5f825cd34904c88aacecfb7f2a6af9d7f55608180bfea98c72b1526a7e9343
MD5 dc9efced2105ce53611dda935cfd3fd8
BLAKE2b-256 616448a39b3fb2e52e14b5ca09e21d49b8c541231869521b9a55ed0026cd58b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 649.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 01638e1d495497bc2b59d17a8ac130c6730ae87f3fbd33a50ae52ce03dc980bc
MD5 be481c2f6338e75d8fa4904035982956
BLAKE2b-256 4aae38e779fe6a722e92a14a7f2e6b80406896e20395ea79eed86bbdd20d3751

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-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.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25aa89367003d438708bb1cd8bf5802fd19b9b6848a4a75843163efb498fd05c
MD5 89ff2f726aa3ddd97690fb3f718ea96a
BLAKE2b-256 78b18d74973b3806e31bfcc67156e1f557bcc12d918237706fd0fdc815e3d6ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 547.8 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 904204efad094369f6f671b37a62b6d6938e9f016fe2b51e5212d67ca9604e20
MD5 5978f99191996a47d632bf1dccfc9dcb
BLAKE2b-256 0f959101900fc34bafcbd4e7afb97af857f4e0aabc0caf6a59a041f09c534649

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 650.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 23547e78d35811346a3633d09430cf95838bc6b9e016972dc574f7933a91369f
MD5 0c192a90d7e12581fa5e274ced68aa35
BLAKE2b-256 df0b0a3824726afe49061b0b7c52f87cce7691c25d5ba1eda771640d2931f66f

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-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.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71903e88a03a678964973a5bac0c23ae4fec43e871b7d0cb68248107e011474b
MD5 62a4947dca3079ae88af9d0bb73b1287
BLAKE2b-256 0b9a1616194f594d7db08eadf93c760b78904f963fa265fb051f6d2cdbef8ec6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.50-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 546.0 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 347f8a324f038eaab767a5873b704a84737573ea1acc45a9fd50c5aa2b32be02
MD5 d4b77df64530c26ea4e004422cddc06b
BLAKE2b-256 fdeeda19fe331decefb9753b36af1d8175320198989504e265f0798cd8f9c926

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 650.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 4e8b34a7676013baaf06275131556eae6256ec2df2b19b57e436d4308c7198f5
MD5 2f5caa3c982ec226f89bd5ec3a44cd94
BLAKE2b-256 3b05b45d9d91cc7730a267e43992a677e21e40103e70774cecce71e8fbd9622f

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-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.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd1e7a1a20758a3b3308d935d6ae018b441aad96f6bfab9e6b5ecb53dedb231e
MD5 5ef8d44f1902b0d2ab6f0a31cb8c6f3a
BLAKE2b-256 267a628762c10a7ac9bf4d628950e4e1081fd554be092a7d1d2a0ab1dc387c9a

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.50-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyabcranger-0.0.50-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 546.0 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for pyabcranger-0.0.50-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2cc636f08b3e1624d07822df4b90ab33c75a239ccaf2c54d25ad543edac72f62
MD5 f121d6fe118f780e7001f256a7d7e884
BLAKE2b-256 91c8160da6e6f54a8bcef65c5f1b42b0bd94bffaa55cb89b3fb973dd5405430c

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