stats

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: BSD-3-Clause Imports: 12 Imported by: 20

README

stats

The stats package provides standard statistic computations operating on the tensor.Tensor standard data representation, using this standard function:

type StatsFunc func(in, out tensor.Tensor) error

See the Cogent Lab Docs for full documentation.

The stats functions always operate on the outermost row dimension, and it is up to the caller to reshape the tensor to accomplish the desired results.

  • To obtain a single summary statistic across all values, use tensor.As1D.

  • For RowMajor data that is naturally organized as a single outer rows dimension with the remaining inner dimensions comprising the cells, the results are the statistic for each such cell computed across the outer rows dimension. For the Mean statistic for example, each cell contains the average of that cell across all the rows.

  • Use tensor.NewRowCellsView to reshape any tensor into a 2D rows x cells shape, with the cells starting at a given dimension. Thus, any number of outer dimensions can be collapsed into the outer row dimension, and the remaining dimensions become the cells.

By contrast, the NumPy Statistics functions take an axis dimension to compute over, but passing such arguments via the universal function calling api for tensors introduces complications, so it is simpler to just have a single designated behavior and reshape the data to achieve the desired results.

All stats are registered in the tensor.Funcs global list (for use in Goal), and can be called through the Stats enum e.g.:

stats.Mean.Call(in, out)

All stats functions skip over NaNs as a missing value, so they are equivalent to the nanmean etc versions in NumPy.

Stats

The following statistics are supported (per the Stats enum in stats.go):

  • Count: count of number of elements
  • Sum: sum of elements
  • L1Norm: L1 Norm: sum of absolute values
  • Prod: product of elements
  • Min: minimum value
  • Max: maximum value
  • MinAbs: minimum of absolute values
  • MaxAbs: maximum of absolute values
  • Mean: mean value
  • Var: sample variance (squared diffs from mean, divided by n-1)
  • Std: sample standard deviation (sqrt of Var)
  • Sem: sample standard error of the mean (Std divided by sqrt(n))
  • SumSq: sum of squared element values
  • L2Norm: L2 Norm: square-root of sum-of-squares
  • VarPop: population variance (squared diffs from mean, divided by n)
  • StdPop: population standard deviation (sqrt of VarPop)
  • SemPop: population standard error of the mean (StdPop divided by sqrt(n))
  • Median: middle value in sorted ordering (uses a Rows view)
  • Q1: Q1 first quartile = 25%ile value = .25 quantile value (uses Rows)
  • Q3: Q3 third quartile = 75%ile value = .75 quantile value (uses Rows)

Here is the general info associated with these function calls:

The output must be a tensor.Values tensor, and it is automatically shaped to hold the stat value(s) for the "cells" in higher-dimensional tensors, and a single scalar value for a 1D input tensor.

Stats functions cannot be computed in parallel, e.g., using VectorizeThreaded or GPU, due to shared writing to the same output values. Special implementations are required if that is needed.

Normalization functions

The stats package also has the following standard normalization functions for transforming data into standard ranges in various ways:

  • UnitNorm subtracts min and divides by resulting max to normalize to 0..1 unit range.
  • ZScore subtracts the mean and divides by the standard deviation.
  • Clamp enforces min, max range, clamping values to those bounds if they exceed them.
  • Binarize sets all values below a given threshold to 0, and those above to 1.

Groups

The Groups function (and TableGroups convenience function for table.Table columns) creates lists of indexes for each unique value in a 1D tensor, and GroupStats calls a stats function on those groups, thereby creating a "pivot table" that summarizes data in terms of the groups present within it. The data is stored in a tensorfs data filesystem, which can be visualized and further manipulated.

For example, with this data:

Person  Score  Time
Alia    40     8
Alia    30     12
Ben     20     10
Ben     10     12

The Groups function called on the Person column would create the following tensorfs structure:

Groups
    Person
        Alia:  [0,1]   // int tensor
        Ben:   [2,3]
    // other groups here if passed

Then the GroupStats function operating on this tensorfs directory, using the Score and Time data and the Mean stat, followed by a second call with the Sem stat, would produce:

Stats
    Person
       Person:    [Alia,Ben] // string tensor of group values of Person
       Score
           Mean:  [35, 15] // float64 tensor of means
           Sem:   [5, 5]
       Time
           Mean:  [10, 11]
           Sem:   [1, 0.5]
    // other groups here..

The Person directory can be turned directly into a table.Table and plotted or otherwise used, in the tensorfs system and associated databrowser.

See the examples/planets example for an interactive exploration of data on exoplanets using the Groups functions.

Vectorize functions

See vec.go for corresponding tensor.Vectorize functions that are used in performing the computations. These cannot be parallelized directly due to shared writing to output accumulators, and other ordering constraints. If needed, special atomic-locking or other such techniques would be required.

Documentation

Overview

Package stats provides standard statistic computations operating on the `tensor.Tensor` standard data representation.

Index

Constants

This section is empty.

Variables

DescriptiveStats are the standard descriptive stats used in Describe function. Cannot apply the final 3 sort-based stats to higher-dimensional data.

Functions

func Binarize

func Binarize(in, threshold tensor.Tensor) tensor.Values

Binarize results in a binary-valued output by setting values >= the threshold to 1, else 0. threshold is treated as a scalar (first value used).

func BinarizeOut

func BinarizeOut(in, threshold tensor.Tensor, out tensor.Values) error

BinarizeOut results in a binary-valued output by setting values >= the threshold to 1, else 0. threshold is treated as a scalar (first value used).

func Clamp

func Clamp(in, minv, maxv tensor.Tensor) tensor.Values

Clamp ensures that all values are within min, max limits, clamping values to those bounds if they exceed them. min and max args are treated as scalars (first value used).

func ClampOut

func ClampOut(in, minv, maxv tensor.Tensor, out tensor.Values) error

ClampOut ensures that all values are within min, max limits, clamping values to those bounds if they exceed them. min and max args are treated as scalars (first value used).

func Count

func Count(in tensor.Tensor) tensor.Values

Count computes the count of non-NaN tensor values. See StatsFunc for general information.

func CountOut

func CountOut(in tensor.Tensor, out tensor.Values) error

CountOut computes the count of non-NaN tensor values. See StatsOutFunc for general information.

func CountOut64

func CountOut64(in tensor.Tensor, out tensor.Values) *tensor.Float64

CountOut64 computes the count of non-NaN tensor values, and returns the Float64 output values for subsequent use.

func Describe

func Describe(dir *tensorfs.Node, tsrs ...tensor.Tensor)

Describe adds standard descriptive statistics for given tensor to the given tensorfs directory, adding a directory for each tensor and result tensor stats for each result. This is an easy way to provide a comprehensive description of data. The DescriptiveStats list is: Count, Mean, Std, Sem, Min, Q1, Median, Q3, Max

func DescribeTable

func DescribeTable(dir *tensorfs.Node, dt *table.Table, columns ...string)

DescribeTable runs Describe on given columns in table.

func DescribeTableAll

func DescribeTableAll(dir *tensorfs.Node, dt *table.Table)

DescribeTableAll runs Describe on all numeric columns in given table.

func Final

func Final(in tensor.Tensor) tensor.Values

Final returns the final tensor value(s), as a stats function, for the ending point in a naturally-ordered set of data. See StatsFunc for general information.

func FinalOut

func FinalOut(in tensor.Tensor, out tensor.Values) error

FinalOut returns the first tensor value(s), as a stats function, for the ending point in a naturally-ordered set of data. See StatsOutFunc for general information.

func First

func First(in tensor.Tensor) tensor.Values

First returns the first tensor value(s), as a stats function, for the starting point in a naturally-ordered set of data. See StatsFunc for general information.

func FirstOut

func FirstOut(in tensor.Tensor, out tensor.Values) error

FirstOut returns the first tensor value(s), as a stats function, for the starting point in a naturally-ordered set of data. See StatsOutFunc for general information.

func GroupAll

func GroupAll(dir *tensorfs.Node, tsrs ...tensor.Tensor) error

GroupAll copies all indexes from the first given tensor, into an "All/All" tensor in the given tensorfs, which can then be used with GroupStats to generate summary statistics across all the data. See Groups for more general documentation.

func GroupDescribe

func GroupDescribe(dir *tensorfs.Node, tsrs ...tensor.Tensor) error

GroupDescribe runs standard descriptive statistics on given tensor data using GroupStats function, with DescriptiveStats list of stats.

func GroupStats

func GroupStats(dir *tensorfs.Node, stat Stats, tsrs ...tensor.Tensor) error

GroupStats computes the given stats function on the unique grouped indexes produced by the Groups function, in the given tensorfs directory, applied to each of the tensors passed here. It creates a "Stats" subdirectory in given directory, with subdirectories with the name of each value tensor (if it does not yet exist), and then creates a subdirectory within that for the statistic name. Within that statistic directory, it creates a String tensor with the unique values of each source Groups tensor, and a aligned Float64 tensor with the statistics results for each such unique group value. See the README.md file for a diagram of the results.

func GroupStatsAsTable

func GroupStatsAsTable(dir *tensorfs.Node) *table.Table

GroupStatsAsTable returns the results from GroupStats in given directory as a table.Table, using tensorfs.DirTable function.

func GroupStatsAsTableNoStatName

func GroupStatsAsTableNoStatName(dir *tensorfs.Node) *table.Table

GroupStatsAsTableNoStatName returns the results from GroupStats in given directory as a table.Table, using tensorfs.DirTable function. Column names are updated to not include the stat name, if there is only one statistic such that the resulting name will still be unique. Otherwise, column names are Value/Stat.

func Groups

func Groups(dir *tensorfs.Node, tsrs ...tensor.Tensor) error

Groups generates indexes for each unique value in each of the given tensors. One can then use the resulting indexes for the tensor.Rows indexes to perform computations restricted to grouped subsets of data, as in the GroupStats function. See [GroupCombined] for function that makes a "Combined" Group that has a unique group for each _combination_ of the separate, independent groups created by this function. It creates subdirectories in a "Groups" directory within given tensorfs, for each tensor passed in here, using the metadata Name property for names (index if empty). Within each subdirectory there are int tensors for each unique 1D row-wise value of elements in the input tensor, named as the string representation of the value, where the int tensor contains a list of row-wise indexes corresponding to the source rows having that value. Note that these indexes are directly in terms of the underlying [Tensor] data rows, indirected through any existing indexes on the inputs, so that the results can be used directly as Indexes into the corresponding tensor data. Uses a stable sort on columns, so ordering of other dimensions is preserved.

func L1Norm

func L1Norm(in tensor.Tensor) tensor.Values

L1Norm computes the sum of absolute-value-of tensor values. See StatsFunc for general information.

func L1NormOut

func L1NormOut(in tensor.Tensor, out tensor.Values) error

L1NormOut computes the sum of absolute-value-of tensor values. See StatsFunc for general information.

func L2Norm

func L2Norm(in tensor.Tensor) tensor.Values

L2Norm computes the square root of the sum of squares of tensor values, known as the L2 norm. See StatsFunc for general information.

func L2NormOut

func L2NormOut(in tensor.Tensor, out tensor.Values) error

L2NormOut computes the square root of the sum of squares of tensor values, known as the L2 norm. See StatsOutFunc for general information.

func L2NormOut64

func L2NormOut64(in tensor.Tensor, out tensor.Values) *tensor.Float64

L2NormOut64 computes the square root of the sum of squares of tensor values, known as the L2 norm, and returns the Float64 output values for use in subsequent computations.

func Max

func Max(in tensor.Tensor) tensor.Values

Max computes the max of tensor values. See StatsFunc for general information.

func MaxAbs

func MaxAbs(in tensor.Tensor) tensor.Values

MaxAbs computes the max of absolute-value-of tensor values. See StatsFunc for general information.

func MaxAbsOut

func MaxAbsOut(in tensor.Tensor, out tensor.Values) error

MaxAbsOut computes the max of absolute-value-of tensor values. See StatsOutFunc for general information.

func MaxOut

func MaxOut(in tensor.Tensor, out tensor.Values) error

MaxOut computes the max of tensor values. See StatsOutFunc for general information.

func Mean

func Mean(in tensor.Tensor) tensor.Values

Mean computes the mean of tensor values. See StatsFunc for general information.

func MeanOut

func MeanOut(in tensor.Tensor, out tensor.Values) error

MeanOut computes the mean of tensor values. See StatsOutFunc for general information.

func MeanOut64

func MeanOut64(in tensor.Tensor, out tensor.Values) (mean64, count64 *tensor.Float64)

MeanOut64 computes the mean of tensor values, and returns the Float64 output values for subsequent use.

func MeanTables added in v0.1.2

func MeanTables(dts []*table.Table) *table.Table

MeanTables returns a table.Table with the mean values across all float columns of the input tables, which must have the same columns but not necessarily the same number of rows.

func Median

func Median(in tensor.Tensor) tensor.Values

Median computes the median (50% quantile) of tensor values. See StatsFunc for general information.

func MedianOut

func MedianOut(in tensor.Tensor, out tensor.Values) error

MedianOut computes the median (50% quantile) of tensor values. See StatsFunc for general information.

func Min

func Min(in tensor.Tensor) tensor.Values

Min computes the min of tensor values. See StatsFunc for general information.

func MinAbs

func MinAbs(in tensor.Tensor) tensor.Values

MinAbs computes the min of absolute-value-of tensor values. See StatsFunc for general information.

func MinAbsOut

func MinAbsOut(in tensor.Tensor, out tensor.Values) error

MinAbsOut computes the min of absolute-value-of tensor values. See StatsOutFunc for general information.

func MinOut

func MinOut(in tensor.Tensor, out tensor.Values) error

MinOut computes the min of tensor values. See StatsOutFunc for general information.

func Prod

func Prod(in tensor.Tensor) tensor.Values

Prod computes the product of tensor values. See StatsFunc for general information.

func ProdOut

func ProdOut(in tensor.Tensor, out tensor.Values) error

ProdOut computes the product of tensor values. See StatsOutFunc for general information.

func Q1

func Q1(in tensor.Tensor) tensor.Values

Q1 computes the first quantile (25%) of tensor values. See StatsFunc for general information.

func Q1Out

func Q1Out(in tensor.Tensor, out tensor.Values) error

Q1Out computes the first quantile (25%) of tensor values. See StatsFunc for general information.

func Q3

func Q3(in tensor.Tensor) tensor.Values

Q3 computes the third quantile (75%) of tensor values. See StatsFunc for general information.

func Q3Out

func Q3Out(in tensor.Tensor, out tensor.Values) error

Q3Out computes the third quantile (75%) of tensor values. See StatsFunc for general information.

func Quantiles

func Quantiles(in, qs tensor.Tensor) tensor.Values

Quantiles returns the given quantile(s) of non-NaN elements in given 1D tensor. Because sorting uses indexes, this only works for 1D case. If needed for a sub-space of values, that can be extracted through slicing and then used. Logs an error if not 1D. qs are 0-1 values, 0 = min, 1 = max, .5 = median, etc. Uses linear interpolation. Because this requires a sort, it is more efficient to get as many quantiles as needed in one pass.

func QuantilesOut

func QuantilesOut(in, qs tensor.Tensor, out tensor.Values) error

QuantilesOut returns the given quantile(s) of non-NaN elements in given 1D tensor. Because sorting uses indexes, this only works for 1D case. If needed for a sub-space of values, that can be extracted through slicing and then used. Returns and logs an error if not 1D. qs are 0-1 values, 0 = min, 1 = max, .5 = median, etc. Uses linear interpolation. Because this requires a sort, it is more efficient to get as many quantiles as needed in one pass.

func Sem

func Sem(in tensor.Tensor) tensor.Values

Sem computes the sample standard error of the mean of tensor values. Standard deviation [StdFunc] / sqrt(n). See also [SemPopFunc]. See StatsFunc for general information.

func SemOut

func SemOut(in tensor.Tensor, out tensor.Values) error

SemOut computes the sample standard error of the mean of tensor values. Standard deviation [StdFunc] / sqrt(n). See also [SemPopFunc]. See StatsOutFunc for general information.

func SemPop

func SemPop(in tensor.Tensor) tensor.Values

SemPop computes the population standard error of the mean of tensor values. Standard deviation [StdPopFunc] / sqrt(n). See also [SemFunc]. See StatsFunc for general information.

func SemPopOut

func SemPopOut(in tensor.Tensor, out tensor.Values) error

SemPopOut computes the population standard error of the mean of tensor values. Standard deviation [StdPopFunc] / sqrt(n). See also [SemFunc]. See StatsOutFunc for general information.

func Std

func Std(in tensor.Tensor) tensor.Values

Std computes the sample standard deviation of tensor values. Sqrt of variance from [VarFunc]. See also [StdPopFunc]. See StatsFunc for general information.

func StdOut

func StdOut(in tensor.Tensor, out tensor.Values) error

StdOut computes the sample standard deviation of tensor values. Sqrt of variance from [VarFunc]. See also [StdPopFunc]. See StatsOutFunc for general information.

func StdOut64

func StdOut64(in tensor.Tensor, out tensor.Values) (std64, mean64, count64 *tensor.Float64)

StdOut64 computes the sample standard deviation of tensor values. and returns the Float64 output values for subsequent use.

func StdPop

func StdPop(in tensor.Tensor) tensor.Values

StdPop computes the population standard deviation of tensor values. Sqrt of variance from [VarPopFunc]. See also [StdFunc]. See StatsFunc for general information.

func StdPopOut

func StdPopOut(in tensor.Tensor, out tensor.Values) error

StdPopOut computes the population standard deviation of tensor values. Sqrt of variance from [VarPopFunc]. See also [StdFunc]. See StatsOutFunc for general information.

func StripPackage

func StripPackage(name string) string

StripPackage removes any package name from given string, used for naming based on FuncName() which could be custom or have a package prefix.

func Sum

func Sum(in tensor.Tensor) tensor.Values

Sum computes the sum of tensor values. See StatsFunc for general information.

func SumOut

func SumOut(in tensor.Tensor, out tensor.Values) error

SumOut computes the sum of tensor values. See StatsOutFunc for general information.

func SumOut64

func SumOut64(in tensor.Tensor, out tensor.Values) *tensor.Float64

SumOut64 computes the sum of tensor values, and returns the Float64 output values for subsequent use.

func SumSq

func SumSq(in tensor.Tensor) tensor.Values

SumSq computes the sum of squares of tensor values, See StatsFunc for general information.

func SumSqDevOut64

func SumSqDevOut64(in tensor.Tensor, out tensor.Values) (ssd64, mean64, count64 *tensor.Float64)

SumSqDevOut64 computes the sum of squared mean deviates of tensor values, and returns the Float64 output values for subsequent use.

func SumSqOut

func SumSqOut(in tensor.Tensor, out tensor.Values) error

SumSqOut computes the sum of squares of tensor values, See StatsOutFunc for general information.

func SumSqOut64

func SumSqOut64(in tensor.Tensor, out tensor.Values) *tensor.Float64

SumSqOut64 computes the sum of squares of tensor values, and returns the Float64 output values for subsequent use.

func SumSqScaleOut64

func SumSqScaleOut64(in tensor.Tensor) (scale64, ss64 *tensor.Float64)

SumSqScaleOut64 is a helper for sum-of-squares, returning scale and ss factors aggregated separately for better numerical stability, per BLAS. Returns the Float64 output values for subsequent use.

func TableGroupDescribe

func TableGroupDescribe(dir *tensorfs.Node, dt *table.Table, columns ...string) error

TableGroupDescribe runs GroupDescribe on the given columns from given table.Table.

func TableGroupStats

func TableGroupStats(dir *tensorfs.Node, stat Stats, dt *table.Table, columns ...string) error

TableGroupStats runs GroupStats using standard Stats on the given columns from given table.Table.

func TableGroups

func TableGroups(dir *tensorfs.Node, dt *table.Table, columns ...string) error

TableGroups runs Groups on the given columns from given table.Table.

func UnitNorm

func UnitNorm(a tensor.Tensor) tensor.Values

UnitNorm computes unit normalized values into given output tensor, subtracting the Min value and dividing by the Max of the remaining numbers.

func UnitNormOut

func UnitNormOut(a tensor.Tensor, out tensor.Values) error

UnitNormOut computes unit normalized values into given output tensor, subtracting the Min value and dividing by the Max of the remaining numbers.

func Var

func Var(in tensor.Tensor) tensor.Values

Var computes the sample variance of tensor values. Squared deviations from mean, divided by n-1. See also [VarPopFunc]. See StatsFunc for general information.

func VarOut

func VarOut(in tensor.Tensor, out tensor.Values) error

VarOut computes the sample variance of tensor values. Squared deviations from mean, divided by n-1. See also [VarPopFunc]. See StatsOutFunc for general information.

func VarOut64

func VarOut64(in tensor.Tensor, out tensor.Values) (var64, mean64, count64 *tensor.Float64)

VarOut64 computes the sample variance of tensor values, and returns the Float64 output values for subsequent use.

func VarPop

func VarPop(in tensor.Tensor) tensor.Values

VarPop computes the population variance of tensor values. Squared deviations from mean, divided by n. See also [VarFunc]. See StatsFunc for general information.

func VarPopOut

func VarPopOut(in tensor.Tensor, out tensor.Values) error

VarPopOut computes the population variance of tensor values. Squared deviations from mean, divided by n. See also [VarFunc]. See StatsOutFunc for general information.

func VarPopOut64

func VarPopOut64(in tensor.Tensor, out tensor.Values) (var64, mean64, count64 *tensor.Float64)

VarPopOut64 computes the population variance of tensor values. and returns the Float64 output values for subsequent use.

func Vectorize2Out64

func Vectorize2Out64(in tensor.Tensor, iniX, iniY float64, fun func(val, ox, oy float64) (float64, float64)) (ox64, oy64 *tensor.Float64)

Vectorize2Out64 is a version of VectorizeOut64 that separately aggregates two output values, x and y as tensor.Float64.

func VectorizeOut64

func VectorizeOut64(in tensor.Tensor, out tensor.Values, ini float64, fun func(val, agg float64) float64) *tensor.Float64

VectorizeOut64 is the general compute function for stats. This version makes a Float64 output tensor for aggregating and computing values, and then copies the results back to the original output. This allows stats functions to operate directly on integer valued inputs and produce sensible results. It returns the Float64 output tensor for further processing as needed.

func VectorizePreOut64

func VectorizePreOut64(in tensor.Tensor, out tensor.Values, ini float64, pre *tensor.Float64, fun func(val, pre, agg float64) float64) *tensor.Float64

VectorizePreOut64 is a version of VectorizeOut64 that takes an additional tensor.Float64 input of pre-computed values, e.g., the means of each output cell.

func ZScore

func ZScore(a tensor.Tensor) tensor.Values

ZScore computes Z-normalized values into output tensor, subtracting the Mean and dividing by the standard deviation.

func ZScoreOut

func ZScoreOut(a tensor.Tensor, out tensor.Values) error

ZScore computes Z-normalized values into given output tensor, subtracting the Mean and dividing by the standard deviation.

Types

type Stats

type Stats int32 //enums:enum -trim-prefix Stat

Stats is a list of different standard aggregation functions, which can be used to choose an aggregation function

const (
	// count of number of elements.
	StatCount Stats = iota

	// sum of elements.
	StatSum

	// L1 Norm: sum of absolute values of elements.
	StatL1Norm

	// product of elements.
	StatProd

	// minimum value.
	StatMin

	// maximum value.
	StatMax

	// minimum of absolute values.
	StatMinAbs

	// maximum of absolute values.
	StatMaxAbs

	// mean value = sum / count.
	StatMean

	// sample variance (squared deviations from mean, divided by n-1).
	StatVar

	// sample standard deviation (sqrt of Var).
	StatStd

	// sample standard error of the mean (Std divided by sqrt(n)).
	StatSem

	// sum of squared values.
	StatSumSq

	// L2 Norm: square-root of sum-of-squares.
	StatL2Norm

	// population variance (squared diffs from mean, divided by n).
	StatVarPop

	// population standard deviation (sqrt of VarPop).
	StatStdPop

	// population standard error of the mean (StdPop divided by sqrt(n)).
	StatSemPop

	// middle value in sorted ordering.
	StatMedian

	// Q1 first quartile = 25%ile value = .25 quantile value.
	StatQ1

	// Q3 third quartile = 75%ile value = .75 quantile value.
	StatQ3

	// first item in the set of data: for data with a natural ordering.
	StatFirst

	// final item in the set of data: for data with a natural ordering.
	StatFinal
)
const StatsN Stats = 22

StatsN is the highest valid value for type Stats, plus one.

func StatsValues

func StatsValues() []Stats

StatsValues returns all possible values for the type Stats.

func (Stats) Call

func (s Stats) Call(in tensor.Tensor) tensor.Values

Call calls this statistic function on given tensors. returning output as a newly created tensor.

func (Stats) Desc

func (i Stats) Desc() string

Desc returns the description of the Stats value.

func (Stats) Func

func (s Stats) Func() StatsFunc

Func returns function for given stat.

func (Stats) FuncName

func (s Stats) FuncName() string

FuncName returns the package-qualified function name to use in tensor.Call to call this function.

func (Stats) Int64

func (i Stats) Int64() int64

Int64 returns the Stats value as an int64.

func (Stats) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (*Stats) SetInt64

func (i *Stats) SetInt64(in int64)

SetInt64 sets the Stats value from an int64.

func (*Stats) SetString

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

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

func (Stats) String

func (i Stats) String() string

String returns the string representation of this Stats value.

func (*Stats) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Stats) Values

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

Values returns all possible values for the type Stats.

type StatsFunc

type StatsFunc = func(in tensor.Tensor) tensor.Values

StatsFunc is the function signature for a stats function that returns a new output vector. This can be less efficient for repeated computations where the output can be re-used: see StatsOutFunc. But this version can be directly chained with other function calls. Function is computed over the outermost row dimension and the output is the shape of the remaining inner cells (a scalar for 1D inputs). Use tensor.As1D, tensor.NewRowCellsView, tensor.Cells1D etc to reshape and reslice the data as needed. All stats functions skip over NaN's, as a missing value. Stats functions cannot be computed in parallel, e.g., using VectorizeThreaded or GPU, due to shared writing to the same output values. Special implementations are required if that is needed.

func AsStatsFunc

func AsStatsFunc(fun any) (StatsFunc, error)

AsStatsFunc returns given function as a StatsFunc function, or an error if it does not fit that signature.

type StatsOutFunc

type StatsOutFunc = func(in tensor.Tensor, out tensor.Values) error

StatsOutFunc is the function signature for a stats function, that takes output values as final argument. See StatsFunc This version is for computationally demanding cases and saves reallocation of output.

Jump to

Keyboard shortcuts

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