maths

package
v0.0.0-...-628071f Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2012 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

The maths package provides a number of mathematical-related helpers:

distributions.go provides basic distribution-generating functions that are used primarily in testing contexts.

helpers_for_testing.go provides a testing assistents for this package and its dependents.

maths_test.go provides a test suite for all tests in the maths package hierarchy. It employs the gocheck framework for test scaffolding.

statistics.go provides basic summary statistics functions for the purpose of metrics aggregation.

statistics_test.go provides a test complement for the statistics.go module.

Index

Constants

This section is empty.

Variables

View Source
var IsNaN Checker = &isNaNChecker{
	&CheckerInfo{Name: "IsNaN", Params: []string{"value"}},
}

This piece provides a simple tester for the gocheck testing library to ascertain if a value is not-a-number.

Functions

func BinomialPDF

func BinomialPDF(k, n int, p float64) float64

Create calculate the value of a probability density for a given binomial statistic, where k is the target count of true cases, n is the number of subjects, and p is the probability.

func Factorial

func Factorial(of int) int64

Go's standard library does not offer a factorial function.

func NearestRank

func NearestRank(input []float64, percentile float64) float64

Calculate the percentile by choosing the nearest neighboring value.

Types

type ReductionMethod

type ReductionMethod func([]float64) float64

ReductionMethod provides a method for reducing metrics into a given scalar value.

var Average ReductionMethod = func(input []float64) float64 {
	count := 0.0
	sum := 0.0

	for _, v := range input {
		sum += v
		count++
	}

	if count == 0 {
		return math.NaN()
	}

	return sum / count
}
var FirstMode ReductionMethod = func(input []float64) float64 {
	valuesToFrequency := map[float64]int64{}
	var largestTally int64 = math.MinInt64
	var largestTallyValue float64 = math.NaN()

	for _, v := range input {
		presentCount, _ := valuesToFrequency[v]
		presentCount++

		valuesToFrequency[v] = presentCount

		if presentCount > largestTally {
			largestTally = presentCount
			largestTallyValue = v
		}
	}

	return largestTallyValue
}

Extract the first modal value.

var Maximum ReductionMethod = func(input []float64) float64 {
	var maximum float64 = math.SmallestNonzeroFloat64

	for _, v := range input {
		maximum = math.Max(maximum, v)
	}

	return maximum
}
var Minimum ReductionMethod = func(input []float64) float64 {
	var minimum float64 = math.MaxFloat64

	for _, v := range input {
		minimum = math.Min(minimum, v)
	}

	return minimum
}

func NearestRankReducer

func NearestRankReducer(percentile float64) ReductionMethod

Generate a ReductionMethod based off of extracting a given percentile value.

Jump to

Keyboard shortcuts

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