40 | 40 |
a[i], a[j] = a[j], a[i]
|
41 | 41 |
}
|
42 | 42 |
|
43 | |
type Invariant func(s *stream, r float64) float64
|
44 | |
|
45 | |
// Biased returns an Invariant for high-biased (>50th) quantiles not known a
|
|
43 |
type invariant func(s *stream, r float64) float64
|
|
44 |
|
|
45 |
// Biased returns an Stream for high-biased (>50th) quantiles not known a
|
46 | 46 |
// priori with associated error bounds e (usually 0.01).
|
47 | 47 |
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
|
48 | |
func Biased(e float64) Invariant {
|
49 | |
return func(s *stream, r float64) float64 {
|
|
48 |
func NewBiased(e float64) *Stream {
|
|
49 |
f := func(s *stream, r float64) float64 {
|
50 | 50 |
return 2 * e * r
|
51 | 51 |
}
|
52 | |
}
|
53 | |
|
54 | |
// Targeted returns an Invariant that is only concerned with a set
|
|
52 |
return newStream(f)
|
|
53 |
}
|
|
54 |
|
|
55 |
// Targeted returns an Stream that is only concerned with a set
|
55 | 56 |
// of quantile values with associated error bounds e (usually 0.01) that are supplied a priori.
|
56 | 57 |
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
|
57 | |
func Targeted(e float64, quantiles ...float64) Invariant {
|
58 | |
return func(s *stream, r float64) float64 {
|
|
58 |
func NewTargeted(e float64, quantiles ...float64) *Stream {
|
|
59 |
f := func(s *stream, r float64) float64 {
|
59 | 60 |
var m float64 = math.MaxFloat64
|
60 | 61 |
var f float64
|
61 | 62 |
for _, q := range quantiles {
|
|
68 | 69 |
}
|
69 | 70 |
return m
|
70 | 71 |
}
|
|
72 |
return newStream(f)
|
71 | 73 |
}
|
72 | 74 |
|
73 | 75 |
// Stream calculates quantiles for a stream of float64s.
|
|
76 | 78 |
b Samples
|
77 | 79 |
}
|
78 | 80 |
|
79 | |
// New returns an initialized Stream with the Invariant ƒ.
|
80 | |
func New(ƒ Invariant) *Stream {
|
|
81 |
func newStream(ƒ invariant) *Stream {
|
81 | 82 |
x := &stream{ƒ: ƒ, l: list.New()}
|
82 | 83 |
return &Stream{x, make(Samples, 0, 500)}
|
83 | 84 |
}
|
|
141 | 142 |
type stream struct {
|
142 | 143 |
n float64
|
143 | 144 |
l *list.List
|
144 | |
ƒ Invariant
|
|
145 |
ƒ invariant
|
145 | 146 |
}
|
146 | 147 |
|
147 | 148 |
func (s *stream) reset() {
|