Documentation
¶
Overview ¶
Package bandit implements a multiarmed strategy. Runs A/B tests while controlling the tradeoff between exploring new arms and exploiting the currently best arm.
The project is based on John Myles White's 'Strategy Algorithms for Website Optimization'.
Index ¶
- func RewardLine(experiment Experiment, selected Variation, reward float64) string
- func SelectionLine(experiment Experiment, selected Variation) string
- func TimestampedTagToTag(timestampedTag string) (string, int64, error)
- type Counters
- type Experiment
- type Experiments
- type Opener
- type Strategy
- func New(arms int, name string, params []float64) (Strategy, error)
- func NewDelayed(s Strategy, o Opener, poll time.Duration) (Strategy, error)
- func NewEpsilonGreedy(arms int, epsilon float64) (Strategy, error)
- func NewSoftmax(arms int, τ float64) (Strategy, error)
- func NewThompson(arms int, α float64) (Strategy, error)
- func NewUCB1(arms int) Strategy
- type Variation
- type Variations
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RewardLine ¶
func RewardLine(experiment Experiment, selected Variation, reward float64) string
RewardLine captures all selected arms. This log can be used in conjunction with reward logs to fully rebuild strategys.
func SelectionLine ¶
func SelectionLine(experiment Experiment, selected Variation) string
SelectionLine captures all selected arms. This log can be used in conjunction with reward logs to fully rebuild strategys.
Types ¶
type Counters ¶
Counters maintain internal strategy state
func GetSnapshot ¶
GetSnapshot returns Counters given a snapshot filename.
func NewCounters ¶
NewCounters constructs counters for given arms
func ParseSnapshot ¶
ParseSnapshot reads in a snapshot file. Snapshot files contain a single line experiment snapshot, for example:
2 0.1 0.5
Tokens are separated by whitespace. The given example encodes an experiment with two variations. First is the number of variations. This is followed by rewards (mean reward for each arm).
type Experiment ¶
type Experiment struct { Name string Strategy Strategy Variations Variations }
Experiment is a single experiment. Variations are in ascending ordinal sorting, where ordinals are contiguous and start at 1.
func NewExperiment ¶
func NewExperiment(o Opener, name string) (*Experiment, error)
NewExperiment loads experiment `name` from the experiments source.
func (*Experiment) GetTaggedVariation ¶
func (e *Experiment) GetTaggedVariation(tag string) (Variation, error)
GetTaggedVariation selects the appropriate variation given it's tag
func (*Experiment) GetVariation ¶
func (e *Experiment) GetVariation(ordinal int) (Variation, error)
GetVariation selects the appropriate variation given it's 1 indexed ordinal
func (*Experiment) Select ¶
func (e *Experiment) Select() Variation
Select calls SelectArm on the strategy and returns the associated variation
func (*Experiment) SelectTimestamped ¶
func (e *Experiment) SelectTimestamped( timestampedTag string, ttl time.Duration) (Variation, string, error)
SelectTimestamped selects the appropriate variation given it's timestampedTag. A timestamped tag is a string in the form <tag>:<timestamp>. If the duration between <timestamp> and the current time is smaller than `d`, the given tagged is used to return variation. If it is larger, Select() is called instead. If the `timestampedTag` argument is the blank string, Select() is called instead.
type Experiments ¶
type Experiments map[string]*Experiment
Experiments is an index of names to experiment
func NewExperiments ¶
func NewExperiments(o Opener) (*Experiments, error)
NewExperiments reads in a json file and converts it to a map of experiments.
func (*Experiments) GetVariation ¶
func (e *Experiments) GetVariation(tag string) (Experiment, Variation, error)
GetVariation returns the Experiment and variation pointed to by a string tag.
type Opener ¶
type Opener interface {
Open() (io.ReadCloser, error)
}
Opener can be used to reopen underlying file descriptors.
func NewFileOpener ¶
NewFileOpener returns an Opener using and underlying file.
func NewHTTPOpener ¶
NewHTTPOpener returns an opener using an underlying URL.
type Strategy ¶
type Strategy interface { SelectArm() int Update(arm int, reward float64) Init(*Counters) error Reset() }
Strategy can select arm or update information
func NewDelayed ¶
NewDelayed wraps a strategy and updates internal counters from a snapshot at `poll` interval.
func NewEpsilonGreedy ¶
NewEpsilonGreedy constructs an epsilon greedy strategy.
func NewSoftmax ¶
NewSoftmax constructs a softmax strategy. Softmax explores arms in proportion to their estimated values.
func NewThompson ¶
NewThompson constructs a thompson sampling strategy.
type Variation ¶
type Variation struct { Ordinal int // 1 indexed arm ordinal URL string // the url associated with this variation, for out of band Tag string // this tag is used throughout the lifecycle of the experiment Description string // freitext }
Variation describes endpoints which are mapped onto strategy arms.
type Variations ¶
type Variations []Variation
Variations is a set of variations sorted by ordinal.
func (Variations) Len ¶
func (v Variations) Len() int
func (Variations) Less ¶
func (v Variations) Less(i, j int) bool
func (Variations) Swap ¶
func (v Variations) Swap(i, j int)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package http provides an HTTP API for strategy experiments.
|
Package http provides an HTTP API for strategy experiments. |
Package main contains bandit-job, which takes as input a log of selects and rewards of the following format: 1379257984 BanditSelection shape-20130822:1:8932478932 1379257987 BanditReward shape-20130822:1:8932478932 0.000000 Fields are interpreted as follows: (logline-timestamp, kind, tag, reward) Tags are interpreted as: experiment-name:variation-ordinal:pinning-time
|
Package main contains bandit-job, which takes as input a log of selects and rewards of the following format: 1379257984 BanditSelection shape-20130822:1:8932478932 1379257987 BanditReward shape-20130822:1:8932478932 0.000000 Fields are interpreted as follows: (logline-timestamp, kind, tag, reward) Tags are interpreted as: experiment-name:variation-ordinal:pinning-time |