lialg

package
v0.0.0-...-e0f4d7c Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompAllClose

func CompAllClose(matrix1, matrix2 Matrix, tolerance float64) bool

tests if two matrices are the same within the given tolerance

similar to this numpy function: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html

func CompDiagonalClose

func CompDiagonalClose(matrix1, matrix2 Matrix, tolerance float64) bool

tests if the diagonal of two quadratic matrices is almost same within given tolerance

func CosineSimilarity

func CosineSimilarity(vec1 Matrix, vec2 Matrix) float64

Calculate cosine similarity between two vectors

func EuclideanDistance

func EuclideanDistance(x, y []float64) float64

Calculates the Euclidian Distance between two vectors

func EuclideanNorm

func EuclideanNorm(x []float64) float64

Calculates Euclidian Norm of Vector

also known as 2-Norm

func RbfKernel

func RbfKernel(x1 []float64, x2 []float64, sigma float64) float64

using the popular rbfKernel (https://en.wikipedia.org/wiki/Radial_basis_function_kernel)

is necessary for the kernel regression and many parts of the algorithms

func SumNorm

func SumNorm(x []float64) float64

Calculates Sum Norm of Vector

also known as 1-Norm

Types

type Eigen

type Eigen struct {
	Values  []float64
	Vectors []Matrix
}

type Matrix

type Matrix struct {
	N, M   int
	Matrix [][]float64
}

N represents the number of columns (so that a vector can be in one array)

M represents the number rows (e.g. dimension of a vector)

func BackwardsSubstitution

func BackwardsSubstitution(matrix *Matrix, vector *Matrix) Matrix

func ComponentWiseMultiplication

func ComponentWiseMultiplication(matrix1, matrix2 Matrix) Matrix

Multiply each element of matrix1 with the coresponding element of matrix2

func CreateAllOnesVector

func CreateAllOnesVector(n int) Matrix

func CreateIdentity

func CreateIdentity(n int) Matrix

creates the n x n identity matrix

func MatrixAddition

func MatrixAddition(matrix1, matrix2 Matrix) Matrix

add the matrices component wise

func MatrixMultiplication

func MatrixMultiplication(matrix1, matrix2 Matrix) Matrix

Basic Matrix Multiplication

func MatrixSubtraction

func MatrixSubtraction(matrix1, matrix2 Matrix) Matrix

subtract the matrices component wise

func NewMatrix

func NewMatrix(n, m int) *Matrix

constructor for Matrix

makes it easier to create the Matrix array

func QPSolve

func QPSolve(D, d Matrix) Matrix

Use the following library https://github.com/badgerodon/quadprog as current solution

might write my own byndings to https://doc.cgal.org/latest/QP_solver/index.html

func SliceToDiagonalMatrix

func SliceToDiagonalMatrix(x []float64) Matrix

convert slice to diagonal Matrix

func (*Matrix) AddDiagonal

func (matrix *Matrix) AddDiagonal(a float64)

adds a component to each diagonal element of matrix

ensure that matrix is quadratic

func (*Matrix) CalculateEigen

func (matrix *Matrix) CalculateEigen() Eigen

Calculate Eigen uses the QR Algorithm to calculate the eigenvalues (Schur Factorization) and the Eigenvectors by solving (A - eigenValue * I) * x = 0 for each eigenvalue

func (*Matrix) CalculateKernelMatrix

func (pointsX *Matrix) CalculateKernelMatrix(pointsY Matrix, sigma float64) Matrix

Applies the Kernel function to every component of the matrix

func (*Matrix) CalculateKernelVector

func (pointsX *Matrix) CalculateKernelVector(point []float64, sigma float64) Matrix

Applies the Kernel function on every component of the vector

func (*Matrix) DiagonalMatrixToSlice

func (matrix *Matrix) DiagonalMatrixToSlice() []float64

convert diagonal Matrix to slice

func (*Matrix) DiagonalMatrixToVector

func (matrix *Matrix) DiagonalMatrixToVector() Matrix

Converts a Diagonal Matrix to a Matrix with N=1

func (Matrix) Inverse

func (matrix Matrix) Inverse() Matrix

calculates the multiplicative Inverse of the matrix, using the Gauss Jordan Algorithm

to keep the complexity in check, this function can only be performed on symmetric matrices

implementation based on this article: https://www.codesansar.com/numerical-methods/python-program-inverse-matrix-using-gauss-jordan.htm

func (*Matrix) InverseDiagonal

func (matrix *Matrix) InverseDiagonal() Matrix

Calculate the Inverse of a DiagonalMatrix

since the inverse of a diagonal matrix can easily be computed by inverting each entry, this function can be used for efficiency

func (*Matrix) MatrixScalarMultiplication

func (matrix *Matrix) MatrixScalarMultiplication(scalar float64) Matrix

Multiply all elements of the matrix with the scalar

func (*Matrix) QrDecomposition

func (matrix *Matrix) QrDecomposition() (Matrix, Matrix)

calculating the QR-Decomposition using the Householder Transformation

Explanation can be found here: https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections

func (*Matrix) SubDiagonal

func (matrix *Matrix) SubDiagonal(a float64)

subtracts a component to each diagonal element of matrix

ensure that matrix is quadratic

func (*Matrix) TransposeMatrix

func (matrix *Matrix) TransposeMatrix() Matrix

Transpose the given matrix

func (*Matrix) VectorToDiagonalMatrix

func (matrix *Matrix) VectorToDiagonalMatrix() Matrix

converts a Matrix with N=1 to a Diagonal Matrix

Jump to

Keyboard shortcuts

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