matrix

package module
v0.0.0-...-79d8c49 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: BSD-3-Clause Imports: 5 Imported by: 23

Documentation

Index

Constants

View Source
const (
	// S is the scaling factor for the softmax
	S = 1.0 - 1e-300
	// LFSRMask is a LFSR mask with a maximum period
	LFSRMask = 0x80000057
)

Variables

View Source
var Iris = [150][5]float32{}/* 150 elements not displayed */

Iris is the iris dataset

View Source
var IrisNames = map[float32]string{
	0: "Iris-setosa",
	1: "Iris-versicolor",
	2: "Iris-virginica",
}

IrisNames is the names of the flowers

Functions

func LinearRegression

func LinearRegression(x, y Matrix) (b0, b1 float64)

LinearRegression computes linear regression https://www.geeksforgeeks.org/linear-regression-python-implementation/

func MetaGMM

func MetaGMM(input Matrix, clusters int) []int

func SelfEntropy

func SelfEntropy(Q, K, V Matrix) []float32

SelfEntropy computes the self entropy of Q, K, V

func SelfEntropy64

func SelfEntropy64(Q, K, V Matrix) []float64

SelfEntropy64 computes the self entropy of Q, K, V

Types

type ComplexMatrix

type ComplexMatrix struct {
	Cols int
	Rows int
	Data []complex128
}

ComplexMatrix is a complex128 matrix

func ComplexSelfAttention

func ComplexSelfAttention(Q, K, V ComplexMatrix) ComplexMatrix

ComplexSelfAttention computes the self attention of Q, K, V

func NewComplexMatrix

func NewComplexMatrix(cols, rows int, data ...complex128) ComplexMatrix

NewComplexMatrix creates a new complex128 matrix

func (ComplexMatrix) T

T tramsposes a matrix

type CompressedGenerator

type CompressedGenerator struct {
	Distribution CompressedRandomMatrix
	Seed         uint32
}

CompressedGenerator generates a matrix by sampling from a probability distribution

func (CompressedGenerator) Sample

func (g CompressedGenerator) Sample() Matrix

Sample samples a matrix

func (CompressedGenerator) Sparse

func (g CompressedGenerator) Sparse() Matrix

Sample samples a matrix

func (CompressedGenerator) Uniform

func (g CompressedGenerator) Uniform() Matrix

Sample samples a matrix

type CompressedRandomMatrix

type CompressedRandomMatrix struct {
	Cols int
	Rows int
	Data Random
}

CompressedRandomMatrix is a compressed random matrix

func NewCompressedRandomMatrix

func NewCompressedRandomMatrix(cols, rows int) CompressedRandomMatrix

NewCompressedRandomMatrix returns a new compressed random matrix

func (CompressedRandomMatrix) Sample

Sample samples a matrix

func (CompressedRandomMatrix) SampleDiscrete

func (r CompressedRandomMatrix) SampleDiscrete(rng *Rand) Matrix

SampleDiscrete generates a discrete matrix sample

type GMM

type GMM struct {
	Optimizer
	Clusters int
}

GMMO is an optimizer based gmm

func (*GMM) Optimize

func (g *GMM) Optimize(input Matrix) []int

type Generator

type Generator struct {
	Distribution RandomMatrix
	Seed         uint32
}

Generator generates a matrix by sampling from a probability distribution

func (Generator) Sample

func (g Generator) Sample() Matrix

Sample samples a matrix

type Matrix

type Matrix struct {
	Cols int
	Rows int
	Data []float32
}

Matrix is a float32 matrix

func NewCoord

func NewCoord(cols, rows int) Matrix

NewCoord creates a new coordinate

func NewIdentityMatrix

func NewIdentityMatrix(size int) Matrix

NewIdentityMatrix creates a new float32 identity matrix of zeros

func NewMatrix

func NewMatrix(cols, rows int, data ...float32) Matrix

NewMatrix creates a new float32 matrix

func NewZeroMatrix

func NewZeroMatrix(cols, rows int) Matrix

NewZeroMatrix creates a new float32 matrix of zeros

func SelfAttention

func SelfAttention(Q, K, V Matrix) Matrix

SelfAttention computes the self attention of Q, K, V

func (Matrix) Add

func (m Matrix) Add(n Matrix) Matrix

Add adds two float32 matrices

func (Matrix) Avg

func (m Matrix) Avg() Matrix

Avg computes the avg of a matrix

func (Matrix) Determinant

func (m Matrix) Determinant() (float64, error)

Determinant calculates the determinant of a matrix

func (Matrix) Everett

func (m Matrix) Everett() Matrix

Everett is the everett activation function

func (Matrix) H

func (m Matrix) H(n Matrix) Matrix

H is the hadamard product of two matricies

func (Matrix) Inverse

func (m Matrix) Inverse(rng *Rand) (ai Matrix)

Inverse computes the matrix inverse

func (Matrix) LU

func (m Matrix) LU() (Matrix, Matrix)

LU lower upper decomposition https://www.geeksforgeeks.org/doolittle-algorithm-lu-decomposition/

func (Matrix) Mul

func (m Matrix) Mul(n Matrix) Matrix

Mul is regular matrix multiplication

func (Matrix) MulT

func (m Matrix) MulT(n Matrix) Matrix

MulT multiplies two matrices and computes the transpose

func (Matrix) Normalize

func (m Matrix) Normalize() Matrix

Normalize normalizes a matrix to the unit vector

func (Matrix) Quadratic

func (m Matrix) Quadratic(n Matrix) Matrix

Quadratic computes the quadratic loss of two matrices

func (Matrix) QuadraticSet

func (m Matrix) QuadraticSet(n Matrix, set []int) Matrix

QuadraticSet computes the quadratic loss of sub sets of two matrices

func (Matrix) Sigmoid

func (m Matrix) Sigmoid() Matrix

Sigmoid computes the sigmoid of a matrix

func (Matrix) Size

func (m Matrix) Size() int

Size is the size of the float32 matrix

func (Matrix) Slice

func (m Matrix) Slice(begin, end int) Matrix

Slice slices a matrix

func (Matrix) Step

func (m Matrix) Step() Matrix

Step computes the step function of a float32 matrix

func (Matrix) String

func (m Matrix) String() string

String returns a string for the matrix

func (Matrix) Sub

func (m Matrix) Sub(n Matrix) Matrix

Sub subtracts two float32 matrices

func (Matrix) T

func (m Matrix) T() Matrix

T tramsposes a matrix

func (Matrix) TaylorSoftmax

func (m Matrix) TaylorSoftmax() Matrix

TaylorSoftmax is the taylor softmax https://arxiv.org/abs/1511.05042

type Multi

type Multi struct {
	E Matrix
	U Matrix
	A Matrix
}

Multi is a multivariate distribution

func NewMulti

func NewMulti(vars int) Multi

NewMulti make a new multi

func NewMultiFromData

func NewMultiFromData(vars Matrix) Multi

NewMultiFromData creates a new multivariate distribution

func (*Multi) LearnA

func (m *Multi) LearnA(rng *Rand, debug *[]float32)

LearnA factors a matrix into AA^T

func (Multi) Sample

func (m Multi) Sample(rng *Rand) Matrix

Sample samples from the multivariate distribution

type Net

type Net struct {
	Optimizer
}

Net is a net

func NewNet

func NewNet(seed uint32, inputs, outputs int) Net

NewNet makes a new network

func (*Net) Fire

func (n *Net) Fire(query, key, value Matrix) (float64, Matrix, Matrix, Matrix)

Fire runs the network

type Optimizer

type Optimizer struct {
	N      int
	Length int
	Scale  float64
	Rng    *Rand
	Vars   [][3]RandomMatrix
	Cost   func(samples []Sample, a ...Matrix)
	Reg    bool
	Norm   bool
}

Optimizer is an optimizer

func NewOptimizer

func NewOptimizer(rng *Rand, n int, scale float64, vars int,
	cost func(samples []Sample, a ...Matrix), a ...Matrix) Optimizer

NewOptimizer creates a new optimizer

func (*Optimizer) Iterate

func (o *Optimizer) Iterate(a ...Matrix) Sample

func (*Optimizer) Optimize

func (o *Optimizer) Optimize(dx float64) Sample

Optimize optimizes a cost function

type Rand

type Rand uint32

Rand is a random number generator

func (*Rand) Float64

func (r *Rand) Float64() float64

Float64 generates a uniform float64

func (*Rand) NormFloat64

func (r *Rand) NormFloat64() float64

NormFloat64 returns a normally distributed float64 in the range -math.MaxFloat64 through +[math.MaxFloat64] inclusive, with standard normal distribution (mean = 0, stddev = 1). To produce a different normal distribution, callers can adjust the output using:

sample = NormFloat64() * desiredStdDev + desiredMean

func (*Rand) Uint32

func (r *Rand) Uint32() uint32

Uint32 returns the next random number

type Random

type Random struct {
	Mean   float64
	StdDev float64
}

Random is a random variable

type RandomMatrix

type RandomMatrix struct {
	Cols int
	Rows int
	Data []Random
}

RandomMatrix is a random matrix

func NewRandomMatrix

func NewRandomMatrix(cols, rows int) RandomMatrix

NewRandomMatrix returns a new random matrix

func (RandomMatrix) Sample

func (r RandomMatrix) Sample(rng *Rand) Generator

Sample samples a matrix

func (RandomMatrix) SampleDiscrete

func (r RandomMatrix) SampleDiscrete(rng *Rand) Matrix

SampleDiscrete generates a discrete matrix sample

type Sample

type Sample struct {
	Cost float64
	Vars [][3]Generator
}

Sample is a sample of the optimizer

func Meta

func Meta(metaSamples int, metaMin, metaScale float64, rng *Rand, n int, scale float64, vars int, reg bool,
	cost func(samples []Sample, a ...Matrix), a ...Matrix) Sample

Meta is the meta optimizer

Directories

Path Synopsis
cmd
lfsr command

Jump to

Keyboard shortcuts

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