Message Boards Message Boards

0
|
1415 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Function for population size from known frequencies?

Posted 8 months ago

Perhaps there is a built-in function for this?

I have vectors of integers. All vectors have the same number of elements c. There are c values in the domain. The values in each vector need not be unique but there may not be duplicate vectors.

Each set of these vectors has a known distribution. For example, for c=5 there is a set with frequencies {1,2,2}. One member of that set looks like {a,b,b,c,c}.

The function I'm seeking would calculate the size (number of vectors) with F[5,{1,2,2}].

In lieu of a function I've attempted to define a formula. There appears to be two trivial distributions: {c} and {1, 1, …, 1}. The former has size c and the latter c!. The others involve products of binomial coefficients.

POSTED BY: Richard Frost
4 Replies
Posted 8 months ago

I think the following function will given you the number of the n^Total[f] arrangements that result in the desired frequencies when looking at length of Total[f]. (Your examples all had n == Total[f] but as long as Length[f] <= n, the formula should work.)

count[n_, f_] := Piecewise[
  {{Binomial[n, Length[f]]*Multinomial[Sequence @@ f]*
  Multinomial[Sequence @@ (Tally[f][[All, 2]])], 
    n \[Element] PositiveIntegers && f \[Element] PositiveIntegers && Length[f] <= n}}]

A working example is

count[5, {1, 2, 2}]
(* 900 *)

As a partial check here is some code that will generate all of the arrangements for specified values of n and f:

arrangements[n_, f_] := Module[{alpha, t},
  (* Unique values *)
  alpha = Alphabet[][[1 ;; n]];
  (* Generate all possible tuples *)
  t = Tuples[alpha, {Total[f]}];
  (* Find frequencies of values *)
  t = {#, Tally[#]} & /@ t;
  (* Keep tuples with Length[f] (same number of unique value) *)
  t = Select[t, Length[#[[2]]] == Length[f] &];
  (* Get frequencies and sort from low to high frequency *)
  t[[All, 2]] = (#[[2, All, 2]] // Sort) & /@ t;
  (* Select tuples with same frequencies in f *)
  t = Select[t, #[[2]] == f &][[All, 1]]
  ]

Matching the previous example:

arrangements[n, f] // Length
(* 900 *)

(This function should be used only for relatively small values of n and f.)

Rationale

For a specific set of values associated with the frequencies the number of arrangements is Multinomial[Sequence@@f] if n = Length[f]. For example, the number of arrangements with n = 3 and f={1,2,3} with a being associated with the frequency of 1, b associated with the frequency of 2, and c associated with the frequency of 3 is Multinomial[1,2,3] which equals 60. But there are 3! different arrangements of assigning a, b, and c to the frequencies. So the total number of arrangements with a, b, and c with a frequency vector of {1,2,3} is Multinomial[1,2,3]*3! which equals 360.

But suppose the frequencies are {1,2,2}. Here there are ties in the frequencies so that there aren’t 3! = 6 different assignments as assigning a b c to the frequencies will result in the same arrangements as a, c, b. Here we would multiply Multinomial[1,2,2] by 3!/(2! 1!) to obtain 90 arrangements.

To clarify this for when there are multiple ties in the frequencies suppose f is {1,2,2,2,3,3,3,3} and n=8. We would multiply Multinomial[1,2,2,2,3,3,3,3] by 8!/(1! 3! 4!) resulting in 3,285,168,606,720,000arrangements. That multiplier is just Multinomial[1,3,4].

Now suppose that n > Length[f]. There are more arrangements to consider. As we are choosing Length[f] values out of n values, that can happen Binomial[n, Length[f]] ways and we multiply by that value. Hence the form of the function count shown above.

POSTED BY: Jim Baldwin
Posted 8 months ago

Are you looking for Multinomial ?

Multinomial[1, 2, 2]
(* 30 *)

But Multinomial[c] equals 1 for any integer value of c. You've show one member of a set. If you could show a few other members (or all members) that would help determine how to obtain the count of members in general.

As an example:

Multinomial[1, 3, 4]
(* 280 *)
Length[Permutations[{a, b, b, b, c, c, c, c}]]
(* 280 *)
POSTED BY: Jim Baldwin

Hi Jim, As an example, consider the general population of vectors of length n = 5 composed of n letters: a,b,c,d,e. This population has well known size n^n.

I'm interested in subsets of this population defined by frequencies of the letters (in this example). Here's an example set of frequencies: {1,2,2}. It has members that look like {a,b,b,c,c}, {a,b,c,b,c}, ..., {d,e,d,e,a}.

Is there a Mathematica function that would calculate the size of this subset, given 5 letters and frequences {1,2,2} ?

POSTED BY: Richard Frost
Posted 8 months ago

I've added in a formula for the total number of arrangements along with a rationale for constructing that formula.

POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract