Documentation ¶
Overview ¶
Package matrix implements matrix and vector operations along with some difficult methods such as the Gram-Schmidt process, Einstein summation convention, eigenvector calculation and more.
Index ¶
- func InnerProduct(matrix Matrix, vector1, vector2 Vector) float64
- func PageRank(linkMatrix Matrix, pages int)
- func PrintVector(vec Vector)
- func Quadratic(a, b, c float64) (float64, float64)
- func Sigmoid(x float64) float64
- func SigmoidPrime(x float64) float64
- func VecToArray(vec Vector) []float64
- type Matrix
- func AllSameNumber(row, column int, number float64) Matrix
- func FromArray(arr []float64) Matrix
- func FromValues(row, column int, values []float64) Matrix
- func Identity(n int) Matrix
- func Matmul(a, b Matrix) Matrix
- func NewMatrix(slice [][]float64) Matrix
- func Ones(row, column int) Matrix
- func RandomValuedMatrix(row, column int) Matrix
- func Zeros(row, column int) Matrix
- func (m Matrix) Add(mat Matrix) Matrix
- func (m Matrix) Adjoint() (Matrix, error)
- func (m *Matrix) At(rowIndex, columnIndex int) float64
- func (m Matrix) Dimensions() (int, int)
- func (m Matrix) Divide(mat Matrix) Matrix
- func (m Matrix) DotProduct(m2 Matrix) float64
- func (m Matrix) EinsteinConvention(m2 Matrix) Matrix
- func (m Matrix) Find2x2Determinant() float64
- func (m Matrix) FindDeterminant() float64
- func (m Matrix) Inverse() Matrix
- func (m Matrix) Inverse2x2() Matrix
- func (m Matrix) MapFunc(f func(x float64) float64) Matrix
- func (m Matrix) Multiply(mat Matrix) Matrix
- func (m Matrix) NumberOfColumns() int
- func (m Matrix) NumberOfElements() int
- func (m Matrix) NumberOfRows() int
- func (m Matrix) PrintByRow()
- func (m Matrix) Randomize() Matrix
- func (m Matrix) RoundtoDecimals(decimals int) Matrix
- func (m Matrix) ScalarAdition(scalar float64) Matrix
- func (m Matrix) ScalarMultiplication(scalar float64) Matrix
- func (m Matrix) Shorten(rowIndex, columnIndex int) Matrix
- func (m Matrix) Slice() [][]float64
- func (m Matrix) Subtract(mat Matrix) Matrix
- func (m Matrix) ToArray() []float64
- func (m Matrix) TransformationInAChangedBasis(basis Matrix) Matrix
- func (m Matrix) Transpose() Matrix
- type Vector
- func CalculateEigenvectors2x2(m Matrix) ([]Vector, error)
- func GramSchmidt(vectors []Vector) ([]Vector, error)
- func NewVector(slice []float64) Vector
- func RandomVector(size int) Vector
- func VecAllSameNumber(size int, number float64) Vector
- func VecOnes(size int) Vector
- func VecZeros(size int) Vector
- func (v Vector) Add(v2 Vector) Vector
- func (v Vector) AddMany(vectors []Vector) Vector
- func (v Vector) AngleBetween(v2 Vector) float64
- func (v Vector) ApplyMatrix(matrix Matrix) Vector
- func (v Vector) ChangingBasis(b1, b2 Vector) (Vector, error)
- func (v Vector) DotProduct(v2 Vector) float64
- func (v Vector) GetLength() float64
- func (v Vector) Map(f func(float64) float64) Vector
- func (v Vector) MultiplyByScalar(scalar float64) Vector
- func (v Vector) NumberOfElements() int
- func (v Vector) ScalarProjection(v2 Vector) float64
- func (v Vector) Slice() []float64
- func (v Vector) Substract(v2 Vector) Vector
- func (v Vector) SubstractMany(vectors []Vector) Vector
- func (v Vector) VectorProjection(v2 Vector) Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InnerProduct ¶
InnerProduct returns the inner product of two vectors via the matrix. Check the dotProduct function for a simplified dot product of two vectors.
func PageRank ¶
PageRank algorithm returns the probabilites of randomly ending up on either of the pages. Page connections should be put inside the link matrix.
func Quadratic ¶
Quadratic takes a,b,c parameters of a quadratic equation as inputs and returns both solutions via the discriminant.
func SigmoidPrime ¶
SigmoidPrime returns the sigmoid derivative of x.
func VecToArray ¶
VecToArray returns a slice of vector elements.
Types ¶
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
Matrix type does matrix math
func AllSameNumber ¶
AllSameNumber returns a row * column matrix of number.
func FromValues ¶
FromValues returns a matrix from a set of values
func RandomValuedMatrix ¶
RandomValuedMatrix returns a row*column random valued matrix.
func (Matrix) Dimensions ¶
Dimensions returns the number of rows and columns of m.
func (Matrix) DotProduct ¶
DotProduct returns the dot product of two matrices
func (Matrix) EinsteinConvention ¶
EinsteinConvention returns the multiplication matrix of two matrices, given that rows of A matches columns of B. According to this convention, when an index variable appears twice in a single term and is not otherwise defined, it implies summation of that term over all the values of the index.
func (Matrix) Find2x2Determinant ¶
Find2x2Determinant returns the determinant of a 2x2 matrix
func (Matrix) FindDeterminant ¶
FindDeterminant returns the matrix determinant
func (Matrix) Inverse2x2 ¶
Inverse2x2 returns the inverse of a 2x2 matrix
func (Matrix) NumberOfColumns ¶
NumberOfColumns returns the number of columns.
func (Matrix) NumberOfElements ¶
NumberOfElements returns the number of elements.
func (Matrix) NumberOfRows ¶
NumberOfRows returns the number of columns.
func (Matrix) RoundtoDecimals ¶
RoundtoDecimals round all elements of a matrix to decimals accuracy.
func (Matrix) ScalarAdition ¶
ScalarAdition adds a scalar to every elements
func (Matrix) ScalarMultiplication ¶
ScalarMultiplication multiplies every element with a scalar
func (Matrix) Shorten ¶
Shorten returns the so-called minor matrix, it shrinks all numbers that lie either with one coordinate on rowIndex or columnIndex
func (Matrix) TransformationInAChangedBasis ¶
TransformationInAChangedBasis function takes a given matrix as an input and outputs it in a changed basis
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector type
func CalculateEigenvectors2x2 ¶
CalculateEigenvectors2x2 returns the eigenvectors of the given 2x2 matrix
func GramSchmidt ¶
GramSchmidt function returns the concatenated matrix of orthogonal based vectors out of the vectors dataset. Based on the Mathematics for Machine learning Specialization.
func VecAllSameNumber ¶
VecAllSameNumber returns a vector of zeros
func (Vector) AngleBetween ¶
AngleBetween returns the angle between two vectors.
func (Vector) ApplyMatrix ¶
ApplyMatrix returns the vector through a matrix transformation.
func (Vector) ChangingBasis ¶
ChangingBasis returns the transformed vector if we were to change its basis vectors. Similar to a simple matrix transformation but inputs are two basis vectors. Basis vectors have to be perpendicular to each other in order to apply this transformation. The function takes care of this for you by sending back an error
func (Vector) DotProduct ¶
DotProduct returns the dot product of two vectors.
func (Vector) MultiplyByScalar ¶
MultiplyByScalar operates by adding a scalar elementary.
func (Vector) NumberOfElements ¶
NumberOfElements returns the number of elements.
func (Vector) ScalarProjection ¶
ScalarProjection returns the scalar projection of v onto v2.
func (Vector) SubstractMany ¶
SubstractMany takes a slice of vectors and outputs their divergence.
func (Vector) VectorProjection ¶
VectorProjection returns the vector projection of v onto v2.