Commit 4b8b45aa authored by Alexandre Delanoë's avatar Alexandre Delanoë

[OPTIM] worse with list

parent f00fcfaa
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -152,9 +152,9 @@ adjacent (FiniteGraph g) isReflexive = ...@@ -152,9 +152,9 @@ adjacent (FiniteGraph g) isReflexive =
transition :: KnownNat n transition :: KnownNat n
=> AdjacencyMatrix n => AdjacencyMatrix n
-> TransitionMatrix n -> TransitionMatrix n
transition m = SMatrix.imap (\i j v -> v * (VS.!) s i) m transition m = SMatrix.imap (\i j v -> v * (List.!!) s i) m
where where
s = sumWith Colonne (\s -> 1 / s) m s = sumWith' Colonne (\s -> 1 / s) m
proxemie :: KnownNat n proxemie :: KnownNat n
...@@ -175,13 +175,13 @@ matconf :: forall n. KnownNat n ...@@ -175,13 +175,13 @@ matconf :: forall n. KnownNat n
matconf False a p = symmetry confmat matconf False a p = symmetry confmat
where where
-- vcount = natToInt @n -- vcount = natToInt @n
degs = sumWith Colonne identity a degs = sumWith' Colonne identity a
sumdeg = VS.sum degs sumdeg = List.sum degs
confmat = DMatrix.imap (\ x y v -> confmat = DMatrix.imap (\ x y v ->
if x < y if x < y
then let then let
prox_y_x_length = v prox_y_x_length = v
prox_y_x_infini = ((VS.!) degs x) / sumdeg prox_y_x_infini = ((List.!!) degs x) / sumdeg
in in
(prox_y_x_length - prox_y_x_infini) (prox_y_x_length - prox_y_x_infini)
/ (prox_y_x_length + prox_y_x_infini) / (prox_y_x_length + prox_y_x_infini)
...@@ -219,15 +219,15 @@ edges_confluence l am tm = -- traceShow ("degs", degs) $ ...@@ -219,15 +219,15 @@ edges_confluence l am tm = -- traceShow ("degs", degs) $
SMatrix.toList matconf' SMatrix.toList matconf'
where where
vcount = natToInt @n vcount = natToInt @n
degs = sumWith Colonne identity am degs = sumWith' Colonne identity am
sumdeg = VS.sum degs sumdeg = List.sum degs
matconf' = SMatrix.imap matconf' = SMatrix.imap
(\x y _ -> (\x y _ ->
if x < y if x < y
then then
let let
deg_x = (VS.!) degs x - 1 deg_x = (List.!!) degs x - 1
deg_y = (VS.!) degs y - 1 deg_y = (List.!!) degs y - 1
tm' = SMatrix.imap (\i j v -> if (i == x && j == y) || ( i == y && j == x) tm' = SMatrix.imap (\i j v -> if (i == x && j == y) || ( i == y && j == x)
then 0 then 0
...@@ -440,5 +440,17 @@ sumWith dir f m = VS.fromList ...@@ -440,5 +440,17 @@ sumWith dir f m = VS.fromList
where where
somme m' = map (sum . SMatrix.toMatrix) m' somme m' = map (sum . SMatrix.toMatrix) m'
sumWith' :: ( Elem a
, Elem t
, KnownNat n
) => Direction -> (t -> a) -> SparseMatrix n n t -> [a]
sumWith' dir f m = map (\v -> f v)
$ case dir of
Colonne -> somme $ SMatrix.getCols m
Ligne -> somme $ SMatrix.getRows m
where
somme m' = map (sum . SMatrix.toMatrix) m'
-------------------------------------------- --------------------------------------------
...@@ -9,6 +9,8 @@ import Data.Text (Text) ...@@ -9,6 +9,8 @@ import Data.Text (Text)
import qualified Eigen.Matrix as Matrix import qualified Eigen.Matrix as Matrix
import Graph.BAC.ProxemyOptim import Graph.BAC.ProxemyOptim
import Graph.FGL import Graph.FGL
import Graph.Types
import Graph.Tools.Random
import Prelude (String) import Prelude (String)
import Protolude import Protolude
import Graph.BAC.ProxemyOptim import Graph.BAC.ProxemyOptim
......
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