Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
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
gargantext
haskell-gargantext
Commits
ececbc7a
Commit
ececbc7a
authored
Mar 04, 2024
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] O1 fix
parent
6d9bcd07
Pipeline
#5700
canceled with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
7 deletions
+69
-7
Similarities.hs
src/Gargantext/Core/Methods/Similarities.hs
+3
-3
Conditional.hs
...ntext/Core/Methods/Similarities/Accelerate/Conditional.hs
+26
-0
Conditional.hs
src/Gargantext/Core/Methods/Similarities/Conditional.hs
+38
-2
Tools.hs
src/Gargantext/Core/Viz/Graph/Tools.hs
+2
-2
No files found.
src/Gargantext/Core/Methods/Similarities.hs
View file @
ececbc7a
...
...
@@ -19,7 +19,7 @@ import Data.Array.Accelerate (Matrix)
import
Data.Swagger
import
Data.Text
(
Text
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Core.Methods.Similarities.Accelerate.Conditional
(
measureConditional
)
import
Gargantext.Core.Methods.Similarities.Accelerate.Conditional
(
measureConditional
'
)
import
Gargantext.Core.Methods.Similarities.Accelerate.Distributional
(
logDistributional2
)
-- import Gargantext.Core.Text.Metrics.Count (coocOn)
-- import Gargantext.Core.Viz.Graph.Index
...
...
@@ -35,13 +35,13 @@ data Similarity = Conditional | Distributional
deriving
(
Show
,
Eq
)
measure
::
Similarity
->
Matrix
Int
->
Matrix
Double
measure
Conditional
x
=
measureConditional
x
measure
Conditional
x
=
measureConditional
'
x
measure
Distributional
x
=
logDistributional2
x
------------------------------------------------------------------------
withMetric
::
GraphMetric
->
Similarity
withMetric
Order1
=
Conditional
withMetric
_
=
Distributional
withMetric
_
=
Distributional
------------------------------------------------------------------------
-- Order2 type is for keeping Database json compatibility
...
...
src/Gargantext/Core/Methods/Similarities/Accelerate/Conditional.hs
View file @
ececbc7a
...
...
@@ -48,8 +48,33 @@ import qualified Gargantext.Prelude as P
-- Filtered with MiniMax.
measureConditional
::
Matrix
Int
->
Matrix
Double
measureConditional
m
=
run
$
x
$
map
fromIntegral
$
use
m
where
x
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
x
mat
=
diagNull
r
$
divByDiag
r
mat
r
::
Dim
r
=
dim
m
_maxOnly
::
Elt
e
=>
Acc
(
SymetricMatrix
e
)
->
Acc
(
Matrix
e
)
_maxOnly
m'
=
backpermute
(
shape
m'
)
(
lift1
(
\
(
Z
:.
(
i
::
Exp
Int
)
:.
(
j
::
Exp
Int
))
->
let
ij
=
lift
(
Z
:.
i
:.
j
)
ji
=
lift
(
Z
:.
j
:.
i
)
in
((
ifThenElse
(
ij
<
ji
)
ij
(
0
:.
Z
))
::
Exp
DIM2
)
)
)
m'
-- This function should be removed
measureConditional'
::
Matrix
Int
->
Matrix
Double
measureConditional'
m
=
run
$
x
$
map
fromIntegral
$
use
m
where
x
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
x
mat
=
matMiniMax
$
matProba
r
mat
...
...
@@ -58,6 +83,7 @@ measureConditional m = run $ x $ map fromIntegral $ use m
r
=
dim
m
-- | To filter the nodes
-- The conditional metric P(i|j) of 2 terms @i@ and @j@, also called
-- "confidence" , is the maximum probability between @i@ and @j@ to see
...
...
src/Gargantext/Core/Methods/Similarities/Conditional.hs
View file @
ececbc7a
...
...
@@ -21,7 +21,9 @@ import Data.HashMap.Strict qualified as Map
import
Data.Set
qualified
as
Set
import
Gargantext.Core.Viz.Graph.Utils
(
getMax
)
import
Gargantext.Prelude
import
Data.Map.Strict
qualified
as
M
import
Gargantext.Core.Methods.Similarities.Accelerate.Conditional
(
measureConditional
)
import
Gargantext.Core.Viz.Graph.Index
(
score
,
MatrixShape
(
..
))
type
HashMap
=
Map
.
HashMap
------------------------------------------------------------------------
...
...
@@ -35,7 +37,11 @@ conditional m' = Map.fromList $ ((catMaybes results') `using` parList rdeepseq)
where
results'
=
[
let
ij
=
(
/
)
<$>
Map
.
lookup
(
i
,
j
)
m
<*>
Map
.
lookup
(
j
,
j
)
m
ji
=
(
/
)
<$>
Map
.
lookup
(
j
,
i
)
m
<*>
Map
.
lookup
(
i
,
i
)
m
-- proba of i|j, high values means i is more generic than j
ji
=
(
/
)
<$>
Map
.
lookup
(
i
,
j
)
m
<*>
Map
.
lookup
(
i
,
i
)
m
-- proba of j|i, high values means j is more generic than i
in
getMax
(
i
,
j
)
ij
ji
|
i
<-
keys
...
...
@@ -50,3 +56,33 @@ conditional m' = Map.fromList $ ((catMaybes results') `using` parList rdeepseq)
(
x
,
y
)
=
unzip
$
Map
.
keys
m
conditional_test
::
HashMap
(
Text
,
Text
)
Double
conditional_test
=
conditional
$
Map
.
fromList
example_matrix
conditional_test'
::
M
.
Map
(
Text
,
Text
)
Double
conditional_test'
=
M
.
filter
(
>
0
)
$
score
Square
measureConditional
$
M
.
fromList
example_matrix
example_matrix
::
[((
Text
,
Text
),
Int
)]
example_matrix
=
concat
[
compte
"polygon"
"polygon"
19
,
compte
"polygon"
"square"
6
,
compte
"polygon"
"triangle"
10
,
compte
"polygon"
"losange"
3
,
compte
"triangle"
"triangle"
11
,
compte
"square"
"square"
7
,
compte
"losange"
"losange"
15
,
compte
"shape"
"shape"
10
,
compte
"circle"
"circle"
6
,
compte
"shape"
"circle"
3
,
compte
"shape"
"square"
2
,
compte
"polygon"
"shape"
10
]
where
compte
a
b
c
=
if
a
/=
b
then
[((
a
,
b
),
c
),
((
b
,
a
),
c
)]
else
[((
a
,
b
),
c
)]
src/Gargantext/Core/Viz/Graph/Tools.hs
View file @
ececbc7a
...
...
@@ -79,8 +79,8 @@ cooc2graph' distance threshold myCooc
$
mat2map
$
measure
distance
$
case
distance
of
Conditional
->
map2mat
Triangle
0
tiSize
_
->
map2mat
Square
0
tiSize
Conditional
->
map2mat
Square
1
tiSize
_
->
map2mat
Square
0
tiSize
$
Map
.
filter
(
>
1
)
myCooc'
where
...
...
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