Commit 7664c2ef authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] last needed function to start tests

parent 786b4880
......@@ -28,29 +28,29 @@ Gaume.
module Graph.BAC.ProxemyOptim
where
import Prelude (String, readLn)
--import Debug.SimpleReflect
import Data.IntMap (IntMap)
import Data.Maybe (isJust)
import Data.Proxy (Proxy(Proxy))
import GHC.TypeLits (KnownNat, Nat, SomeNat(SomeNat), type(+), natVal, sameNat, someNatVal)
import Data.Reflection
--import Debug.SimpleReflect
import Data.Map (Map)
import Eigen.Internal (CTriplet(..), Elem(..), toC, fromC, C(..), natToInt, Row(..), Col(..))
import Eigen.Matrix (sum, unsafeCoeff)
import Eigen.SparseMatrix (SparseMatrix, SparseMatrixXd, (!), toMatrix, _unsafeCoeff)
import GHC.TypeLits (KnownNat, Nat, SomeNat(SomeNat), type(+), natVal, sameNat, someNatVal)
import Graph.FGL
import Prelude (String, readLn)
import Protolude hiding (sum, natVal)
import qualified Eigen.Matrix as DenseMatrix
import Eigen.SparseMatrix (SparseMatrix, SparseMatrixXd, (!), toMatrix, _unsafeCoeff)
import Eigen.Internal (CTriplet(..), Elem(..), toC, fromC, C(..), natToInt, Row(..), Col(..))
import Eigen.Matrix (sum, unsafeCoeff)
import qualified Eigen.Matrix as DMatrix
import qualified Data.Graph.Inductive as DGI
import qualified Data.Graph.Inductive.PatriciaTree as DGIP
import qualified Data.List as List
import qualified Data.Map as Map
import qualified Data.Vector.Storable as VS
import qualified Data.IntMap as Dict
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Eigen.Matrix as DMatrix
import qualified Eigen.SparseMatrix as SMatrix
import qualified Prelude as Prelude
import qualified Prelude as Prelude
import qualified Data.Set as Set
-- | Main Types
type Length = Int
......@@ -112,8 +112,10 @@ data SimilarityMatrix n = SimConf (ConfluenceMatrix n)
| SimMod (ModularityMatrix n)
data Similarity = Conf | Mod
data Clustering a = Clustering { partitions :: Set (Set a)
, score :: Double
type Dict = IntMap
data Clustering a = Clustering { parts :: Dict (Set a)
, index :: Dict Int
, score :: Double
}
-- TODO
......@@ -256,12 +258,52 @@ sort_edges n = List.concat
---------------------------------------------------------------
updateWith :: Clustering Node -> (Int -> Int -> Double) -> (Int,Int) -> (Int,Int) -> Clustering Node
updateWith c@(Clustering parts idx _) f (modX,x) (modY,y) = Clustering parts' idx' score'
where
parts' = Dict.alter (del y) modY $ Dict.alter (add y) modX parts
add y Nothing = Just (Set.singleton y)
add y (Just y') = Just (Set.insert y y')
del y Nothing = Nothing
del y (Just y') = Just (Set.delete y y')
idx' = Dict.alter (alter modY) y idx
alter my _ = Just my
px = fromMaybe Set.empty $ Dict.lookup x parts'
py = fromMaybe Set.empty $ Dict.lookup y parts'
score' = Prelude.sum [ f x'' y''
| x'' <- Set.toList px
, y'' <- Set.toList py
]
updateClustering :: Clustering Node -> (Int -> Int -> Double) -> Int -> Int -> Clustering Node
updateClustering c@(Clustering parts idx currentScore) f x y =
let modX = fromMaybe 0 $ Dict.lookup x idx
modY = fromMaybe 0 $ Dict.lookup y idx
in case x == y || modX == modY of
True -> c -- do case x' or y' are Nothing
False -> let c' = updateWith c f (x,modX) (y,modY)
in case score c' > currentScore of
True -> c'
False -> c
make_clust_part :: KnownNat n
=> SortedEdges
-> SimilarityMatrix n
-> Clustering Node
make_clust_part = undefined
make_clust_part se sm = foldl' (\c (e1,e2,_) -> updateClustering c (\x y -> unsafeCoeff e1 e2 sm') e1 e2)
(Clustering Dict.empty Dict.empty 0) se
where
sm' = case sm of
SimConf cm -> cm
SimMod mm -> mm
---------------------------------------------------------------
make_clust_over :: KnownNat n
=> SimilarityMatrix n
-> StrictClustering a
......
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