{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Datamining.Clustering.SGMInternal where
import Prelude hiding (lookup)
import Control.DeepSeq (NFData)
import Data.List (foldl', minimumBy, sortBy)
import qualified Data.Map.Strict as M
import Data.Ord (comparing)
import GHC.Generics (Generic)
exponential :: (Floating a, Integral t) => a -> a -> t -> a
exponential :: a -> a -> t -> a
exponential a
r0 a
d t
t = a
r0 a -> a -> a
forall a. Num a => a -> a -> a
* a -> a
forall a. Floating a => a -> a
exp (-a
da -> a -> a
forall a. Num a => a -> a -> a
*a
t')
where t' :: a
t' = t -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
t
data SGM t x k p = SGM
{
SGM t x k p -> Map k (p, t)
toMap :: M.Map k (p, t),
SGM t x k p -> t -> x
learningRate :: t -> x,
SGM t x k p -> Int
maxSize :: Int,
SGM t x k p -> x
diffThreshold :: x,
SGM t x k p -> Bool
allowDeletion :: Bool,
SGM t x k p -> p -> p -> x
difference :: p -> p -> x,
SGM t x k p -> p -> x -> p -> p
makeSimilar :: p -> x -> p -> p,
SGM t x k p -> k
nextIndex :: k
} deriving ((forall x. SGM t x k p -> Rep (SGM t x k p) x)
-> (forall x. Rep (SGM t x k p) x -> SGM t x k p)
-> Generic (SGM t x k p)
forall x. Rep (SGM t x k p) x -> SGM t x k p
forall x. SGM t x k p -> Rep (SGM t x k p) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x k p x. Rep (SGM t x k p) x -> SGM t x k p
forall t x k p x. SGM t x k p -> Rep (SGM t x k p) x
$cto :: forall t x k p x. Rep (SGM t x k p) x -> SGM t x k p
$cfrom :: forall t x k p x. SGM t x k p -> Rep (SGM t x k p) x
Generic, SGM t x k p -> ()
(SGM t x k p -> ()) -> NFData (SGM t x k p)
forall a. (a -> ()) -> NFData a
forall t x k p.
(NFData k, NFData p, NFData t, NFData x) =>
SGM t x k p -> ()
rnf :: SGM t x k p -> ()
$crnf :: forall t x k p.
(NFData k, NFData p, NFData t, NFData x) =>
SGM t x k p -> ()
NFData)
makeSGM
:: Bounded k
=> (t -> x) -> Int -> x -> Bool -> (p -> p -> x)
-> (p -> x -> p -> p) -> SGM t x k p
makeSGM :: (t -> x)
-> Int
-> x
-> Bool
-> (p -> p -> x)
-> (p -> x -> p -> p)
-> SGM t x k p
makeSGM t -> x
lr Int
n x
dt Bool
ad p -> p -> x
diff p -> x -> p -> p
ms =
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0
then [Char] -> SGM t x k p
forall a. HasCallStack => [Char] -> a
error [Char]
"max size for SGM <= 0"
else Map k (p, t)
-> (t -> x)
-> Int
-> x
-> Bool
-> (p -> p -> x)
-> (p -> x -> p -> p)
-> k
-> SGM t x k p
forall t x k p.
Map k (p, t)
-> (t -> x)
-> Int
-> x
-> Bool
-> (p -> p -> x)
-> (p -> x -> p -> p)
-> k
-> SGM t x k p
SGM Map k (p, t)
forall k a. Map k a
M.empty t -> x
lr Int
n x
dt Bool
ad p -> p -> x
diff p -> x -> p -> p
ms k
forall a. Bounded a => a
minBound
isEmpty :: SGM t x k p -> Bool
isEmpty :: SGM t x k p -> Bool
isEmpty = Map k (p, t) -> Bool
forall k a. Map k a -> Bool
M.null (Map k (p, t) -> Bool)
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
numModels :: SGM t x k p -> Int
numModels :: SGM t x k p -> Int
numModels = Map k (p, t) -> Int
forall k a. Map k a -> Int
M.size (Map k (p, t) -> Int)
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
modelMap :: SGM t x k p -> M.Map k p
modelMap :: SGM t x k p -> Map k p
modelMap = ((p, t) -> p) -> Map k (p, t) -> Map k p
forall a b k. (a -> b) -> Map k a -> Map k b
M.map (p, t) -> p
forall a b. (a, b) -> a
fst (Map k (p, t) -> Map k p)
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> Map k p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
counterMap :: SGM t x k p -> M.Map k t
counterMap :: SGM t x k p -> Map k t
counterMap = ((p, t) -> t) -> Map k (p, t) -> Map k t
forall a b k. (a -> b) -> Map k a -> Map k b
M.map (p, t) -> t
forall a b. (a, b) -> b
snd (Map k (p, t) -> Map k t)
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> Map k t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
modelAt :: Ord k => SGM t x k p -> k -> p
modelAt :: SGM t x k p -> k -> p
modelAt SGM t x k p
s k
k = (SGM t x k p -> Map k p
forall t x k p. SGM t x k p -> Map k p
modelMap SGM t x k p
s) Map k p -> k -> p
forall k a. Ord k => Map k a -> k -> a
M.! k
k
labels :: SGM t x k p -> [k]
labels :: SGM t x k p -> [k]
labels = Map k (p, t) -> [k]
forall k a. Map k a -> [k]
M.keys (Map k (p, t) -> [k])
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> [k]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
models :: SGM t x k p -> [p]
models :: SGM t x k p -> [p]
models = ((p, t) -> p) -> [(p, t)] -> [p]
forall a b. (a -> b) -> [a] -> [b]
map (p, t) -> p
forall a b. (a, b) -> a
fst ([(p, t)] -> [p])
-> (SGM t x k p -> [(p, t)]) -> SGM t x k p -> [p]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (p, t) -> [(p, t)]
forall k a. Map k a -> [a]
M.elems (Map k (p, t) -> [(p, t)])
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> [(p, t)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
counters :: SGM t x k p -> [t]
counters :: SGM t x k p -> [t]
counters = ((p, t) -> t) -> [(p, t)] -> [t]
forall a b. (a -> b) -> [a] -> [b]
map (p, t) -> t
forall a b. (a, b) -> b
snd ([(p, t)] -> [t])
-> (SGM t x k p -> [(p, t)]) -> SGM t x k p -> [t]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (p, t) -> [(p, t)]
forall k a. Map k a -> [a]
M.elems (Map k (p, t) -> [(p, t)])
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> [(p, t)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
time :: Num t => SGM t x k p -> t
time :: SGM t x k p -> t
time = [t] -> t
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([t] -> t) -> (SGM t x k p -> [t]) -> SGM t x k p -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((p, t) -> t) -> [(p, t)] -> [t]
forall a b. (a -> b) -> [a] -> [b]
map (p, t) -> t
forall a b. (a, b) -> b
snd ([(p, t)] -> [t])
-> (SGM t x k p -> [(p, t)]) -> SGM t x k p -> [t]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (p, t) -> [(p, t)]
forall k a. Map k a -> [a]
M.elems (Map k (p, t) -> [(p, t)])
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> [(p, t)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap
addNode
:: (Num t, Enum k, Ord k)
=> p -> SGM t x k p -> SGM t x k p
addNode :: p -> SGM t x k p -> SGM t x k p
addNode p
p SGM t x k p
s = if SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
numModels SGM t x k p
s Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
maxSize SGM t x k p
s
then [Char] -> SGM t x k p
forall a. HasCallStack => [Char] -> a
error [Char]
"SGM is full"
else SGM t x k p
s { toMap :: Map k (p, t)
toMap=Map k (p, t)
gm', nextIndex :: k
nextIndex=k -> k
forall a. Enum a => a -> a
succ k
k }
where gm :: Map k (p, t)
gm = SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap SGM t x k p
s
k :: k
k = SGM t x k p -> k
forall t x k p. SGM t x k p -> k
nextIndex SGM t x k p
s
gm' :: Map k (p, t)
gm' = k -> (p, t) -> Map k (p, t) -> Map k (p, t)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert k
k (p
p, t
0) Map k (p, t)
gm
deleteNode :: Ord k => k -> SGM t x k p -> SGM t x k p
deleteNode :: k -> SGM t x k p -> SGM t x k p
deleteNode k
k SGM t x k p
s = SGM t x k p
s { toMap :: Map k (p, t)
toMap=Map k (p, t)
gm' }
where gm :: Map k (p, t)
gm = SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap SGM t x k p
s
gm' :: Map k (p, t)
gm' = if k -> Map k (p, t) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member k
k Map k (p, t)
gm
then k -> Map k (p, t) -> Map k (p, t)
forall k a. Ord k => k -> Map k a -> Map k a
M.delete k
k Map k (p, t)
gm
else [Char] -> Map k (p, t)
forall a. HasCallStack => [Char] -> a
error [Char]
"no such node"
incrementCounter :: (Num t, Ord k) => k -> SGM t x k p -> SGM t x k p
incrementCounter :: k -> SGM t x k p -> SGM t x k p
incrementCounter k
k SGM t x k p
s = SGM t x k p
s { toMap :: Map k (p, t)
toMap=Map k (p, t)
gm' }
where gm :: Map k (p, t)
gm = SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap SGM t x k p
s
gm' :: Map k (p, t)
gm' = if k -> Map k (p, t) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member k
k Map k (p, t)
gm
then ((p, t) -> (p, t)) -> k -> Map k (p, t) -> Map k (p, t)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust (p, t) -> (p, t)
forall b a. Num b => (a, b) -> (a, b)
inc k
k Map k (p, t)
gm
else [Char] -> Map k (p, t)
forall a. HasCallStack => [Char] -> a
error [Char]
"no such node"
inc :: (a, b) -> (a, b)
inc (a
p, b
t) = (a
p, b
tb -> b -> b
forall a. Num a => a -> a -> a
+b
1)
trainNode
:: (Num t, Ord k)
=> SGM t x k p -> k -> p -> SGM t x k p
trainNode :: SGM t x k p -> k -> p -> SGM t x k p
trainNode SGM t x k p
s k
k p
target = SGM t x k p
s { toMap :: Map k (p, t)
toMap=Map k (p, t)
gm' }
where gm :: Map k (p, t)
gm = SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap SGM t x k p
s
gm' :: Map k (p, t)
gm' = ((p, t) -> (p, t)) -> k -> Map k (p, t) -> Map k (p, t)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust (p, t) -> (p, t)
tweakModel k
k Map k (p, t)
gm
r :: x
r = (SGM t x k p -> t -> x
forall t x k p. SGM t x k p -> t -> x
learningRate SGM t x k p
s) (SGM t x k p -> t
forall t x k p. Num t => SGM t x k p -> t
time SGM t x k p
s)
tweakModel :: (p, t) -> (p, t)
tweakModel (p
p, t
t) = (SGM t x k p -> p -> x -> p -> p
forall t x k p. SGM t x k p -> p -> x -> p -> p
makeSimilar SGM t x k p
s p
target x
r p
p, t
t)
leastUsefulNode :: Ord t => SGM t x k p -> k
leastUsefulNode :: SGM t x k p -> k
leastUsefulNode SGM t x k p
s = if SGM t x k p -> Bool
forall t x k p. SGM t x k p -> Bool
isEmpty SGM t x k p
s
then [Char] -> k
forall a. HasCallStack => [Char] -> a
error [Char]
"SGM has no nodes"
else (k, (p, t)) -> k
forall a b. (a, b) -> a
fst ((k, (p, t)) -> k)
-> (SGM t x k p -> (k, (p, t))) -> SGM t x k p -> k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, (p, t)) -> (k, (p, t)) -> Ordering)
-> [(k, (p, t))] -> (k, (p, t))
forall (t :: * -> *) a.
Foldable t =>
(a -> a -> Ordering) -> t a -> a
minimumBy (((k, (p, t)) -> t) -> (k, (p, t)) -> (k, (p, t)) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing ((p, t) -> t
forall a b. (a, b) -> b
snd ((p, t) -> t) -> ((k, (p, t)) -> (p, t)) -> (k, (p, t)) -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k, (p, t)) -> (p, t)
forall a b. (a, b) -> b
snd))
([(k, (p, t))] -> (k, (p, t)))
-> (SGM t x k p -> [(k, (p, t))]) -> SGM t x k p -> (k, (p, t))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (p, t) -> [(k, (p, t))]
forall k a. Map k a -> [(k, a)]
M.toList (Map k (p, t) -> [(k, (p, t))])
-> (SGM t x k p -> Map k (p, t)) -> SGM t x k p -> [(k, (p, t))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k (p, t)
forall t x k p. SGM t x k p -> Map k (p, t)
toMap (SGM t x k p -> k) -> SGM t x k p -> k
forall a b. (a -> b) -> a -> b
$ SGM t x k p
s
deleteLeastUsefulNode :: (Ord t, Ord k) => SGM t x k p -> SGM t x k p
deleteLeastUsefulNode :: SGM t x k p -> SGM t x k p
deleteLeastUsefulNode SGM t x k p
s = k -> SGM t x k p -> SGM t x k p
forall k t x p. Ord k => k -> SGM t x k p -> SGM t x k p
deleteNode k
k SGM t x k p
s
where k :: k
k = SGM t x k p -> k
forall t x k p. Ord t => SGM t x k p -> k
leastUsefulNode SGM t x k p
s
addModel
:: (Num t, Ord t, Enum k, Ord k)
=> p -> SGM t x k p -> SGM t x k p
addModel :: p -> SGM t x k p -> SGM t x k p
addModel p
p SGM t x k p
s = p -> SGM t x k p -> SGM t x k p
forall t k p x.
(Num t, Enum k, Ord k) =>
p -> SGM t x k p -> SGM t x k p
addNode p
p SGM t x k p
s'
where s' :: SGM t x k p
s' = if SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
numModels SGM t x k p
s Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
maxSize SGM t x k p
s
then SGM t x k p -> SGM t x k p
forall t k x p. (Ord t, Ord k) => SGM t x k p -> SGM t x k p
deleteLeastUsefulNode SGM t x k p
s
else SGM t x k p
s
classify
:: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)
=> SGM t x k p -> p -> (k, x, M.Map k (p, x))
classify :: SGM t x k p -> p -> (k, x, Map k (p, x))
classify SGM t x k p
s p
p = (k
bmu, x
bmuDiff, Map k (p, x)
report)
where sFull :: SGM t x k p
sFull = SGM t x k p
s { maxSize :: Int
maxSize = SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
numModels SGM t x k p
s, allowDeletion :: Bool
allowDeletion = Bool
False }
(k
bmu, x
bmuDiff, Map k (p, x)
report, SGM t x k p
_) = SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
classify' SGM t x k p
sFull p
p
classify'
:: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)
=> SGM t x k p -> p -> (k, x, M.Map k (p, x), SGM t x k p)
classify' :: SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
classify' SGM t x k p
s p
p
| SGM t x k p -> Bool
forall t x k p. SGM t x k p -> Bool
isEmpty SGM t x k p
s = SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
classify' (p -> SGM t x k p -> SGM t x k p
forall t k p x.
(Num t, Ord t, Enum k, Ord k) =>
p -> SGM t x k p -> SGM t x k p
addModel p
p SGM t x k p
s) p
p
| x
bmuDiff x -> x -> Bool
forall a. Ord a => a -> a -> Bool
> SGM t x k p -> x
forall t x k p. SGM t x k p -> x
diffThreshold SGM t x k p
s
Bool -> Bool -> Bool
&& (SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
numModels SGM t x k p
s Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< SGM t x k p -> Int
forall t x k p. SGM t x k p -> Int
maxSize SGM t x k p
s Bool -> Bool -> Bool
|| SGM t x k p -> Bool
forall t x k p. SGM t x k p -> Bool
allowDeletion SGM t x k p
s)
= SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
classify' (p -> SGM t x k p -> SGM t x k p
forall t k p x.
(Num t, Ord t, Enum k, Ord k) =>
p -> SGM t x k p -> SGM t x k p
addModel p
p SGM t x k p
s) p
p
| Bool
otherwise = (k
bmu, x
bmuDiff, Map k (p, x)
report, SGM t x k p
s')
where report :: Map k (p, x)
report
= (p -> (p, x)) -> Map k p -> Map k (p, x)
forall a b k. (a -> b) -> Map k a -> Map k b
M.map (\p
p0 -> (p
p0, SGM t x k p -> p -> p -> x
forall t x k p. SGM t x k p -> p -> p -> x
difference SGM t x k p
s p
p p
p0)) (Map k p -> Map k (p, x))
-> (SGM t x k p -> Map k p) -> SGM t x k p -> Map k (p, x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SGM t x k p -> Map k p
forall t x k p. SGM t x k p -> Map k p
modelMap (SGM t x k p -> Map k (p, x)) -> SGM t x k p -> Map k (p, x)
forall a b. (a -> b) -> a -> b
$ SGM t x k p
s
(k
bmu, x
bmuDiff)
= [(k, x)] -> (k, x)
forall a. [a] -> a
head ([(k, x)] -> (k, x))
-> (Map k (p, x) -> [(k, x)]) -> Map k (p, x) -> (k, x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, x) -> (k, x) -> Ordering) -> [(k, x)] -> [(k, x)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (k, x) -> (k, x) -> Ordering
forall a b. (Ord a, Ord b) => (a, b) -> (a, b) -> Ordering
matchOrder ([(k, x)] -> [(k, x)])
-> (Map k (p, x) -> [(k, x)]) -> Map k (p, x) -> [(k, x)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, (p, x)) -> (k, x)) -> [(k, (p, x))] -> [(k, x)]
forall a b. (a -> b) -> [a] -> [b]
map (\(k
k, (p
_, x
x)) -> (k
k, x
x))
([(k, (p, x))] -> [(k, x)])
-> (Map k (p, x) -> [(k, (p, x))]) -> Map k (p, x) -> [(k, x)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (p, x) -> [(k, (p, x))]
forall k a. Map k a -> [(k, a)]
M.toList (Map k (p, x) -> (k, x)) -> Map k (p, x) -> (k, x)
forall a b. (a -> b) -> a -> b
$ Map k (p, x)
report
s' :: SGM t x k p
s' = k -> SGM t x k p -> SGM t x k p
forall t k x p. (Num t, Ord k) => k -> SGM t x k p -> SGM t x k p
incrementCounter k
bmu SGM t x k p
s
matchOrder :: (Ord a, Ord b) => (a, b) -> (a, b) -> Ordering
matchOrder :: (a, b) -> (a, b) -> Ordering
matchOrder (a
a, b
b) (a
c, b
d) = (b, a) -> (b, a) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (b
b, a
a) (b
d, a
c)
trainAndClassify
:: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)
=> SGM t x k p -> p -> (k, x, M.Map k (p, x), SGM t x k p)
trainAndClassify :: SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
trainAndClassify SGM t x k p
s p
p = (k
bmu, x
bmuDiff, Map k (p, x)
report, SGM t x k p
s3)
where (k
bmu, x
bmuDiff, Map k (p, x)
report, SGM t x k p
s2) = SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
classify' SGM t x k p
s p
p
s3 :: SGM t x k p
s3 = SGM t x k p -> k -> p -> SGM t x k p
forall t k x p.
(Num t, Ord k) =>
SGM t x k p -> k -> p -> SGM t x k p
trainNode SGM t x k p
s2 k
bmu p
p
train
:: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)
=> SGM t x k p -> p -> SGM t x k p
train :: SGM t x k p -> p -> SGM t x k p
train SGM t x k p
s p
p = SGM t x k p
s'
where (k
_, x
_, Map k (p, x)
_, SGM t x k p
s') = SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> (k, x, Map k (p, x), SGM t x k p)
trainAndClassify SGM t x k p
s p
p
trainBatch
:: (Num t, Ord t, Num x, Ord x, Enum k, Ord k)
=> SGM t x k p -> [p] -> SGM t x k p
trainBatch :: SGM t x k p -> [p] -> SGM t x k p
trainBatch = (SGM t x k p -> p -> SGM t x k p)
-> SGM t x k p -> [p] -> SGM t x k p
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' SGM t x k p -> p -> SGM t x k p
forall t x k p.
(Num t, Ord t, Num x, Ord x, Enum k, Ord k) =>
SGM t x k p -> p -> SGM t x k p
train