Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- import Data.Typeable
- import Data.Char
- import System.Directory
- import Types
- type Image = [Float]
- type Sample = (Int, Image)
- strToArr::String->[Float]
- strToArr line = [(read x::Float)| x<-(words line)]
- strToMatrix::String->[[Float]]
- strToMatrix mt = [(strToArr x)| x<-(lines mt)]
- arrToStr::[Float]->String
- arrToStr [] = ""
- arrToStr (h:t) = (show h::String) ++ " " ++ (arrToStr t)
- matrixToStr::[[Float]]->String
- matrixToStr [] = ""
- matrixToStr (h:t) = (arrToStr h) ++ "\n" ++ (matrixToStr t)
- listRamdom::Int->IO [Float]
- listRamdom 0 = return []
- listRamdom sz = do
- readIn::IO Data
- readIn = do
- wH <- readFile "Weight_hidden.txt"
- bH <- readFile "Biases_hidden.txt"
- wO <- readFile "Weight_Output.txt"
- bO <- readFile "Biases_Output.txt"
- return $ Data (strToMatrix wH) (strToArr bH) (strToMatrix wO) (strToArr bO)
- writeIn::Data->IO()
- writeIn elem = do
- writeFile "Weight_hidden.txt" (matrixToStr (wHidden elem))
- writeFile "Biases_hidden.txt" (arrToStr (bHidden elem))
- writeFile "Weight_Output.txt" (matrixToStr (wOutput elem))
- writeFile "Biases_Output.txt" (arrToStr (bOutput elem))
- isEmptyFile::String->IO Bool
- isEmptyFile path = do
- elem <- readFile path
- if (length elem) == 0 then return True
- else return False
- pickNumber::FilePath->Int
- pickNumber "" = -1
- pickNumber (h:t)
- | h == '-' = digitToInt $ t!!0
- | otherwise = (pickNumber t)
- makeImage::FilePath->IO Image
- makeImage path = do
- elem <- readFile path
- let ret = (strToArr elem)
- return ret
- makeSample::FilePath->String->IO Sample
- makeSample archive path = do
- let number = (pickNumber archive)
- mt <- (makeImage $ path++archive)
- return (number, mt)
- listSample::[FilePath]->String->IO [Sample]
- listSample [] path = return []
- listSample (h:t) path = do
- head <- makeSample h path
- tail <- listSample t path
- return $ head:tail
- getTest::IO [Sample]
- getTest = do
- let caminho = "C:/Users/Amandio/Documents/Programacao/Hecome_Bumans/Tests" -- change
- elems <- (getDirectoryContents caminho) -- Colocar diretorio
- ret <- listSample (filter (/= ".") $ filter (/= "..") elems) caminho
- return ret
- getTrain::IO [Sample]
- getTrain = do
- let caminho = "C:/Users/Amandio/Documents/Programacao/Hecome_Bumans/Trains" -- change
- elems <- (getDirectoryContents caminho) -- Colocar diretorio
- ret <- listSample (filter (/= ".") $ filter (/= "..") elems) caminho
- return ret
- main::IO()
- main = do
- d <- readIn
- print $ typeOf d
- print d
Advertisement
Add Comment
Please, Sign In to add comment