> module ColumnOperationsOnMatrices > (averageColumns, > foldlColumns, > standardDeviationColumns, > standardDeviationUnbiasedColumns, > zipWithColumns) functions in this module perform column operations on matrices represented as sequences of rows, and do so without transposing the matrices > where > import SequenceUtilities(apply) foldlColumns applies foldl to the columns of matrix, using elements from zs as starting points: foldlColumns op [z1, z2, ... zj] [[x11, x12, ..., x1n], [x21, x22, ..., x2n], ... [xm1, xm2, ..., xmn]] = [foldl op z1 [x11, x21, ..., xm1], foldl op z2 [x12, x22, ..., xm2], ... foldl op zk [x1k, x2k, ..., xmk]] where k = min j n > foldlColumns :: (a -> b -> a) -> [a] -> [[b]] -> [a] > foldlColumns op = foldl (zipWith op) zipWithColumns zips a given column-vector into the columns of a matrix zipWithColumns op [c1, c2, ... ck] [[x11, x12, ..., x1n], [x21, x22, ..., x2n], ... [xm1, xm2, ..., xmn]] = [[c1 `op` x11, c1 `op` x12, ..., c1 `op` x1n], [c2 `op` x21, c2 `op` x22, ..., c2 `op` x2n], ... [ck `op` xj1, ck `op` xj2, ..., cj `op` xjn]] where k = min j m > zipWithColumns :: (a -> b -> c) -> [a] -> [[b]] -> [[c]] > zipWithColumns op = zipWith map . map op arithmetic means of columns of matrix containing one or more rows > averageColumns :: Fractional num => [[num]] -> [num] > averageColumns(row : rows) = > foldlColumns includeAnotherSample row rowsIndexed > where > rowsIndexed = zipWithColumns (,) [2 ..] rows > includeAnotherSample runningAverage (sampleNumber, sample) = > runningAverage + (sample - runningAverage)/fromRealFrac sampleNumber standard deviations of columns of matrix containing one or more rows > standardDeviationColumns :: Floating num => [[num]] -> [num] > standardDeviationColumns matrix = > (map sqrt . averageColumns . > map(map(^2)) . map(zipWith subtract means)) matrix > where > means = averageColumns matrix standard deviations of columns of matrix containing one or more rows unbiased estimate > standardDeviationUnbiasedColumns:: Floating num => [[num]] -> [num] > standardDeviationUnbiasedColumns matrix = > (map (*(fromIntegral m / fromIntegral(m-1))) . > standardDeviationColumns) matrix > where > m = length matrix