sampler

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: BSD-3-Clause Imports: 9 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfRange = errors.New("out of range")

Functions

This section is empty.

Types

type Source added in v1.10.18

type Source interface {
	// Uint64 returns a random number in [0, MaxUint64] and advances the
	// generator's state.
	Uint64() uint64
}

type Uniform

type Uniform interface {
	Initialize(sampleRange uint64)
	// Sample returns length numbers in the range [0,sampleRange). If there
	// aren't enough numbers in the range, an error is returned. If length is
	// negative the implementation may panic.
	Sample(length int) ([]uint64, error)

	Reset()
	Next() (uint64, error)
}

Uniform samples values without replacement in the provided range

func NewBestUniform

func NewBestUniform(expectedSampleSize int) Uniform

NewBestUniform returns a new sampler

func NewDeterministicUniform added in v1.10.18

func NewDeterministicUniform(source Source) Uniform

NewDeterministicUniform returns a new sampler

func NewUniform

func NewUniform() Uniform

NewUniform returns a new sampler

type Weighted

type Weighted interface {
	Initialize(weights []uint64) error
	Sample(sampleValue uint64) (int, error)
}

Weighted defines how to sample a specified valued based on a provided weighted distribution

func NewDeterministicWeighted added in v1.6.0

func NewDeterministicWeighted() Weighted

func NewWeighted

func NewWeighted() Weighted

NewWeighted returns a new sampler

type WeightedWithoutReplacement

type WeightedWithoutReplacement interface {
	Initialize(weights []uint64) error
	Sample(count int) ([]int, error)
}

WeightedWithoutReplacement defines how to sample weight without replacement. Note that the behavior is to sample the weight without replacement, not the indices. So duplicate indices can be returned.

func NewBestWeightedWithoutReplacement

func NewBestWeightedWithoutReplacement(
	expectedSampleSize int,
) WeightedWithoutReplacement

NewBestWeightedWithoutReplacement returns a new sampler

func NewDeterministicWeightedWithoutReplacement added in v1.6.0

func NewDeterministicWeightedWithoutReplacement(source Source) WeightedWithoutReplacement

NewWeightedWithoutReplacement returns a new sampler

func NewWeightedWithoutReplacement

func NewWeightedWithoutReplacement() WeightedWithoutReplacement

NewWeightedWithoutReplacement returns a new sampler

Jump to

Keyboard shortcuts

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