Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
efed71e554 | ||
![]() |
fab9a94593 |
@ -61,7 +61,7 @@ library
|
|||||||
|
|
||||||
-- Other library packages from which modules are imported.
|
-- Other library packages from which modules are imported.
|
||||||
build-depends:
|
build-depends:
|
||||||
base, containers, lens, split
|
base, containers, lens, split, hmatrix
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
|
@ -104,3 +104,120 @@ instructionVectorFloatShove state = instructionShove state vectorFloat
|
|||||||
|
|
||||||
instructionVectorFloatShoveDup :: State -> State
|
instructionVectorFloatShoveDup :: State -> State
|
||||||
instructionVectorFloatShoveDup state = instructionShoveDup state vectorFloat
|
instructionVectorFloatShoveDup state = instructionShoveDup state vectorFloat
|
||||||
|
|
||||||
|
instructionVectorFloatMean :: State -> State
|
||||||
|
instructionVectorFloatMean state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = mean vf : fs}
|
||||||
|
[] -> state -- Do nothing if _vectorFloat is empty
|
||||||
|
where
|
||||||
|
mean [] = 0
|
||||||
|
mean xs = sum xs / fromIntegral (length xs)
|
||||||
|
|
||||||
|
instructionVectorFloatMax :: State -> State
|
||||||
|
instructionVectorFloatMax state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = maximum vf : fs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatMin :: State -> State
|
||||||
|
instructionVectorFloatMin state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = minimum vf : fs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatSum :: State -> State
|
||||||
|
instructionVectorFloatSum state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = sum vf : fs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatMode :: State -> State
|
||||||
|
instructionVectorFloatMode state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = mode vf : fs}
|
||||||
|
[] -> state
|
||||||
|
where
|
||||||
|
mode [] = 0
|
||||||
|
mode xs = head $ maximumBy (comparing length) (group (sort xs))
|
||||||
|
|
||||||
|
instructionVectorFloatNorm :: State -> State
|
||||||
|
instructionVectorFloatNorm state@(State {_vectorFloat = vfs, _float = fs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = vfs', _float = realToFrac (norm vf) : fs}
|
||||||
|
[] -> state
|
||||||
|
where
|
||||||
|
norm xs = norm_2 (vector xs)
|
||||||
|
|
||||||
|
instructionVectorFloatCummulativeMean :: State -> State
|
||||||
|
instructionVectorFloatCummulativeMean state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral vf)) [1..] : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatCummulativeSum :: State -> State
|
||||||
|
instructionVectorFloatCummulativeSum state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = scanl1 (+) vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatCummulativeMax :: State -> State
|
||||||
|
instructionVectorFloatCummulativeMax state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = scanl1 maximum vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatCummulativeMin :: State -> State
|
||||||
|
instructionVectorFloatCummulativeMin state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = scanl1 minimum vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatExp :: State -> State
|
||||||
|
instructionVectorFloatExp state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map exp vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
|
||||||
|
instructionVectorFloatLog :: State -> State
|
||||||
|
instructionVectorFloatLog state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map log vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatCos :: State -> State
|
||||||
|
instructionVectorFloatCos state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map cos vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatSin :: State -> State
|
||||||
|
instructionVectorFloatSin state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map sin vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatAbs :: State -> State
|
||||||
|
instructionVectorFloatAbs state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map abs vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatSquare :: State -> State
|
||||||
|
instructionVectorFloatSquare state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map (^2) vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatCube :: State -> State
|
||||||
|
instructionVectorFloatCube state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map (^3) vf : vfs'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorFloatSqrt :: State -> State
|
||||||
|
instructionVectorFloatSqrt state@(State {_vectorFloat = vfs}) =
|
||||||
|
case vfs of
|
||||||
|
(vf:vfs') -> state {_vectorFloat = map (sqrt . fromIntegral) vf : vfs'}
|
||||||
|
[] -> state
|
@ -2,6 +2,9 @@ module Instructions.VectorIntInstructions where
|
|||||||
|
|
||||||
import Instructions.GenericInstructions
|
import Instructions.GenericInstructions
|
||||||
import State
|
import State
|
||||||
|
import Data.List (maximumBy, group, sort)
|
||||||
|
import Data.Ord (comparing)
|
||||||
|
import Numeric.LinearAlgebra (vector, norm_2)
|
||||||
|
|
||||||
instructionVectorIntConcat :: State -> State
|
instructionVectorIntConcat :: State -> State
|
||||||
instructionVectorIntConcat state = instructionConcat state vectorInt
|
instructionVectorIntConcat state = instructionConcat state vectorInt
|
||||||
@ -104,3 +107,120 @@ instructionVectorIntShove state = instructionShove state vectorChar
|
|||||||
|
|
||||||
instructionVectorIntShoveDup :: State -> State
|
instructionVectorIntShoveDup :: State -> State
|
||||||
instructionVectorIntShoveDup state = instructionShoveDup state vectorChar
|
instructionVectorIntShoveDup state = instructionShoveDup state vectorChar
|
||||||
|
|
||||||
|
instructionVectorIntMean :: State -> State
|
||||||
|
instructionVectorIntMean state@(State {_vectorInt = vis, _float = fs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _float = mean vi : fs}
|
||||||
|
[] -> state -- Do nothing if _vectorInt is empty
|
||||||
|
where
|
||||||
|
mean [] = 0
|
||||||
|
mean xs = fromIntegral (sum xs) / fromIntegral (length xs)
|
||||||
|
|
||||||
|
instructionVectorIntMax :: State -> State
|
||||||
|
instructionVectorIntMax state@(State {_vectorInt = vis, _int = is}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _int = maximum vi : is}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntMin :: State -> State
|
||||||
|
instructionVectorIntMin state@(State {_vectorInt = vis, _int = is}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _int = minimum vi : is}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntSum :: State -> State
|
||||||
|
instructionVectorIntSum state@(State {_vectorInt = vis, _int = is}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _int = sum vi : is}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntMode :: State -> State
|
||||||
|
instructionVectorIntMode state@(State {_vectorInt = vis, _int = is}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _int = mode vi : is}
|
||||||
|
[] -> state
|
||||||
|
where
|
||||||
|
mode [] = 0
|
||||||
|
mode xs = head $ maximumBy (comparing length) (group (sort xs))
|
||||||
|
|
||||||
|
instructionVectorIntNorm :: State -> State
|
||||||
|
instructionVectorIntNorm state@(State {_vectorInt = vis, _float = fs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _float = realToFrac (norm (map fromIntegral vi)) : fs}
|
||||||
|
[] -> state
|
||||||
|
where
|
||||||
|
norm xs = norm_2 (vector xs)
|
||||||
|
|
||||||
|
instructionVectorIntCummulativeMean :: State -> State
|
||||||
|
instructionVectorIntCummulativeMean state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis, _vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral vi)) [1..] : vfs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntCummulativeSum :: State -> State
|
||||||
|
instructionVectorIntCummulativeSum state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = scanl1 (+) vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntCummulativeMax :: State -> State
|
||||||
|
instructionVectorIntCummulativeMax state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = scanl1 maximum vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntCummulativeMin :: State -> State
|
||||||
|
instructionVectorIntCummulativeMin state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = scanl1 minimum vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntExp :: State -> State
|
||||||
|
instructionVectorIntExp state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (exp . fromIntegral) vi : vfs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
|
||||||
|
instructionVectorIntLog :: State -> State
|
||||||
|
instructionVectorIntLog state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (log . fromIntegral) vi : vfs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntCos :: State -> State
|
||||||
|
instructionVectorIntCos state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (cos . fromIntegral) vi : vfs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntSin :: State -> State
|
||||||
|
instructionVectorIntSin state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sin . fromIntegral) vi : vfs}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntAbs :: State -> State
|
||||||
|
instructionVectorIntAbs state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = map abs vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntSquare :: State -> State
|
||||||
|
instructionVectorIntSquare state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = map (^2) vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntCube :: State -> State
|
||||||
|
instructionVectorIntCube state@(State {_vectorInt = vis}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = map (^3) vi : vis'}
|
||||||
|
[] -> state
|
||||||
|
|
||||||
|
instructionVectorIntSqrt :: State -> State
|
||||||
|
instructionVectorIntSqrt state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
|
case vis of
|
||||||
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sqrt . fromIntegral) vi : vfs}
|
||||||
|
[] -> state
|
@ -287,6 +287,7 @@ main = do
|
|||||||
vectorIntTestFunc "instructionVectorIntReplaceFirst-2" [[0,1,2,3,4,5,3,5,3]] [GeneInt 99, GeneInt (-2), GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplaceFirst] emptyState
|
vectorIntTestFunc "instructionVectorIntReplaceFirst-2" [[0,1,2,3,4,5,3,5,3]] [GeneInt 99, GeneInt (-2), GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplaceFirst] emptyState
|
||||||
vectorIntTestFunc "instructionVectorIntRemove" [[0,1,2,4,5,5]] [GeneInt 3, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntRemove] emptyState
|
vectorIntTestFunc "instructionVectorIntRemove" [[0,1,2,4,5,5]] [GeneInt 3, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntRemove] emptyState
|
||||||
intTestFunc "instructionVectorIntIterate" [66] [GeneInt 40, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntIterate, StateFunc instructionIntAdd] emptyState
|
intTestFunc "instructionVectorIntIterate" [66] [GeneInt 40, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntIterate, StateFunc instructionIntAdd] emptyState
|
||||||
|
floatTestFunc "instructionVectorIntMean" [3.0] [GeneVectorInt [1,2,3,4,5], StateFunc instructionVectorIntMean] emptyState
|
||||||
|
|
||||||
-- vector float functions
|
-- vector float functions
|
||||||
vectorFloatTestFunc "instructionVectorFloatConcat" [[4.0, 5.0, 6.0, 1.0, 2.0, 3.0]] [GeneVectorFloat [1.0, 2.0, 3.0], GeneVectorFloat [4.0, 5.0, 6.0], StateFunc instructionVectorFloatConcat] emptyState
|
vectorFloatTestFunc "instructionVectorFloatConcat" [[4.0, 5.0, 6.0, 1.0, 2.0, 3.0]] [GeneVectorFloat [1.0, 2.0, 3.0], GeneVectorFloat [4.0, 5.0, 6.0], StateFunc instructionVectorFloatConcat] emptyState
|
||||||
|
Loading…
x
Reference in New Issue
Block a user