improved estimation of stale proportion by using maximum-likelihood estimator instead...
authorForrest Voight <forrest@forre.st>
Mon, 23 Jan 2012 01:18:21 +0000 (20:18 -0500)
committerForrest Voight <forrest@forre.st>
Mon, 23 Jan 2012 01:18:21 +0000 (20:18 -0500)
p2pool/main.py
p2pool/util/math.py

index 76313e7..f844319 100644 (file)
@@ -785,9 +785,12 @@ def main(args, net, datadir_path):
                             conf = 0.95
                             if shares:
                                 stale_shares = stale_orphan_shares + stale_doa_shares
-                                this_str += u' Own: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius(math.binomial_conf_interval(stale_shares, shares, conf)))
+                                stale_center, stale_radius = math.binomial_conf_center_radius(stale_shares, shares, conf)
+                                this_str += u' Own: %i±%i%%' % (int(100*stale_center+.5), int(100*stale_radius+.5))
                                 if stale_prop < .99:
-                                    this_str += u' Own efficiency: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius((1 - y)/(1 - stale_prop) for y in math.binomial_conf_interval(stale_shares, shares, conf)[::-1]))
+                                    eff_center = (1 - stale_center)/(1 - stale_prop)
+                                    eff_radius = stale_radius/(1 - stale_prop)
+                                    this_str += u' Own efficiency: %i±%i%%' % (int(100*eff_center+.5), int(100*eff_radius+.5))
                             if this_str != last_str or time.time() > last_time + 15:
                                 print this_str
                                 last_str = this_str
index 3600064..3c7af42 100644 (file)
@@ -117,8 +117,11 @@ def binomial_conf_interval(x, n, conf=0.95):
     bottom = 1 + z**2/n
     return (topa - topb)/bottom, (topa + topb)/bottom
 
-def interval_to_center_radius((low, high)):
-    return (high+low)/2, (high-low)/2
+
+def binomial_conf_center_radius(x, n, conf=0.95):
+    p = x/n
+    left, right = binomial_conf_interval(x, n, conf)
+    return p, max(p - left, right - p)
 
 def reversed(x):
     try: