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
90283042
Commit
90283042
authored
Jul 01, 2021
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thx to Alp for his help
parent
28cfe091
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
23 deletions
+120
-23
gargantext-graph.cabal
gargantext-graph.cabal
+2
-1
Coeff.hs
src/Data/Eigen/Coeff.hs
+113
-0
ProxemyOptim.hs
src/Graph/BAC/ProxemyOptim.hs
+5
-22
No files found.
gargantext-graph.cabal
View file @
90283042
...
...
@@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash:
2529152eda79b364f7b62e5d9eaf053e8f4e54488749bd83614d515e92c44d26
-- hash:
0738cfbe36f67275fe7fcd289fd26bddd3727957358ad06543242f719c4f34f1
name: gargantext-graph
version: 0.1.0.0
...
...
@@ -28,6 +28,7 @@ source-repository head
library
exposed-modules:
Data.Array.Accelerate.Utils
Data.Eigen.Coeff
Graph.BAC.Clustering
Graph.BAC.Proxemy
Graph.BAC.ProxemyOptim
...
...
src/Data/Eigen/Coeff.hs
0 → 100644
View file @
90283042
{-| Module : Data.Eigen.Coeff
Description : Safe coeff for Eigen Matrix
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Author: Alp Mestanogullari (Well Typed)
-}
{-# LANGUAGE DataKinds, GADTs, RankNTypes, ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications, TypeOperators, TypeFamilies #-}
module
Data.Eigen.Coeff
(
coeffSM
,
coeffDM
)
where
import
Eigen.Internal
(
Row
(
..
),
Col
(
..
),
Elem
(
..
))
import
Data.Maybe
(
fromMaybe
)
import
Data.Proxy
import
Data.Reflection
import
Data.Type.Equality
import
GHC.TypeLits
import
Unsafe.Coerce
import
Eigen.SparseMatrix
(
SparseMatrix
)
import
Eigen.Matrix
(
Matrix
)
import
qualified
Eigen.SparseMatrix
as
SMatrix
import
qualified
Eigen.Matrix
as
DMatrix
data
(
:<=?
)
(
i
::
Nat
)
(
n
::
Nat
)
where
IsLTE
::
(
i
<=?
n
)
:~:
'T
r
ue
->
i
:<=?
n
IsGT
::
i
:<=?
n
isLTE
::
(
KnownNat
i
,
KnownNat
n
)
=>
Proxy
i
->
Proxy
n
->
i
:<=?
n
isLTE
pi
pn
|
natVal
pi
<=
natVal
pn
=
IsLTE
(
unsafeCoerce
Refl
)
|
otherwise
=
IsGT
reifyNatLT
::
forall
r
n
.
KnownNat
n
=>
Int
->
Proxy
n
->
r
-- ^ what to return if the given 'Int' is > n
->
(
forall
i
.
(
KnownNat
i
,
i
<=
n
)
=>
Proxy
i
->
r
)
-- ^ what to do if the given 'Int' indeed is <= n
->
r
reifyNatLT
i
pn
r
k
=
reifyNat
(
fromIntegral
i
)
$
\
pi
->
case
isLTE
pi
pn
of
IsLTE
Refl
->
k
pi
_
->
r
-- * matrix use case
{-
-- say we're given those things (origin Eigen lib)
data Mat (n :: Nat) (m :: Nat) a
data Row (i :: Nat) = Row
data Col (j :: Nat) = Col
coeff
:: (KnownNat i, KnownNat j, KnownNat n, KnownNat m, i <= n, j <= m)
=> Row i -> Col j -> Mat n m a -> a
coeff = SMatrix.coeff
-}
-- we can now get:
coeffSM
::
forall
n
m
.
(
KnownNat
n
,
KnownNat
m
)
=>
Int
->
Int
->
SparseMatrix
n
m
Double
->
Double
coeffSM
x
y
m
=
fromMaybe
0
$
coeffSM'
x
y
m
coeffSM'
::
forall
n
m
a
.
(
KnownNat
n
,
KnownNat
m
,
Elem
a
)
=>
Int
->
Int
->
SparseMatrix
n
m
a
->
Maybe
a
coeffSM'
i
j
mat
=
reifyNatLT
i
pn
Nothing
$
\
pi
->
reifyNatLT
j
pm
Nothing
$
\
pj
->
Just
$
SMatrix
.
coeff
(
proxyRow
pi
)
(
proxyCol
pj
)
mat
where
pn
=
Proxy
@
n
pm
=
Proxy
@
m
coeffDM
::
forall
n
m
.
(
KnownNat
n
,
KnownNat
m
)
=>
Int
->
Int
->
Matrix
n
m
Double
->
Double
coeffDM
x
y
m
=
fromMaybe
0
$
coeffDM'
x
y
m
coeffDM'
::
forall
n
m
a
.
(
KnownNat
n
,
KnownNat
m
,
Elem
a
)
=>
Int
->
Int
->
Matrix
n
m
a
->
Maybe
a
coeffDM'
i
j
mat
=
reifyNatLT
i
pn
Nothing
$
\
pi
->
reifyNatLT
j
pm
Nothing
$
\
pj
->
Just
$
DMatrix
.
coeff
(
proxyRow
pi
)
(
proxyCol
pj
)
mat
where
pn
=
Proxy
@
n
pm
=
Proxy
@
m
-- helpers
proxyRow
::
Proxy
i
->
Row
i
proxyRow
_
=
Row
proxyCol
::
Proxy
j
->
Col
j
proxyCol
_
=
Col
src/Graph/BAC/ProxemyOptim.hs
View file @
90283042
...
...
@@ -29,12 +29,13 @@ module Graph.BAC.ProxemyOptim
where
--import Debug.SimpleReflect
import
Data.Eigen.Coeff
(
coeffSM
,
coeffDM
)
import
Data.IntMap
(
IntMap
)
import
Data.Maybe
(
isJust
)
import
Data.Proxy
(
Proxy
(
Proxy
))
import
Data.Reflection
import
Eigen.Internal
(
CTriplet
(
..
),
Elem
(
..
),
toC
,
fromC
,
C
(
..
),
natToInt
,
Row
(
..
),
Col
(
..
))
import
Eigen.Matrix
(
sum
,
unsafeCoeff
)
import
Eigen.Matrix
(
sum
)
import
Eigen.SparseMatrix
(
SparseMatrix
,
SparseMatrixXd
,
(
!
),
toMatrix
)
import
GHC.TypeLits
(
KnownNat
,
Nat
,
SomeNat
(
SomeNat
),
type
(
+
),
natVal
,
sameNat
,
someNatVal
)
import
Graph.FGL
...
...
@@ -80,23 +81,6 @@ withG :: (Show a, Show b)
->
r
withG
g
f
=
reifyNat
(
fromIntegral
$
length
$
nodes
g
)
$
\
n
->
f
(
buildFiniteGraph
n
g
)
-- ∀ x. P x -> ∃ x. P x
data
T
a
b
where
T
::
forall
n
a
b
.
KnownNat
n
=>
Proxy
n
->
FiniteGraph
n
a
b
->
T
a
b
data
Dim
(
n
::
Nat
)
=
Dim
Nat
---------------------------------------------------------------
getDim
::
Graph
a
b
->
Integer
getDim
=
undefined
getDim'
::
T
a
b
->
Integer
getDim'
(
T
p
_
)
=
natVal
p
tab
::
Graph
a
b
->
T
a
b
tab
g
=
do
let
Just
someNat
=
someNatVal
(
fromIntegral
$
length
$
nodes
g
)
case
someNat
of
SomeNat
p
->
T
p
(
FiniteGraph
g
)
---------------------------------------------------------------
---------------------------------------------------------------
type
DenseMatrix
n
=
DenseMatrix
.
Matrix
n
n
Double
...
...
@@ -200,7 +184,7 @@ matconf True _a _p = panic "MatConf True: TODO but not needed for now"
symmetry
::
KnownNat
n
=>
DenseMatrix
n
->
DenseMatrix
n
symmetry
m
=
DMatrix
.
imap
(
\
x
y
v
->
if
x
<
y
then
v
else
DMatrix
.
unsafeCoeff
y
x
m
)
m
symmetry
m
=
DMatrix
.
imap
(
\
x
y
v
->
if
x
<
y
then
v
else
coeffDM
y
x
m
)
m
matmod
::
forall
n
a
b
.
KnownNat
n
=>
FiniteGraph
n
a
b
->
ModularityMatrix
n
matmod
fg
=
symmetry
$
toMatrix
modmat
...
...
@@ -233,8 +217,7 @@ edges_confluence l fg am tm = SMatrix.toList matconf
matconf
=
SMatrix
.
imap
(
\
x
y
v
->
let
am'
=
SMatrix
.
add
am
(
SMatrix
.
fromList
[(
x
,
y
,
-
v
)])
v'
=
doProx
l
(
sparseVectorFromList
(
Proxy
@
n
)
[(
1
,
y
,
1
)])
am'
prox_y_x_length
=
SMatrix
.
coeff
(
Row
x
)
(
Col
1
)
v'
-- FIXME
-- prox_y_x_length = _unsafeCoeff x 1 v'
prox_y_x_length
=
coeffSM
x
1
v'
prox_y_x_infini
=
((
VS
.!
)
degs
x
-
1
)
/
(
sumdeg
-
2
)
in
(
prox_y_x_length
-
prox_y_x_length
)
...
...
@@ -297,7 +280,7 @@ make_clust_part :: KnownNat n
=>
SortedEdges
->
SimilarityMatrix
n
->
Clustering
Node
make_clust_part
se
sm
=
foldl'
(
\
c
(
e1
,
e2
,
_
)
->
updateClustering
c
(
\
x
y
->
unsafeCoeff
e1
e2
sm'
)
e1
e2
)
make_clust_part
se
sm
=
foldl'
(
\
c
(
e1
,
e2
,
_
)
->
updateClustering
c
(
\
x
y
->
coeffDM
e1
e2
sm'
)
e1
e2
)
(
Clustering
Dict
.
empty
Dict
.
empty
0
)
se
where
sm'
=
case
sm
of
...
...
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