From d17f76bc6067fbcbfa75ab0cb811aade8bc941ab Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 18 Aug 2016 11:14:37 -0400 Subject: [PATCH] Take surrounding context into account when computing bases. ``` 1 `div` 2 = 0 2 `div` 2 = 1 3 `div` 2 = 1 ``` etc. This means that given _q_ = 3, the base for b in [a, b, c, d] will be [a, b, c] instead of [b, c, d]. This means that grams encode limited sibling ordering information both forwards and backwards, making them slightly more stable. --- src/Data/RandomWalkSimilarity.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/RandomWalkSimilarity.hs b/src/Data/RandomWalkSimilarity.hs index 97345fcf1..a914794be 100644 --- a/src/Data/RandomWalkSimilarity.hs +++ b/src/Data/RandomWalkSimilarity.hs @@ -91,7 +91,7 @@ pqGramDecorator getLabel p q = cata algebra where algebra term = let label = getLabel term in cofree ((gram label .: headF term) :< assignParentAndSiblingLabels (tailF term) label) gram label = Gram (padToSize p []) (padToSize q (pure (Just label))) - assignParentAndSiblingLabels functor label = (`evalState` (siblingLabels functor)) (for functor (assignLabels label)) + assignParentAndSiblingLabels functor label = (`evalState` (replicate (q `div` 2) Nothing <> siblingLabels functor)) (for functor (assignLabels label)) assignLabels :: label -> Cofree f (Record (Gram label ': fields)) -> State [Maybe label] (Cofree f (Record (Gram label ': fields))) assignLabels label a = case runCofree a of RCons gram rest :< functor -> do