gomathlib

package module
v0.0.0-...-4871bd4 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

README

Go Math Library

Collection of several mathematical functions and data structures. Find a list of supported functions below:

Number Theory

  • Totient function
  • Möbius function
  • Greatest Common Divisor
  • Prime Factorization, Prime Factor Exponent

Stack Data Structure

  • First-In-First-Out (FIFO)

Image Processing

This section lists functions applied on matrices (provided by gonum.org/v1/gonum/mat) for image manipulation:

  • Average Filter
  • Gauss Filter

Data Scalers

List of scalers for data:

  • MinMaxScaler
  • StandardScaler
  • Limiter (to cap values between min and max)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GCD

func GCD(a int, b int) int

GCD calculates the greatest common divisor of two given numbers

func Moebius

func Moebius(n int) int

Implementation of the Möbius function. Returns +1 if n is a square-free positive integer with an even number of prime factors, -1 if n is a square-free positive integer with an odd number of prime factors, 0 if n has a squared prime factor.

func NewMatrixWithValue

func NewMatrixWithValue(nrows, ncols int, fillValue float64) *mat.Dense

NewMatrixWithValue returns a new matrix populated with a specific value.

func PrimeFactorExponent

func PrimeFactorExponent(n int, p int) int

PrimeFactorExponent calculates how many times a prime `p` exists in the factorization of a given number `n`.

func PrimeFactorization

func PrimeFactorization(n int) []int

PrimeFactorization return an array of the prime factors of the number n.

func Totient

func Totient(n int) []int

Totient implements Euler's totient function (Euler's Phi Function) to find all numbers which are coprime to n (starting at 1 to n).

Types

type AverageFilter

type AverageFilter struct {
	// contains filtered or unexported fields
}

#region Average Filter

func NewAverageFilter

func NewAverageFilter(k int) *AverageFilter

NewAverageFilter constructs a kernel of size 2*k+1, resulting in a filter matrix of size (2k+1)x(2k+1).

func (*AverageFilter) Apply

func (f *AverageFilter) Apply(data *mat.Dense) *mat.Dense

type FIFOStack

type FIFOStack[T any] struct {
	// contains filtered or unexported fields
}

FIFOStack provides an implementation of a First-In-First-Out (FIFO) data structure.

func NewFIFOStack

func NewFIFOStack[T any](maxSize int) *FIFOStack[T]

NewFIFOStack initializes a new stack with the given maximum number of elements (maxSize).

func (*FIFOStack[T]) Clear

func (s *FIFOStack[T]) Clear()

Clear removes all elements from the stack.

func (*FIFOStack[T]) Elements

func (s *FIFOStack[T]) Elements() []*T

Elements returns the stacked elements in correct order.

func (*FIFOStack[T]) IsFull

func (s *FIFOStack[T]) IsFull() bool

IsFull returns true when no nil-elements are in the stack.

func (*FIFOStack[T]) Push

func (s *FIFOStack[T]) Push(data *T)

Push adds the new element to the stack and enforces the maxSize limit by removing the last item.

func (*FIFOStack[T]) Size

func (s *FIFOStack[T]) Size() int

Size returns the number of non-nil elements in the stack.

type Filter

type Filter interface {
	Apply(data *mat.Dense) *mat.Dense
}

type GaussianFilter

type GaussianFilter struct {
	// contains filtered or unexported fields
}

#region GaussianFilter

func NewGaussianFilter

func NewGaussianFilter(k int, sigma *float64) *GaussianFilter

NewGaussianFilter constructs a gauss kernel of size 2*k+1, resulting in a filter matrix of size (2k+1)x(2k+1).

func (*GaussianFilter) Apply

func (f *GaussianFilter) Apply(data *mat.Dense) *mat.Dense

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter(min, max float64) *Limiter

func (*Limiter) Fit

func (s *Limiter) Fit(data []float64)

func (*Limiter) GetParam

func (s *Limiter) GetParam(key string) *float64

func (*Limiter) InverseTransform

func (s *Limiter) InverseTransform(v float64) float64

InverseTransform of the limiter is incapable of reversing the transformation, thus returning the input value.

func (*Limiter) Transform

func (s *Limiter) Transform(v float64) float64

type MinMaxScaler

type MinMaxScaler struct {
	// contains filtered or unexported fields
}

#region MinMaxScaler

func NewMinMaxScaler

func NewMinMaxScaler() *MinMaxScaler

NewMinMaxScaler returns a new instance of the MinMaxScaler.

func (*MinMaxScaler) Fit

func (s *MinMaxScaler) Fit(data []float64)

func (*MinMaxScaler) GetParam

func (s *MinMaxScaler) GetParam(key string) *float64

func (*MinMaxScaler) InverseTransform

func (s *MinMaxScaler) InverseTransform(v float64) float64

func (*MinMaxScaler) Transform

func (s *MinMaxScaler) Transform(v float64) float64

type Scaler

type Scaler interface {
	Fit(data []float64)                 // Fit the scaler to the data
	Transform(v float64) float64        // Scale the data.
	InverseTransform(v float64) float64 // Unscale the data.
	GetParam(key string) *float64       // Returns the parameter for the given key, and nil if the parameter does not exist.
}

type StandardScaler

type StandardScaler struct {
	// contains filtered or unexported fields
}

#region StandardScaler

func NewStandardScaler

func NewStandardScaler() *StandardScaler

StandardScaler returns a new instance of the StandardScaler.

func (*StandardScaler) Fit

func (s *StandardScaler) Fit(data []float64)

func (*StandardScaler) GetParam

func (s *StandardScaler) GetParam(key string) *float64

func (*StandardScaler) InverseTransform

func (s *StandardScaler) InverseTransform(v float64) float64

func (*StandardScaler) Transform

func (s *StandardScaler) Transform(v float64) float64

Jump to

Keyboard shortcuts

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