Skip to main content

redsho

Robust Evolutionary Direction Set Hyperparameter Optimizer

Redsho is a discrete optimizer, which means that it works with parameters that can only take on a certain set of values. This works well for evaluating machine learning models with a collection of hyperparameters that influence their behavior, such as gradient boosted decision trees and all manner of neural networks. It's also useful for evaluting complex systems where entire algorithmic blocks can be swapped in for each other. It's intended especially for larger models and systems since they take so long to train and test, and since the hyperparameters can have non-intuitive, strongly non-linear, and interactive effects.

Redsho is an evolutionary search algorithm variant inspired by direction set methods like Powell's method, so much so that it was originally called Evolutionary Powell's method. Here is a detailed description of how it works.

Animated demo of Redsho in operation on a 2D variant of the sinc function

This demo illustrates how redsho

  1. Peppers the parameter space with a few starting points
  2. Chooses neighboring points in varying directions to test
  3. Leans toward neighbors of the highest performing points, but
  4. Also explores more broadly

Installation

It's on PyPI, so install as part of a uv environment (recommended)

uv add redsho

or via pip

pip install redsho

Usage

Start with an evaluation function that takes some hyperparameters as keyword arguments.

def evaluate(*, a, b, c):
    return a * b**3 % c

(the leading * tells Python that everything that follows is a required keyword argument)

Build a collection of values to try for each parameter.

values = {
    "a": [4, 7, 9],
    "b": [2, 5, 6],
    "c": [5, 8, 11],
}

Call the optimizer.

from redsho.optimizer import optimize

lowest_error, best_parameters = optimize(evaluate, values)

where error is the lowest error achieved, best_parameters is the collection of parameter values that achieved it.

Examples

There are some standalone examples of how redsho can be used in a separate repo called redsho-examples , including finding the maximum of a sinc function.

Developing

If you want to extend or tweak the approach, then DEVELOPING.md is for you.

Some terminology

  • REDSHO: robust evolutionary direction set hyperparameter optimizer
  • robust: it doesn't assume smoothness or continutiy
  • evolutionary: it randomly explores new options based on the most successful of its previous tries.
  • direction set: it alternates through its hyperparameters, exploring by varying one parameter at a time
  • hyperparameter: in this context, any variable that has an influence on the result of the evaluation function. Also referred to as a direction or a dimension.
  • hyperparameter space: if each hyperparameter is a direction, then taken together, n hyperparameters form an n-dimensional space
  • condition: a full collection of hyperparameter names and one valid value for each. Each condition is a point in the hyperparameter space.
  • condition grid: the set of all conditions in the hyperparameter space. Forms an irregularly-spaced n-dimensional grid.
  • evaluation function: pretty much anything that can take in a set of parameters and return a number that evaluates its performance. It can be a mathematical expression, a traditional machine learning model, an arbitrary chunk of Python code, whatever.
  • error: the result, after a condition has been evaluated. Also called the "loss" is the context of machine learning. Lower is always better. (If you have a "higher is better" evaluator just slap a negative sign on it.) The algorithm is trying to find the condition with the lowest error.
  • error landscape: picturing a two-dimensional hyperparameter space, the error can be imagined as the height of a mountainous landscape in an extra dimension of that space. This can be generalized to higher dimensions (harder to picture in your head, but the math doesn't mind). The goal of the algorithm is to find the bottom of the lowest valley.
  • parent: a condition chosen as a point from which to select the next generation of conditions to evaluate. The fact that this is a direction set method means that one of the parent's parameters will be varied in to find candidates.
  • child: conditions chosen based on a parent are its children.

Assumptions

  • assumes the evaluator is deterministic, that it will give the same answer every time for the same set of hyperparameters. If this is not the case for your application you can approximate a stochastic solution by running it several times and looking for a grouping in the winning conditions.
  • assumes discrete valued parameters. Even if parameters are continuous, the way you feed them in forces you to choose a handful of specific values to try.

Non-assumptions

  • does not assume that the error landscape is smooth or continuous. As a result, redsho often takes more iterations to find an optimimal combination than fancier methods that that assume smoothness, like Bayesian or Gradient-based hyperparameter optimization. But it usually takes fewer samples than random or exhaustive grid search. (See https://en.wikipedia.org/wiki/Hyperparameter_optimization ) And, on average, it settles into a "pretty good" solution rather quickly.
  • does not assume that hyperparameter values are numerical. This opens up Redsho to handling categorical arguments, such as booleans or strings. It can also be used with string arguments for a Python function, or even whole functions, classes, or subsystems. Any valid Python object can be used as a hyperparameter value. This is helpful when evaluating models that have options such as method which can be assigned any one of several strings or arguments that accept functions, similar to how to SciPy's optimize.minimize does.

Release files for redsho 0.3.3

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

Source distribution (sdist)

Source distribution for redsho 0.3.3
File Size Uploaded
redsho-0.3.3.tar.gz 17.7 kB Details

Built distribution (wheel)

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

Total release size: 30.4 kB

Release files / redsho-0.3.3.tar.gz

Download URL redsho-0.3.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
04655f6133c84d77cd5237ac17956711ec0887d076ff6411f7028c8efb9595b9
BLAKE2b-256 checksum
How to use checksums
62c69044e36399aa763eff113b2b6eecd5ca1503f3c9bad010177b8ca04d0a4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.1

Release files / redsho-0.3.3-py3-none-any.whl

Download URL redsho-0.3.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d3b2d3ee9c141845086ccbad91006adba52d1bc532811eb192336b706e52fd0
BLAKE2b-256 checksum
How to use checksums
093571948a5f9e52953e37ff327a4178be26525e14fad67b26a4c24b1795cf3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.1

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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