simple

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package simple implements an unweighted reservoir sampling algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Simple

type Simple struct {
	// contains filtered or unexported fields
}

Simple implements unweighted reservoir sampling using Algorithm R from "Random sampling with a reservoir" by Jeffrey Vitter (1985) https://en.wikipedia.org/wiki/Reservoir_sampling#Algorithm_R

func New

func New(capacity int, rnd *rand.Rand) *Simple

New returns a simple reservoir sampler with given capacity (i.e., reservoir size) and random number generator.

func (*Simple) Add

func (s *Simple) Add(span varopt.Sample)

Add considers a new observation for the sample. Items have unit weight.

func (*Simple) Count

func (s *Simple) Count() int

Count returns the number of items that were observed.

func (*Simple) Get

func (s *Simple) Get(i int) varopt.Sample

Get returns the i'th selected item from the sample.

func (*Simple) Size

func (s *Simple) Size() int

Get returns the number of items in the sample. If the reservoir is full, Size() equals Capacity().

func (*Simple) Weight

func (s *Simple) Weight() float64

Weight returns the adjusted weight of each item in the sample.

Jump to

Keyboard shortcuts

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