Documentation ¶
Overview ¶
Package vec32 has some basic functions on slices of float32.
Index ¶
- Constants
- func Count(a []float32) float32
- func Dup(a []float32) []float32
- func Fill(a []float32)
- func FillAt(a []float32, i int) (float32, error)
- func FillCov(a []float32)
- func FillMeanMissing(a []float32)
- func FillStdDev(a []float32)
- func FillStep(a []float32)
- func Geo(a []float32) float32
- func GeoE(a []float32) float32
- func IQRR(a []float32)
- func Max(a []float32) float32
- func Mean(xs []float32) float32
- func MeanAndStdDev(a []float32) (float32, float32, error)
- func MeanE(xs []float32) float32
- func MeanMissing(xs []float32) float32
- func Min(a []float32) float32
- func New(size int) []float32
- func Norm(a []float32, minStdDev float32)
- func RemoveMissingDataSentinel(arr []float32) []float32
- func SSE(xs []float32, base float32) float32
- func ScaleBy(a []float32, b float32)
- func StdDev(xs []float32, base float32) float32
- func StdDevRatio(arr []float32) (float32, float32, float32, float32, error)
- func Sum(xs []float32) float32
- func SumE(xs []float32) float32
- func ToFloat64(in []float32) []float64
- func TwoSidedStdDev(arr []float32) (float32, float32, float32, error)
Constants ¶
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 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 ¶
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 ¶
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 ¶
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.
func Max ¶
Max returns the largest value in the vector, or math.MinFloat32 if no non-MissingDataSentinel values are found.
func Mean ¶
Mean calculates and returns the Mean value of the given []float32.
Returns 0 for an array with no non-MissingDataSentinenl values.
func MeanAndStdDev ¶
MeanAndStdDev returns the mean, stddev, and if an error occurred while doing the calculation. MissingDataSentinenls are ignored.
func MeanE ¶
MeanE calculates and returns the Mean value of the given []float32.
Returns MissingDataSentinenl for an array with no non-MissingDataSentinenl values.
func MeanMissing ¶
MeanMissing calculates and returns the Mean value of the given []float32.
Returns MissingDataSentinenl for an array with all MissingDataSentinenl values.
func Min ¶
Min returns the smallest value in the vector, or math.MaxFloat32 if no non-MissingDataSentinel values are found.
func Norm ¶
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 ¶
RemoveMissingDataSentinel returns a new slice with all the values that are equal to the MissingDataSentinel removed.
func SSE ¶
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 ¶
ScaleBy divides each non-sentinel value in the slice by 'b', converting resulting NaNs and Infs into sentinel values.
func StdDevRatio ¶
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 ¶
Sum calculates and returns the sum of the given []float32.
Returns 0 for an array with no non-MissingDataSentinenl values.
func SumE ¶
SumE calculates and returns the sum of the given []float32.
Returns MissingDataSentinenl for an array with no non-MissingDataSentinenl values.
func TwoSidedStdDev ¶
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.