Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-graph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Moutinho
gargantext-graph
Commits
178eb573
Commit
178eb573
authored
Sep 22, 2021
by
Alp Mestanogullari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
505cb059
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
164 deletions
+100
-164
Main.hs
app/Main.hs
+10
-9
ProxemyOptim.hs
src/Graph/BAC/ProxemyOptim.hs
+50
-118
Import.hs
src/Graph/Tools/Import.hs
+17
-14
Main.hs
test/Main.hs
+23
-23
No files found.
app/Main.hs
View file @
178eb573
...
...
@@ -40,9 +40,8 @@ import qualified Data.IntMap.Strict as IntMap
import
qualified
Data.IntSet
as
IntSet
import
qualified
Data.Text
as
Text
setupEnv
::
Either
String
Int
->
IO
(
Dict
[
Text
],
Graph
()
()
)
setupEnv
(
Left
fp
)
=
getUnlabGraph
(
WithFile
fp
)
setupEnv
(
Right
n
)
=
getUnlabGraph
(
Random
n
)
setupEnv
::
FilePath
->
IO
(
Graph
[
Text
]
Double
)
setupEnv
fp
=
getGraph
(
WithFile
fp
)
main
::
IO
()
main
=
do
...
...
@@ -54,23 +53,25 @@ main = do
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
gc
)
setupEnv
fpin
>>=
\
g
->
do
let
(
Clust
clusts
dico
score
)
=
withG
g
(
\
fg
->
clusteringOptim
3
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
)
$
IntMap
.
toList
clusts
putStrLn
$
"#clusters: "
++
show
(
length
clusts'
)
$
IntMap
.
elems
clusts
putStrLn
$
"#clusters: "
++
show
(
IntMap
.
size
clusts
)
putStrLn
$
"max cluster size: "
++
show
(
length
(
clusts'
Prelude
.!!
0
))
putStrLn
$
"Clustering score: "
++
show
score
withFile
fpout
WriteMode
$
\
hndl
->
forM_
clusts'
$
\
clust
->
hPutStrLn
hndl
$
"len="
++
show
(
length
clust
)
++
" ["
++
intercalate
", "
[
"'"
++
Text
.
unpack
w
++
"'"
|
[
w
]
<-
clust
]
++
"]
\n
"
" ["
++
intercalate
", "
[
escapestr
w
|
[
w
]
<-
clust
]
++
"]
\n
"
where
flipOrd
LT
=
GT
flipOrd
GT
=
LT
flipOrd
EQ
=
EQ
lkp
dico
i
=
fromMaybe
(
Prelude
.
error
"Node not in dictionary?!"
)
$
IntMap
.
lookup
i
dico
escapestr
w
|
"'"
`
Text
.
isInfixOf
`
w
=
"
\"
"
++
Text
.
unpack
w
++
"
\"
"
|
otherwise
=
"'"
++
Text
.
unpack
w
++
"'"
src/Graph/BAC/ProxemyOptim.hs
View file @
178eb573
This diff is collapsed.
Click to expand it.
src/Graph/Tools/Import.hs
View file @
178eb573
...
...
@@ -10,6 +10,7 @@ Portability : POSIX
-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NoImplicitPrelude #-}
...
...
@@ -39,31 +40,33 @@ import Data.Reflection
import
qualified
Data.IntMap.Strict
as
IntMap
------------------------------------------------------------------------
data
GetGraph
=
WithFile
{
filepath
::
FilePath
}
|
Random
Int
data
GetGraph
a
b
where
WithFile
::
{
filepath
::
FilePath
}
->
GetGraph
[
Text
]
Double
Random
::
Int
->
GetGraph
()
()
data
GraphData
=
LightGraph
{
lightGraph
::
Graph
()
()
}
|
LabelledGraph
{
labelledGraph
::
Graph
[
Text
]
Double
}
deriving
(
Show
)
data
GraphData
a
b
where
LightGraph
::
{
lightGraph
::
Graph
()
()
}
->
GraphData
()
()
LabelledGraph
::
{
labelledGraph
::
Graph
[
Text
]
Double
}
->
GraphData
[
Text
]
Double
getGraph
::
GetGraph
->
IO
GraphData
getGraph
(
Random
n
)
=
reifyNat
(
fromIntegral
n
)
$
\
(
pn
::
Proxy
n
)
->
getGraph
'
::
GetGraph
a
b
->
IO
(
GraphData
a
b
)
getGraph
'
(
Random
n
)
=
reifyNat
(
fromIntegral
n
)
$
\
(
pn
::
Proxy
n
)
->
randomAdjacency
@
n
>>=
\
m
->
pure
$
LightGraph
$
mkGraphUfromEdges
$
List
.
map
(
\
(
x
,
y
,
_
)
->
(
x
,
y
))
$
SMatrix
.
toList
m
getGraph
(
WithFile
fp
)
=
do
getGraph
'
(
WithFile
fp
)
=
do
g
<-
readFileGraph
CillexGraph
fp
pure
$
LabelledGraph
g
get
UnlabGraph
::
GetGraph
->
IO
(
Dict
[
Text
],
Graph
()
()
)
get
UnlabGraph
gg
=
getUnlabGraph'
<$>
getGraph
gg
get
Graph
::
GetGraph
a
b
->
IO
(
Graph
a
b
)
get
Graph
gg
=
toGraph'
<$>
getGraph'
gg
getUnlabGraph'
::
GraphData
->
(
Dict
[
Text
],
Graph
()
()
)
getUnlabGraph'
(
LightGraph
g
)
=
(
Dict
.
empty
,
g
)
getUnlabGraph'
(
LabelledGraph
g
)
=
(
dico
,
Graph
.
unlab
g
)
where
dico
=
IntMap
.
fromList
(
Graph
.
labNodes
g
)
toGraph'
::
GraphData
a
b
->
Graph
a
b
toGraph'
(
LightGraph
g
)
=
g
toGraph'
(
LabelledGraph
g
)
=
g
test/Main.hs
View file @
178eb573
...
...
@@ -24,33 +24,33 @@ import qualified Data.IntSet as IntSet
main
::
IO
()
main
=
hspec
$
do
describe
"Graph Toy first test"
$
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
)
]
main
=
return
()
--
hspec $ do
--
describe "Graph Toy first test" $ 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
=
Clust
{
cparts
=
Dict
.
fromList
[
(
0
,
IntSet
.
fromList
[
0
,
4
,
5
,
6
])
,
(
1
,
IntSet
.
fromList
[
1
,
2
,
3
])
,
(
7
,
IntSet
.
fromList
[
7
,
8
])
]
,
cindex
=
VU
.
fromList
[
0
,
1
,
1
,
1
,
0
,
0
,
0
,
7
,
7
]
,
cscore
=
3.0558391780792453
}
--
clustering_result =
--
Clust
--
{ cparts = Dict.fromList
--
[ (0, IntSet.fromList [0,4,5,6])
--
, (1, IntSet.fromList [1,2,3])
--
, (7, IntSet.fromList [7,8])
--
]
-- , cindex = Dict.fromList [(0, 0)
, 1, 1, 1, 0, 0, 0, 7, 7]
--
, cscore = 3.0558391780792453
--
}
g
::
Graph
()
()
g
=
mkGraphUfromEdges
edges_test
--
g :: Graph () ()
--
g = mkGraphUfromEdges edges_test
result
=
withG
g
(
\
fg
->
identity
$
clusteringOptim
3
Conf
fg
beta
)
it
"Graph Toy test exact result"
$
do
result
`
shouldBe
`
clustering_result
-- result = withG g (\fg -> clusteringOptim 3
fg beta)
--
it "Graph Toy test exact result" $ do
--
result `shouldBe` clustering_result
where
beta
=
0.0
--
where beta = 0.0
{-
m <- randomAdjacency
describe "Random Matrix of fixed size (TODO dynamic size)" $ do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment