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 /sml/trunk/src/MLRISC/library/probability.sml
 [smlnj] / sml / trunk / src / MLRISC / library / probability.sml

# Diff of /sml/trunk/src/MLRISC/library/probability.sml

revision 1152, Tue Mar 19 21:36:30 2002 UTC revision 1153, Wed Mar 20 19:04:04 2002 UTC
# Line 24  Line 24
24      val - : (prob * prob) -> prob      val - : (prob * prob) -> prob
25      val * : (prob * prob) -> prob      val * : (prob * prob) -> prob
26      val / : (prob * int) -> prob      val / : (prob * int) -> prob
27        val not : prob -> prob              (* not p == always - p *)
28
29      val percent : int -> prob      val percent : int -> prob
30
# Line 51  Line 52
52
54
55      val never = PROB(0w0, 0w0)      val never = PROB(0w0, 0w1)
56      val unlikely = PROB(0w1, 0w1000)      val unlikely = PROB(0w1, 0w1000)
57      val likely = PROB(0w999, 0w1000)      val likely = PROB(0w999, 0w1000)
58      val always = PROB(0w1, 0w1)      val always = PROB(0w1, 0w1)
# Line 161  Line 162
162                  end                  end
163          (* compute the true probability *)          (* compute the true probability *)
164            val t as PROB(tn, td) = normalize(n12*sn, d12*sd)            val t as PROB(tn, td) = normalize(n12*sn, d12*sd)
165              val maxDenom = 0wx8000
166              val t as PROB(tn, td) = if td > maxDenom
167                    then let
168                    (* round down a bit to avoid future overflow *)
169                      fun lp (d, i) = let
170                            val d' = Word.>>(d, 0w1)
171                            in
172                              if (d' > maxDenom) then lp(d', i+0w1) else (d', i)
173                            end
174                      val (d, i) = lp(td, 0w1)
175                      val n = Word.>>(tn, i)
176                      in
177                        PROB(if n > 0w0 then n else 0w1, d)
178                      end
179                    else t
180          (* compute the false probability *)          (* compute the false probability *)
181            val f = PROB(td-tn, td)            val f = PROB(td-tn, td)
182            in            in
183              {t = t, f = f}              {t = t, f = f}
184            end            end
185
186        fun not (PROB(n, d)) = PROB(d-n, n)
187