2 Module : Gargantext.Viz.Phylo.Tools
3 Description : Phylomemy Tools to build/manage it
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Viz.Phylo.Metrics.Proximity
20 import Data.List (null)
21 import Data.Map (Map,elems,unionWith,intersectionWith,intersection,size)
22 import Gargantext.Prelude
24 -- | To process the weightedLogJaccard between two PhyloGroup fields
25 weightedLogJaccard :: Double -> Map (Int, Int) Double -> Map (Int, Int) Double -> Double
26 weightedLogJaccard s f1 f2
28 | wUnion == wInter = 1
29 | s == 0 = (fromIntegral $ length wInter)/(fromIntegral $ length wUnion)
30 | s > 0 = (sumInvLog wInter)/(sumInvLog wUnion)
31 | otherwise = (sumLog wInter)/(sumLog wUnion)
33 --------------------------------------
35 wInter = elems $ intersectionWith (+) f1 f2
36 --------------------------------------
38 wUnion = elems $ unionWith (+) f1 f2
39 --------------------------------------
40 sumInvLog :: [Double] -> Double
41 sumInvLog l = foldl (\mem x -> mem + (1 / log (s + x))) 0 l
42 --------------------------------------
43 sumLog :: [Double] -> Double
44 sumLog l = foldl (\mem x -> mem + log (s + x)) 0 l
45 --------------------------------------
48 -- | To process the Hamming distance between two PhyloGroup fields
49 hamming :: Map (Int, Int) Double -> Map (Int, Int) Double -> Double
50 hamming f1 f2 = fromIntegral $ max ((size inter) - (size f1)) ((size inter) - (size f2))
52 --------------------------------------
53 inter :: Map (Int, Int) Double
54 inter = intersection f1 f2
55 --------------------------------------