Make a dice success probability analysis, cast n Dice, the first chance of success is a, and then cast a successful dice, need to cast 1 times, the odds of success is B. The second successful dice is the final success.
To analyze the N-dice, the probability of the final success of 0 to N.
I wrote an algorithm, to find the results, total 0 to n probability is not approximate 1, and the difference is very big, ask you big algorithm what error.
The basic idea of my algorithm:
First count the probability list of the first successful 0-n dice. This step I think I have no problem, the total calculation results approximate 1
for (var i = 0; i <= n; i++){ FirstSuccessRateTbl.Add(i , Utils.C(n, i)*(decimal)(Math.Pow((double)firstSucessRate,i)*Math.Pow((double)firstLoseRate,n-i)));}
Where UTILS.C is the function I wrote by C probability formula. FIRSTSUCCESSRATETBL uses a hash table.
Then, the probability of a successful x after the first success is counted as conditional probability, that is, the probability of the second successful X if the first successful x and above dice are accumulated.
decimal sucessXRate = 0;for (int i = x; i <= n; i++) { sucessXRate += FirstSuccessRateTbl[i] * (decimal)(Math.Pow((double)secordSucessRate, i)*Utils.C(i,i-x)*Math.Pow((double)secordFailRate,i-x));}return sucessXRate;
But according to this algorithm, 2 times the chance of success 0-n the total is not 1, do not know where the error.
On the problem of probabilistic algorithms, do not know where the logic is wrong, ask for debug >> CSharp
The answer is quite clear:
Http://www.goodpm.net/postreply/csharp/1010000008918700/on the problem of probabilistic algorithms do not know where logic is wrong to seek debug.html
The problem of probabilistic algorithms, do not know where the logic is wrong, to debug