Skip to main content

rubberruler

rubberruler tells you whether your algorithm-selection features should be computed value-based (from the objective values) or rank-based (from their ranks).

R² of value-based and rank-based features: on the test instances value 0.41 and rank 0.30; on the transformed test instances value 0.26 and rank 0.31; a dashed line marks the R² without features, 0.13 and 0.14

Installation

pip install rubberruler

rubberruler needs Python 3.11 or later.

Quickstart

pip install rubberruler scikit-learn
curl -O https://raw.githubusercontent.com/shuheitnk/rubberruler/main/examples/example1.py
python example1.py

The Quickstart is example1.py, the first of the examples. It defines a portfolio of three SciPy optimizers, a feature extractor of four features, and a random forest, and ends with the test:

predictor = RandomForestRegressor(random_state=0)

result = rr.run_test(
    portfolio,
    simple_features,
    predictor,
    # Small settings for a first try.
    # Without them, run_test takes about an hour on a 16-core PC.
    dimension=2,
    budget_per_dimension=100,
    n_runs=5,
)
print(result)

It takes about half a minute on 24 CPUs and prints the card:

Rubber Ruler Test: use RANK-based features
  R^2 on the transformed test instances: rank 0.31 > value 0.26

                       R^2 on                       R^2 on
feature type   test instances   transformed test instances   degradation
value                    0.41                         0.26          0.14
rank                     0.30                         0.31         -0.01
no features              0.13                         0.14         -0.01

With value-based features, the predictor does not generalize to
strictly increasing transformations of the objective.

3 algorithms, 2400 training instances, 240 test instances,
240 transformed test instances
seed=42, suite=bbob, dimension=2 (default 10),
budget_per_dimension=100 (default 1000), n_runs=5 (default 31)

The first line is the answer: the feature type with the larger R² on the transformed test instances. The degradation is the drop in R² from the test to the transformed test instances. The row "no features" is a reference: features that help the predictor score above it.

Use your own portfolio, feature extractor, and predictor

import numpy as np
from sklearn.ensemble import RandomForestRegressor

import rubberruler as rr


# An algorithm minimizes problem(x) until rubberruler ends the run at the budget.
def random_search(problem):
    rng = np.random.default_rng(problem.seed)
    while True:
        problem(rng.uniform(problem.lower_bounds, problem.upper_bounds))


def local_search(problem):
    rng = np.random.default_rng(problem.seed)
    x = rng.uniform(problem.lower_bounds, problem.upper_bounds)
    fx = problem(x)
    while True:
        step = rng.normal(0, 0.5, problem.dimension)
        candidate = np.clip(x + step, problem.lower_bounds, problem.upper_bounds)
        if (value := problem(candidate)) <= fx:
            x, fx = candidate, value


# A feature extractor maps a sample X of shape (n, d) and its values y to features.
def my_features(X, y):
    return {"mean": float(np.mean(y)), "spread": float(np.std(y))}


portfolio = {"random-search": random_search, "local-search": local_search}
predictor = RandomForestRegressor(random_state=0)  # any regressor with fit and predict
result = rr.run_test(portfolio, my_features, predictor)
print(result)

examples/README.md connects ModularCMAES, ModDE, pymoo, pycma, Nevergrad, pflacco, DeepELA, and PyTorch.

Options

  • MA-BBOB: rr.run_test(..., suite="ma-bbob").
  • example2.py: your own objective functions, with rr.run_test(..., instances=rr.objective_instances(objectives, split_seed=1)).
  • Precomputed tables: rr.run_test(..., performance=result.performance, features=result.features).
  • example3.py: augmentation, with rr.transform_objective, which applies a random rubber ruler to any objective function.
  • example7.py: a feature-free model, with an extractor that returns the sample itself.
  • Parallel computation and memory: rr.run_test(..., n_jobs=4).
  • Settings: the defaults follow the paper (dimension 10, 50 x dimension sample points, a budget of 1000 x dimension evaluations, 31 runs, training instances 11-110 and test instances 1-10 on BBOB, and the same distribution of rubber rulers), except that the sample points are uniform random rather than a Latin hypercube and the test uses one seed rather than the paper's 11. Finished runs are cached in cache_dir, and help(rr.run_test) lists every setting.

How it works

rubberruler takes training and test instances from BBOB, from MA-BBOB (suite="ma-bbob"), or from your own objective functions (the suite "objectives", given with instances=rr.objective_instances(...)), and makes a transformed test instance from each test instance by passing its objective through a random strictly increasing function, the rubber ruler. It runs every algorithm on every instance and measures its performance J, the probability that one of its runs beats a run of another algorithm, with a tie counting as half. For each feature type, the extractor receives uniform random points and their values (value) or the ranks of their values (rank), both min-max normalized to [0, 1], and the predictor fitted on the training instances is scored by R² on the test and the transformed test instances. The answer is the feature type with the larger R² on the transformed test instances; a tie selects rank. The row "no features" predicts the mean J of each algorithm on the training instances, so it shows how much of R² needs no features.

Citing

Please cite rubberruler with CITATION.cff; "Cite this repository" on GitHub gives it in APA and BibTeX.

License

MIT

Metadata

Release files for rubberruler 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rubberruler 0.1.0
File Size Uploaded Provenance Actions
rubberruler-0.1.0.tar.gz 61.4 kB With provenance Details for rubberruler-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rubberruler 0.1.0
File Interpreter ABI Platform Actions
rubberruler-0.1.0-py3-none-any.whl Python 3 none any Details for rubberruler-0.1.0-py3-none-any.whl

Total release size: 132.4 kB

Release files / rubberruler-0.1.0.tar.gz

Download URL rubberruler-0.1.0.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
31dcdb68673940045be0597864a1484e2ede8cc7b1a56e3e9d3c75c69bc0e954
BLAKE2b-256 checksum
How to use checksums
90358872b163e354e750e42c0e1b847d988e4ea406fb29da279a4a8cd0879686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / rubberruler-0.1.0-py3-none-any.whl

Download URL rubberruler-0.1.0-py3-none-any.whl
Size 71.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c54739a6b41f1c05b5534d544f82dd2d1c939939b3244c2c871c7a04e4403fea
BLAKE2b-256 checksum
How to use checksums
3d140ce543f011abd6d9b1469679d13acf2fb45877e2412dd95ef288f3fcb39e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for rubberruler 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rubberruler-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page