utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Overview

Package utils contains subpackages for independence tests (e.g. Chi-Square) and clustering (e.g. K-Means), and also contains VarData, String Concat and Union-Find.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogZero = ln(0) = -inf
	LogZero float64
	EpsZero float64
)

Functions

func AntiLog

func AntiLog(l float64) float64

AntiLog is the antilog with base e of l. It is equivalent to e raised to the power of l. Thus the following identities apply

antiln(ln(k)) = k
ln(antiln(k)) = k

Returns a float64 that corresponds to the antilog of l.

func Inf

func Inf(sig int) float64

Inf is a typedef for math.Inf.

func Log

func Log(p float64) float64

Log is a typedef for math.Log.

func LogProd

func LogProd(p []float64) float64

LogProd is the log of the product of probabilities given by

prod_i p_i -> sum_i ln(p_i)

Returns a float64 with the resulting log operation. To convert back use utils.AntiLog.

func LogSum

func LogSum(p []float64) float64

LogSum is the log of the sum of probabilities given by

sum_i p_i -> P + ln(sum_i e^(ln(p_i) - P)), where P = max_i ln(p_i)

Returns a float64 with the resulting log operation. To convert back use utils.AntiLog.

func LogSumExp

func LogSumExp(a []float64) float64

LogSumExp takes a slice of floats a={a_1,...,a_n} and computes ln(exp(a_1)+...+exp(a_n)).

func LogSumExpPair

func LogSumExpPair(l, r float64) float64

LogSumExpPair takes two floats l and r and computes ln(l+r). Particular case of LogSumExp.

func LogSumLog

func LogSumLog(v []float64, s []int) (float64, int)

LogSumLog is a function to compute the log of sum of logs.

func LogSumPair

func LogSumPair(p1, p2 float64) float64

LogSumPair is the result of the operation:

ln(p1+p2)=ln(p1)+ln(1+p2/p1)

func Mean

func Mean(c []int) float64

Mean returns the mean of a slice.

func MuSigma

func MuSigma(c []int) (float64, float64)

MuSigma returns both the mean and standard deviation of a slice.

func PartitionQuantiles

func PartitionQuantiles(X []int, m int) [][]float64

PartitionQuantiles takes a slice of values X of a single variable from the dataset and the number m of quantiles to partition the data. Returns a slice of pair of values containing mean and standard deviation (in this order).

func StdDev

func StdDev(c []int) float64

StdDev returns the standard deviation of a slice.

func StringConcat

func StringConcat(s1, s2 string) string

StringConcat concatenates two strings.

func Trim

func Trim(a []float64, c float64) []float64

Trim removes elements from a slice of floats that have the same value as c.

func UFVarids

func UFVarids(x *UFNode) []int

UFVarids returns a slice with all varids in union-find tree x.

Types

type UFNode

type UFNode struct {

	// Pa is Parent of UFNode. Since we use the Path-compression heuristic, this is usually the
	// representative of the set (i.e. the root node).
	Pa *UFNode

	// Children.
	Ch []*UFNode
	// contains filtered or unexported fields
}

UFNode is a Union-Find node on a Union-Find tree. Holds an integer as value. In this case we wish to store the variable ID.

func Find

func Find(x *UFNode) *UFNode

Find returns the representative of x's set.

func MakeSet

func MakeSet(varid int) *UFNode

MakeSet creates a unary set with varid as representative of the resulting set.

func Union

func Union(x, y *UFNode) (*UFNode, int)

Union takes the sets S_1 and S_2, where x is in S_1 and y is in S_2 and unifies S_1 with S_2, returning the union's representative. Returns the union set and 1 if the first argument is the new representative or 2 if the second.

type VarData

type VarData struct {
	// Variable ID.
	Varid int
	// Number of possible instantiations (levels/categories) of Varid.
	Categories int
	// Observed data.
	Data []int
}

VarData is a wrapper struct that contains a variable ID and its observed data. Observed data is data that is to be used in learning. Each data instance i in data (i.e. data[i]) is a variable instantiation.

func NewVarData

func NewVarData(varid, categories int, data []int) *VarData

NewVarData constructs a new VarData. Equivalent to &VarData{varid, categories, data}.

Directories

Path Synopsis
Package cluster contains clustering algorithms.
Package cluster contains clustering algorithms.
metrics
Package metrics contains distance metrics (e.g.
Package metrics contains distance metrics (e.g.
Package indep contains independence test algorithms (e.g.
Package indep contains independence test algorithms (e.g.

Jump to

Keyboard shortcuts

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