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
e741619e
Commit
e741619e
authored
Oct 27, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Distances] Distributional WIP
parent
ccd5a835
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
26 deletions
+88
-26
package.yaml
package.yaml
+1
-0
Distributional.hs
...ntext/Core/Methods/Distances/Accelerate/Distributional.hs
+11
-4
Utils.hs
src/Gargantext/Core/Methods/Matrix/Accelerate/Utils.hs
+76
-22
No files found.
package.yaml
View file @
e741619e
...
...
@@ -108,6 +108,7 @@ library:
-
SHA
-
Unique
-
accelerate
-
accelerate-utility
-
accelerate-arithmetic
-
aeson
-
aeson-lens
...
...
src/Gargantext/Core/Methods/Distances/Accelerate/Distributional.hs
View file @
e741619e
...
...
@@ -52,15 +52,22 @@ import qualified Gargantext.Prelude as P
-----------------------------------------------------------------------
-- * Distributional Distance
distributional'
::
Elt
a
=>
Matrix
a
->
Matrix
a
distributional'
_m'
=
undefined
{-
distributional''
::
(
P
.
Num
(
Exp
a
)
,
P
.
Fractional
(
Exp
a
)
,
Elt
a
)
=>
Matrix
a
->
Matrix
a
distributional''
m'
=
run
$
mi
where
m
=
use
m'
n
=
dim
m'
-}
d_m
=
(
.*
)
(
matrixIdentity
n
)
m
o_d_m
=
(
#*#
)
(
matrixOne
n
)
d_m
d_m_o
=
(
#*#
)
d_m
(
matrixOne
n
)
mi
=
(
.*
)
((
./
)
m
o_d_m
)
((
./
)
m
o_d_m
)
...
...
src/Gargantext/Core/Methods/Matrix/Accelerate/Utils.hs
View file @
e741619e
...
...
@@ -33,12 +33,81 @@ module Gargantext.Core.Methods.Matrix.Accelerate.Utils
import
qualified
Data.Foldable
as
P
(
foldl1
)
import
Debug.Trace
(
trace
)
import
Data.Array.Accelerate
import
Data.Array.Accelerate.Array.Sugar
(
Elt
(
..
),
Shape
(
..
),
Slice
(
..
),
(
:.
))
import
Data.Array.Accelerate.Smart
(
Exp
(
..
))
import
Data.Array.Accelerate.Interpreter
(
run
)
import
qualified
Gargantext.Prelude
as
P
import
Data.Array.Accelerate.LinearAlgebra
hiding
(
Matrix
,
transpose
,
Vector
)
-----------------------------------------------------------------------
runExp
::
Elt
e
=>
Exp
e
->
e
runExp
e
=
indexArray
(
run
(
unit
e
))
Z
-- | Main operators
-- Matrix Multiplication
(
#*#
)
::
(
Shape
ix
,
Slice
ix
,
Elt
a
,
P
.
Num
(
Exp
a
)
)
=>
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
(
#*#
)
=
multiplyMatrixMatrix
-- | Matrix cell by cell multiplication
(
.*
)
::
(
Shape
ix
,
Slice
ix
,
Elt
a
,
P
.
Num
(
Exp
a
)
)
=>
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
(
.*
)
=
zipWith
(
*
)
(
./
)
::
(
Shape
ix
,
Slice
ix
,
Elt
a
,
P
.
Num
(
Exp
a
)
,
P
.
Fractional
(
Exp
a
)
)
=>
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
->
Acc
(
Array
((
ix
:.
Int
)
:.
Int
)
a
)
(
./
)
=
zipWith
(
/
)
-----------------------------------------------------------------------
matrixOne
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
matrixOne
n'
=
ones
where
ones
=
fill
(
index2
n
n
)
1
n
=
constant
n'
matrixIdentity
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
matrixIdentity
n'
=
let
zeros
=
fill
(
index2
n
n
)
0
ones
=
fill
(
index1
n
)
1
n
=
constant
n'
in
permute
const
zeros
(
\
(
unindex1
->
i
)
->
index2
i
i
)
ones
matrixEye
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
matrixEye
n'
=
let
ones
=
fill
(
index2
n
n
)
1
zeros
=
fill
(
index1
n
)
0
n
=
constant
n'
in
permute
const
ones
(
\
(
unindex1
->
i
)
->
index2
i
i
)
zeros
diagNull
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
diagNull
n
m
=
zipWith
(
*
)
m
(
matrixEye
n
)
-----------------------------------------------------------------------
_runExp
::
Elt
e
=>
Exp
e
->
e
_runExp
e
=
indexArray
(
run
(
unit
e
))
Z
-----------------------------------------------------------------------
-- | Define a vector
...
...
@@ -164,23 +233,10 @@ filterWith' :: (Elt a, Ord a) => Exp a -> Exp a -> Acc (Matrix a) -> Acc (Matrix
filterWith'
t
v
m
=
map
(
\
x
->
ifThenElse
(
x
>
t
)
x
v
)
m
-- run $ (identityMatrix (DAA.constant (10::Int)) :: DAA.Acc (DAA.Matrix Int)) Matrix (Z :. 10 :. 10)
identityMatrix
::
Num
a
=>
Exp
Int
->
Acc
(
Matrix
a
)
identityMatrix
n
=
let
zeros
=
fill
(
index2
n
n
)
0
ones
=
fill
(
index1
n
)
1
in
permute
const
zeros
(
\
(
unindex1
->
i
)
->
index2
i
i
)
ones
------------------------------------------------------------------------
------------------------------------------------------------------------
eyeMatrix
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
eyeMatrix
n'
=
let
ones
=
fill
(
index2
n
n
)
1
zeros
=
fill
(
index1
n
)
0
n
=
constant
n'
in
permute
const
ones
(
\
(
unindex1
->
i
)
->
index2
i
i
)
zeros
-- | TODO use Lenses
data
Direction
=
MatCol
(
Exp
Int
)
|
MatRow
(
Exp
Int
)
|
Diag
...
...
@@ -259,11 +315,6 @@ selfMatrix' m' = run $ selfMatrix n
m = use m'
-}
-------------------------------------------------
diagNull
::
Num
a
=>
Dim
->
Acc
(
Matrix
a
)
->
Acc
(
Matrix
a
)
diagNull
n
m
=
zipWith
(
*
)
m
eye
where
eye
=
eyeMatrix
n
-------------------------------------------------
crossProduct
::
Dim
->
Acc
(
Matrix
Double
)
->
Acc
(
Matrix
Double
)
crossProduct
n
m
=
{-trace (P.show (run m',run m'')) $-}
zipWith
(
*
)
m'
m''
...
...
@@ -313,6 +364,9 @@ p_ m = zipWith (/) m (n_ m)
) m
-}
theMatrix'
::
Int
->
Matrix
Double
theMatrix'
n
=
run
$
map
fromIntegral
(
use
$
theMatrix
n
)
theMatrix
::
Int
->
Matrix
Int
theMatrix
n
=
matrix
n
(
dataMatrix
n
)
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