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
fb3674dc
Commit
fb3674dc
authored
Jul 01, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GRAPH] Distances fun with Accelerate (linear algebra in practice) (WIP)
parent
5c5f0bc4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
15 deletions
+35
-15
Matrice.hs
src/Gargantext/Viz/Graph/Distances/Matrice.hs
+35
-15
No files found.
src/Gargantext/Viz/Graph/Distances/Matrice.hs
View file @
fb3674dc
...
...
@@ -240,7 +240,6 @@ distributional m = run -- $ matMiniMax
-- $ myMin
$
filter'
0
$
s_mi
$
diag2null
n
$
map
fromIntegral
-- ^ from Int to Double
$
use
m
-- ^ push matrix in Accelerate type
where
...
...
@@ -252,20 +251,21 @@ distributional m = run -- $ matMiniMax
mat1
=
matSumCol
n
$
zipWith
min'
(
myMin
mat
)
(
myMin
$
transpose
mat
)
mat2
=
total
mat
myMin
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
myMin
=
replicate
(
constant
(
Z
:.
n
:.
All
))
.
minimum
-- TODO fix NaN
-- Quali TEST: OK
s_mi
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
s_mi
m'
=
zipWith
(
\
a
b
->
log
(
a
/
b
))
m'
s_mi
m'
=
zipWith
(
\
x
y
->
log
(
x
/
y
))
(
diagNull
n
m'
)
$
zipWith
(
/
)
(
crossProduct
n
m'
)
(
total
m'
)
-- crossProduct n m'
total
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
total
=
replicate
(
constant
(
Z
:.
n
:.
n
))
.
sum
.
sum
min'
x
y
|
runExp
(
x
>
y
&&
x
/=
0
)
=
x
|
P
.
otherwise
=
y
myMin
::
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
myMin
=
replicate
(
constant
(
Z
:.
n
:.
All
))
.
minimum
n
::
Dim
n
=
dim
m
...
...
@@ -280,19 +280,39 @@ identityMatrix n =
eyeMatrix
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
eyeMatrix
n'
m
=
let
zero
s
=
fill
(
index2
n
n
)
1
one
s
=
fill
(
index1
n
)
0
let
one
s
=
fill
(
index2
n
n
)
1
zero
s
=
fill
(
index1
n
)
0
n
=
constant
n'
in
permute
const
zeros
(
\
(
unindex1
->
i
)
->
index2
i
i
)
ones
permute
const
ones
(
\
(
unindex1
->
i
)
->
index2
i
i
)
zeros
selfMatrix
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
selfMatrix
n'
m
=
let
zeros
=
fill
(
index2
n
n
)
0
ones
=
fill
(
index2
n
n
)
1
n
=
constant
n'
in
permute
const
ones
(
lift1
(
\
(
Z
:.
(
i
::
Exp
Int
)
:.
(
j
::
Exp
Int
))
->
-- ifThenElse (i /= j)
-- (Z :. i :. j)
(
Z
:.
i
:.
i
)
))
zeros
diag2null
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
diag2null
n
m
=
zipWith
(
*
)
m
eye
selfMatrix'
m'
=
run
$
selfMatrix
n
m
where
n
=
dim
m'
m
=
use
m'
-------------------------------------------------
diagNull
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
diagNull
n
m
=
zipWith
(
*
)
m
eye
where
eye
=
eyeMatrix
n
m
-------------------------------------------------
crossProduct
::
Dim
->
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
crossProduct
n
m
=
trace
(
P
.
show
(
run
m'
,
run
m''
))
$
zipWith
(
*
)
m'
m''
where
...
...
@@ -317,7 +337,7 @@ runWith f m = run . f (dim m) (use m)
-- | cross
cross
::
Dim
->
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
cross
n
mat
=
zipWith
(
-
)
(
matSumCol
n
mat
)
(
mat
)
cross
n
mat
=
diagNull
n
(
matSumCol
n
$
diagNull
n
mat
)
cross'
::
Matrix
Double
->
Matrix
Double
cross'
mat
=
run
$
cross
n
mat'
...
...
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