towersampling

package module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

README

Tower sampling

Tower sampling samples events according to given discrete distribution. It can be used to generate events for giving distribution. For example, for following distribution,


const (
	Sleep = towersampling.Action("Sleep")
	Walk  = towersampling.Action("Walk")
	Watch = towersampling.Action("Watch")
	Eat   = towersampling.Action("Eat")
)

sampler := towersampling.Sampler([]towersampling.Event{
	{Name: Sleep, Probability: 0.33},
	{Name: Walk, Probability: 0.05},
	{Name: Watch, Probability: 0.35},
	{Name: Eat, Probability: 0.27},
})

value, err := sampler()

the sampler will return Sleep event with 33% probability and Walk event with 5% probability.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sampler

func Sampler(events []Event) func() (Action, error)

Sampler samples data according to given discrete distribution This can be used to generate events for giving distribution For example, for following distribution,

const (
	Sleep = towersampling.Action("Sleep")
	Walk  = towersampling.Action("Walk")
	Watch = towersampling.Action("Watch")
	Eat   = towersampling.Action("Eat")
)
...
sampler := towersampling.Sampler([]towersampling.Event{
	{Name: Sleep, Probability: 0.33},
	{Name: Walk, Probability: 0.05},
	{Name: Watch, Probability: 0.35},
	{Name: Eat, Probability: 0.27},
})
value, err := sampler()

the sampler will return Sleep with 33% probability.

Types

type Action

type Action string

Action or event name

type Event added in v0.1.2

type Event struct {
	Name        Action
	Probability float32
	Description string
}

Event is event object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL