Results 1 to 11 of 11
Like Tree5Thanks
  • 1 Post By romsek
  • 1 Post By romsek
  • 1 Post By Plato
  • 1 Post By romsek
  • 1 Post By romsek

Thread: 5 cards changing with different probability. Probability of 0-5 cards changing?

  1. #1
    PDC
    PDC is offline
    Newbie
    Joined
    Nov 2016
    From
    UK
    Posts
    8

    5 cards changing with different probability. Probability of 0-5 cards changing?

    We have 5 white cards, numbered 1 to 5.


    Each card can change to blue but this will have a different probability of happening for each card, e.g.:


    card 1: 5% probability of turning into blue
    card 2: 3% "
    card 3: 4% "
    card 4: 5% "
    card 5: 1% "


    Is it possible to calculate the chance of having: no blue cards, 1 blue card, 2 blue cards, 3 blue cards, 4 blue cards, all (5) blue cards, respectively? (the sum of these probabilities will obviously be 100%).


    N.B.: for e.g. a "3-blue-cards" combination, any 3 of the 5 cards can be changed, e.g. cards 1,2,3 or 1,3,5 or 2,4,5 etc...


    Thanks
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,401
    Thanks
    2290

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    We must assume all cards are independent from each other.

    1) for a given # of cards $n \in 0,~1~\dots 5$, list all the combinations of changing cards that gets you this number

    2) for each set from above examine the cards that changed. If the card changed use it's probability of change from your table. If it didn't change use (1-prob).

    Form the product of all these probabilities for each combination associated with $n$ cards changing

    Sum these products for all the combinations associated with $n$ cards changing.

    For example

    0 cards changing has probability

    $p_0= (1-0.05)(1-0.03)(1-0.04)(1-0.05)(1-0.01)$

    1 card changing has probability

    $p_1 = \\(0.05)(1-0.03)(1-0.04)(1-0.05)(1-0.01) + \\(1-0.05)(0.03)(1-0.04)(1-0.05)(1-0.01) + \\ (1-0.05)(1-0.03)(0.04)(1-0.05)(1-0.01)+ \\(1-0.05)(1-0.03)(1-0.04)(0.05)(1-0.01)+ \\(1-0.05)(1-0.03)(1-0.04)(1-0.05)(0.01)$

    and 5 cards changing has probability

    $p_5 = (0.05)(0.03)(0.04)(0.05)(0.01)$

    2,3, and 4 cards changing are move involved and I leave these to you. I highly suggest using software.
    Thanks from PDC
    Follow Math Help Forum on Facebook and Google+

  3. #3
    PDC
    PDC is offline
    Newbie
    Joined
    Nov 2016
    From
    UK
    Posts
    8

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    Thanks very much romsek,

    any suggestion on the software I may use ?

    Cheers.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,401
    Thanks
    2290

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    Quote Originally Posted by PDC View Post
    Thanks very much romsek,

    any suggestion on the software I may use ?

    Cheers.
    5 cards changing with different probability. Probability of 0-5 cards changing?-clipboard01.jpg

    there you go.

    I don't know what software you have available. You could probably make excel work.
    Thanks from PDC
    Follow Math Help Forum on Facebook and Google+

  5. #5
    PDC
    PDC is offline
    Newbie
    Joined
    Nov 2016
    From
    UK
    Posts
    8

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    wow! thanks. will give it a go.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor

    Joined
    Aug 2006
    Posts
    20,738
    Thanks
    2459
    Awards
    1

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    Quote Originally Posted by PDC View Post
    We have 5 white cards, numbered 1 to 5.
    Each card can change to blue but this will have a different probability of happening for each card, e.g.:
    card 1: 5% probability of turning into blue
    card 2: 3% "
    card 3: 4% "
    card 4: 5% "
    card 5: 1% "
    Is it possible to calculate the chance of having: no blue cards, 1 blue card, 2 blue cards, 3 blue cards, 4 blue cards, all (5) blue cards, respectively? (the sum of these probabilities will obviously be 100%).
    There is also a mathematical model for this. It can be done with bit-strings (zeros & ones) of length five/
    The string $01011$ mean cards two,four & five turn blue with probability
    $\underbrace {[(.05)^0(.95)^1]}_{card\,1}\underbrace {[(.03)^1(.97)^0]}_{card\,2}\underbrace {[(.04)^0(.96)^1]}_{card\,3}\underbrace {[(.05)^1(.95)^0]}_{card\,4}\underbrace {[(.01)^1(.99)^0]}_{card\,5}$

    To list a these possible bit strings it takes a $32\times 5$ matrix, $M(j,k)=\left\lceil {\dfrac{j}{{{2^{5 - k}}}}} \right\rceil {\bmod _2}$

    This is like programming a truth table with five variables. As for software I personally would chose MathCad as I find it much easier to use.
    Last edited by Plato; Nov 27th 2016 at 02:03 PM.
    Thanks from PDC
    Follow Math Help Forum on Facebook and Google+

  7. #7
    PDC
    PDC is offline
    Newbie
    Joined
    Nov 2016
    From
    UK
    Posts
    8

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    Hey romsek,
    thanks again for your script. I downloaded the WM trial version and ran your script successfully for up to 10 cards. The result comes in about 1 second. If I use 11 cards or more it freezes for a long time before saying that there is insufficient memory. I am wondering if the problem is actually the memory (I have an old hp laptop, 6 GB RAM) or is there anything in your script (which I am not embarassed to say that I can't decipher) limiting the number of cards to max 10 ?

    My objective would be to run it on 25 cards.

    Thanks for any comment you can provide on this.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,401
    Thanks
    2290

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    Quote Originally Posted by PDC View Post
    Hey romsek,
    thanks again for your script. I downloaded the WM trial version and ran your script successfully for up to 10 cards. The result comes in about 1 second. If I use 11 cards or more it freezes for a long time before saying that there is insufficient memory. I am wondering if the problem is actually the memory (I have an old hp laptop, 6 GB RAM) or is there anything in your script (which I am not embarassed to say that I can't decipher) limiting the number of cards to max 10 ?

    My objective would be to run it on 25 cards.

    Thanks for any comment you can provide on this.
    I'll take a look
    Follow Math Help Forum on Facebook and Google+

  9. #9
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,401
    Thanks
    2290

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    certainly nothing limiting it to 10.

    Execution time starts to crawl at around 20 cards.

    One thing to note is that the probability of say 8 or more cards changing starts to get pretty close to 0.

    That's with a uniform distribution but even with a non-uniform one at some point well less than 25 cards the probability of some number of cards or more changing is going to be negligible.

    The sheet can be modified to only look at cases where N or fewer cards change, N around 10 or so.

    I suspect it's an artifact of the trial version rather than the full version. My pc has 16 GB though so maybe you do have too little RAM. Don't know.

    What happens is that as you get a lot of cards the number of ways to have a fair number of cards change starts to get huge.

    I'll continue to investigate as time allows.
    Thanks from PDC
    Follow Math Help Forum on Facebook and Google+

  10. #10
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,401
    Thanks
    2290

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    ok try this

    adjust ncards, probs, pThresh as desired

    note that calcs for ncards > 20 still crawl, even on my pc.

    -------------------------------------------------------------------------------------------------------------------------
    (* the cards *)
    ncards = 20;
    cards = Array[# &, ncards];

    (* the probability of changing for each card *)
    (* I just selected random probabilities. You would set these to your system *)
    probs = Array[RandomReal[{0, 1}] &, ncards];
    probs = probs/(probs /. List -> Plus);
    notprobs = 1 - probs;

    (* Probability threshold. This will stop the loop when probabilities fall below this level *)
    pThresh = 10^-6;

    (* a function that takes a combination list and generates the probability of that combination occurring *)
    comboProb[c_] := Product[If[Cases[c, k] == {}, notprobs[[k]], probs[[k]]], {k, 1, ncards}];

    (* Initialize array of probabilities of k cards changing in case you want to save results *)
    changeProb = ConstantArray[0, ncards+1];

    (* Find the probabilities for k cards changing. Do this in a loop rather than in tables to save memory *)
    For[k = 0, k <= ncards, k++,
    combos = Subsets[cards, {k}];
    p = Sum[comboProb[combos[[i]]], {i, 1, Length[combos]}];
    Print[{k, p}];

    (* set this probability in the changeProb array *)
    changeProb[[k + 1]] = p;

    (* check to see if probabilities have gotten small enough to stop computing them *)
    If[p < pThresh, Print["Probabilility threshold reached. Stopping."]; Break[]];
    ];

    changeProb // MatrixForm
    ------------------------------------------------------------------------------------------------------------------------
    Last edited by romsek; Dec 6th 2016 at 02:03 PM.
    Thanks from PDC
    Follow Math Help Forum on Facebook and Google+

  11. #11
    PDC
    PDC is offline
    Newbie
    Joined
    Nov 2016
    From
    UK
    Posts
    8

    Re: 5 cards changing with different probability. Probability of 0-5 cards changing?

    That's amazing.

    Thank you so much...also for your comment on why my laptop was crashing. Chances are that only a "huge beast" could deal with the 25 cards...however your new script really works perfectly for what I need to do.

    Many thanks again.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Probability of cards
    Posted in the Discrete Math Forum
    Replies: 14
    Last Post: Dec 10th 2012, 01:10 AM
  2. Cards & Probability: P(2 pairs) if dealt 4 cards
    Posted in the Statistics Forum
    Replies: 4
    Last Post: May 11th 2012, 06:36 AM
  3. Replies: 0
    Last Post: Apr 7th 2012, 07:42 PM
  4. probability of 5 correct cards out of 6 cards
    Posted in the Statistics Forum
    Replies: 8
    Last Post: May 20th 2011, 06:44 AM
  5. probability with cards(not 52)
    Posted in the Statistics Forum
    Replies: 1
    Last Post: Jul 5th 2007, 10:11 AM

/mathhelpforum @mathhelpforum