Bitcoin Forum
November 19, 2017, 01:11:29 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How do you calculate probability?  (Read 3317 times)
mizerydearia
Hero Member
*****
Offline Offline

Activity: 574



View Profile
July 19, 2010, 03:13:43 AM
 #1

.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
1511097089
Hero Member
*
Offline Offline

Posts: 1511097089

View Profile Personal Message (Offline)

Ignore
1511097089
Reply with quote  #2

1511097089
Report to moderator
1511097089
Hero Member
*
Offline Offline

Posts: 1511097089

View Profile Personal Message (Offline)

Ignore
1511097089
Reply with quote  #2

1511097089
Report to moderator
Join ICO Now Coinlancer is Disrupting the Freelance marketplace!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1511097089
Hero Member
*
Offline Offline

Posts: 1511097089

View Profile Personal Message (Offline)

Ignore
1511097089
Reply with quote  #2

1511097089
Report to moderator
llama
Member
**
Offline Offline

Activity: 103


View Profile
July 19, 2010, 03:38:52 AM
 #2

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]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!