amnh / PCG

𝙋𝙝𝙮𝙡𝙤𝙜𝙚𝙣𝙚𝙩𝙞𝙘 𝘾𝙤𝙢𝙥𝙤𝙣𝙚𝙣𝙩 𝙂𝙧𝙖𝙥𝙝 ⸺ Haskell program and libraries for general phylogenetic graph search
28 stars 1 forks source link

Make postorder and preorder functions perform a single memoized pass of the graph #117

Open Boarders opened 5 years ago

Boarders commented 5 years ago

The candidate network edges function makes use of vectors written in the form of openly recursive 'memoized producers'. That is, they are given as types defined as follows (in Data.Vector.Utility): newtype DVector a = DVector {getDVector :: (Int -> a) -> Int -> a}

From a DVector one can then produce a memoized vector. We should factor out the memoization used in postorderSequence' (defined in Bio.Graph.PhylogeneticDAG.Postorder) and preorderSequence (defined in Bio.Graph.PhylogeneticDAG.Preorder) to make use of this new type. For any cached data that these functions make use of we should write the functions that collect this data (largely defined in Bio.Graph.ReferenceDAG.Internal) in the form of a DVector which is to be consumed by the postorder or preorder.

With the DVector type it may be worth thinking about adding custom rules as in this toy example: https://gist.github.com/Boarders/10d5697fd32dc21b0fe0219cea239f80 It is worth researching how best to write these rules to allow for further fusion optimisation if this is relevant and otherwise simply a way to not produce an intermediate data structure.