Re: Help with my vec matching function

2009-12-28 Thread Tom Hicks
A technique that works for me is to create sequences which are "augmented" with properties and then filter and transform those sequences in a kind of pipeline. Using that approach I came up with the following: (defn eval-candidate [needle candidate] "Returns a map representing derived informatio

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
That makes sense. I updated the function to: (defn closest-match "Returns the closest matches of needle in the haystack" [#^IPersistentVector needle #^IPersistentVector haystack] (letfn [(matching [candidate] (println ">> checking " candidate) (reduce

Re: Help with my vec matching function

2009-12-28 Thread ajuc
On 28 Gru, 20:57, Robert Campbell wrote: > How might I add a third and final condition, where those candidates > with equal scores AND equal counts are all returned together? Reduce can work with functions like f : x * y -> x So we can modify function closest to be like that (untested): (clos

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
How might I add a third and final condition, where those candidates with equal scores AND equal counts are all returned together? A first try was this: (defn closest-match "Searches the haystack vecs for the closest match to the needle vec" [#^IPersistentVector needle #^IPersistentVector hays

Re: Help with my vec matching function

2009-12-28 Thread Robert Campbell
Thanks ajuc. I updated the implementation to match your algorithm: (defn closest-match "Searches the haystack vecs for the closest match to the needle vec" [#^IPersistentVector needle #^IPersistentVector haystack] (letfn [(matching [candidate] (reduce + (map #(if (= %1 %

Re: Help with my vec matching function

2009-12-28 Thread ajuc
I don't know if I understan correctly the requirements, but this is my try. (def v #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} ) (defn matching [p v] (reduce + (map #(if (= %1 %2) 1 0) p v))) (defn better-match [p v1 v2] (if (or (> (matching p v1) (matching p v2))

Re: Help with my vec matching function

2009-12-28 Thread ajuc
I would write this like that: (def v #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} ) (defn better-match [pattern match1 match2] ;;here choosing better matching vec from these 2 - sorry, I'm too lazy :) ) (reduce #(better-match [1 2 3] %1 %2) [] v) -- You received this messa

Help with my vec matching function

2009-12-28 Thread Robert Campbell
When given the following set of vecs #{[1 2 3] [9 8 3] [1 2] [1] [1 0 3 4] [1 2 3 4 5]} find the closest match to [1 2 3] (defn closest-match "Searches the haystack vecs for the closest match to the needle vec" [#^IPersistentVector needle #^IPersistentVector haystack] (second