minmax

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: BSD-3-Clause Imports: 1 Imported by: 68

Documentation

Overview

Package minmax provides basic minimum / maximum values for float32 and float64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NiceRoundNumber

func NiceRoundNumber(x float64, below bool) float64

NiceRoundNumber returns the closest nice round number either above or below the given number, based on the observation that numbers 1, 2, 5 at any power are "nice". This is used for choosing graph labels, and auto-scaling ranges to contain a given value. if below == true then returned number is strictly less than given number otherwise it is strictly larger.

Types

type AvgMax32

type AvgMax32 struct {
	Avg    float32
	Max    float32
	MaxIdx int     `desc:"index of max item"`
	Sum    float32 `desc:"sum for computing average"`
	N      int     `desc:"number of items in sum"`
}

AvgMax holds average and max statistics

func (*AvgMax32) CalcAvg

func (am *AvgMax32) CalcAvg()

CalcAvg computes the average given the current Sum and N values

func (*AvgMax32) CopyFrom

func (am *AvgMax32) CopyFrom(oth *AvgMax32)

CopyFrom copies from other AvgMax32

func (*AvgMax32) Init

func (am *AvgMax32) Init()

Init initializes prior to new updates

func (*AvgMax32) UpdateFrom

func (am *AvgMax32) UpdateFrom(oth *AvgMax32)

UpdateFrom updates these values from other AvgMax32

func (*AvgMax32) UpdateVal

func (am *AvgMax32) UpdateVal(val float32, idx int)

UpdateVal updates stats from given value

type AvgMax64

type AvgMax64 struct {
	Avg    float64
	Max    float64
	MaxIdx int     `desc:"index of max item"`
	Sum    float64 `desc:"sum for computing average"`
	N      int     `desc:"number of items in sum"`
}

AvgMax holds average and max statistics

func (*AvgMax64) CalcAvg

func (am *AvgMax64) CalcAvg()

CalcAvg computes the average given the current Sum and N values

func (*AvgMax64) CopyFrom

func (am *AvgMax64) CopyFrom(oth *AvgMax64)

CopyFrom copies from other AvgMax64

func (*AvgMax64) Init

func (am *AvgMax64) Init()

Init initializes prior to new updates

func (*AvgMax64) UpdateFrom

func (am *AvgMax64) UpdateFrom(oth *AvgMax64)

UpdateFrom updates these values from other AvgMax64

func (*AvgMax64) UpdateVal

func (am *AvgMax64) UpdateVal(val float64, idx int)

UpdateVal updates stats from given value

type F32

type F32 struct {
	Min float32
	Max float32
}

F32 represents a min / max range for float32 values. Supports clipping, renormalizing, etc

func (*F32) ClipNormVal added in v1.0.0

func (mr *F32) ClipNormVal(val float32) float32

ClipNormVal clips then normalizes given value within 0-1 Note: a NaN will remain as a NaN

func (*F32) ClipVal

func (mr *F32) ClipVal(val float32) float32

ClipVal clips given value within Min / Max range Note: a NaN will remain as a NaN

func (*F32) FitInRange

func (mr *F32) FitInRange(oth F32) bool

FitInRange adjusts our Min, Max to fit within those of other F32 returns true if we had to adjust to fit.

func (*F32) FitValInRange

func (mr *F32) FitValInRange(val float32) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*F32) InRange

func (mr *F32) InRange(val float32) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*F32) IsHigh

func (mr *F32) IsHigh(val float32) bool

IsHigh tests whether value is higher than the maximum

func (*F32) IsLow

func (mr *F32) IsLow(val float32) bool

IsLow tests whether value is lower than the minimum

func (*F32) IsValid

func (mr *F32) IsValid() bool

IsValid returns true if Min <= Max

func (*F32) Midpoint

func (mr *F32) Midpoint() float32

Midpoint returns point halfway between Min and Max

func (*F32) NormVal

func (mr *F32) NormVal(val float32) float32

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*F32) ProjVal

func (mr *F32) ProjVal(val float32) float32

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*F32) Range

func (mr *F32) Range() float32

Range returns Max - Min

func (*F32) Scale

func (mr *F32) Scale() float32

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*F32) Set

func (mr *F32) Set(min, max float32)

Set sets the min and max values

func (*F32) SetInfinity

func (mr *F32) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

type F64

type F64 struct {
	Min float64
	Max float64
}

F64 represents a min / max range for float64 values. Supports clipping, renormalizing, etc

func (*F64) ClipNormVal added in v1.0.0

func (mr *F64) ClipNormVal(val float64) float64

ClipNormVal clips then normalizes given value within 0-1 Note: a NaN will remain as a NaN

func (*F64) ClipVal

func (mr *F64) ClipVal(val float64) float64

ClipVal clips given value within Min / Max range Note: a NaN will remain as a NaN

func (*F64) FitInRange

func (mr *F64) FitInRange(oth F64) bool

FitInRange adjusts our Min, Max to fit within those of other F64 returns true if we had to adjust to fit.

func (*F64) FitValInRange

func (mr *F64) FitValInRange(val float64) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*F64) InRange

func (mr *F64) InRange(val float64) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*F64) IsHigh

func (mr *F64) IsHigh(val float64) bool

IsHigh tests whether value is higher than the maximum

func (*F64) IsLow

func (mr *F64) IsLow(val float64) bool

IsLow tests whether value is lower than the minimum

func (*F64) IsValid

func (mr *F64) IsValid() bool

IsValid returns true if Min <= Max

func (*F64) Midpoint

func (mr *F64) Midpoint() float64

Midpoint returns point halfway between Min and Max

func (*F64) NormVal

func (mr *F64) NormVal(val float64) float64

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*F64) ProjVal

func (mr *F64) ProjVal(val float64) float64

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*F64) Range

func (mr *F64) Range() float64

Range returns Max - Min

func (*F64) Scale

func (mr *F64) Scale() float64

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*F64) Set

func (mr *F64) Set(min, max float64)

Set sets the min and max values

func (*F64) SetInfinity

func (mr *F64) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

type Int added in v1.0.1

type Int struct {
	Min int
	Max int
}

Int represents a min / max range for int values. Supports clipping, renormalizing, etc

func (*Int) ClipNormVal added in v1.0.1

func (mr *Int) ClipNormVal(val int) float32

ClipNormVal clips then normalizes given value within 0-1

func (*Int) ClipVal added in v1.0.1

func (mr *Int) ClipVal(val int) int

ClipVal clips given value within Min / Max rangee

func (*Int) FitInRange added in v1.0.1

func (mr *Int) FitInRange(oth Int) bool

FitInRange adjusts our Min, Max to fit within those of other Int returns true if we had to adjust to fit.

func (*Int) FitValInRange added in v1.0.1

func (mr *Int) FitValInRange(val int) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*Int) InRange added in v1.0.1

func (mr *Int) InRange(val int) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*Int) IsHigh added in v1.0.1

func (mr *Int) IsHigh(val int) bool

IsHigh tests whether value is higher than the maximum

func (*Int) IsLow added in v1.0.1

func (mr *Int) IsLow(val int) bool

IsLow tests whether value is lower than the minimum

func (*Int) IsValid added in v1.0.1

func (mr *Int) IsValid() bool

IsValid returns true if Min <= Max

func (*Int) Midpoint added in v1.0.1

func (mr *Int) Midpoint() float32

Midpoint returns point halfway between Min and Max

func (*Int) NormVal added in v1.0.1

func (mr *Int) NormVal(val int) float32

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*Int) ProjVal added in v1.0.1

func (mr *Int) ProjVal(val float32) float32

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*Int) Range added in v1.0.1

func (mr *Int) Range() int

Range returns Max - Min

func (*Int) Scale added in v1.0.1

func (mr *Int) Scale() float32

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*Int) Set added in v1.0.1

func (mr *Int) Set(min, max int)

Set sets the min and max values

func (*Int) SetInfinity added in v1.0.1

func (mr *Int) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

type Range32

type Range32 struct {
	F32    `desc:"Min and Max range values"`
	FixMin bool `desc:"fix the minimum end of the range"`
	FixMax bool `desc:"fix the maximum end of the range"`
}

Range32 represents a range of values for plotting, where the min or max can optionally be fixed

func (*Range32) Range

func (rr *Range32) Range() float32

Range returns Max - Min

func (*Range32) SetMax

func (rr *Range32) SetMax(max float32)

SetMax sets a fixed max value

func (*Range32) SetMin

func (rr *Range32) SetMin(min float32)

SetMin sets a fixed min value

type Range64

type Range64 struct {
	F64    `desc:"Min and Max range values"`
	FixMin bool `desc:"fix the minimum end of the range"`
	FixMax bool `desc:"fix the maximum end of the range"`
}

Range64 represents a range of values for plotting, where the min or max can optionally be fixed

func (*Range64) Range

func (rr *Range64) Range() float64

Range returns Max - Min

func (*Range64) SetMax

func (rr *Range64) SetMax(max float64)

SetMax sets a fixed max value

func (*Range64) SetMin

func (rr *Range64) SetMin(min float64)

SetMin sets a fixed min value

Jump to

Keyboard shortcuts

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