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

Uploaded Source

Built Distributions

pyabcranger-0.0.51-cp39-cp39-win_amd64.whl (595.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyabcranger-0.0.51-cp39-cp39-macosx_10_9_x86_64.whl (571.8 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyabcranger-0.0.51-cp38-cp38-win_amd64.whl (595.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyabcranger-0.0.51-cp38-cp38-macosx_10_9_x86_64.whl (571.8 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyabcranger-0.0.51-cp37-cp37m-win_amd64.whl (595.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

pyabcranger-0.0.51-cp37-cp37m-macosx_10_9_x86_64.whl (570.1 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pyabcranger-0.0.51-cp36-cp36m-win_amd64.whl (595.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

pyabcranger-0.0.51-cp36-cp36m-macosx_10_9_x86_64.whl (570.1 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51.tar.gz
  • Upload date:
  • Size: 54.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51.tar.gz
Algorithm Hash digest
SHA256 e0acea0f0fe61a6f5989f1fbaf38df606d6a198780f56ceca9f3653ecd09ed17
MD5 42aacc4a8cda964737ca53b5ecf78400
BLAKE2b-256 70cb6110c2d080de6f270e18e04d2fe14a262d9159cb1a15f6b7146dc36a6050

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 595.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1db796fce9018e5622b9e670b9baf6fd8ff139787fcb33bf01a541daba31b322
MD5 6724ba299914e63d48d39798e722bd0d
BLAKE2b-256 2a10dd642140abbc87d063ae60351e1cb43af940cba84426b9ee5748056a32e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80ca85a2abfaf9f097ba1da4d2ffcd33263378296dae9d3b87f0cb1a9cd7d62a
MD5 d6b74f581ce30c274fa712e4a6a5ffb4
BLAKE2b-256 363664f4daa0fb2fc5eeaabb2dfd8f01ce9e3d111b9d6ed17ff98b82b7412849

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 571.8 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7823c7463ce76d8c8df37a7dca98f5661a9baf3051ef82247db0379774e00ff4
MD5 9b9a1b867e637dd3774b0773f50152f0
BLAKE2b-256 6201a404d39a296b38c967b6a603f00979696582210198f392cfe6eb5dcfe5de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 595.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1cf7bde313a10a61d45b28df639e191621358e2e087374b809c2e7731e8710c1
MD5 93440c7f5b3db58e8366ddf3bb2864a0
BLAKE2b-256 1e57a5942022aa998c8ae357fe0f8970544126bb384e29ecf6293a9819781b0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1612d33bbf1c25e94875cd54d3730796f62008327542b58bec9bf8b881a3e51
MD5 dd0e7c4e782f9df6ad1bf4f98f8802b5
BLAKE2b-256 0c69b6f9eb9bddc375530ec50b7ec85a03714eae50b8aa4e722c033c0251f3f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 571.8 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 579174c6f430cc654643d7578c79e313ff41569db28f69cc3e4bb1a8351fcef9
MD5 a75768911f17f25eac2190907c1ab253
BLAKE2b-256 38837e5a70057536db36b4004ee42a49c69ecf552c8710b95a792bb715801d38

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 595.6 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 eea2c234738d20ad3d22965d70697f02353bc997e935a6737ca7698c5f9665da
MD5 35d9366a4cc0b5777db40e717e594c2b
BLAKE2b-256 ed098f0ee0c4f8d87808cabe1cbc80b6b53edde26bbf1a82d20be7f04f25d017

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f7e27263d206310576a78576f5bf07363ce77ec719f05a20d27fbdfe51b10a41
MD5 e641b9bc116a76e05374535579726b7b
BLAKE2b-256 343629c09d85da6bbe9d081b9ce93784f6fe69cb0a567358525840da9e7981c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 570.1 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3c246edfbbfb01c6f7a66bdc8f3f820f9633900a91d532fb249b09e82d5185b8
MD5 8db1e60688b965b05288d13d0ac2ae58
BLAKE2b-256 648fcee395d5359cd0302479fe24c8a6bc473026f1f4e5f9900f7df5e4e04bd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 595.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 3d100e9fdf3e4957837e8717e85d8858f3203796e8cd1cbaaca179e096f6e7dc
MD5 89c6fdf121df6bc0fcd3801d3d90d5b1
BLAKE2b-256 d84409902809a8ef48a8b2167ae721be0d12155437c67427b5219392c459752a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50e86c67a7d31e86d0aeb72fb5ca7de98d56865d8e3581489c4044203d677501
MD5 bfed310bfb08f19d277c2c26f08f2b03
BLAKE2b-256 ef81119c2c4f3f9a922aea43f28512ea59024c480dcc072453e1802c7df224b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyabcranger-0.0.51-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 570.1 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for pyabcranger-0.0.51-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 edace42d17656c3eee7be727674c05a8e7bdb7c3ddefed9648d61e35319d4feb
MD5 2835665659c2fb3c3f47402ff296a8dc
BLAKE2b-256 e47f13bd2a61ecf3c41cde9440f7f8931efec2cb2d7a9b61c951158c28c02c98

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