Skip to main content

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

Project description

ABC random forests for model choice and parameters estimation

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), PLS is optimized for univariate, see 5.1. For linear algebra optimization purposes on large reftables, the Linux version of binaries (standalone and python wheel) are statically linked with Intel’s Math Kernel Library, in order to leverage multicore and SIMD extensions on modern cpus.

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, presented in MER (Molecular Ecology Resources, Special Issue), (Collin et al. 2021).

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)

Various

Partial Least Squares algorithm

  1. X_{0}=X ; y_{0}=y
  2. For k=1,2,...,s :
    1. w_{k}=\frac{X_{k-1}^{T} y_{k-1}}{y_{k-1}^{T} y_{k-1}}
    2. Normalize w_k to 1
    3. t_{k}=\frac{X_{k-1} w_{k}}{w_{k}^{T} w_{k}}
    4. p_{k}=\frac{X_{k-1}^{T} t_{k}}{t_{k}^{T} t_{k}}
    5. X_{k}=X_{k-1}-t_{k} p_{k}^{T}
    6. q_{k}=\frac{y_{k-1}^{T} t_{k}}{t_{k}^{T} t_{k}}
    7. u_{k}=\frac{y_{k-1}}{q_{k}}
    8. y_{k}=y_{k-1}-q_{k} t_{k}

Comment When there isn’t any missing data, stages 2.1 and 2.2 could be replaced by w_{k}=\frac{X_{k-1}^{T} y_{k-1}}{\left\|X_{k-1}^{T} y_{k-1}\right\|} and 2.3 by t_{k}=X_{k-1}w_{k}

To get W so that T=XW we compute :

\mathbf{W}=\mathbf{W}^{*}\left(\widetilde{\mathbf{P}} \mathbf{W}^{*}\right)^{-1}

where \widetilde{\mathbf{P}}_{K \times p}=\mathbf{t}\left[p_{1}, \ldots, p_{K}\right] where \mathbf{W}^{*}_{p \times K} = [w_1, \ldots, w_K]

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

  • Linux CI build with intel/MKL optimizations
  • osX CI build
  • Windows CI 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 et al. 2020).

Collin, François-David, Ghislain Durif, Louis Raynal, Eric Lombaert, Mathieu Gautier, Renaud Vitalis, Jean-Michel Marin, and Arnaud Estoup. 2021. “Extending Approximate Bayesian Computation with Supervised Machine Learning to Infer Demographic History from Genetic Polymorphisms Using DIYABC Random Forest.” Molecular Ecology Resources 21 (8): 2598–2613. https://doi.org/https://doi.org/10.1111/1755-0998.13413.

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, et al. 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.

Lintusaari, Jarno, Henri Vuollekoski, Antti Kangasrääsiö, Kusti Skytén, Marko Järvenpää, Pekka Marttinen, Michael U. Gutmann, Aki Vehtari, Jukka Corander, and Samuel Kaski. 2018. “ELFI: Engine for Likelihood-Free Inference.” Journal of Machine Learning Research 19 (16): 1–7. http://jmlr.org/papers/v19/17-374.html.

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

Uploaded Source

Built Distributions

pyabcranger-0.0.63-cp311-cp311-win_amd64.whl (614.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

pyabcranger-0.0.63-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.63-cp311-cp311-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyabcranger-0.0.63-cp310-cp310-win_amd64.whl (614.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

pyabcranger-0.0.63-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.63-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.63-cp39-cp39-win_amd64.whl (612.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

pyabcranger-0.0.63-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.63-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.63-cp38-cp38-win_amd64.whl (614.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

pyabcranger-0.0.63-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyabcranger-0.0.63-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.63-cp37-cp37m-win_amd64.whl (614.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

pyabcranger-0.0.63-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

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

pyabcranger-0.0.63-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.63.tar.gz.

File metadata

  • Download URL: pyabcranger-0.0.63.tar.gz
  • Upload date:
  • Size: 56.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyabcranger-0.0.63.tar.gz
Algorithm Hash digest
SHA256 82e7114056abca6c4a526d6361294ac9281d45cd0932125792555b1d92e2a9ee
MD5 0ff30da862e657158bb43deee207e5c6
BLAKE2b-256 0aae7722aa6d528982bda09c9ad1f2f75a31d58343b5b4f0d5b894650c6abf62

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.63-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d46a5b193b49c58560a9d19aae7a26076fc83aa03a75bd0d5cfbe575534031fc
MD5 f7411af64f87b582c9c07f150fc1754c
BLAKE2b-256 2a239c5fcb9f5c77dd4fd2585d2e8d30263337842b110882864cfee0645d9125

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.63-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ae947a7ecc7e2e75aa2cfec0c69b8329d989617b6fc1d4c55b7e98fd9d2f48a
MD5 7b114ba561abf1972552020527a5205c
BLAKE2b-256 08081d13447735aab6a224eb95b797ff3a03e764cefba04d9aa0407754fd30f9

See more details on using hashes here.

File details

Details for the file pyabcranger-0.0.63-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 40296ba6397b161b7869561bb6382917e7b5e06c2d45f9c0a7e969a49134e8cc
MD5 2189ebfcf367adeea4f44e95b533e4c5
BLAKE2b-256 28a933bfef45497ea1f82d1ef05b368c450e265597b14b0f2f8070ea6f941aa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1aed08c2e69aebef07ce25d52777d39c19624155e355b365f7225c3e229dafd6
MD5 45915c21e1f12c2a7ef0c069fca738c6
BLAKE2b-256 453ca4779467b968a13717dd0849a60bde31dae99551c9d1988a849b27b062f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5ca7327b479f706f64a7d07033df714703e780f7e48d249456f28dbc4b2da02
MD5 ed411abf1d6f0f87e757272757966815
BLAKE2b-256 a290cb38b7e5bcf48a11f5a4d7137606000ed5124d7b18fb830b0bf097eb3719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9fac97a48d55568fc9edb69a49131037a2c9b2d982f34b880d93c8d5e1c90bba
MD5 c909d73b48d16e17f91321212f95cb5c
BLAKE2b-256 ac4368372deb91a61a5ce0c997782d222c74bad624bc53df6f8d8254d1f7270a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a303c93c5645410ed348ac656a6f20a01dc21cdaa242aa3061b51013bd84a3e8
MD5 f635e77a00393c619efe0b2dec23081c
BLAKE2b-256 3392f013c1498526da1e65b6758081a0d4ebfb55c818375a1ee4a09fc85a2694

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a69f0a6b3816f93691531d13d0fc0c10f133eae05d10a77d4c68a0fc3ce76417
MD5 82e8992830559b5d76bd5f3666846ab7
BLAKE2b-256 200eb56d47c8098f984d2c96194e87a830fc756c680808518900ae3c878d42c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 80738f502eb81316504814930d494df670565491e8a3fdcd261091dd8dd6ef9c
MD5 813c5d0c590e9f8e03995005df04c6cd
BLAKE2b-256 f279ff60119a27a9ddbb0822b1d10fdbeaba424848c6366ea0599af769c99192

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bd5500dd889ac8603005492943b5a12eac94924dd3d15b7e4d960b30a02e1ea3
MD5 c324431133485aefe8766b7fadbbc2d1
BLAKE2b-256 5565e623f8e92be900d300c4a332fb83b5564373b19ff6513b93aba6b7c6d1ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3573647db4861bbc7e4dfb44c0c64a524caa3b13896159e796023539f452811
MD5 dbd3cd0bd784a5cce58a37cfe109548d
BLAKE2b-256 9dda818d1ed7307def469f316f7af2b13d434ac0eed14d24da17284a1ef42530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ce05b35993bf233de08f916f850fadd52444aac907df0b201eead7f151fe08b5
MD5 5c7fb84e79d8195e239f05d0958e0326
BLAKE2b-256 8f49d5ffaad71d653a7dd6cc2ca7f4ef8c06748e219203f9a9aa0dc1f85ae9ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 2029e97731eb261d6a9a2f88637abc4a953c6a42c0c524b5b8794aaa9df80dd1
MD5 6713f10f9c2e9fb3173d347051106249
BLAKE2b-256 72ccb05c811095bfd5edc322b8774686da407a7b1b224ac834bd84785869f765

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b44dba3125208c0365cea4a280bdd78d9eeabc6e26d807b52b695c0cccca8e2a
MD5 da6e681b61a8629fb594f7d758f2869d
BLAKE2b-256 688172361d35c72ebcf2d42ac5bc83e31308d23bcc368f97ce5d0ad1a046c7a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyabcranger-0.0.63-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0ee298b10e1e902a889d7446ce4b8ddd4839f7474879ff24598ee6c07bdbe546
MD5 8dc295f143f3fc520bf7fdb8d9906f05
BLAKE2b-256 af85e3b9b6889519f1301d3086cade87cfacae86a2b55367b654c4e83e513756

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