-
Notifications
You must be signed in to change notification settings - Fork 669
/
weighted_without_replacement.go
41 lines (35 loc) · 1.16 KB
/
weighted_without_replacement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package sampler
// 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.
type WeightedWithoutReplacement interface {
Initialize(weights []uint64) error
Sample(count int) ([]int, error)
Seed(int64)
ClearSeed()
}
// NewWeightedWithoutReplacement returns a new sampler
func NewDeterministicWeightedWithoutReplacement() WeightedWithoutReplacement {
return &weightedWithoutReplacementGeneric{
u: NewUniform(),
w: NewDeterministicWeighted(),
}
}
// NewWeightedWithoutReplacement returns a new sampler
func NewWeightedWithoutReplacement() WeightedWithoutReplacement {
return &weightedWithoutReplacementGeneric{
u: NewUniform(),
w: NewWeighted(),
}
}
// NewBestWeightedWithoutReplacement returns a new sampler
func NewBestWeightedWithoutReplacement(
expectedSampleSize int,
) WeightedWithoutReplacement {
return &weightedWithoutReplacementGeneric{
u: NewBestUniform(expectedSampleSize),
w: NewWeighted(),
}
}