I don't know what I did wrong here. 

I wanted to build an accuracy test for some search matching code we wrote. 
We match text using things like Levenshtein distance and Jaro-Winkler 
scores. These parameters can be fine-tuned, so I wrote a small app that 
fires 10 million requests at our search match service, with different 
values for the parameters. The idea is to find the number of True 
Positives, False Positives, True Negatives and False Negatives, for each 
algorithm, for each level of strictness. 

So I create a map in an atom, which gets updated, from various workers, in 
different threads. The numbers bounce around:

 {:false {:allowed_jaro_winkler_distance {0.88 192, 0.9 192, 0.92 192, 0.94 
160}, :allowed_levenshtein_distance {2 184, 5 184, 8 184, 11 184}, 
:allowed_high_score {30 184, 40 184, 50 184, 60 184}, 
:allowed_exact_match_score {14 192, 19 192, 24 176, 29 176}}, :total 736}

{:false {:allowed_jaro_winkler_distance {0.88 192, 0.9 192, 0.92 192, 0.94 
166}, :allowed_levenshtein_distance {2 188, 5 186, 8 184, 11 184}, 
:allowed_high_score {30 186, 40 186, 50 185, 60 185}, 
:allowed_exact_match_score {14 192, 19 192, 24 182, 29 176}}, :total 742}

"total" at the end goes from 736 to 742. Normally that wouldn't surprise 
me, given that I'm incrementing from different workers, but what is strange 
is that the intermediate values don't ever appear. It's not that they 
appear out of order, which would be normal, it's that they don't appear at 
all. Why might that be? 

As to the function, I tried to write this with (merge-with) but I could not 
get the syntax correct, so I gave up and went with something simple. Anyone 
who can suggest a more idiomatic approach, please do. 

(defn increment-accuracy-and-precision
  [true-positive-or-false-negative api-context]
  {:pre [(keyword? true-positive-or-false-negative)]}
  "We want to increment true positives and false negatives, for all of the 
different parameters that we tried, so we build a 3 dimensional map that 
tracts :true or :false, plus the parameter, plus the value of the 
parameter, and we increment the total that is 3 dimensions deep."
  (swap! accuracy-and-precision
         (fn [old-values]
           (let [fnil-inc (fnil inc 0)

                 old-values (update-in old-values 
[true-positive-or-false-negative :allowed_jaro_winkler_distance 
(:allowed_jaro_winkler_distance api-context)] fnil-inc)

                 old-values (update-in old-values 
[true-positive-or-false-negative :allowed_levenshtein_distance 
(:allowed_levenshtein_distance api-context)] fnil-inc)

                 old-values (update-in old-values 
[true-positive-or-false-negative :allowed_high_score (:allowed_high_score 
api-context)] fnil-inc)

                 old-values (update-in old-values 
[true-positive-or-false-negative :allowed_exact_match_score 
(:allowed_exact_match_score api-context)] fnil-inc)
                 old-values (update-in old-values [:total] fnil-inc) 
                 ]
             old-values)))
  (timbre/log :trace @accuracy-and-precision))










-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to