About the problem of probabilistic algorithm, do not know where the logic is wrong, ask for debug

Source: Internet
Author: User
Tags pow

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:

    1. 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.

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.