-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdentest.hs
62 lines (51 loc) · 1.77 KB
/
Edentest.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# LANGUAGE FlexibleInstances #-}
module Edentest (initialize,halfioref,main) where
import Som.Parallel
import Som.Lrn
import Som.Som
import Data.Array.IArray
import Data.Array.Base
import Data.IORef
import Data.Word
import System.Random
import Control.Parallel.Eden
import Control.Concurrent
instance DataPoint [Float] where
a +. b = seq a seq b zipWith (+) a b
a *. b = map (* b) a
ddistance a b = sum $ map (**2) $ zipWith (-) a b
fromList = id
dzero = repeat 0
instance Inf [Float] where
inf = repeat inf
instance Coordinate (Int,Int) where
cdistance (a1,b1) (a2,b2) = sqrt $ fromIntegral ((a1-a2)^2+(b1-b2)^2)
halfioref ioref =
do a <- readIORef ioref
writeIORef ioref (a/2)
return a
initialize :: (Ix a) => (a,a) -> IO (Array a [Float])
initialize bounds = do gen<-getStdGen
let l = triples2 $ randoms gen :: [[Float]]
return $ array bounds $ zip (range bounds) (fromList l)
triples2 (a:b:c:tl) = [a,b,c]:(triples2 tl)
instance Trans (Array (Int,Int) [Float]) -- genügt schon?
main = do print "Test"
let w=50
h=100
arr1 <- initialize ((0,0),(w,h)) :: IO (Array (Int,Int) [Float])
arr2 <- initialize ((0,0),(w,h)) :: IO (Array (Int,Int) [Float])
print "Atest";
som1 <- newIORef arr1
som2 <- newIORef arr2
radius <- newIORef 0.1
datasets <- readLrnFile "/home/basti/coding/haskell/som/som/Atom.lrn"
print "Ctest";
let learndata = map snd datasets
r <- halfioref radius
s1 <- readIORef som1
s2 <- readIORef som2
let soms = [s1,s2]
let u = foldl (learndataparallel r) soms learndata
print u
print "Etest";