linda-0.1.2: LINear Discriminant Analysis

Portability portable experimental lennart...schmitt@gmail.com

Numeric.Matrix

Description

This module includes a few (standard) functions to work with matrixes.

Synopsis

# Data Types

data Matrix t

Matrix representation suitable for GSL and LAPACK computations.

The elements are stored in a continuous memory array.

Instances

 Joinable Matrix Matrix Joinable Matrix Vector Joinable Vector Matrix Normed Matrix Double Normed Matrix Float Container Vector a => Container Matrix a Normed Matrix (Complex Double) Normed Matrix (Complex Float) (Element a, Read a) => Read (Matrix a) (Show a, Element a) => Show (Matrix a) (Binary a, Element a, Storable a) => Binary (Matrix a)

Represents a matrix

type RawMatrix a = [[a]]Source

A matrix represented by a list of lists.

class Storable a => Element a

Supported matrix elements.

This class provides optimized internal operations for selected element types. It provides unoptimised defaults for any `Storable` type, so you can create instances simply as: `instance Element Foo`.

Instances

 Element Double Element Float Element (Complex Double) Element (Complex Float)

The elements of a matrix

# Convert a Matrix into another Type

flatten :: Element t => Matrix t -> Vector t

Creates a vector by concatenation of rows

```> flatten (`ident` 3)
9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]```

Flattens a matrix to a vector

toColumns :: Element t => Matrix t -> [Vector t]

Creates a list of vectors from the columns of a matrix

Converts the representation of a matrix to a list of vectors by its columns.

toLists :: Element t => Matrix t -> [[t]]

the inverse of `Data.Packed.Matrix.fromLists`

Converts the representation of a matrix to a list of lists. (NOT equivalent with toRows!!!)

toRows :: Element t => Matrix t -> [Vector t]

extracts the rows of a matrix as a list of vectors

Converts the representation of a matrix to a list of vectors by its rows.

# Convert some Data into Matrix-Type

asRow :: Storable a => Vector a -> Matrix a

creates a 1-row matrix from a vector

Converts the representation of a matrix from a list of vectors to a matrix (by rows)

fromLists :: Element t => [[t]] -> Matrix t

Creates a `Matrix` from a list of lists (considered as rows).

```> fromLists [[1,2],[3,4],[5,6]]
(3><2)
[ 1.0, 2.0
, 3.0, 4.0
, 5.0, 6.0 ]```

Converts the representation of a matrix from a list of lists to a matrix (NOT equivalent with asRows!!!)

Builds a quadratic matrix out of a list

# Matrix calculations/transformations

(@@>) :: Storable t => Matrix t -> (Int, Int) -> t

Get the matrix-element in row x and col y (like (!!) for lists)

Calculates the eigenvalue of a matrix, e.g.

``` eigenvalue (fromLists [[0.77143,-0.25714],[-0.42245,0.14082]])
```

returns

``` 0.9122456375784809
```

Calculates one eigenvector of a given matrix, e.g.

``` eigenvector (fromLists [[-0.14081563757848092,-0.25714],[-0.42245,-0.7714256375784809]])
```

returns

``` [0.8770950095147589,-0.48031692067249215]
```

inv :: Field t => Matrix t -> Matrix t

Inverse of a square matrix. See also `invlndet`.

Calculates the invariant matrix of the input matrix

Calculates the identity matrix (n x n) by given scale (n)

A simple map-Function which maps a given function on every element of the given matrix

Calculates the reduced matrix of a given matrix (by reducing the given matrix), e.g.

``` reduceMatrix (fromLists [[0.77143,-0.25714],[-0.42245,0.14082]])
```

returns

``` (2><2)[ -0.14081563757848092,-0.25714,-0.42245,-0.7714256375784809]
```

Calculates the scalarproduct (with a scalar and matrix)

Calculates the difference (matrix) between two matrixes

trans :: Matrix t -> Matrix t

Matrix transpose.

Transposes a matrix

zipAllWith :: (RawVector a -> b) -> RawMatrix a -> RawVector bSource

Zipps a matrix col by col

``` zipAllWith sum [[1,2,3],[1,2,3],[1,2,3]] == [3,6,9]
```