Skip to main content

Distributional Random Forests with different split metrics, test statistics and a Rust backend

Project description

drforest logo

drforest

CI Python License

drforest is a Python and Rust implementation of distributional random forests. Instead of returning a single prediction, a fitted forest produces a sparse, row-stochastic weight matrix over the training responses. Conditional means, quantiles, CDFs, and distributional scores are then plug-ins on the same weights.

The package supports scalar and multivariate responses and provides several split criteria behind one forest implementation:

  • CART mean separation;
  • Gaussian maximum mean discrepancy (MMD) using random Fourier features;
  • anisotropic and adaptive-frequency MMD variants; and
  • sliced Wasserstein separation.

The split search is Rust-backed, while the statistical interfaces and benchmark harnesses remain in Python.

Project status

Version 0.1.0 is a research release. The core implementation is tested, but the public API may still change. The current fixed-fraction subsampling interface is intended for prediction and benchmarking; it does not claim the inference-valid regime required by the asymptotic forest theory. Missing-value handling is not implemented.

The accompanying characterization note is available as a repository PDF. It studies when distributional splitting helps, compares the implemented criteria, and gives a finite-node analysis of mean versus kernel-mean split signal. An arXiv link and formal citation will be added after the note is posted.

Installation

The initial release is installed from source with pixi:

git clone https://github.com/silaskoemen/drforest.git
cd drforest
pixi install
pixi run build-rust

PyPI and conda-forge installation instructions will be added when packages are published.

Quick start

Responses are represented as a two-dimensional array with shape (n_samples, n_outputs), including scalar-response problems.

import numpy as np

from drforest.criteria import MmdRffCriterion
from drforest.features.rff import median_heuristic
from drforest.forest import DistributionalRandomForest
from drforest.targets import weighted_mean, weighted_quantile
from drforest.tree import TreeParams

rng = np.random.default_rng(0)
X = rng.normal(size=(500, 4))
Y = (X[:, 0] + (0.5 + np.abs(X[:, 1])) * rng.normal(size=500))[:, None]

X_train, X_test = X[:400], X[400:]
Y_train = Y[:400]

forest = DistributionalRandomForest(
    criterion_factory=lambda y: MmdRffCriterion.from_data(
        y,
        n_features=128,
        bandwidth_rule=median_heuristic,
    ),
    seed=0,
    n_trees=100,
    subsample=0.5,
    tree_params=TreeParams(
        min_samples_leaf=5,
        honesty_fraction=0.5,
        colsample=0.7,
        max_cutpoints=32,
    ),
).fit(X_train, Y_train)

weights = forest.weights(X_test)
mean = weighted_mean(weights, Y_train)
quantiles = weighted_quantile(weights, Y_train, np.array([0.1, 0.5, 0.9]))

assert mean.shape == (100, 1)
assert quantiles.shape == (100, 1, 3)

To use ordinary CART splitting while retaining distributional forest weights, replace the criterion factory with:

from drforest.criteria import CartCriterion

criterion_factory = lambda y: CartCriterion()

The resulting weight matrix also works with weighted_cdf and with the CRPS, energy-score, and RMSE functions in drforest.metrics.

Design

The weight matrix is the central object:

forest structure -> sparse conditional weights -> targets and scores

This keeps split geometry separate from downstream estimation. A criterion can be changed without changing the mean, quantile, CDF, or scoring implementations, and the same fitted forest can serve multiple targets.

Trees support honest structure/leaf sample splitting, explicit per-tree and per-node random-number streams, row subsampling, feature subsampling, and a shared candidate-cutpoint cap. The MMD bandwidth is configured once from the training responses; random Fourier frequencies are resampled per node.

Benchmarks and paper

Study entry points live in benchmarks/studies:

pixi run python benchmarks/studies/run_synthetic_splitting.py
pixi run python benchmarks/studies/run_real_benchmark.py \
  --datasets diabetes \
  --criteria cart mmd_rff \
  --honesty-fractions 0.5 0.0

Generated datasets and result files are intentionally not tracked. The tables and figures used by the note are committed under paper, together with the LaTeX source and compiled PDF.

Development

Install the development environment and pre-commit hooks with:

pixi install
pixi run build-rust
pixi run setup

Before submitting a change, run:

pixi run lint
pixi run pytest
pixi run build-wheel
pixi run check-wheel

Security issues should be reported through the process described in SECURITY.md.

Citation

A citation for the characterization note will be added after its arXiv release. Until then, cite the repository and the specific release used so that the code and results remain reproducible.

License

drforest is released under the MIT License.

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

drforest-0.1.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

drforest-0.1.0-cp314-cp314-win_amd64.whl (266.2 kB view details)

Uploaded CPython 3.14Windows x86-64

drforest-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (432.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

drforest-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (381.2 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

drforest-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl (387.3 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

drforest-0.1.0-cp313-cp313-win_amd64.whl (266.0 kB view details)

Uploaded CPython 3.13Windows x86-64

drforest-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (432.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

drforest-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (380.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

drforest-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl (387.0 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

drforest-0.1.0-cp312-cp312-win_amd64.whl (266.1 kB view details)

Uploaded CPython 3.12Windows x86-64

drforest-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (433.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

drforest-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (380.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

drforest-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (386.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

drforest-0.1.0-cp311-cp311-win_amd64.whl (267.1 kB view details)

Uploaded CPython 3.11Windows x86-64

drforest-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

drforest-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (382.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

drforest-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl (388.4 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file drforest-0.1.0.tar.gz.

File metadata

  • Download URL: drforest-0.1.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0dc77e9c6b2a3973c8e7e2f2d2571b4d4539e113c776b614bb8a94bdb9400302
MD5 4f679e082eb91f7b439f80507a9cdfe2
BLAKE2b-256 3459883760ce7c0a8f09581acba3e4d92d3504d6e89bd01e25718260e59400f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0.tar.gz:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: drforest-0.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 266.2 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 75af040299da363e599944ebc41b8b248821e995bb3c530a862e48349f6c9d5a
MD5 b653b2b2f6385ea356c78554753ea853
BLAKE2b-256 ffa0a26d806f87cf0d041ed6f99543873b77cfaa9a3317eb432f50770fbf41a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp314-cp314-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f045b59fb094694a8996dff8ac600064b20f20593d452350f648dd040a730d0d
MD5 b8a0ca43d48ac4c68e8c7409e5f44747
BLAKE2b-256 8c72783245f73c1fcce57fb4c0f43e9e582defdfcd5f18d1d2c3989ef2e146c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94b29709372db6b299912fd8f79e7895cfc792b6d02a8245fb8149feb4c36598
MD5 c2e96272201dfe93c4d1192054c665d5
BLAKE2b-256 cda99bafcbb8f2254a867a72297ace2c197ee03fbf62dee78949c989c110995e

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dae8144a63f3bdf56f8c8deae9e6ea7eb60ad37b2b794fc6d06caeed3a50f2e0
MD5 ffb370cba7967492931a8eea8cdb5ce0
BLAKE2b-256 4f6bae8b007ef21fe350f056aa9a109147b66d91e282d4b9a07d6b989890cc68

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: drforest-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 266.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c5f23d835e125d65870870ffeb1e5b1e4dceb4833165e1fc9b8710de63871eda
MD5 922965a447c6948a2a7983416d88afb8
BLAKE2b-256 906a53ea666e17984d7fbf64791adfa07697e6094c6743b3959ea2d7c28ba188

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3bc267dae561025b263558a6326d34802e8be3ef6991c33dd5d8ed3a31f18258
MD5 9264db246d4fa49da0898b3dbc8f1582
BLAKE2b-256 939d9eddc20707cf34d551eec393dbbde8eefc73cc4a3a98c03a9d3c3938dce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95fe3eb3a3e14764b846501e84103b897d4164050e6d0afd43013a80ad624c1f
MD5 7b05b552d0a8ea2aa0563c25764ece04
BLAKE2b-256 20414f4d9ef076ad6dd37253add82e0db3b720dab024d71cf0de2e91a4c680b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c77753cd1e07f28ff860ff99b191e86fd322dbf51ae6b14011debef454bf742
MD5 50f6ac9d8becc437c2b0ae497bf83130
BLAKE2b-256 0185e5e752be7f8363eaee039c85d823753711f4592b8eaf7b2f7aadbbc5e7e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: drforest-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 266.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 99e0414206fa74379f92e0ef9e1830a248f40ef83317eda9e25557f360d0429f
MD5 1de144d7bcedf6b950bcbcabc0e93643
BLAKE2b-256 f0df7a5b4a9ad00e7ed9a747d4680a096753b4bb0b38c80e745f744e722bd702

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdacd2b39e2d0a25ab7d5a78ee32df9a957bec091fdd054a7ff87709a46255e8
MD5 31e2fc7c851129a018d75d400dc3abc9
BLAKE2b-256 486d9dde70b559af7579b659cbadb3d31762f7190176a3e6bf647bfd54ea0039

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf3c60ba99ad44fa88c33a2914951357f03da92761f1db07be14310078691682
MD5 f59b3fa094f04e29b13f39778509d389
BLAKE2b-256 54725fb35e00ec36aeaaae2b2dbf3cbb1b7a2cc4d65dec3d413f060665b047e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a693c494cf35811f65c9b103fa615b4dbe3d991f9a74c9a931855f8cc0557707
MD5 f8558d849fb8175e1e6cf1654978ab70
BLAKE2b-256 53ae23ff1fcca9a563c38e423501eb08591e843b61b704aacbc4a180ecac77c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: drforest-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 267.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5b2512bfab17ce3cb6ed751ed58386e367c29ccbe4da2abda78395fe8586fbbf
MD5 3b340775ab14525521542a5846004d6b
BLAKE2b-256 36f24982f0e0ee1e9f6a1e2c72fc4fae49c5edcc4487b92e2822b219ed563653

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a32bfb3aa90e0edb338d1ac3c631b32ab98be27967259bc0829737fbd027c99a
MD5 8ba7690cc33a95430c048486e11e3e5c
BLAKE2b-256 a3f56581de05231226f98ea2fd27f4656b6278dbabde742d91eb3ccaaf914043

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05fd7bc610e7f6dd1dce149fad7931bf21b1c4e8a5b795d2353492cc8eb129a0
MD5 c9f5f80f256f2b608e2de7243156a864
BLAKE2b-256 a6d9b4f5b11e5f0d1305dfb00a75e3b5c2780d57a9f676f3e6d9b22fc2834d5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e7b9be67e42140f0b5b6de51341f50b6c7f8eafb2c062c0ed7c55e554836d15f
MD5 d3f4ff7a51154d083aabb477fe6729ff
BLAKE2b-256 981ec220cf889874b4316518bf7043946799fd1438a0ce26945a932474501c39

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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