src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
changeset 57403 5e65e3d108a1
parent 57402 b532b879acd0
child 57404 a68ae60c1504
equal deleted inserted replaced
57402:b532b879acd0 57403:5e65e3d108a1
   402     val ln_afreq = Math.ln (Real.fromInt num_facts)
   402     val ln_afreq = Math.ln (Real.fromInt num_facts)
   403     fun tfidf feat = ln_afreq - Math.ln (Real.fromInt (Vector.sub (dffreq, feat)))
   403     fun tfidf feat = ln_afreq - Math.ln (Real.fromInt (Vector.sub (dffreq, feat)))
   404 
   404 
   405     val overlaps_sqr = Array.tabulate (num_facts, rpair 0.0)
   405     val overlaps_sqr = Array.tabulate (num_facts, rpair 0.0)
   406 
   406 
   407     fun inc_overlap v j =
       
   408       let val (_, ov) = Array.sub (overlaps_sqr, j) in
       
   409         Array.update (overlaps_sqr, j, (j, v + ov))
       
   410       end
       
   411 
       
   412     fun do_feat (s, sw0) =
   407     fun do_feat (s, sw0) =
   413       let
   408       let
   414         val sw = sw0 * tfidf s
   409         val sw = sw0 * tfidf s
   415         val w2 = sw * sw
   410         val w2 = sw * sw
       
   411 
       
   412         fun inc_overlap j =
       
   413           let val (_, ov) = Array.sub (overlaps_sqr, j) in
       
   414             Array.update (overlaps_sqr, j, (j, w2 + ov))
       
   415           end
   416       in
   416       in
   417         List.app (inc_overlap w2) (Array.sub (feat_facts, s))
   417         List.app inc_overlap (Array.sub (feat_facts, s))
   418       end
   418       end
   419 
   419 
   420     val _ = List.app do_feat goal_feats
   420     val _ = List.app do_feat goal_feats
   421     val _ = heap (Real.compare o pairself snd) num_facts num_facts overlaps_sqr
   421     val _ = heap (Real.compare o pairself snd) num_facts num_facts overlaps_sqr
   422     val no_recommends = Unsynchronized.ref 0
   422     val no_recommends = Unsynchronized.ref 0
   423     val recommends = Array.tabulate (num_facts, rpair 0.0)
   423     val recommends = Array.tabulate (num_facts, rpair 0.0)
   424     val age = Unsynchronized.ref 500000000.0
   424     val age = Unsynchronized.ref 500000000.0
   425 
   425 
   426     fun inc_recommend j v =
   426     fun inc_recommend j v =
   427       let val ov = snd (Array.sub (recommends, j)) in
   427       let val (_, ov) = Array.sub (recommends, j) in
   428         if ov <= 0.0 then
   428         if ov <= 0.0 then
   429           (no_recommends := !no_recommends + 1; Array.update (recommends, j, (j, !age + ov)))
   429           (no_recommends := !no_recommends + 1; Array.update (recommends, j, (j, !age + ov)))
   430         else if ov < !age + 1000.0 then
   430         else if ov < !age + 1000.0 then
   431           Array.update (recommends, j, (j, v + ov))
   431           Array.update (recommends, j, (j, v + ov))
   432         else
   432         else
  1273 
  1273 
  1274 fun is_fact_in_graph access_G = can (Graph.get_node access_G) o nickname_of_thm
  1274 fun is_fact_in_graph access_G = can (Graph.get_node access_G) o nickname_of_thm
  1275 
  1275 
  1276 val chained_feature_factor = 0.5 (* FUDGE *)
  1276 val chained_feature_factor = 0.5 (* FUDGE *)
  1277 val extra_feature_factor = 0.05 (* FUDGE *)
  1277 val extra_feature_factor = 0.05 (* FUDGE *)
  1278 val num_extra_feature_facts = 10 (* FUDGE *)
  1278 val num_extra_feature_facts = 0 (* FUDGE *)
  1279 
  1279 
  1280 (* FUDGE *)
  1280 (* FUDGE *)
  1281 fun weight_of_proximity_fact rank =
  1281 fun weight_of_proximity_fact rank =
  1282   Math.pow (1.3, 15.5 - 0.2 * Real.fromInt rank) + 15.0
  1282   Math.pow (1.3, 15.5 - 0.2 * Real.fromInt rank) + 15.0
  1283 
  1283