{-|
Module      : Gargantext.Graph.Distances
Description : Distance management tools
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE Strict            #-}

module Gargantext.Core.Methods.Distances
  where

import Debug.Trace (trace)
import Data.Aeson
import Data.Array.Accelerate (Matrix)
import Data.Swagger
import GHC.Generics (Generic)
import Gargantext.Core.Methods.Distances.Accelerate.Conditional (measureConditional)
import Gargantext.Core.Methods.Distances.Accelerate.Distributional (logDistributional)
import Gargantext.Prelude (Ord, Eq, Int, Double, Show, ($), show)
import Prelude (Enum, Bounded, minBound, maxBound)
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary

------------------------------------------------------------------------
data Distance = Conditional | Distributional
  deriving (Int -> Distance -> ShowS
[Distance] -> ShowS
Distance -> String
(Int -> Distance -> ShowS)
-> (Distance -> String) -> ([Distance] -> ShowS) -> Show Distance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Distance] -> ShowS
$cshowList :: [Distance] -> ShowS
show :: Distance -> String
$cshow :: Distance -> String
showsPrec :: Int -> Distance -> ShowS
$cshowsPrec :: Int -> Distance -> ShowS
Show, Distance -> Distance -> Bool
(Distance -> Distance -> Bool)
-> (Distance -> Distance -> Bool) -> Eq Distance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Distance -> Distance -> Bool
$c/= :: Distance -> Distance -> Bool
== :: Distance -> Distance -> Bool
$c== :: Distance -> Distance -> Bool
Eq)

measure :: Distance -> Matrix Int -> Matrix Double
measure :: Distance -> Matrix Int -> Matrix Double
measure Distance
Conditional    Matrix Int
x = Matrix Int -> Matrix Double
measureConditional Matrix Int
x
measure Distance
Distributional Matrix Int
x = String -> Matrix Double -> Matrix Double
forall a. String -> a -> a
trace (Matrix Double -> String
forall a. Show a => a -> String
show Matrix Double
y) (Matrix Double -> Matrix Double) -> Matrix Double -> Matrix Double
forall a b. (a -> b) -> a -> b
$ Matrix Double
y
  where
    y :: Matrix Double
y = Matrix Int -> Matrix Double
logDistributional Matrix Int
x

------------------------------------------------------------------------
withMetric :: GraphMetric -> Distance
withMetric :: GraphMetric -> Distance
withMetric GraphMetric
Order1 = Distance
Conditional
withMetric GraphMetric
Order2 = Distance
Distributional

------------------------------------------------------------------------
data GraphMetric = Order1 | Order2
    deriving ((forall x. GraphMetric -> Rep GraphMetric x)
-> (forall x. Rep GraphMetric x -> GraphMetric)
-> Generic GraphMetric
forall x. Rep GraphMetric x -> GraphMetric
forall x. GraphMetric -> Rep GraphMetric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GraphMetric x -> GraphMetric
$cfrom :: forall x. GraphMetric -> Rep GraphMetric x
Generic, GraphMetric -> GraphMetric -> Bool
(GraphMetric -> GraphMetric -> Bool)
-> (GraphMetric -> GraphMetric -> Bool) -> Eq GraphMetric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GraphMetric -> GraphMetric -> Bool
$c/= :: GraphMetric -> GraphMetric -> Bool
== :: GraphMetric -> GraphMetric -> Bool
$c== :: GraphMetric -> GraphMetric -> Bool
Eq, Eq GraphMetric
Eq GraphMetric
-> (GraphMetric -> GraphMetric -> Ordering)
-> (GraphMetric -> GraphMetric -> Bool)
-> (GraphMetric -> GraphMetric -> Bool)
-> (GraphMetric -> GraphMetric -> Bool)
-> (GraphMetric -> GraphMetric -> Bool)
-> (GraphMetric -> GraphMetric -> GraphMetric)
-> (GraphMetric -> GraphMetric -> GraphMetric)
-> Ord GraphMetric
GraphMetric -> GraphMetric -> Bool
GraphMetric -> GraphMetric -> Ordering
GraphMetric -> GraphMetric -> GraphMetric
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: GraphMetric -> GraphMetric -> GraphMetric
$cmin :: GraphMetric -> GraphMetric -> GraphMetric
max :: GraphMetric -> GraphMetric -> GraphMetric
$cmax :: GraphMetric -> GraphMetric -> GraphMetric
>= :: GraphMetric -> GraphMetric -> Bool
$c>= :: GraphMetric -> GraphMetric -> Bool
> :: GraphMetric -> GraphMetric -> Bool
$c> :: GraphMetric -> GraphMetric -> Bool
<= :: GraphMetric -> GraphMetric -> Bool
$c<= :: GraphMetric -> GraphMetric -> Bool
< :: GraphMetric -> GraphMetric -> Bool
$c< :: GraphMetric -> GraphMetric -> Bool
compare :: GraphMetric -> GraphMetric -> Ordering
$ccompare :: GraphMetric -> GraphMetric -> Ordering
$cp1Ord :: Eq GraphMetric
Ord, Int -> GraphMetric
GraphMetric -> Int
GraphMetric -> [GraphMetric]
GraphMetric -> GraphMetric
GraphMetric -> GraphMetric -> [GraphMetric]
GraphMetric -> GraphMetric -> GraphMetric -> [GraphMetric]
(GraphMetric -> GraphMetric)
-> (GraphMetric -> GraphMetric)
-> (Int -> GraphMetric)
-> (GraphMetric -> Int)
-> (GraphMetric -> [GraphMetric])
-> (GraphMetric -> GraphMetric -> [GraphMetric])
-> (GraphMetric -> GraphMetric -> [GraphMetric])
-> (GraphMetric -> GraphMetric -> GraphMetric -> [GraphMetric])
-> Enum GraphMetric
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: GraphMetric -> GraphMetric -> GraphMetric -> [GraphMetric]
$cenumFromThenTo :: GraphMetric -> GraphMetric -> GraphMetric -> [GraphMetric]
enumFromTo :: GraphMetric -> GraphMetric -> [GraphMetric]
$cenumFromTo :: GraphMetric -> GraphMetric -> [GraphMetric]
enumFromThen :: GraphMetric -> GraphMetric -> [GraphMetric]
$cenumFromThen :: GraphMetric -> GraphMetric -> [GraphMetric]
enumFrom :: GraphMetric -> [GraphMetric]
$cenumFrom :: GraphMetric -> [GraphMetric]
fromEnum :: GraphMetric -> Int
$cfromEnum :: GraphMetric -> Int
toEnum :: Int -> GraphMetric
$ctoEnum :: Int -> GraphMetric
pred :: GraphMetric -> GraphMetric
$cpred :: GraphMetric -> GraphMetric
succ :: GraphMetric -> GraphMetric
$csucc :: GraphMetric -> GraphMetric
Enum, GraphMetric
GraphMetric -> GraphMetric -> Bounded GraphMetric
forall a. a -> a -> Bounded a
maxBound :: GraphMetric
$cmaxBound :: GraphMetric
minBound :: GraphMetric
$cminBound :: GraphMetric
Bounded, Int -> GraphMetric -> ShowS
[GraphMetric] -> ShowS
GraphMetric -> String
(Int -> GraphMetric -> ShowS)
-> (GraphMetric -> String)
-> ([GraphMetric] -> ShowS)
-> Show GraphMetric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GraphMetric] -> ShowS
$cshowList :: [GraphMetric] -> ShowS
show :: GraphMetric -> String
$cshow :: GraphMetric -> String
showsPrec :: Int -> GraphMetric -> ShowS
$cshowsPrec :: Int -> GraphMetric -> ShowS
Show)

instance FromJSON  GraphMetric
instance ToJSON    GraphMetric
instance ToSchema  GraphMetric
instance Arbitrary GraphMetric where
  arbitrary :: Gen GraphMetric
arbitrary = [GraphMetric] -> Gen GraphMetric
forall a. [a] -> Gen a
elements [ GraphMetric
forall a. Bounded a => a
minBound .. GraphMetric
forall a. Bounded a => a
maxBound ]

------------------------------------------------------------------------