HNumeric 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+90/−16 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ HNum.CSV: DataFrame :: Header -> Matrix a -> Label -> DataFrame a
+ HNum.CSV: [dat] :: DataFrame a -> Matrix a
+ HNum.CSV: [header] :: DataFrame a -> Header
+ HNum.CSV: [lab] :: DataFrame a -> Label
+ HNum.CSV: class Functor f => CSVtize f
+ HNum.CSV: cm :: [String] -> String
+ HNum.CSV: data DataFrame a
+ HNum.CSV: dataframe :: Header -> Matrix a -> DataFrame a
+ HNum.CSV: dataframe' :: Header -> Matrix a -> Label -> DataFrame a
+ HNum.CSV: fromVectors :: Header -> [Vector a] -> DataFrame a
+ HNum.CSV: fromVectors' :: Header -> [Vector a] -> Label -> DataFrame a
+ HNum.CSV: instance GHC.Base.Functor HNum.CSV.DataFrame
+ HNum.CSV: instance GHC.Classes.Eq a => GHC.Classes.Eq (HNum.CSV.DataFrame a)
+ HNum.CSV: instance GHC.Show.Show a => GHC.Show.Show (HNum.CSV.DataFrame a)
+ HNum.CSV: instance HNum.CSV.CSVtize HNum.CSV.DataFrame
+ HNum.CSV: instance HNum.CSV.CSVtize HNum.Vector.Matrix
+ HNum.CSV: instance HNum.CSV.CSVtize HNum.Vector.Vector
+ HNum.CSV: toString :: (CSVtize f, Show a) => f a -> String
+ HNum.CSV: type Header = [String]
+ HNum.CSV: type Label = [String]
+ HNum.CSV: write :: (CSVtize f, Show a) => String -> f a -> IO ()
Files
- HNumeric.cabal +3/−2
- README.md +18/−14
- src/HNum/CSV.hs +69/−0
HNumeric.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3e62d8d2cc17a8f3e541031e3eb49a7cd3da4b6da8e7837ff11ff044e7b895f1+-- hash: ce543fbe9d1a2354607564a7cc9b45578ee49880af97240e46e90d23d3a5579b name: HNumeric-version: 0.3.0.0+version: 0.3.1.0 synopsis: Haskell Numeric Library with pure functionality, R & MATLAB Syntax. description: Please see the README on GitHub at <https://github.com/Axect/HNumeric#readme> category: HNum, library, Numeric, LinearAlgebra, Statistics, bsd3@@ -28,6 +28,7 @@ library exposed-modules:+ HNum.CSV HNum.Stats HNum.Vector other-modules:
README.md view
@@ -29,7 +29,8 @@ extra-deps: - git: https://github.com/Axect/HNumeric.git commit: [Latest Commit]- - normaldistribution-1.1.0,3+ - normaldistribution-1.1.0.3+ - random-1.1 ``` * Replace [Latest Commit] with latest commit in [HNumeric Commit](https://github.com/Axect/HNumeric/commits/master)@@ -42,6 +43,7 @@ - base - HNumeric - normaldistribution+- random ``` Then enjoy!@@ -56,10 +58,10 @@ ### Basic Vector Usage ```haskell--- HNumeric-0.2.0.0 Documentation+-- HNumeric-0.3.0.0 Documentation let a = vector [1,2,3] -- Vector declaration-let b = vector [4,5,6]+let b = Vector [4,5,6] -- small v and large V are same (for convenient) -- Print Vector print a@@ -68,7 +70,7 @@ (+1) <$> a -- Or MATLAB-like operator (.+, .-, .*, ./, .^)-a .+ 1+a .+ 1 -- do not 1 .+ a (. means position of vector) -- You can make list from vector toList a -- [1, 2, 3]@@ -118,15 +120,15 @@ vcat c d -- Matrix [[1,2],[3,4],[5,6],[7,8]] -- Insert Vector to Matrix-Vector [1, 2] .: c -- Matrix [[1,2],[1,2],[3,4]]+vector [1, 2] .: c -- Matrix [[1,2],[1,2],[3,4]] ``` ### Basic Stats Usage ```haskell -- Sample Vector (import Vector)-v = Vector [1..10]-w = Vector [10, 9 .. 1]+v = vector [1..10]+w = vector [10, 9 .. 1] -- Mean mean v@@ -156,11 +158,13 @@ rse v w ``` -### TODO+### DONE -* ~~Effective Matrix Multiplication~~-* Write Vector to CSV-* ~~Haddock~~-* DataFrame using Map-* ~~Fix Matrix Implementation~~-* ~~Numeric Class Define~~+* Effective Matrix Structure (R-like Structure)+* Divide and Conquer Matrix Multiplication, Determinant, Inverse++### TODO (2018.06.08)++* DSL Documentation by LaTeX (Soon)+* Make CSV Package+* Make DataFrame type
+ src/HNum/CSV.hs view
@@ -0,0 +1,69 @@+{-|+Module : HNum.CSV+Description : Simple CSV Library for HNumeric+CopyRight : (c) Tae Geun Kim, 2018+License : BSD3+Maintainer : edeftg@gmail.com+Stability : Experimental+-}+module HNum.CSV where++import HNum.Vector++-- | Type Aliases for convenience+type Header = [String]+type Label = [String]++-- | DataFrame structure to write csv+data DataFrame a = DataFrame { header :: Header, dat :: Matrix a, lab :: Label} deriving (Show, Eq)++-- | No label dataframe+dataframe :: Header -> Matrix a -> DataFrame a+dataframe h m | length h == row m = DataFrame h m (replicate n "value")+ | otherwise = error "Length of Header != Length of Data"+ where n = length m `div` length h++-- | With label dataframe+dataframe' :: Header -> Matrix a -> Label -> DataFrame a+dataframe' h m l+ | length h == row m && row m == length l = DataFrame h m l+ | otherwise = error "Length of Header != Length of Data != Length of Label"++-- | No label dataframe from Vectors+fromVectors :: Header -> [Vector a] -> DataFrame a+fromVectors h vs = dataframe h (matrix vs') where vs' = map toList vs++-- | With label dataframe from Vectors+fromVectors' :: Header -> [Vector a] -> Label -> DataFrame a+fromVectors' h vs = dataframe' h (matrix vs') where vs' = map toList vs++instance Functor DataFrame where+ fmap f df = df { dat = fmap f (dat df) }++-- | Class to write csv file+class Functor f => CSVtize f where+ toString :: Show a => f a -> String+ write :: Show a => String -> f a -> IO ()++instance CSVtize Vector where+ toString v = foldr (\x y -> x ++ "\n" ++ y) "" (show <$> v)+ write title v = writeFile title (toString v)++instance CSVtize Matrix where+ toString m = foldr ((\x y -> x ++ "\n" ++ y) . cm) "" m1+ where m1 = matForm (show <$> m)+ write title m = writeFile title (toString m)++instance CSVtize DataFrame where+ toString (DataFrame h m l) = h' ++ "\n" ++ m'+ where h' = cm h ++ ",label"+ m' = foldr ((\x y -> x ++ "\n" ++ y) . cm) "" $ matForm $ hcat (show <$> transpose m) l'+ l' = transpose $ matrix [l]+ write title df = writeFile title (toString df)+++-- | Convenient +cm :: [String] -> String+cm [] = []+cm (x : xs) | null xs = x+ | otherwise = x ++ "," ++ cm xs