examples: drive both examples with the bandit module - #11
Merged
Conversation
Both examples carried their own ~120-line Thompson Sampling adapter over
stitchfix/mab, written before this repository shipped a bandit of its own.
That made the first thing a reader meets a page of glue rather than the
cache, and it pulled gonum and golang.org/x/exp into an example module
that needs neither. Both now call bandit.NewThompson.
The basic example's adapter was also broken. Its GetRewards ranged the
per-arm map and used the PolicyType as a slice index:
for i, arm := range crs.stats { // i is a PolicyType, not an index
distributions[i] = mab.Beta(...) // LFU == 2, len(distributions) == 2
so the first SelectPolicy after an epoch elapsed would panic with an index
out of range. It compiled and was never run, which is the whole reason for
the -smoke flag added here.
Both examples take -smoke: build the cache, drive 100 keys through it,
report, exit 0, without serving. CI runs it for both, and for migration
across all three strategies -- which shows the strategies actually differ:
strategy=cold LRU -> LFU 0/100 keys readable after the switch
strategy=warm LRU -> LFU 100/100 keys readable after the switch
strategy=gradual LRU -> LFU 100/100 keys readable after the switch
Neither example's policy set, epoch settings nor cache construction
changed; only the bandit did.
docs/design.md loses the pointer to the removed adapter and gains a short
illustrative skeleton for wrapping an outside bandit, with the two traps
that catch people: consuming randomness while ranging a map breaks a
seeded run, and an arm with no requests is not an arm that scored zero.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both examples carried their own ~120-line Thompson Sampling adapter over
stitchfix/mab, written before this repository shipped a bandit of its own.The first thing a reader met was a page of glue rather than the cache, and it
pulled
gonumandgolang.org/x/expinto example modules that need neither.Both now call
bandit.NewThompson.The basic example's adapter was broken
Its
GetRewardsranged the per-arm map and used thePolicyTypeas a sliceindex:
so the first
SelectPolicyafter an epoch elapsed panicked with an index outof range. It compiled, and was never run.
Both examples take
-smokeBuild the cache, drive 100 keys through it, report, exit 0, without serving.
CI runs it for both examples, and for migration across all three strategies —
which demonstrates the strategies actually differ rather than only that the
binary starts:
Neither example's policy set, epoch settings nor cache construction changed;
only the bandit did.
Docs
docs/design.mdloses the pointer to the removed adapter and gains a shortillustrative skeleton for wrapping an outside bandit — checked line by line
against
interfaces.go— with the two traps that catch people: consumingrandomness while ranging a map breaks a seeded run, and an arm that saw no
requests is not an arm that scored zero.
docs/getting-started.mddropsstitchfix/mabfrom its references.Verification