Commit ececbc7a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[WIP] O1 fix

parent 6d9bcd07
Pipeline #5700 canceled with stages
......@@ -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
......
......@@ -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
......
......@@ -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)]
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment