summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoredeftg <>2018-06-13 07:37:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-06-13 07:37:00 (GMT)
commit2702426b0e7be61f83e0626bf06d3af6e684d8a3 (patch)
treec1339334dbe8396c3372dd9e3fed8840247bb8ec
parent5b214fc23f1559e267e9a4768dca791ae85c484f (diff)
version 0.4.0.00.4.0.0
-rw-r--r--ChangeLog.md6
-rw-r--r--HNumeric.cabal5
-rw-r--r--README.md21
-rw-r--r--src/HNum/CSV.hs18
-rw-r--r--src/HNum/F.hs44
-rw-r--r--src/HNum/Vector.hs46
6 files changed, 130 insertions, 10 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 93b46cb..e636986 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
# Changelog for HNumeric
-## Unreleased changes
+## 0.4.0.0
+
+* Add HNum.F (Functional Programming Library for HNum)
+* Add Convertable Class (HNumObj String -> HNumObj (Int or Integer or Double))
+* Add (!) for Vector (v ! 1 == (toList v) !! 1)
diff --git a/HNumeric.cabal b/HNumeric.cabal
index 1cf64c9..63a73d8 100644
--- a/HNumeric.cabal
+++ b/HNumeric.cabal
@@ -2,10 +2,10 @@
--
-- see: https://github.com/sol/hpack
--
--- hash: 35b947c6b91e1d075b0700a52de393b87f6749f5649ab43e268623c898e675e3
+-- hash: a31a8bb1239bf98ba7561f43ae6c7fe1005cd190658fb003dd7a222ffd8ae071
name: HNumeric
-version: 0.3.3.0
+version: 0.4.0.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
@@ -29,6 +29,7 @@ source-repository head
library
exposed-modules:
HNum.CSV
+ HNum.F
HNum.Stats
HNum.Vector
other-modules:
diff --git a/README.md b/README.md
index 71759b1..0946d36 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,9 @@
## Packages
* HNum.Vector : Contain vector, matrix, linear algebra
-* HNum.Stats : Contain statistical functions
+* HNum.Stats : Contain statistical functions
+* HNum.CSV : CSV Tools for HNum (Contain DataFrame)
+* HNum.F : Functional Programming Tools for HNum
## Installation
@@ -48,12 +50,20 @@ dependecies:
Then enjoy!
+## Documentation
+
+Documentation is prepared on authorea
+
+[HNumeric Documentation](https://www.authorea.com/users/223838/articles/307659-hnumeric-documentation)
+
## Usage
### Import Module
* HNum.Vector
* HNum.Stats
+* HNum.CSV
+* HNum.F
### Basic Vector Usage
@@ -162,9 +172,10 @@ rse v w
* Effective Matrix Structure (R-like Structure)
* Divide and Conquer Matrix Multiplication, Determinant, Inverse
+* Module CSV with DataFrame (read / write)
+* FuncTools
-### TODO (2018.06.08)
+### TODO (2018.06.13)
-* DSL Documentation by LaTeX (Soon)
-* Make CSV Package
-* Make DataFrame type
+* DSL Documentation by LaTeX (Developing)
+* More Statistical Tools
diff --git a/src/HNum/CSV.hs b/src/HNum/CSV.hs
index 1509805..a54bc7d 100644
--- a/src/HNum/CSV.hs
+++ b/src/HNum/CSV.hs
@@ -17,7 +17,9 @@ import HNum.Vector
type Header = [String]
-- | DataFrame structure to write csv
-data DataFrame a = DataFrame { header :: Header, dat :: Matrix a} deriving (Show, Eq)
+data DataFrame a = DataFrame { header :: Header
+ , dat :: Matrix a
+ } deriving (Show, Eq)
-- | dataframe constructor
dataframe :: Header -> Matrix a -> DataFrame a
@@ -29,9 +31,22 @@ dataframe h m | length h == row m = DataFrame h m
fromVectors :: Header -> [Vector a] -> DataFrame a
fromVectors h vs = dataframe h (matrix vs') where vs' = map toList vs
+-- | Extract Vector in DataFrame
+(#) :: Eq a => DataFrame a -> String -> Vector a
+df # hd | hd `notElem` header df = error "No specific header in dataFrame"
+ | otherwise = vec $ bd !! i
+ where
+ i = hd `fd` header df
+ bd = matForm $ transpose $ dat df
+
instance Functor DataFrame where
fmap f df = df { dat = fmap f (dat df) }
+instance Convertable DataFrame where
+ readInt df = read <$> df :: DataFrame Int
+ readInteger df = read <$> df :: DataFrame Integer
+ readDouble df = read <$> df :: DataFrame Double
+
-----------------------------------------------
-- Write to CSV
-----------------------------------------------
@@ -97,3 +112,4 @@ rmQuot x | null temp = clean
clean = takeWhile (/= '"') x
temp = dropWhile (/= '"') x
clean' = tail temp
+
diff --git a/src/HNum/F.hs b/src/HNum/F.hs
new file mode 100644
index 0000000..a69ff7f
--- /dev/null
+++ b/src/HNum/F.hs
@@ -0,0 +1,44 @@
+module HNum.F where
+
+import HNum.Vector
+import HNum.CSV
+
+-- | Functional Programming Tools for HNum Object
+class Functor f => FuncTools f where
+ -- | Absolute Abstraction with Scalar Function
+ hflat :: ([a] -> a) -> f a -> a
+ -- | Absolute Abstraction with Vector Function
+ hlift :: ([a] -> [b]) -> f a -> f b
+ -- | Like map
+ hmap :: (a -> b) -> f a -> f b
+ -- | Like filter
+ hfilter :: (a -> Bool) -> f a -> f a
+ -- | Like take
+ htake :: Int -> f a -> f a
+ -- | Like takeWhile
+ htakeWhile :: (a -> Bool) -> f a -> f a
+ -- | Like drop
+ hdrop :: Int -> f a -> f a
+ -- | Like dropWhile
+ hdropWhile :: (a -> Bool) -> f a -> f a
+
+instance FuncTools Vector where
+ hflat f = f . toList
+ hlift f = vec . f . toList
+ hmap = hlift . map
+ hfilter = hlift . filter
+ htake n = hlift (take n)
+ htakeWhile f = hlift (takeWhile f)
+ hdrop n = hlift (drop n)
+ hdropWhile f = hlift (dropWhile f)
+
+instance FuncTools Matrix where
+ hflat = undefined
+ hlift f = matrix . map f . matForm
+ hmap = hlift . map
+ hfilter = hlift . filter
+ htake n = hlift (take n)
+ htakeWhile f = hlift (takeWhile f)
+ hdrop n = hlift (drop n)
+ hdropWhile f = hlift (dropWhile f)
+
diff --git a/src/HNum/Vector.hs b/src/HNum/Vector.hs
index e99f8df..bab7dee 100644
--- a/src/HNum/Vector.hs
+++ b/src/HNum/Vector.hs
@@ -71,19 +71,33 @@ instance Foldable Vector where
-- Class for Vector with List
class List m where
+ -- | to List
toList :: m a -> [a]
+ -- | From List
fromList :: [a] -> m a
+ -- | Extract Element
+ (!) :: m a -> Int -> a
+ -- | Find Position of Element
+ findFirst :: Eq a => a -> m a -> Int
instance List Vector where
toList (Vector xs) = xs
fromList = Vector
+ v ! n = toList v !! n
+ findFirst n v | n `notElem` v = error "Not element!"
+ | otherwise = snd $ head $ dropWhile (\x -> fst x /= n) idx
+ where idx = zip (toList v) [0..]
---------------------------------------------------
-- Matrix
---------------------------------------------------
-- |Definition of Matrix
-data Matrix a = Matrix {val :: Vector a, row :: Int, col :: Int, byRow :: Bool} deriving (Eq)
+data Matrix a = Matrix { val :: Vector a
+ , row :: Int
+ , col :: Int
+ , byRow :: Bool
+ } deriving (Eq)
-- |matrix is syntactic sugar to create Matrix
matrix :: [[a]] -> Matrix a
@@ -91,7 +105,9 @@ matrix = formMat
-- |Matrices is necessary class for Matrix
class Matrices m where
+ -- | Matrix to Array
matForm :: m a -> [[a]]
+ -- | Array to Matrix
formMat :: [[a]] -> m a
instance Matrices Matrix where
@@ -159,6 +175,28 @@ instance Foldable Matrix where
foldl f z (Matrix (Vector xs) _ _ _) = foldl f z xs
---------------------------------------------------
+-- Type Conversion
+---------------------------------------------------
+-- | Syntactic Sugar of read of functor
+class Functor f => Convertable f where
+ -- | Read String to Int
+ readInt :: f String -> f Int
+ -- | Read String to Integer
+ readInteger :: f String -> f Integer
+ -- | Read String to Double
+ readDouble :: f String -> f Double
+
+instance Convertable Vector where
+ readInt v = read <$> v :: Vector Int
+ readInteger v = read <$> v :: Vector Integer
+ readDouble v = read <$> v :: Vector Double
+
+instance Convertable Matrix where
+ readInt m = read <$> m :: Matrix Int
+ readInteger m = read <$> m :: Matrix Integer
+ readDouble m = read <$> m :: Matrix Double
+
+---------------------------------------------------
-- Operation
---------------------------------------------------
{-|
@@ -423,3 +461,9 @@ invMat m
a12 = negMap a00 %-*-% m12 %-*-% s00
a21 = negMap s00 %-*-% m21 %-*-% a00
a22 = s00
+
+-- | Find First
+fd :: Eq a => a -> [a] -> Int
+fd n v | n `notElem` v = error "Not element!"
+ | otherwise = snd $ head $ dropWhile (\x -> fst x /= n) idx
+ where idx = zip v [0 ..]