matrix

package module
v0.0.0-...-38bc2a7 Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

matrix

GoDoc License Travis CI Go Report Card codecov

This Go package contains various function useful when working with gonum matrices which are not provided by gonum mat package.

Get started

Get the package:

$ go get -u github.com/milosgajdos83/matrix

Get dependencies:

$ make godep && make dep

Run the tests:

$ make test

Contributing

YES PLEASE!

Please make sure you run the following command before you open a new PR:

$ make all

Documentation

Overview

Package matrix provides a list of useful functions when working with gonum matrices.

Among many other functions it allows you calculate sums, mean and stddev values along chosen matrix dimensions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddVal

func AddVal(m *mat.Dense, val float64) (*mat.Dense, error)

AddVal adds a constant value to every element of matrix It modifies the matrix m passed in as a paramter. AddConstant fails with error if empty matrix is supplied

func BlockDiag

func BlockDiag(mx []mat.Matrix) *mat.Dense

BlockDiag accepts a slice of matrices, turns them into a block diagonal matrix and returns it. It skips zero sized matrices when assembling the block diagonal matrix.

func BlockSymDiag

func BlockSymDiag(mx []mat.Symmetric) *mat.SymDense

BlockSymDiag turns a slice of symmetric matrices into a symmetric block diagonal matrix and returns it. It skips zero sized matrices when assembling the symmetric block diagonal matrix.

func ColsMax

func ColsMax(cols int, m *mat.Dense) ([]float64, error)

ColsMax returns a slice of max values of first cols number of matrix columns It returns error if passed in matrix is nil, has zero size or requested number of columns exceeds the number of columns in the matrix passed in as parameter.

func ColsMean

func ColsMean(cols int, m *mat.Dense) ([]float64, error)

ColsMean returns a slice of mean values of first cols matrix columns It returns error if passed in matrix is nil or has zero size or requested number of columns exceeds the number of columns in matrix m.

func ColsMin

func ColsMin(cols int, m *mat.Dense) ([]float64, error)

ColsMin returns a slice of min values of first cols number of matrix columns It returns error if passed in matrix is nil, has zero size or requested number of columns exceeds the number of columns in the matrix passed in as parameter.

func ColsStdev

func ColsStdev(cols int, m *mat.Dense) ([]float64, error)

ColsStdev returns a slice of standard deviations of first cols matrix columns It returns error if passed in matrix is nil or has zero size or requested number of columns exceeds the number of columns in matrix m.

func ColsSum

func ColsSum(cols int, m *mat.Dense) ([]float64, error)

ColsSum returns a slice of sum values of first cols number of matrix columns It returns error if passed in matrix is nil, has zero size or requested number of columns exceeds the number of columns in the matrix passed in as parameter.

func Cov

func Cov(m *mat.Dense, dim string) (*mat.SymDense, error)

Cov calculates a covariance matrix with data stored in m along dim dimension. It returns error if the covariance could not be calculated.

func Format

func Format(m mat.Matrix) fmt.Formatter

Format returns matrix formatter for printing matrices

func NewDenseRand

func NewDenseRand(rows, cols int, min, max float64) (*mat.Dense, error)

NewDenseRand creates a new matrix with provided number of rows and columns which is initialized to random numbers uniformly distributed in interval [min, max]. NewDenseRand fails if non-positive matrix dimensions are requested.

func NewDenseVal

func NewDenseVal(rows, cols int, val float64) (*mat.Dense, error)

NewDenseVal returns a matrix with rows x cols whose each element is set to val. NewDenseVal fails if invalid matrix dimensions are requested.

func NewDenseValIdentity

func NewDenseValIdentity(n int, val float64) (*mat.Dense, error)

NewDenseValIdentity returns a matrix with size n x n whose diagonal elements are set to val. NewDenseValIdentity fails if invalid matrix dimensions are requested.

func RowsMax

func RowsMax(rows int, m *mat.Dense) ([]float64, error)

RowsMax returns a slice of max values of first rows matrix rows. It returns error if passed in matrix is nil or has zero size or requested number of rows exceeds the number of rows in matrix m.

func RowsMean

func RowsMean(rows int, m *mat.Dense) ([]float64, error)

RowsMean returns a slice of mean values of first rows matrix rows It returns error if passed in matrix is nil or has zero size or requested number of columns exceeds the number of columns in matrix m.

func RowsMin

func RowsMin(rows int, m *mat.Dense) ([]float64, error)

RowsMin returns a slice of min values of first rows matrix rows. It returns error if passed in matrix is nil or has zero size or requested number of rows exceeds the number of rows in matrix m.

func RowsSum

func RowsSum(rows int, m *mat.Dense) ([]float64, error)

RowsSum returns a slice of sum values of first rows number of matrix columns It returns error if passed in matrix is nil, has zero size or requested number of columns exceeds the number of columns in the matrix passed in as parameter.

func SetVals

func SetVals(m *mat.Dense, vals []float64, byRow bool) (err error)

SetVals sets all elements of a matrix to values stored in vals passed in as a parameter. It fails with error if number of elements of the matrix is bigger than number of elements of the slice.

func ToSymDense

func ToSymDense(m *mat.Dense) (*mat.SymDense, error)

ToSymDense converts m to SymDense (symmetric Dense matrix) if possible. It returns error if the provided Dense matrix is not symmetric.

func Unroll

func Unroll(m *mat.Dense, byRow bool) *mat.VecDense

Unroll unrolls all elements of matrix into *mat.VecDense and returns it Matrix elements can be unrolled either by row or by a column.

Types

This section is empty.

Jump to

Keyboard shortcuts

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