Dear Colleagues: Is anyone aware of a Mata strategy for computing all possible partitions of a vector? A template of what I have in mind is
where the z that is returned is the 5x3 matrix[
That is, the elements in each row of z indicate the partition membership index. In this example there are five partitions; in set notation
The number of partitions of a given vector (=set) is given by Bell's Number https://oeis.org/A000110
It would be easy enough to brute force code this by hand for small sets, e.g. #S=3 or #S=4. But beyond this it would be nice to have a general function that did the heavy lifting.
Any suggestions or references would be appreciated. If I need to write something from scratch that's understandable, but if something already exists then all the better.
Thanks in advance.
Code:
v=4,5,6 z=allpartitions(v)
Code:
1 2 3 +-------------+ 1 | 1 1 1 | 2 | 1 1 2 | 3 | 1 2 1 | 4 | 1 2 2 | 5 | 1 2 3 | +-------------+
Code:
Partition 1: {4,5,6} Partition 2: {4,5},{6} Partition 3: {4,6},{5} Partition 4: {4},{5,6} Partition 5: {4},{5},{6}
It would be easy enough to brute force code this by hand for small sets, e.g. #S=3 or #S=4. But beyond this it would be nice to have a general function that did the heavy lifting.
Any suggestions or references would be appreciated. If I need to write something from scratch that's understandable, but if something already exists then all the better.
Thanks in advance.
Comment