statistics-0.13.2.3: A library of statistical types, data, and functions

Copyright 2011 Aleksey Khudyakov, 2014 Bryan O'Sullivan BSD3 None Haskell98

Statistics.Matrix

Description

Basic matrix operations.

There isn't a widely used matrix package for Haskell yet, so we implement the necessary minimum here.

Synopsis

# Documentation

data Matrix Source

Two-dimensional matrix, stored in row-major order.

Constructors

 Matrix Fieldsrows :: !IntRows of matrix.cols :: !IntColumns of matrix.exponent :: !IntIn order to avoid overflows during matrix multiplication, a large exponent is stored separately._vector :: !VectorMatrix data.

Instances

 Eq Matrix Show Matrix

Arguments

 :: Int Number of rows. -> Int Number of columns. -> [Double] Flat list of values, in row-major order. -> Matrix

Convert from a row-major list.

Arguments

 :: Int Number of rows. -> Int Number of columns. -> Vector Double Flat list of values, in row-major order. -> Matrix

Convert from a row-major vector.

Convert to a row-major flat vector.

toList :: Matrix -> [Double] Source

Convert to a row-major flat list.

dimension :: Matrix -> (Int, Int) Source

Return the dimensions of this matrix, as a (row,column) pair.

Element in the center of matrix (not corrected for exponent).

Matrix-matrix multiplication. Matrices must be of compatible sizes (note: not checked).

Matrix-vector multiplication.

Raise matrix to nth power. Power must be positive (/note: not checked).

Calculate the Euclidean norm of a vector.

Return the given column.

row :: Matrix -> Int -> Vector Source

Return the given row.

for :: Monad m => Int -> Int -> (Int -> m ()) -> m () Source

Simple for loop. Counts from start to end-1.

Arguments

 :: Matrix -> Int Row. -> Int Column. -> Double

Indicate whether any element of the matrix is `NaN`.

bounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r Source

Given row and column numbers, calculate the offset into the flat row-major vector.

unsafeBounds :: (Vector -> Int -> r) -> Matrix -> Int -> Int -> r Source

Given row and column numbers, calculate the offset into the flat row-major vector, without checking.