Perturbation (astronomy): Difference between revisions
en>Teapeat |
en>Gob Lofa |
||
Line 1: | Line 1: | ||
{{Incomplete|date=November 2011}} | |||
A '''random permutation''' is a [[random]] ordering of a set of objects, that is, a [[permutation]]-valued [[random variable]]. The use of random permutations is often fundamental to fields that use [[randomized algorithm]]s such as [[coding theory]], [[cryptography]], and [[simulation]]. A good example of a random permutation is the [[shuffling]] of a [[card deck|deck of cards]]: this is ideally a random permutation of the 52 cards. | |||
==Generating random permutations== | |||
===Entry-by-entry brute force method=== | |||
One method of generating a random permutation of a set of length ''n'' [[uniform distribution (discrete)|uniformly at random]] (i.e., each of the ''n''! [[permutation]]s is equally likely to appear) is to generate a sequence by taking a random number between 1 and ''n'' sequentially, ensuring that there is no repetition, and interpreting this sequence (''x''<sub>1</sub>, ..., ''x''<sub>''n''</sub>) as the permutation | |||
: <math>\begin{pmatrix} | |||
1 & 2 & 3 & \cdots & n \\ | |||
x_1 & x_2 & x_3 & \cdots & x_n \\ | |||
\end{pmatrix},</math> | |||
shown here in [[permutation#Notation|two-line notation]]. | |||
This brute-force method will require occasional retries whenever the random number picked is a repeat of a number already selected. This can be avoided if, on the ''i''th step (when ''x''<sub>1</sub>, ..., ''x''<sub>''i'' − 1</sub> have already been chosen), one chooses a number ''j'' at random between 1 and ''n'' − ''i'' + 1 and sets ''x''<sub>''i''</sub> equal to the ''j''th largest of the unchosen numbers. | |||
===Knuth shuffles=== | |||
A simple [[algorithm]] to generate a permutation of ''n'' items uniformly at random without retries, known as the [[Knuth shuffle]], is to start with any permutation (for example, the [[Identity function|identity permutation]]), and then go through the positions 1 through ''n'' − 1, and for each position ''i'' '''swap''' the element currently there with a randomly chosen element from positions ''i'' through ''n'', inclusive. It's easy to verify that any permutation of ''n'' elements will be produced by this algorithm with probability exactly 1/''n''!, thus yielding a uniform distribution over all such permutations. | |||
The initializaton to the identity permutation and the shuffling may be combined, as in the following example. It requires a function <code>uniform(m)</code> which returns a random integer between 0 and ''m'' inclusive. | |||
<source lang="c"> | |||
unsigned uniform(unsigned m); /* Returns a random integer 0 <= uniform(m) <= m */ | |||
unsigned permute(unsigned permutation[], unsigned n) | |||
{ | |||
unsigned i; | |||
for (i = 0; i < n; i++) { | |||
unsigned j = uniform(i); | |||
permutation[i] = permutation[j]; | |||
permutation[j] = i; | |||
} | |||
} | |||
</source> | |||
Note that the first assignment to <code>permutation[i]</code> might be copying an uninitialized value, if <code>j</code> happens to be equal to <code>i</code>. However, in this case, it is immediately overwritten with a defined value on the next line. | |||
It is also important to note that the <code>uniform()</code> function can ''not'' be implemented simply as <code>random() % (m+1)</code> unless a bias in the results is acceptable. | |||
==Statistics on random permutations== | |||
===Fixed points=== | |||
{{main|Rencontres numbers}} | |||
The [[probability distribution]] of the number of [[Fixed point (mathematics)|fixed points]] of a uniformly distributed random permutation approaches a [[Poisson distribution]] with [[expected value]] 1 as ''n'' grows. In particular, it is an elegant application of the [[inclusion-exclusion principle]] to show that the probability that there are no fixed points approaches 1/''e''. The first ''n'' [[moment (mathematics)|moments]] of this distribution are exactly those of the Poisson distribution. | |||
== Randomness testing == | |||
As with all random processes, the quality of the resulting distribution of an implementation of a randomized algorithm such as the Knuth shuffle (i.e., how close it is to the desired uniform distribution) depends on the quality of the underlying source of randomness, such as a [[pseudorandom number generator]]. There are many possible [[randomness test]]s for random permutations, such as some of the [[Diehard tests]]. A typical example of such a test is to take some [[permutation statistic]] for which the distribution is known and test whether the distribution of this statistic on a set of randomly generated permutations closely approximates the true distribution. | |||
== See also == | |||
* [[Ewens's sampling formula]] — a connection with [[population genetics]] | |||
* [[Golomb–Dickman constant]] | |||
* [[Faro shuffle|Perfect shuffle]] | |||
* [[Random permutation statistics]] | |||
* [[Shuffle#Shuffling algorithms|Shuffling algorithms]] — random sort method, iterative exchange method | |||
== External links == | |||
* [http://mathworld.wolfram.com/RandomPermutation.html Random permutation] at [[MathWorld]] | |||
* [http://www.techuser.net/randpermgen.html Random permutation generation] -- detailed and practical explanation of Knuth shuffle algorithm and its variants for generating ''k''-permutations (permutations of ''k'' elements chosen from a list) and ''k''-subsets (generating a subset of the elements in the list without replacement) with pseudocode | |||
[[Category:Permutations]] | |||
[[Category:Randomness]] |
Revision as of 20:15, 25 January 2014
A random permutation is a random ordering of a set of objects, that is, a permutation-valued random variable. The use of random permutations is often fundamental to fields that use randomized algorithms such as coding theory, cryptography, and simulation. A good example of a random permutation is the shuffling of a deck of cards: this is ideally a random permutation of the 52 cards.
Generating random permutations
Entry-by-entry brute force method
One method of generating a random permutation of a set of length n uniformly at random (i.e., each of the n! permutations is equally likely to appear) is to generate a sequence by taking a random number between 1 and n sequentially, ensuring that there is no repetition, and interpreting this sequence (x1, ..., xn) as the permutation
shown here in two-line notation.
This brute-force method will require occasional retries whenever the random number picked is a repeat of a number already selected. This can be avoided if, on the ith step (when x1, ..., xi − 1 have already been chosen), one chooses a number j at random between 1 and n − i + 1 and sets xi equal to the jth largest of the unchosen numbers.
Knuth shuffles
A simple algorithm to generate a permutation of n items uniformly at random without retries, known as the Knuth shuffle, is to start with any permutation (for example, the identity permutation), and then go through the positions 1 through n − 1, and for each position i swap the element currently there with a randomly chosen element from positions i through n, inclusive. It's easy to verify that any permutation of n elements will be produced by this algorithm with probability exactly 1/n!, thus yielding a uniform distribution over all such permutations.
The initializaton to the identity permutation and the shuffling may be combined, as in the following example. It requires a function uniform(m)
which returns a random integer between 0 and m inclusive.
unsigned uniform(unsigned m); /* Returns a random integer 0 <= uniform(m) <= m */
unsigned permute(unsigned permutation[], unsigned n)
{
unsigned i;
for (i = 0; i < n; i++) {
unsigned j = uniform(i);
permutation[i] = permutation[j];
permutation[j] = i;
}
}
Note that the first assignment to permutation[i]
might be copying an uninitialized value, if j
happens to be equal to i
. However, in this case, it is immediately overwritten with a defined value on the next line.
It is also important to note that the uniform()
function can not be implemented simply as random() % (m+1)
unless a bias in the results is acceptable.
Statistics on random permutations
Fixed points
Mining Engineer (Excluding Oil ) Truman from Alma, loves to spend time knotting, largest property developers in singapore developers in singapore and stamp collecting. Recently had a family visit to Urnes Stave Church. The probability distribution of the number of fixed points of a uniformly distributed random permutation approaches a Poisson distribution with expected value 1 as n grows. In particular, it is an elegant application of the inclusion-exclusion principle to show that the probability that there are no fixed points approaches 1/e. The first n moments of this distribution are exactly those of the Poisson distribution.
Randomness testing
As with all random processes, the quality of the resulting distribution of an implementation of a randomized algorithm such as the Knuth shuffle (i.e., how close it is to the desired uniform distribution) depends on the quality of the underlying source of randomness, such as a pseudorandom number generator. There are many possible randomness tests for random permutations, such as some of the Diehard tests. A typical example of such a test is to take some permutation statistic for which the distribution is known and test whether the distribution of this statistic on a set of randomly generated permutations closely approximates the true distribution.
See also
- Ewens's sampling formula — a connection with population genetics
- Golomb–Dickman constant
- Perfect shuffle
- Random permutation statistics
- Shuffling algorithms — random sort method, iterative exchange method
External links
- Random permutation at MathWorld
- Random permutation generation -- detailed and practical explanation of Knuth shuffle algorithm and its variants for generating k-permutations (permutations of k elements chosen from a list) and k-subsets (generating a subset of the elements in the list without replacement) with pseudocode