Bitcoin Forum
October 17, 2017, 10:20:30 AM
 Welcome, Guest. Please login or register.
 News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 Home Help Search Donate Login Register
 Pages: [1]
 Author Topic: How do you calculate probability?  (Read 3299 times)
mizerydearia
Hero Member

Offline

Activity: 574

 July 19, 2010, 03:13:43 AM

.I am trying to correct some PHP code to calculate probability of generating a block for bitbot.  bd_ and llama have provided some debate regarding how to calculate it and I suggest it be moved to forum for further eyes to analyze their findings and to come to a conclusion on best formula to calculate probability.

For now, here's code I've been using:
Code:
//var p = target*rate*1000/Math.pow(2,256);
//var txt = "<table border='1'>
// <tr style='font-weight:bold'> <td>Probability</td> <td>Time</td></tr>\n"+"
// <tr> <td>Average</td> <td>"+getHumanTime(1/p)+"</td></tr>\n"+getRow(0.50,p)+getRow(0.95,p)+"</table>";
//document.getElementById('answer').innerHTML = txt;
//function getRow(prob,p) { return "<tr><td>"+100*prob+"%</td><td>"+getHumanTime(-Math.log(1-prob)/p)+"</td></tr>\n";

bcscale(256);
\$a = bcsub(bcpow(2,256),1);
\$b = bcmul(bcpow(2,32),\$difficulty);
\$target = bcdiv(\$a,\$b); // target
\$pph = bcdiv(\$target,bcpow(2,256)); // probability per hash
if (isset(\$_GET["r"]) && \$_GET["r"] != "") {
\$rate = \$_GET["r"];
if (is_numeric(\$rate)) {
function humantime(\$secs) {
if (\$secs<0) return false;
\$m = (int)(\$secs / 60); \$s = \$secs % 60; \$s = (\$s <= 9) ? "0\$s" : \$s;
\$h = (int)(\$m / 60); \$m = \$m % 60; \$m = (\$m <= 9) ? "0\$m" : \$m;
\$d = (int)(\$h / 24); \$h = \$h % 24;
return \$d."d \$h:\$m:\$s";
}
echo "http://bitcointalk.org/index.php?topic=471.0";exit;
// Where does this go?
// <bd_> To compute the number of hashes needed to reach a success probability of P_targ, you'll want n >= log(P_targ)/log(1-P)
// <bd_> So time needed is (log(P_targ)/log(1-P))/rate

// <bd_> To compute the probability per second, you'll want 1-(1-p)^rate, where p is the probability of a single hash being correct
//\$pps = bcdiv(bcmul(\$target,1000),bcpow(2,256)); // probability per second (according to bd_ this is wrong)
bcscale(16); // Next calculation takes too long for higher bits
\$pps = bcsub(1,bcpow(bcsub(1,\$pph),\$rate)); // probability per second
//echo "probabiliy per second == 1-(1-p)^rate == 1-(1-\$pph)^\$rate == \$pps";exit;
// Comment next line for 256-bits of data
bcscale(16);
\$ppr = bcmul(\$pps,\$rate);
//\$ppr = \$pps;
\$etaAvg = humantime(bcdiv(1,\$ppr));
\$eta25 = humantime(bcdiv(-log(.75),\$ppr));
\$eta50 = humantime(bcdiv(-log(.5),\$ppr));
\$eta75 = humantime(bcdiv(-log(.25),\$ppr));
\$eta95 = humantime(bcdiv(-log(.05),\$ppr));
\$eta99 = humantime(bcdiv(-log(.01),\$ppr));
echo "ProbabilityPerSecond(\$ppr) Avg(\$etaAvg) 25%(\$eta25) 50%(\$eta50) 75%(\$eta75) 95%(\$eta95) 99%(\$eta99)";
} else echo "This command requires either no argument or a numeric argument representing khash/sec.";
}
else {
bcscale(32);
\$pph = bcmul(\$pph,1);
echo "ProbabilityPerHash(\$pph)";
}

http://nullvoid.org/bitcoin/bc.php?q=gethashprobability&r=2000 where r is your khash/sec
1508235630
Hero Member

Offline

Posts: 1508235630

Ignore
 1508235630

1508235630
 Report to moderator
1508235630
Hero Member

Offline

Posts: 1508235630

Ignore
 1508235630

1508235630
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1508235630
Hero Member

Offline

Posts: 1508235630

Ignore
 1508235630

1508235630
 Report to moderator
llama
Member

Offline

Activity: 103

 July 19, 2010, 03:38:52 AM

Actually, it seems that BD_ and I have come to an agreement!

To calculate average (expected value of generation time):

1/(pr)

To calculate how long until you have a T chance of producing at least 1 block:

-ln(1-T)/pr

Where:

p = probability of a given hash resulting in success (TARGET / 2^256)
r = rate in hashes / sec
T = target probability, such as 0.95
ln = log base e

I got to mine just by plugging variables and rearranging the poisson distribution.  BD_ can give you a different formula for the second equation, which he heroically derived from the binomial distribution, but which yields the same effective results.

 Pages: [1]
 « previous topic next topic »
Jump to:

Sponsored by , a Bitcoin-accepting VPN.