Commit d13b3802 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[TESTS] ready for optim

parent 13f59d55
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main where
import Graph.Tools
import Graph.BAC.Clustering
import System.Environment (getArgs)
import Data.Set as Set
import Data.String.Conversions (cs)
import Data.Text (Text)
import Graph.BAC.ProxemyOptim
import Graph.BAC.ProxemyOptim
import Graph.FGL
import Prelude (String)
import Protolude
import qualified Data.IntMap as Dict
import qualified Data.List as List
import qualified Eigen.Matrix as Matrix
import qualified Eigen.SparseMatrix as SMatrix
import qualified Prelude as Prelude
main :: IO ()
main = do
[fp] <- getArgs
graph <- readFileGraph TestGraph fp
print (clusterGraph 3 graph)
m <- randomAdjacency
let
g :: Graph () ()
g = mkGraphUfromEdges
$ List.map (\(x,y,_) -> (x,y))
$ SMatrix.toList m
result = withG g (identity . (clusteringOptim 3 Conf))
print (result)
{-# LANGUAGE NoImplicitPrelude #-}
module Main2 where
import Graph.Tools
import Graph.BAC.Clustering
import System.Environment (getArgs)
import Protolude
main :: IO ()
main = do
[fp] <- getArgs
graph <- readFileGraph TestGraph fp
print (clusterGraph 3 graph)
......@@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 0738cfbe36f67275fe7fcd289fd26bddd3727957358ad06543242f719c4f34f1
-- hash: 4cecc6b992a2dda8a33d66136d8ffcda1eb4fcfed9fb2a21df529821278d524d
name: gargantext-graph
version: 0.1.0.0
......@@ -68,6 +68,7 @@ library
executable gargantext-graph-exe
main-is: Main.hs
other-modules:
Main2
Paths_gargantext_graph
hs-source-dirs:
app
......
#!/bin/bash
#
stack install --profile # --test
stack install --profile # --test # --haddock
......@@ -58,6 +58,8 @@ executables:
- -rtsopts
- -with-rtsopts=-N
- -fprof-auto
# - -Wmissing-signatures
# - -Wcompat
dependencies:
- gargantext-graph
......
#!/bin/bash
~/.local/bin/gargantext-graph-exe $1 +RTS -p # -sstderr
#~/.local/bin/gargantext-graph-exe $1 +RTS -p # -sstderr
time ~/.local/bin/gargantext-graph-exe +RTS -p # -sstderr
......@@ -97,13 +97,13 @@ data ClusteringMode = Part | Over | Both
type StrictClustering a = Clustering a
type OverlapsClustering a = Clustering a
data Clustering a = ClusteringIs { parts :: Dict (Set a)
, index :: Dict Int
, score :: Double
, mode :: ClusteringMode
data Clustering a = ClusteringIs { parts :: !(Dict (Set a))
, index :: !(Dict Int)
, score :: !(Double)
, mode :: !ClusteringMode
}
| Clusterings { strict :: StrictClustering a
, over :: OverlapsClustering a
| Clusterings { strict :: !(StrictClustering a)
, over :: !(OverlapsClustering a)
}
deriving (Show, Eq)
---------------------------------------------------------------
......@@ -122,8 +122,8 @@ type MatrixS n = SparseMatrix n n Double
data Similarity = Conf | Mod
data SimilarityMatrix n = SimConf (ConfluenceMatrix n)
| SimMod (ModularityMatrix n)
data SimilarityMatrix n = SimConf !(ConfluenceMatrix n)
| SimMod !(ModularityMatrix n)
type Dict = IntMap
......@@ -460,5 +460,5 @@ randomAdjacency = do
m1 <- randomMatrix
m2 <- randomMatrix
pure $ SMatrix.fromMatrix
$ DMatrix.imap (\i j v -> if i < j && v > 0.5 then 1 else 0)
$ DMatrix.imap (\i j v -> if i < j && v > 0.9 then 1 else 0)
$ DMatrix.mul m1 m2
{-# LANGUAGE NoImplicitPrelude #-}
module Spec where
import Data.Set as Set
import Data.String.Conversions (cs)
import Data.Text (Text)
......@@ -15,25 +17,37 @@ import qualified Eigen.SparseMatrix as SMatrix
import qualified Prelude as Prelude
import qualified Data.List as List
edges_test :: [(Int,Int)]
edges_test=[(0,1),(0,2),(0,4),(0,5),(0,3),(0,6)
,(1,2),(1,3),(2,3),(4,5),(4,6),(5,6)
,(7,8),(7,3),(7,4),(8,2),(8,5)
]
main_test :: IO ()
main_test = do
main :: IO ()
main = do
let
edges_test :: [(Int,Int)]
edges_test=[(0,1),(0,2),(0,4),(0,5),(0,3),(0,6)
,(1,2),(1,3),(2,3),(4,5),(4,6),(5,6)
,(7,8),(7,3),(7,4),(8,2),(8,5)
]
clustering_result =
ClusteringIs { parts = Dict.fromList [(0, Set.fromList [0,4,5,6])
,(1, Set.fromList [1,2,3])
,(7, Set.fromList [7,8])]
, index = Dict.fromList [(0,0),(1,1),(2,1)
,(3,1),(4,0),(5,0)
,(6,0),(7,7),(8,7)
]
, score = 3.0558391780792453
, mode = Part
}
g :: Graph () ()
g = mkGraphUfromEdges edges_test
result = withG g (identity . (clusteringOptim 3 Conf))
test = ClusteringIs { parts = Dict.fromList [(0, Set.fromList [0,4,5,6]),(1, Set.fromList [1,2,3]),(7, Set.fromList [7,8])], index = Dict.fromList [(0,0),(1,1),(2,1),(3,1),(4,0),(5,0),(6,0),(7,7),(8,7)], score = 3.0558391780792453, mode = Part}
print $ result == test
print $ result == clustering_result
test_random :: IO ()
test_random = do
m <- randomAdjacency
let
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment