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
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-graph
Commits
67a730e4
Commit
67a730e4
authored
Jul 09, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TEST] hspec
parent
6050f41e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
90 deletions
+84
-90
gargantext-graph.cabal
gargantext-graph.cabal
+5
-3
install
install
+1
-1
package.yaml
package.yaml
+4
-1
ProxemyOptim.hs
src/Graph/BAC/ProxemyOptim.hs
+9
-24
Main.hs
test/Main.hs
+65
-0
Spec.hs
test/Spec.hs
+0
-61
No files found.
gargantext-graph.cabal
View file @
67a730e4
...
...
@@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash:
c963b0693d31715c24d7005b13eb4c408cd00c23009b3e68b6dbf329a47db200
-- hash:
f8da0e8f0d95addc40b203c0fc52a4e61e8af8847f134c289ba4acc5bfefd8d7
name: gargantext-graph
version: 0.1.0.0
...
...
@@ -102,7 +102,7 @@ executable gargantext-graph-exe
test-suite gargantext-graph-test
type: exitcode-stdio-1.0
main-is:
Spec
.hs
main-is:
Main
.hs
other-modules:
Paths_gargantext_graph
hs-source-dirs:
...
...
@@ -110,7 +110,8 @@ test-suite gargantext-graph-test
default-extensions: DataKinds FlexibleInstances OverloadedStrings
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
accelerate
QuickCheck
, accelerate
, accelerate-arithmetic
, accelerate-utility
, base >=4.7 && <5
...
...
@@ -122,6 +123,7 @@ test-suite gargantext-graph-test
, fgl
, gargantext-graph
, haskell-igraph >=0.6.0
, hspec
, lens
, pretty-simple
, protolude
...
...
install
View file @
67a730e4
#!/bin/bash
stack
install
--profile
#
--test # --haddock
stack
install
--profile
--test
# --haddock
package.yaml
View file @
67a730e4
...
...
@@ -62,10 +62,11 @@ executables:
-
-Wcompat
dependencies
:
-
gargantext-graph
-
criterion
tests
:
gargantext-graph-test
:
main
:
Spec
.hs
main
:
Main
.hs
source-dirs
:
test
ghc-options
:
-
-threaded
...
...
@@ -73,3 +74,5 @@ tests:
-
-with-rtsopts=-N
dependencies
:
-
gargantext-graph
-
hspec
-
QuickCheck
src/Graph/BAC/ProxemyOptim.hs
View file @
67a730e4
...
...
@@ -152,9 +152,9 @@ adjacent (FiniteGraph g) isReflexive =
transition
::
KnownNat
n
=>
AdjacencyMatrix
n
->
TransitionMatrix
n
transition
m
=
SMatrix
.
imap
(
\
i
j
v
->
v
*
(
List
.!
!
)
s
i
)
m
transition
m
=
SMatrix
.
imap
(
\
i
j
v
->
v
*
(
VS
.
!
)
s
i
)
m
where
s
=
sumWith
'
Colonne
(
\
s
->
1
/
s
)
m
s
=
sumWith
Colonne
(
\
s
->
1
/
s
)
m
proxemie
::
KnownNat
n
...
...
@@ -175,13 +175,13 @@ matconf :: forall n. KnownNat n
matconf
False
a
p
=
symmetry
confmat
where
-- vcount = natToInt @n
degs
=
sumWith
'
Colonne
identity
a
sumdeg
=
List
.
sum
degs
degs
=
sumWith
Colonne
identity
a
sumdeg
=
VS
.
sum
degs
confmat
=
DMatrix
.
imap
(
\
x
y
v
->
if
x
<
y
then
let
prox_y_x_length
=
v
prox_y_x_infini
=
((
List
.!
!
)
degs
x
)
/
sumdeg
prox_y_x_infini
=
((
VS
.
!
)
degs
x
)
/
sumdeg
in
(
prox_y_x_length
-
prox_y_x_infini
)
/
(
prox_y_x_length
+
prox_y_x_infini
)
...
...
@@ -219,15 +219,15 @@ edges_confluence l am tm = -- traceShow ("degs", degs) $
SMatrix
.
toList
matconf'
where
vcount
=
natToInt
@
n
degs
=
sumWith
'
Colonne
identity
am
sumdeg
=
List
.
sum
degs
degs
=
sumWith
Colonne
identity
am
sumdeg
=
VS
.
sum
degs
matconf'
=
SMatrix
.
imap
(
\
x
y
_
->
if
x
<
y
then
let
deg_x
=
(
List
.!
!
)
degs
x
-
1
deg_y
=
(
List
.!
!
)
degs
y
-
1
deg_x
=
(
VS
.
!
)
degs
x
-
1
deg_y
=
(
VS
.
!
)
degs
y
-
1
tm'
=
SMatrix
.
imap
(
\
i
j
v
->
if
(
i
==
x
&&
j
==
y
)
||
(
i
==
y
&&
j
==
x
)
then
0
...
...
@@ -404,7 +404,6 @@ symmetryS :: KnownNat n => MatrixS n -> MatrixS n
symmetryS
m
=
SMatrix
.
imap
(
\
x
y
v
->
if
x
<
y
then
v
else
coeffSM
y
x
m
)
m
---------------------------
class
KnownNat
n
=>
Vector
n
a
where
fromList
::
KnownNat
n
=>
Proxy
n
->
[(
Integer
,
Double
)]
->
a
...
...
@@ -425,7 +424,6 @@ vectorFromListD :: KnownNat n => Proxy n -> [(Integer, Double)] -> VectorD n
vectorFromListD
pn
ns
=
toMatrix
$
vectorFromListS
pn
ns
------------------------------
data
Direction
=
Ligne
|
Colonne
sumWith
::
(
Elem
a
...
...
@@ -440,17 +438,4 @@ sumWith dir f m = VS.fromList
where
somme
m'
=
map
(
sum
.
SMatrix
.
toMatrix
)
m'
sumWith'
::
(
Elem
a
,
Elem
t
,
KnownNat
n
)
=>
Direction
->
(
t
->
a
)
->
SparseMatrix
n
n
t
->
[
a
]
sumWith'
dir
f
m
=
map
(
\
v
->
f
v
)
$
case
dir
of
Colonne
->
somme
$
SMatrix
.
getCols
m
Ligne
->
somme
$
SMatrix
.
getRows
m
where
somme
m'
=
map
(
sum
.
SMatrix
.
toMatrix
)
m'
--------------------------------------------
test/Main.hs
0 → 100644
View file @
67a730e4
{-# LANGUAGE NoImplicitPrelude #-}
module
Main
where
import
Data.Set
as
Set
import
Data.String.Conversions
(
cs
)
import
Data.Text
(
Text
)
import
qualified
Eigen.Matrix
as
Matrix
import
Graph.BAC.ProxemyOptim
import
Graph.FGL
import
Graph.Types
import
Graph.Tools.Random
import
Prelude
(
String
)
import
Protolude
import
Graph.BAC.ProxemyOptim
import
Test.Hspec
import
qualified
Data.IntMap
as
Dict
import
qualified
Eigen.SparseMatrix
as
SMatrix
import
qualified
Prelude
as
Prelude
import
qualified
Data.List
as
List
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
)
]
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
))
it
"Graph Toy test exact result"
$
do
shouldBe
True
(
result
==
clustering_result
)
{-
m <- randomAdjacency
describe "Random Matrix of fixed size (TODO dynamic size)" $ do
let
g :: Graph () ()
g = mkGraphUfromEdges
$ List.map (\(x,y,_) -> (x,y))
$ SMatrix.toList m
result = withG g (parts . (clusteringOptim 3 Conf))
it "Random test, checking clustering size" $ do
shouldBe True (let n = (Dict.size result) in n > 1 && n < 10)
-}
test/Spec.hs
deleted
100644 → 0
View file @
6050f41e
{-# LANGUAGE NoImplicitPrelude #-}
module
Spec
where
import
Data.Set
as
Set
import
Data.String.Conversions
(
cs
)
import
Data.Text
(
Text
)
import
qualified
Eigen.Matrix
as
Matrix
import
Graph.BAC.ProxemyOptim
import
Graph.FGL
import
Graph.Types
import
Graph.Tools.Random
import
Prelude
(
String
)
import
Protolude
import
Graph.BAC.ProxemyOptim
import
qualified
Data.IntMap
as
Dict
import
qualified
Eigen.SparseMatrix
as
SMatrix
import
qualified
Prelude
as
Prelude
import
qualified
Data.List
as
List
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
))
print
$
result
==
clustering_result
test_random
::
IO
()
test_random
=
do
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
)
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