Count, sample and race the strategies of an engine
A packer or a router is a pipeline of stages, and each stage has options with params. @mark1russell7/strategy-space gives these stages as data. Then its functions count the space, make a grid or a seeded sample, give one id to each point and race the strategies. Each demo on this page uses the real functions of the package in your browser.
- Count. The configs of a space, stage by stage.
- Sample. A grid, or a sample from a seed.
- Id. One id for each point of the space.
- Race. Fewer measures than a full screen.
pnpm add @mark1russell7/strategy-space
1. Count a space
The space below is a packer with three stages. The stage local-search is optional. A constraint keeps out each config with the input order and no local search. Change the JSON: checkSpace examines it, and spaceSize counts its configs.
2. Make a grid or a sample
enumerateSpace makes the configs of the space of demo 1. A grid gives each point at the levels. A sample draws n configs from a seed, and the same seed gives the same configs each time.
The share of each option in a sample
With reject, a draw that breaks a constraint draws again. With walk, each stage draws only from the options that keep the constraints, from the largest stage down.
3. One id for each point
configId gives the first 16 hex characters of the SHA-256 of the canonical form of a config. The order of the keys, a default value and an unused stage do not change the id.
Add a stage to the space
A space grows: an engine gets a new optional stage. Without omitUnused, the canonical form of each old config gets the new stage as null, so each old id changes.
4. Race the strategies
A full screen measures each strategy on each input. race measures the live strategies one input at a time. After the first inputs, a paired sign-flip test with the Holm correction drops each strategy that is worse than the best.
The costs come from a seeded model: the waste of area in percent. Each input has its own difficulty, and each strategy adds its gap and a noise.
Use it
import { checkSpace, configId, enumerateSpace, race, spaceSize } from "@mark1russell7/strategy-space";
checkSpace(space); // [] when the space is good
spaceSize(space, { levels: 2 }).base; // 243n for the packer of demo 1
const sample = enumerateSpace(space, { mode: "sample", n: 8, seed: 7 });
const ids = sample.map((config) => configId(space, config));
const { best, live } = race(ids, (id, input) => cost(id, input), { inputs: 40 });
The package @mark1russell7/strategy-search in the same repository searches a space: sweeps, a genetic search and Pareto fronts. Releases shows each version, and Status shows the open work.