I was trying to investigate the following problem I made up:

A bag contains n distinctly coloured marbles. A marble is drawn at random. It is replaced and a second identical marble of the same colour is added. This is repeated r times. What is the expected value distribution of the coloured marbles in the bag from most most frequent to least frequent.

To start with I decided to investigate small cases, e.g. n=2 and n=3.

I decided to create a probability tree with initial root node of:

root={{1,{1,1}}} (*n=2 case*)
root={{1,{1,1,1}} (*n=3 case, etc*)

where the first value represent the probability of this node occurring and the second list represents the state of the bag.

I then created a function to determine all daughter nodes from a given node:


This successfully created all daughter nodes and could work with Map and Flatten on successive generations.

In:> Flatten[Map[daughters,root],1]
Out:> {{1/2,{2,1}},{1/2,{1,2}}
In:> Flatten[Map[daughters,%],1]
Out:> {{1/3,{3,1}},{1/6,{2,2}},{1/6,{2,2}},{1/3,{1,3}}

At this point (as I was expecting) there is duplication within the tree and I could write some code to combine nodes with the same state into a single node by adding their probabilities.

Coming up with this function wasn't too tricky as nodes which need to be combined always ended up next to each other.

However this whole problem got me thinking is there a better way to do problems like this (probability trees with a certain probability and a specific state (including ones where nodes to combine may not be adjacent)). So my question is are their built in functions I should be using for exploring a probability tree problem like this that handle automatically handle the combining of daughters? If not how would I write an efficient method which combines daughters which are not necessarily adjacent?

Thanks in advance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.