changed formatting of stale proportion/efficiency. ±, you will be missed
authorForrest Voight <forrest@forre.st>
Sun, 29 Jan 2012 01:42:48 +0000 (20:42 -0500)
committerForrest Voight <forrest@forre.st>
Sun, 29 Jan 2012 01:42:48 +0000 (20:42 -0500)
p2pool/main.py
p2pool/util/math.py

index 87bf7a8..ed69998 100644 (file)
@@ -828,10 +828,11 @@ def main(args, net, datadir_path):
                             this_str += '\nAverage time between blocks: %.2f days' % (
                                 2**256 / current_work.value['bits'].target / real_att_s / (60 * 60 * 24),
                             )
-                            this_str += '\nPool stales: %i%%' % (int(100*stale_prop+.5),)
-                            stale_center, stale_radius = math.binomial_conf_center_radius(stale_orphan_shares + stale_doa_shares, shares, 0.95)
-                            this_str += u' Own: %i±%i%%' % (int(100*stale_center+.5), int(100*stale_radius+.5))
-                            this_str += u' Own efficiency: %i±%i%%' % (int(100*(1 - stale_center)/(1 - stale_prop)+.5), int(100*stale_radius/(1 - stale_prop)+.5))
+                            this_str += '\nPool stales: %i%% Own: %s Own efficiency: %s' % (
+                                int(100*stale_prop+.5),
+                                math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95),
+                                math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95, lambda x: (1 - x)/(1 - stale_prop)),
+                            )
                             if this_str != last_str or time.time() > last_time + 15:
                                 print this_str
                                 last_str = this_str
index 574f43a..06c9244 100644 (file)
@@ -98,9 +98,11 @@ def erf(x):
 def find_root(y_over_dy, start, steps=10, bounds=(None, None)):
     guess = start
     for i in xrange(steps):
-        guess = guess - y_over_dy(guess)
+        prev, guess = guess, guess - y_over_dy(guess)
         if bounds[0] is not None and guess < bounds[0]: guess = bounds[0]
         if bounds[1] is not None and guess > bounds[1]: guess = bounds[1]
+        if guess == prev:
+            break
     return guess
 
 def ierf(z):
@@ -131,7 +133,7 @@ else:
             top = right**(x+1) * (1-right)**(n-x+1) * left*(1-left) - left**(x+1) * (1-left)**(n-x+1) * right * (1-right)
             bottom = (x - n*right)*left*(1-left) - (x - n*left)*right*(1-right)
             return top/bottom/b
-        left_a = find_root(f, (1-conf)/2, 12, (0, 1-conf))
+        left_a = find_root(f, (1-conf)/2, bounds=(0, 1-conf))
         return special.betaincinv(x+1, n-x+1, left_a), special.betaincinv(x+1, n-x+1, left_a + conf)
 
 def binomial_conf_center_radius(x, n, conf=0.95):
@@ -141,6 +143,14 @@ def binomial_conf_center_radius(x, n, conf=0.95):
     p = x/n
     return p, max(p - left, right - p)
 
+minmax = lambda x: (min(x), max(x))
+
+def format_binomial_conf(x, n, conf=0.95, f=lambda x: x):
+    if n == 0:
+        return '???'
+    left, right = minmax(map(f, binomial_conf_interval(x, n, conf)))
+    return '~%i%% (%i-%i%%)' % (int(100*f(x/n)+1/2), int(100*left), 100-int(100-100*right))
+
 def reversed(x):
     try:
         return __builtin__.reversed(x)