norm

package
v2.0.0-dev0.0.19 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 4 Imported by: 5

README

norm

Docs: GoDoc

norm provides normalization and norm metric computations, e.g., L2 = sqrt of sum of squares of a vector. The basic functions operate on either []float32 or []float64 data, but Tensor versions are available too.

  • DivNorm does divisive normalization of elements
  • SubNorm does subtractive normalization of elements
  • ZScore subtracts the mean and divides by the standard deviation
  • Abs performs absolute-value on all elements (e.g., use prior to tsragg to produce Mean of Abs vals etc).

Documentation

Overview

Package norm provides normalization and norm metric computations e.g., L2 = sqrt of sum of squares of a vector.

DivNorm does divisive normalization of elements SubNorm does subtractive normalization of elements ZScore subtracts the mean and divides by the standard deviation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs32

func Abs32(a []float32)

Abs32 applies the Abs function to each element in given slice

func Abs64

func Abs64(a []float64)

Abs64 applies the Abs function to each element in given slice

func AddVec64

func AddVec64(a []float64, val float64)

AddVec64 adds scalar to vector

func AddVector32

func AddVector32(a []float32, val float32)

AddVector32 adds scalar to vector

func Binarize32

func Binarize32(a []float32, thr, hiVal, loVal float32)

Binarize32 turns vector into binary-valued, by setting anything >= the threshold to the high value, and everything below to the low value.

func Binarize64

func Binarize64(a []float64, thr, hiVal, loVal float64)

Binarize64 turns vector into binary-valued, by setting anything >= the threshold to the high value, and everything below to the low value.

func DivNorm32

func DivNorm32(a []float32, nfunc Func32)

DivNorm32 does divisive normalization by given norm function i.e., it divides each element by the norm value computed from nfunc.

func DivNorm64

func DivNorm64(a []float64, nfunc Func64)

DivNorm64 does divisive normalization by given norm function i.e., it divides each element by the norm value computed from nfunc.

func L132

func L132(a []float32) float32

L132 computes the sum of absolute values (L1 Norm). Skips NaN's

func L164

func L164(a []float64) float64

L164 computes the sum of absolute values (L1 Norm). Skips NaN's

func L232

func L232(a []float32) float32

L232 computes the square-root of sum-of-squares of vector, i.e., the L2 norm. Skips NaN's. Uses optimized algorithm from BLAS that avoids numerical overflow.

func L264

func L264(a []float64) float64

L264 computes the square-root of sum-of-squares of vector, i.e., the L2 norm. Skips NaN's. Uses optimized algorithm from BLAS that avoids numerical overflow.

func Max32

func Max32(a []float32) float32

Max32 computes the max over vector values. Skips NaN's

func Max64

func Max64(a []float64) float64

Max64 computes the max over vector values. Skips NaN's

func MaxAbs32

func MaxAbs32(a []float32) float32

MaxAbs32 computes the max of absolute value over vector values. Skips NaN's

func MaxAbs64

func MaxAbs64(a []float64) float64

MaxAbs64 computes the max over vector values. Skips NaN's

func MaxIndex32

func MaxIndex32(a []float32) (float32, int)

MaxIndex32 computes the max over vector values, and returns index of max as well Skips NaN's

func MaxIndex64

func MaxIndex64(a []float64) (float64, int)

MaxIndex64 computes the max over vector values, and returns index of max as well Skips NaN's

func Mean32

func Mean32(a []float32) float32

Mean32 computes the mean of the vector (sum / N). Skips NaN's

func Mean64

func Mean64(a []float64) float64

Mean64 computes the mean of the vector (sum / N). Skips NaN's

func Min32

func Min32(a []float32) float32

Min32 computes the max over vector values. Skips NaN's

func Min64

func Min64(a []float64) float64

Min64 computes the max over vector values. Skips NaN's

func MinAbs32

func MinAbs32(a []float32) float32

MinAbs32 computes the max of absolute value over vector values. Skips NaN's

func MinAbs64

func MinAbs64(a []float64) float64

MinAbs64 computes the max over vector values. Skips NaN's

func MinIndex32

func MinIndex32(a []float32) (float32, int)

MinIndex32 computes the min over vector values, and returns index of min as well Skips NaN's

func MinIndex64

func MinIndex64(a []float64) (float64, int)

MinIndex64 computes the min over vector values, and returns index of min as well Skips NaN's

func MultVec64

func MultVec64(a []float64, val float64)

MultVec64 multiplies vector elements by scalar

func MultVector32

func MultVector32(a []float32, val float32)

MultVector32 multiplies vector elements by scalar

func N32

func N32(a []float32) float32

N32 computes the number of non-NaN vector values. Skips NaN's

func N64

func N64(a []float64) float64

N64 computes the number of non-NaN vector values. Skips NaN's

func Std32

func Std32(a []float32) float32

Std32 returns the sample standard deviation of non-NaN elements in vector.

func Std64

func Std64(a []float64) float64

Std64 returns the sample standard deviation of non-NaN elements in vector.

func SubNorm32

func SubNorm32(a []float32, nfunc Func32)

SubNorm32 does subtractive normalization by given norm function i.e., it subtracts norm computed by given function from each element.

func SubNorm64

func SubNorm64(a []float64, nfunc Func64)

SubNorm64 does subtractive normalization by given norm function i.e., it subtracts norm computed by given function from each element.

func Sum32

func Sum32(a []float32) float32

Sum32 computes the sum of vector values. Skips NaN's

func Sum64

func Sum64(a []float64) float64

Sum64 computes the sum of vector values. Skips NaN's

func SumSquares32

func SumSquares32(a []float32) float32

SumSquares32 computes the sum-of-squares of vector. Skips NaN's. Uses optimized algorithm from BLAS that avoids numerical overflow.

func SumSquares64

func SumSquares64(a []float64) float64

SumSquares64 computes the sum-of-squares of vector. Skips NaN's. Uses optimized algorithm from BLAS that avoids numerical overflow.

func TensorAbs32

func TensorAbs32(a *etensor.Float32)

TensorAbs32 applies the Abs function to each element in given tensor

func TensorAbs64

func TensorAbs64(a *etensor.Float64)

TensorAbs64 applies the Abs function to each element in given tensor

func TensorDivNorm32

func TensorDivNorm32(tsr *etensor.Float32, ndim int, nfunc Func32)

TensorDivNorm32 does divisive normalization by given norm function computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0.

func TensorDivNorm64

func TensorDivNorm64(tsr *etensor.Float64, ndim int, nfunc Func64)

TensorDivNorm64 does divisive normalization by given norm function computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0.

func TensorSubNorm32

func TensorSubNorm32(tsr *etensor.Float32, ndim int, nfunc Func32)

TensorSubNorm32 does subtractive normalization by given norm function computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0 (panics).

func TensorSubNorm64

func TensorSubNorm64(tsr *etensor.Float64, ndim int, nfunc Func64)

TensorSubNorm64 does subtractive normalization by given norm function computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0.

func TensorUnit32

func TensorUnit32(tsr *etensor.Float32, ndim int)

TensorUnit32 subtracts the min and divides by the max, so that values are in 0-1 unit range computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0 (panics).

func TensorUnit64

func TensorUnit64(tsr *etensor.Float64, ndim int)

TensorUnit64 subtracts the min and divides by the max, so that values are in 0-1 unit range computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0 (panics).

func TensorZScore32

func TensorZScore32(tsr *etensor.Float32, ndim int)

TensorZScore32 subtracts the mean and divides by the standard deviation computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0 (panics).

func TensorZScore64

func TensorZScore64(tsr *etensor.Float64, ndim int)

TensorZScore64 subtracts the mean and divides by the standard deviation computed on the first ndim dims of the tensor, where 0 = all values, 1 = norm each of the sub-dimensions under the first outer-most dimension etc. ndim must be < NumDims() if not 0 (panics).

func Thresh32

func Thresh32(a []float32, hi bool, hiThr float32, lo bool, loThr float32)

Thresh32 thresholds the values of the vector -- anything above the high threshold is set to the high value, and everything below the low threshold is set to the low value.

func Thresh64

func Thresh64(a []float64, hi bool, hiThr float64, lo bool, loThr float64)

Thresh64 thresholds the values of the vector -- anything above the high threshold is set to the high value, and everything below the low threshold is set to the low value.

func Unit32

func Unit32(a []float32)

Unit32 subtracts the min and divides by the max, so that values are in 0-1 unit range

func Unit64

func Unit64(a []float64)

Unit64 subtracts the min and divides by the max, so that values are in 0-1 unit range

func Var32

func Var32(a []float32) float32

Var32 returns the sample variance of non-NaN elements.

func Var64

func Var64(a []float64) float64

Var64 returns the sample variance of non-NaN elements.

func ZScore32

func ZScore32(a []float32)

ZScore32 subtracts the mean and divides by the standard deviation

func ZScore64

func ZScore64(a []float64)

ZScore64 subtracts the mean and divides by the standard deviation

Types

type Func32

type Func32 func(a []float32) float32

Func32 is a norm function operating on slice of float32 numbers

func StdFunc32

func StdFunc32(std StdNorms) Func32

StdFunc32 returns a standard norm function as specified

type Func64

type Func64 func(a []float64) float64

Func64 is a norm function operating on slices of float64 numbers

func StdFunc64

func StdFunc64(std StdNorms) Func64

StdFunc64 returns a standard norm function as specified

type StdNorms

type StdNorms int32 //enums:enum

StdNorms are standard norm functions, including stats

const (
	L1 StdNorms = iota
	L2
	SumSquares
	N
	Sum
	Mean
	Var
	Std
	Max
	MaxAbs
	Min
	MinAbs
)
const StdNormsN StdNorms = 12

StdNormsN is the highest valid value for type StdNorms, plus one.

func StdNormsValues

func StdNormsValues() []StdNorms

StdNormsValues returns all possible values for the type StdNorms.

func (StdNorms) Desc

func (i StdNorms) Desc() string

Desc returns the description of the StdNorms value.

func (StdNorms) Int64

func (i StdNorms) Int64() int64

Int64 returns the StdNorms value as an int64.

func (StdNorms) MarshalText

func (i StdNorms) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*StdNorms) SetInt64

func (i *StdNorms) SetInt64(in int64)

SetInt64 sets the StdNorms value from an int64.

func (*StdNorms) SetString

func (i *StdNorms) SetString(s string) error

SetString sets the StdNorms value from its string representation, and returns an error if the string is invalid.

func (StdNorms) String

func (i StdNorms) String() string

String returns the string representation of this StdNorms value.

func (*StdNorms) UnmarshalText

func (i *StdNorms) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (StdNorms) Values

func (i StdNorms) Values() []enums.Enum

Values returns all possible values for the type StdNorms.

Jump to

Keyboard shortcuts

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