Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
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
Przemyslaw Kaminski
haskell-gargantext
Commits
0ce69ad8
Commit
0ce69ad8
authored
Jul 06, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] Node size back
parent
92951126
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
48 deletions
+110
-48
build
bin/build
+1
-1
install
bin/install
+1
-1
Graph.hs
src/Gargantext/Viz/Graph.hs
+2
-2
API.hs
src/Gargantext/Viz/Graph/API.hs
+1
-1
Matrice.hs
src/Gargantext/Viz/Graph/Distances/Matrice.hs
+102
-42
Tools.hs
src/Gargantext/Viz/Graph/Tools.hs
+3
-1
No files found.
bin/build
View file @
0ce69ad8
#!/bin/bash
stack build
--profile
# --test # --haddock
stack build
#
--profile # --test # --haddock
bin/install
View file @
0ce69ad8
#!/bin/bash
stack
install
--profile
# --test --haddock
stack
install
#
--profile # --test --haddock
src/Gargantext/Viz/Graph.hs
View file @
0ce69ad8
...
...
@@ -116,8 +116,8 @@ instance ToSchema GraphMetadata where
makeLenses
''
G
raphMetadata
data
Graph
=
Graph
{
_graph_nodes
::
[
Node
]
,
_graph_edges
::
[
Edge
]
data
Graph
=
Graph
{
_graph_nodes
::
[
Node
]
,
_graph_edges
::
[
Edge
]
,
_graph_metadata
::
Maybe
GraphMetadata
}
deriving
(
Show
,
Generic
)
...
...
src/Gargantext/Viz/Graph/API.hs
View file @
0ce69ad8
...
...
@@ -149,7 +149,7 @@ computeGraph cId d nt repo = do
-- TODO split diagonal
myCooc
<-
Map
.
filter
(
>
1
)
<$>
getCoocByNgrams
(
Diagonal
Fals
e
)
<$>
getCoocByNgrams
(
Diagonal
Tru
e
)
<$>
groupNodesByNgrams
ngs
<$>
getNodesByNgramsOnlyUser
cId
(
lIds
<>
[
lId
])
nt
(
Map
.
keys
ngs
)
...
...
src/Gargantext/Viz/Graph/Distances/Matrice.hs
View file @
0ce69ad8
...
...
@@ -30,6 +30,7 @@ Implementation use Accelerate library which enables GPU and CPU computation:
module
Gargantext.Viz.Graph.Distances.Matrice
where
import
qualified
Data.Foldable
as
P
(
foldl1
)
import
Debug.Trace
(
trace
)
import
Data.Array.Accelerate
import
Data.Array.Accelerate.Interpreter
(
run
)
...
...
@@ -137,11 +138,10 @@ divByDiag d mat = zipWith (/) mat (replicate (constant (Z :. (d :: Int) :. All))
-- [ 0.0, 4.0, 7.0,
-- 0.0, 5.0, 8.0,
-- 0.0, 6.0, 9.0]
matMiniMax
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
matMiniMax
m
=
map
(
\
x
->
ifThenElse
(
x
>
miniMax'
)
x
0
)
(
transpose
m
)
matMiniMax
::
(
Elt
a
,
Ord
a
,
P
.
Num
a
)
=>
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
matMiniMax
m
=
filterWith'
miniMax'
(
constant
0
)
m
where
miniMax'
=
(
the
$
minimum
$
maximum
m
)
miniMax'
=
the
$
minimum
$
maximum
m
-- | Filters the matrix with a constant
...
...
@@ -157,10 +157,14 @@ filter' t m = filterWith t 0 m
filterWith
::
Double
->
Double
->
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
filterWith
t
v
m
=
map
(
\
x
->
ifThenElse
(
x
>
(
constant
t
))
x
(
constant
v
))
(
transpose
m
)
filterWith'
::
(
Elt
a
,
Ord
a
)
=>
Exp
a
->
Exp
a
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
filterWith'
t
v
m
=
map
(
\
x
->
ifThenElse
(
x
>
t
)
x
v
)
m
-----------------------------------------------------------------------
-- * Me
asure
s of proximity
-- * Me
tric
s of proximity
-----------------------------------------------------------------------
-- ** Conditional distance
...
...
@@ -168,10 +172,10 @@ filterWith t v m = map (\x -> ifThenElse (x > (constant t)) x (constant v)) (tra
-- | Conditional distance (basic version)
--
-- 2 main me
asure
s are actually implemented in order to compute the
-- 2 main me
tric
s are actually implemented in order to compute the
-- proximity of two terms: conditional and distributional
--
-- Conditional me
asure is an absolute measure
which reflects
-- Conditional me
tric is an absolute metric
which reflects
-- interactions of 2 terms in the corpus.
measureConditional
::
Matrix
Int
->
Matrix
Double
--measureConditional m = run (matMiniMax $ matProba (dim m) $ map fromIntegral $ use m)
...
...
@@ -184,7 +188,7 @@ measureConditional m = run $ matProba (dim m)
-- | Conditional distance (advanced version)
--
-- The conditional me
asure
P(i|j) of 2 terms @i@ and @j@, also called
-- The conditional me
tric
P(i|j) of 2 terms @i@ and @j@, also called
-- "confidence" , is the maximum probability between @i@ and @j@ to see
-- @i@ in the same context of @j@ knowing @j@.
--
...
...
@@ -216,12 +220,12 @@ conditional' m = ( run $ ie $ map fromIntegral $ use m
-----------------------------------------------------------------------
-- ** Distributional Distance
-- | Distributional Distance
Measure
-- | Distributional Distance
metric
--
-- Distributional me
asure is a relative measure
which depends on the
-- Distributional me
tric is a relative metric
which depends on the
-- selected list, it represents structural equivalence of mutual information.
--
-- The distributional me
asure
P(c) of @i@ and @j@ terms is: \[
-- The distributional me
tric
P(c) of @i@ and @j@ terms is: \[
-- S_{MI} = \frac {\sum_{k \neq i,j ; MI_{ik} >0}^{} \min(MI_{ik},
-- MI_{jk})}{\sum_{k \neq i,j ; MI_{ik}>0}^{}} \]
--
...
...
@@ -242,8 +246,8 @@ conditional' m = ( run $ ie $ map fromIntegral $ use m
--
distributional
::
Matrix
Int
->
Matrix
Double
distributional
m
=
run
-- $ matMiniMax
--
$ diagNull n
$
r
i
$
diagNull
n
$
r
IJ
n
$
filterWith
0
100
$
filter'
0
$
s_mi
...
...
@@ -253,14 +257,14 @@ distributional m = run -- $ matMiniMax
{- push matrix in Accelerate type -}
where
ri
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
ri
mat
=
mat1
-- zipWith (/) mat1 mat2
_
ri
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
_
ri
mat
=
mat1
-- zipWith (/) mat1 mat2
where
mat1
=
matSumCol
n
$
zipWith
min
(
myMin
mat
)
(
myMin
$
filterWith
0
100
$
diagNull
n
$
transpose
mat
)
mat2
=
total
mat
mat1
=
matSumCol
n
$
zipWith
min
(
_myMin
mat
)
(
_
myMin
$
filterWith
0
100
$
diagNull
n
$
transpose
mat
)
_
mat2
=
total
mat
myMin
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
myMin
=
replicate
(
constant
(
Z
:.
n
:.
All
))
.
minimum
_
myMin
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
_
myMin
=
replicate
(
constant
(
Z
:.
n
:.
All
))
.
minimum
-- TODO fix NaN
...
...
@@ -303,21 +307,66 @@ nullOf n' dir =
zeros
=
fill
(
index2
n
n
)
0
n
=
constant
n'
in
permute
const
ones
-- (\(unindex2 -> i) -> let Exp (x,y) = i in index2 x y)
(
lift1
(
\
(
Z
:.
(
i
::
Exp
Int
)
:.
(
_j
::
Exp
Int
))
permute
const
ones
(
lift1
(
\
(
Z
:.
(
i
::
Exp
Int
)
:.
(
_j
::
Exp
Int
))
->
case
dir
of
MatCol
m
->
(
Z
:.
i
:.
m
)
MatRow
m
->
(
Z
:.
m
:.
i
)
Diag
->
(
Z
:.
i
:.
i
)
)
)
)
)
zeros
nullOfWithDiag
::
Num
a
=>
Dim
->
Direction
->
Acc
(
Matrix
a
)
nullOfWithDiag
n
dir
=
zipWith
(
*
)
(
nullOf
n
dir
)
(
nullOf
n
Diag
)
rIJ'
::
Matrix
Int
->
Matrix
Double
rIJ'
m
=
run
$
sumRowMin
(
dim
m
)
m'
where
m'
=
(
map
fromIntegral
$
use
m
)
rIJ
::
(
Elt
a
,
Ord
a
,
P
.
Fractional
(
Exp
a
),
P
.
Num
a
)
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
rIJ
n
m
=
matMiniMax
$
divide
a
b
where
a
=
sumRowMin
n
m
b
=
sumColMin
n
m
divide
::
(
Elt
a
,
Ord
a
,
P
.
Fractional
(
Exp
a
),
P
.
Num
a
)
=>
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
divide
=
zipWith
divide'
where
divide'
a
b
=
ifThenElse
(
b
>
(
constant
0
))
(
a
/
b
)
(
constant
0
)
-- | Nominator
sumRowMin
::
(
Num
a
,
Ord
a
)
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
sumRowMin
n
m
=
{-trace (P.show $ run m') $-}
m'
where
m'
=
reshape
(
shape
m
)
vs
vs
=
P
.
foldl1
(
++
)
$
P
.
map
(
\
z
->
sumRowMin1
n
(
constant
z
)
m
)
[
0
..
n
-
1
]
sumRowMin1
::
(
Num
a
,
Ord
a
)
=>
Dim
->
Exp
Int
->
Acc
(
Matrix
a
)
->
Acc
(
Vector
a
)
sumRowMin1
n
x
m
=
trace
(
P
.
show
(
run
m
,
run
$
transpose
m
))
$
m''
where
m''
=
sum
$
zipWith
min
(
transpose
m
)
m
_m'
=
zipWith
(
*
)
(
zipWith
(
*
)
(
nullOf
n
(
MatCol
x
))
$
nullOfWithDiag
n
(
MatRow
x
))
m
-- | Denominator
sumColMin
::
(
Num
a
,
Ord
a
)
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
sumColMin
n
m
=
reshape
(
shape
m
)
vs
where
vs
=
P
.
foldl1
(
++
)
$
P
.
map
(
\
z
->
sumColMin1
n
(
constant
z
)
m
)
[
0
..
n
-
1
]
sumColMin1
::
(
Num
a
)
=>
Dim
->
Exp
Int
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
sumColMin1
n
x
m
=
zipWith
(
*
)
(
nullOfWithDiag
n
(
MatCol
x
))
m
{- | WIP fun with indexes
selfMatrix :: Num a => Dim -> Acc (Matrix a)
...
...
@@ -478,28 +527,39 @@ p_ m = zipWith (/) m (n_ m)
-- | Test perfermance with this matrix
-- TODO : add this in a benchmark folder
distriTest
::
Int
->
Matrix
Double
distriTest
n
=
distributional
(
matrix
n
theMatrix
)
distriTest
n
=
distributional
(
theMatrix
n
)
theMatrix
::
Int
->
Matrix
Int
theMatrix
n
=
matrix
n
(
dataMatrix
n
)
where
theMatrix
|
(
P
.==
)
n
2
=
[
1
,
1
,
1
,
2
]
|
(
P
.==
)
n
3
=
[
1
,
1
,
2
,
1
,
2
,
3
,
2
,
3
,
4
]
|
(
P
.==
)
n
4
=
[
1
,
1
,
2
,
3
,
1
,
2
,
3
,
4
,
2
,
3
,
4
,
5
,
3
,
4
,
5
,
6
]
|
P
.
otherwise
=
P
.
undefined
theResult
|
(
P
.==
)
n
2
=
let
r
=
1.6094379124341003
in
[
0
,
r
,
r
,
0
]
|
P
.
otherwise
=
[
1
,
1
]
dataMatrix
::
Int
->
[
Int
]
dataMatrix
x
|
(
P
.==
)
x
2
=
[
1
,
1
,
1
,
2
]
|
(
P
.==
)
x
3
=
[
1
,
1
,
2
,
1
,
2
,
3
,
2
,
3
,
4
]
|
(
P
.==
)
x
4
=
[
1
,
1
,
2
,
3
,
1
,
2
,
3
,
4
,
2
,
3
,
4
,
5
,
3
,
4
,
5
,
6
]
|
P
.
otherwise
=
P
.
undefined
{-
theResult :: Int -> Matrix Double
theResult n | (P.==) n 2 = let r = 1.6094379124341003 in [ 0, r, r, 0]
| P.otherwise = [ 1, 1 ]
-}
colMatrix
::
Elt
e
=>
Int
->
[
e
]
->
Acc
(
Array
((
Z
:.
Int
)
:.
Int
)
e
)
colMatrix
n
ns
=
replicate
(
constant
(
Z
:.
(
n
::
Int
)
:.
All
))
v
where
v
=
use
$
vector
(
P
.
length
ns
)
ns
-----------------------------------------------------------------------
src/Gargantext/Viz/Graph/Tools.hs
View file @
0ce69ad8
...
...
@@ -60,7 +60,9 @@ cooc2graph distance threshold myCooc = do
let
(
ti
,
_
)
=
createIndices
myCooc
myCooc'
=
toIndex
ti
myCooc
matCooc
=
map2mat
0
(
Map
.
size
ti
)
$
Map
.
filter
(
>
1
)
myCooc'
matCooc
=
map2mat
0
(
Map
.
size
ti
)
$
Map
.
filterWithKey
(
\
(
a
,
b
)
_
->
a
/=
b
)
$
Map
.
filter
(
>
1
)
myCooc'
distanceMat
=
measure
distance
matCooc
distanceMap
=
Map
.
filter
(
>
threshold
)
$
mat2map
distanceMat
...
...
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