Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /MLRISC/releases/release-110.84/library/probability.sml
ViewVC logotype

Diff of /MLRISC/releases/release-110.84/library/probability.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1136, Tue Mar 12 19:44:02 2002 UTC revision 1144, Thu Mar 14 19:53:15 2002 UTC
# Line 27  Line 27 
27    
28      val percent : int -> prob      val percent : int -> prob
29    
30      (* combine a conditional branch probability (trueProb) with a
31       * prediction heuristic (takenProb) using Dempster-Shafer theory.
32       *)
33        val combineProb2 : {trueProb : prob, takenProb : prob} -> {t : prob, f : prob}
34    
35      val toReal : prob -> real      val toReal : prob -> real
36      val toString : prob -> string      val toString : prob -> string
37    
# Line 135  Line 140 
140              concat [toStr n, "/", toStr d]              concat [toStr n, "/", toStr d]
141            end            end
142    
143      (* combine a conditional branch probability (trueProb) with a
144       * prediction heuristic (takenProb) using Dempster-Shafer theory.
145       * The basic equations (from Wu-Larus 1994) are:
146       *    t = trueProb*takenProb / d
147       *    f = ((1-trueProb)*(1-takenProb)) / d
148       * where
149       *    d = trueProb*takenProb + ((1-trueProb)*(1-takenProb))
150       *)
151        fun combineProb2 {trueProb=PROB(n1, d1), takenProb=PROB(n2, d2)} = let
152            (* compute sd/sn, where
153             *    sn/sd = (trueProb*takenProb) + (1-trueProb)*(1-takenProb)
154             *)
155              val d12 = d1*d2
156              val n12 = n1*n2
157              val (sn, sd) = let
158                    val n = d12 + 0w2*n12 - (d2*n1) - (d1*n2)
159                    in
160                      (d12, n)
161                    end
162            (* compute the true probability *)
163              val t as PROB(tn, td) = normalize(n12*sn, d12*sd)
164            (* compute the false probability *)
165              val f = PROB(td-tn, td)
166              in
167                {t = t, f = f}
168              end
169    
170      val op + = add      val op + = add
171      val op - = sub      val op - = sub
172      val op * = mul      val op * = mul

Legend:
Removed from v.1136  
changed lines
  Added in v.1144

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0