vec32

package
v0.0.0-...-7d312d8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: BSD-3-Clause Imports: 4 Imported by: 8

Documentation

Overview

Package vec32 has some basic functions on slices of float32.

Index

Constants

View Source
const (
	// MissingDataSentinel signifies a missing sample value.
	//
	// JSON doesn't support NaN or +/- Inf, so we need a valid float32 to signal
	// missing data that also has a compact JSON representation.
	MissingDataSentinel float32 = 1e32
)

Variables

This section is empty.

Functions

func Count

func Count(a []float32) float32

Count the number of non MissingDataSentinel values in a vector.

func Dup

func Dup(a []float32) []float32

Dup a slice of float32.

func Fill

func Fill(a []float32)

Fill in non-sentinel values with nearby points.

Sentinel values are filled with points later in the array, except for the end of the array where we can't do that, so we fill those points in using the first non sentinel found when searching backwards from the end.

So

[1e32, 1e32,   2, 3, 1e32, 5]

becomes

[2,    2,      2, 3, 5,    5]

and

[3, 1e32, 5, 1e32, 1e32]

becomes

[3, 5,    5, 5,    5]

Note that a vector filled with all sentinels will be filled with 0s.

func FillAt

func FillAt(a []float32, i int) (float32, error)

FillAt returns the value at the given index of a vector, using non-sentinel values with nearby points if the original is MissingDataSentinenl.

Note that the input vector is unchanged.

Returns non-nil error if the given index is out of bounds.

func FillCov

func FillCov(a []float32)

FillCov fills the slice with the Coefficient of Variation of the values in the slice.

If the mean is 0 or the slice is filled with only MissingDataSentinenl then the slice will be filled with MissingDataSentinenl.

func FillMeanMissing

func FillMeanMissing(a []float32)

FillMeanMissing fills the slice with the mean of all the values in the slice using MeanMissing.

func FillStdDev

func FillStdDev(a []float32)

FillStdDev fills the slice with the Standard Deviation of the values in the slice.

If slice is filled with only MissingDataSentinenl then the slice will be filled with MissingDataSentinenl.

func FillStep

func FillStep(a []float32)

FillStep fills the slice with the step function value, i.e. the ratio of the ave of the first half of the trace values divided by the ave of the second half of the trace values.

If the second mean is 0 or the slice is filled with only MissingDataSentinenl then the slice will be filled with MissingDataSentinenl.

func Geo

func Geo(a []float32) float32

Geo takes the geomentric mean of all the values in the trace, ignoring negative values and MissingDataSentinels. If no values match that critera then it returns 0.

func GeoE

func GeoE(a []float32) float32

GeoE takes the geomentric mean of all the values in the trace, ignoring negative values and MissingDataSentinels. If no values match that critera then it returns MissingDataSentinel.

func IQRR

func IQRR(a []float32)

IQRR sets each outlier, as computed by the interquartile rule, to the missing data sentinel.

See https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/box-whisker-plots/a/identifying-outliers-iqr-rule

func Max

func Max(a []float32) float32

Max returns the largest value in the vector, or math.MinFloat32 if no non-MissingDataSentinel values are found.

func Mean

func Mean(xs []float32) float32

Mean calculates and returns the Mean value of the given []float32.

Returns 0 for an array with no non-MissingDataSentinenl values.

func MeanAndStdDev

func MeanAndStdDev(a []float32) (float32, float32, error)

MeanAndStdDev returns the mean, stddev, and if an error occurred while doing the calculation. MissingDataSentinenls are ignored.

func MeanE

func MeanE(xs []float32) float32

MeanE calculates and returns the Mean value of the given []float32.

Returns MissingDataSentinenl for an array with no non-MissingDataSentinenl values.

func MeanMissing

func MeanMissing(xs []float32) float32

MeanMissing calculates and returns the Mean value of the given []float32.

Returns MissingDataSentinenl for an array with all MissingDataSentinenl values.

func Min

func Min(a []float32) float32

Min returns the smallest value in the vector, or math.MaxFloat32 if no non-MissingDataSentinel values are found.

func New

func New(size int) []float32

New creates a new []float32 of the given size pre-populated with MissingDataSentinenl.

func Norm

func Norm(a []float32, minStdDev float32)

Norm normalizes the slice to a mean of 0 and a standard deviation of 1.0. The minStdDev is the minimum standard deviation that is normalized. Slices with a standard deviation less than that are not normalized for variance.

func RemoveMissingDataSentinel

func RemoveMissingDataSentinel(arr []float32) []float32

RemoveMissingDataSentinel returns a new slice with all the values that are equal to the MissingDataSentinel removed.

func SSE

func SSE(xs []float32, base float32) float32

SSE calculates and returns the sum squared error from the given base of []float32.

Returns 0 for an array with no non-MissingDataSentinenl values.

func ScaleBy

func ScaleBy(a []float32, b float32)

ScaleBy divides each non-sentinel value in the slice by 'b', converting resulting NaNs and Infs into sentinel values.

func StdDev

func StdDev(xs []float32, base float32) float32

StdDev returns the sample standard deviation.

func StdDevRatio

func StdDevRatio(arr []float32) (float32, float32, float32, float32, error)

StdDevRatio returns the number of standard deviations that the last point in arr is away from the median of the remaining points in arr.

Does not presume that arr is sorted.

In detail, this calculates a measure of how likely the last point in the slice is to come from the population, as represented by the remaining elements of the slice.

We calculate TwoSidedStdDev:

median, lower, upper = TwoSidedStdDev(values)

Then calculate the std dev ratio (d):

d = (x-median)/[lower|upper]

The value of d is the difference between the last point in arr (x) and the median, divided by the lower or upper standard deviation. If x > median then we divide by upper, else we divide by lower.

This d is a unitless dimension, the number of standard deviations the trybot value is either above or below the median.

Returns the stddevRatio, median, lower, upper, and an error if one occurred.

func Sum

func Sum(xs []float32) float32

Sum calculates and returns the sum of the given []float32.

Returns 0 for an array with no non-MissingDataSentinenl values.

func SumE

func SumE(xs []float32) float32

SumE calculates and returns the sum of the given []float32.

Returns MissingDataSentinenl for an array with no non-MissingDataSentinenl values.

func ToFloat64

func ToFloat64(in []float32) []float64

ToFloat64 creates a slice of float64 from the given slice of float32.

func TwoSidedStdDev

func TwoSidedStdDev(arr []float32) (float32, float32, float32, error)

TwoSidedStdDev returns the median, and the stddev of all the points below and above the median respectively.

That is, the vector is sorted, the median found, and then the stddev of all the points below the median are returned, along with the stddev of all the points above the median.

This is useful because performance measurements are inherintly asymmetric. A benchmark can always run 2x slower, or 10x slower, there's no upper bound. On the other hand a performance metric can only run 100% faster, i.e. have a value of 0. This implies that the distribution of samples from a benchmark are skewed.

MissingDataSentinenls are ignored.

The median is chosen as the midpoint instead of the mean because that ensures that both sides have the same number of points (+/- 1).

Types

This section is empty.

Jump to

Keyboard shortcuts

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