aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/stats/sample/sample.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-07-24 12:08:49 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-07-24 14:39:45 +0000
commit49e6369fe732c0f81e5b03b36e345afbf3c79a15 (patch)
tree651e322e41a8084abd6f2c80e4f9b7ff50a1dfe9 /pkg/stats/sample/sample.go
parent1f032c27c8158e44723253179928104813d45cdc (diff)
pkg/stat: rename package name to singular form
Go package names should generally be singular form: https://go.dev/blog/package-names https://rakyll.org/style-packages https://groups.google.com/g/golang-nuts/c/buBwLar1gNw
Diffstat (limited to 'pkg/stats/sample/sample.go')
-rw-r--r--pkg/stats/sample/sample.go73
1 files changed, 0 insertions, 73 deletions
diff --git a/pkg/stats/sample/sample.go b/pkg/stats/sample/sample.go
deleted file mode 100644
index 740f9aefe..000000000
--- a/pkg/stats/sample/sample.go
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2021 syzkaller project authors. All rights reserved.
-// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
-
-// Package sample provides various statistical operations and algorithms.
-package sample
-
-import (
- "math"
- "sort"
-)
-
-// Sample represents a single sample - set of data points collected during an experiment.
-type Sample struct {
- Xs []float64
- Sorted bool
-}
-
-func (s *Sample) Percentile(p float64) float64 {
- s.Sort()
- // The code below is taken from golang.org/x/perf/internal/stats
- // Unfortunately, that package is internal and we cannot just import and use it.
- N := float64(len(s.Xs))
- n := 1/3.0 + p*(N+1/3.0) // R8
- kf, frac := math.Modf(n)
- k := int(kf)
- if k <= 0 {
- return s.Xs[0]
- } else if k >= len(s.Xs) {
- return s.Xs[len(s.Xs)-1]
- }
- return s.Xs[k-1] + frac*(s.Xs[k]-s.Xs[k-1])
-}
-
-func (s *Sample) Median() float64 {
- return s.Percentile(0.5)
-}
-
-// Remove outliers by the Tukey's fences method.
-func (s *Sample) RemoveOutliers() *Sample {
- if len(s.Xs) < 4 {
- // If the data set is too small, we cannot reliably detect outliers anyway.
- return s.Copy()
- }
- s.Sort()
- Q1 := s.Percentile(0.25)
- Q3 := s.Percentile(0.75)
- minValue := Q1 - 1.5*(Q3-Q1)
- maxValue := Q3 + 1.5*(Q3-Q1)
- xs := []float64{}
- for _, value := range s.Xs {
- if value >= minValue && value <= maxValue {
- xs = append(xs, value)
- }
- }
- return &Sample{
- Xs: xs,
- Sorted: s.Sorted,
- }
-}
-
-func (s *Sample) Copy() *Sample {
- return &Sample{
- Xs: append([]float64{}, s.Xs...),
- Sorted: s.Sorted,
- }
-}
-
-func (s *Sample) Sort() {
- if !s.Sorted {
- sort.Slice(s.Xs, func(i, j int) bool { return s.Xs[i] < s.Xs[j] })
- s.Sorted = true
- }
-}