Difference between revisions of "Shuffle"
Line 10: | Line 10: | ||
= Independent Shuffles = | = Independent Shuffles = | ||
− | If ''a'' | + | If ''a'' has two dimension, say I and Run, Shuffle(a, I) shuffles the sample over I independently for each value of Run. Shuffle(a, Run) -- or Shuffle(a), which is equivalent, because it assumes Run by default -- will shuffle each sample independently for each value of I. |
− | + | ||
− | + | Like other distribution functions, you can add an extra dimension using the Over parameter. For example, if B is a sample with no indexes other than Run, | |
+ | Shuffle(B, Over: I) | ||
+ | returns an array of samples indexed by I, where the sample for each value of I is shuffled independently. | ||
If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method: | If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method: |
Revision as of 19:56, 2 April 2008
What's new in Analytica 4.0? >
Function Shuffle(a , i)
Shuffle returns a random reordering (permutation) of the values in array a over index i. If you omit i, by default it shuffles over Run -- i.e. it shuffles a random sample. You can use it generate an independent random sample from an existing probability distribution, a.
Independent Shuffles
If a has two dimension, say I and Run, Shuffle(a, I) shuffles the sample over I independently for each value of Run. Shuffle(a, Run) -- or Shuffle(a), which is equivalent, because it assumes Run by default -- will shuffle each sample independently for each value of I.
Like other distribution functions, you can add an extra dimension using the Over parameter. For example, if B is a sample with no indexes other than Run,
Shuffle(B, Over: I)
returns an array of samples indexed by I, where the sample for each value of I is shuffled independently.
If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method:
A[@I = Shuffle(@I,I)]
This shuffles A over index I, but does not shuffle each slice of A for each value of I.
Examples
To generate a random permutation of the numbers 1..100:
Index I:=1..100; Shuffle(I,I)
Enable comment auto-refresher