packages feed

tsne 1.0.0.1 → 1.1.0

raw patch · 5 files changed

+68/−15 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Algorithm.TSNE: [tsneCost] :: TSNEOutput3D -> Double
- Data.Algorithm.TSNE: [tsneIteration] :: TSNEOutput3D -> Int
- Data.Algorithm.TSNE.Internals: initState :: Int -> IO TSNEState
- Data.Algorithm.TSNE.Internals: runTSNE :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput3D IO ()
- Data.Algorithm.TSNE.Types: [tsneCost] :: TSNEOutput3D -> Double
- Data.Algorithm.TSNE.Types: [tsneIteration] :: TSNEOutput3D -> Int
+ Data.Algorithm.TSNE: TSNEOutput2D :: Int -> [Position2D] -> Double -> TSNEOutput2D
+ Data.Algorithm.TSNE: [tsneCost2D] :: TSNEOutput2D -> Double
+ Data.Algorithm.TSNE: [tsneCost3D] :: TSNEOutput3D -> Double
+ Data.Algorithm.TSNE: [tsneIteration2D] :: TSNEOutput2D -> Int
+ Data.Algorithm.TSNE: [tsneIteration3D] :: TSNEOutput3D -> Int
+ Data.Algorithm.TSNE: [tsneSolution2D] :: TSNEOutput2D -> [Position2D]
+ Data.Algorithm.TSNE: data TSNEOutput2D
+ Data.Algorithm.TSNE: forTsne2D :: (TSNEOutput2D -> IO ()) -> TSNEOptions -> TSNEInput -> IO ()
+ Data.Algorithm.TSNE: tsne2D :: TSNEOptions -> TSNEInput -> Producer TSNEOutput2D IO ()
+ Data.Algorithm.TSNE.Internals: initSolution2D :: Int -> IO [[Double]]
+ Data.Algorithm.TSNE.Internals: initState2D :: Int -> IO TSNEState
+ Data.Algorithm.TSNE.Internals: initState3D :: Int -> IO TSNEState
+ Data.Algorithm.TSNE.Internals: output2D :: [[Double]] -> TSNEState -> TSNEOutput2D
+ Data.Algorithm.TSNE.Internals: runTSNE2D :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput2D IO ()
+ Data.Algorithm.TSNE.Internals: runTSNE3D :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput3D IO ()
+ Data.Algorithm.TSNE.Internals: solution2D :: [[Double]] -> [Position2D]
+ Data.Algorithm.TSNE.Types: TSNEOutput2D :: Int -> [Position2D] -> Double -> TSNEOutput2D
+ Data.Algorithm.TSNE.Types: [tsneCost2D] :: TSNEOutput2D -> Double
+ Data.Algorithm.TSNE.Types: [tsneCost3D] :: TSNEOutput3D -> Double
+ Data.Algorithm.TSNE.Types: [tsneIteration2D] :: TSNEOutput2D -> Int
+ Data.Algorithm.TSNE.Types: [tsneIteration3D] :: TSNEOutput3D -> Int
+ Data.Algorithm.TSNE.Types: [tsneSolution2D] :: TSNEOutput2D -> [Position2D]
+ Data.Algorithm.TSNE.Types: data TSNEOutput2D
+ Data.Algorithm.TSNE.Types: instance GHC.Classes.Eq Data.Algorithm.TSNE.Types.TSNEOutput2D
+ Data.Algorithm.TSNE.Types: instance GHC.Show.Show Data.Algorithm.TSNE.Types.TSNEOutput2D
+ Data.Algorithm.TSNE.Types: type Position2D = (Double, Double)

Files

example/Main.hs view
@@ -40,6 +40,6 @@  outputResult :: TSNEOutput3D -> IO () outputResult s = do-    putStrLn $ "iteration: " ++ (show.tsneIteration) s-    putStrLn $ "cost: " ++ (show.tsneCost) s+    putStrLn $ "iteration: " ++ (show.tsneIteration3D) s+    putStrLn $ "cost: " ++ (show.tsneCost3D) s 
src/Data/Algorithm/TSNE.hs view
@@ -1,8 +1,11 @@ module Data.Algorithm.TSNE ( +        TSNEOptions(..),         tsne3D,         forTsne3D,-        TSNEOptions(..),-        TSNEOutput3D(..)+        TSNEOutput3D(..),+        tsne2D,+        forTsne2D,+        TSNEOutput2D(..)     ) where  import Pipes@@ -14,8 +17,8 @@ -- | Generates an infinite stream of 3D tSNE iterations. tsne3D :: TSNEOptions -> TSNEInput -> Producer TSNEOutput3D IO () tsne3D opts input = do-    st <- liftIO $ initState $ length input-    runTSNE opts input ps st+    st <- liftIO $ initState3D $ length input+    runTSNE3D opts input ps st         where ps = neighbourProbabilities opts input  -- | Executes an IO action for each iteration of the 3D tSNE algorithm.@@ -24,3 +27,15 @@     runEffect $ for (tsne3D opts input) $ \o -> do         lift $ action o     +-- | Generates an infinite stream of 2D tSNE iterations.+tsne2D :: TSNEOptions -> TSNEInput -> Producer TSNEOutput2D IO ()+tsne2D opts input = do+    st <- liftIO $ initState2D $ length input+    runTSNE2D opts input ps st+        where ps = neighbourProbabilities opts input++-- | Executes an IO action for each iteration of the 2D tSNE algorithm.+forTsne2D :: (TSNEOutput2D -> IO ()) -> TSNEOptions -> TSNEInput -> IO ()+forTsne2D action opts input = do+    runEffect $ for (tsne2D opts input) $ \o -> do+        lift $ action o    
src/Data/Algorithm/TSNE/Internals.hs view
@@ -35,13 +35,20 @@             n = inputSize i             s = stSolution st     -initState :: Int -> IO TSNEState-initState n = do+initState3D :: Int -> IO TSNEState+initState3D n = do     s <- initSolution3D n     return $ TSNEState 0 s (rr 1) (rr 0)         where             rr = repeat.repeat +initState2D :: Int -> IO TSNEState+initState2D n = do+    s <- initSolution2D n+    return $ TSNEState 0 s (rr 1) (rr 0)+        where+            rr = repeat.repeat+ initSolution3D :: Int -> IO [[Double]] initSolution3D n = do     let ns = normalsIO' (0, 1e-4)@@ -50,12 +57,25 @@     zs <- ns     return $ take n <$> [xs,ys,zs] -runTSNE :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput3D IO ()-runTSNE opts vs ps st = do+initSolution2D :: Int -> IO [[Double]]+initSolution2D n = do+    let ns = normalsIO' (0, 1e-4)+    xs <- ns+    ys <- ns+    return $ take n <$> [xs,ys]++runTSNE3D :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput3D IO ()+runTSNE3D opts vs ps st = do+    yield $ output3D ps st     let st' = force $ stepTSNE opts vs ps st-    yield $ output3D ps st'-    runTSNE opts vs ps st'+    runTSNE3D opts vs ps st' +runTSNE2D :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> Producer TSNEOutput2D IO ()+runTSNE2D opts vs ps st = do+    yield $ output2D ps st+    let st' = force $ stepTSNE opts vs ps st+    runTSNE2D opts vs ps st'+ stepTSNE :: TSNEOptions -> TSNEInput -> [[Probability]] -> TSNEState -> TSNEState stepTSNE opts vs ps st = TSNEState i' s'' g' d'     where@@ -109,6 +129,16 @@     where         i = stIteration st         s = (solution3D . stSolution) st+        c = cost pss st++solution2D :: [[Double]] -> [Position2D]+solution2D (xs:ys:_) = zip xs ys++output2D :: [[Double]] -> TSNEState -> TSNEOutput2D+output2D pss st = TSNEOutput2D i s c+    where+        i = stIteration st+        s = (solution2D . stSolution) st         c = cost pss st  cost :: [[Double]] -> TSNEState -> Double
src/Data/Algorithm/TSNE/Types.hs view
@@ -18,9 +18,17 @@ type Position3D = (Double,Double,Double)  data TSNEOutput3D = TSNEOutput3D {-    tsneIteration :: Int,+    tsneIteration3D :: Int,     tsneSolution3D :: [Position3D],-    tsneCost :: Double+    tsneCost3D :: Double+} deriving (Show, Eq)++type Position2D = (Double,Double)++data TSNEOutput2D = TSNEOutput2D {+    tsneIteration2D :: Int,+    tsneSolution2D :: [Position2D],+    tsneCost2D :: Double } deriving (Show, Eq)  instance Default TSNEOptions where
tsne.cabal view
@@ -1,5 +1,5 @@ name:                tsne-version:             1.0.0.1+version:             1.1.0 synopsis:            t-SNE description:         Pure Haskell implementation of the t-SNE dimension reduction algorithm. homepage:            https://bitbucket.org/robagar/haskell-tsne