Commit 505cb059 authored by Alp Mestanogullari's avatar Alp Mestanogullari

add ability to run GC phase or not, and pick beta, through CLI

parent 9b340ca4
......@@ -46,12 +46,16 @@ setupEnv (Right n) = getUnlabGraph (Random n)
main :: IO ()
main = do
[fpin, fpout] <- getArgs >>= \xs ->
if length xs /= 2
then Prelude.error "Usage: gargantext-graph-exe input_graph.csv output_file.txt"
[fpin, fpout, gcstr, betastr] <- getArgs >>= \xs ->
if length xs /= 4
then Prelude.error "Usage: gargantext-graph-exe input_graph.csv output_file.txt <'gc' or 'nogc'> <beta>"
else return xs
let gc = if gcstr == "gc" then True else False
beta = case readMaybe betastr of
Just d -> d
_ -> Prelude.error "beta must be a Double"
setupEnv (Left fpin) >>= \(dico, ~g) -> do
let (clusts, score) = withG g (\fg -> clusteringOptim 3 Conf fg beta)
let (clusts, score) = withG g (\fg -> clusteringOptim 3 Conf fg beta gc)
clusts' = Prelude.map (sort . Prelude.map (lkp dico) . IntSet.toList)
$ sortBy (\a b -> flipOrd $ comparing IntSet.size a b)
$ Prelude.map (\(n, ns) -> IntSet.insert n ns)
......@@ -65,8 +69,7 @@ main = do
"len=" ++ show (length clust) ++
" [" ++ intercalate ", " [ "'" ++ Text.unpack w ++ "'" | [w] <- clust ] ++ "]\n"
where beta = 0.0
flipOrd LT = GT
where flipOrd LT = GT
flipOrd GT = LT
flipOrd EQ = EQ
lkp dico i = fromMaybe (Prelude.error "Node not in dictionary?!") $
......
......@@ -73,8 +73,9 @@ clusteringOptim :: forall n a b. KnownNat n
-> Similarity
-> FiniteGraph n a b
-> Double -- beta
-> Bool -- True = run GC, False = don't
-> (Dict IntSet, Double)
clusteringOptim l s fg@(FiniteGraph g) beta = runClustering beta adj' prox sorted_edges
clusteringOptim l s fg@(FiniteGraph g) beta gc = runClustering gc beta adj' prox sorted_edges
where
!adj' = symAdjacent fg True
!tra' = symTransition adj'
......@@ -474,15 +475,24 @@ data Clust = Clust
runClustering
:: forall (n :: Nat). KnownNat n
=> Double -- ^ beta
=> Bool -- ^ do we run the 'garbage collector'?
-> Double -- ^ beta
-> SMatrix.Matrix n n Double -- ^ adjacency
-> SMatrix.Matrix n n Double -- ^ proxemie
-> SortedEdges
-> (Dict IntSet, Double)
runClustering beta adj prox se = trace "clustering starts" $ runST $ do
runClustering gc beta adj prox se = trace "clustering starts" $ runST $ do
mclust <- newMClustering n
forM_ se $ \(x, y, _) -> clusteringStep beta adj prox mclust (x, y)
trace "basic clusters done, running collector now" $ clusteringCollector beta adj prox mclust
if gc
then trace "basic clusters done, running collector now" $ clusteringCollector beta adj prox mclust
else do cps <- V.unsafeFreeze (mparts mclust)
let cps' = Dict.fromList
[ (n, xs)
| (n, Just (PartData xs _)) <- zip [0..] (V.toList cps)
]
sc <- MVU.unsafeRead (mscore mclust) 0
return (cps', sc)
where n = fromIntegral $ natVal (Proxy :: Proxy n)
sestr = intercalate "\n"
......
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