Fast unique random permutations

Versione 1.2.0.0 (2,82 KB) da Michal
Fast random sample (without replacement) from unique permutations of an integer vector
28 download
Aggiornato 24 mag 2018

Visualizza la licenza

%uniqperms: unique permutations of an input vector x
% Usage: nPerms = uniqperms(x)
% [nPerms pInds] = uniqperms(x)
% [nPerms pInds Perms] = uniqperms(x)
% [nPerms pInds] = uniqperms(x, k)
% [nPerms pInds Perms] = uniqperms(x, k)
% [nPerms pInds Perms] = uniqperms(x,k,first)
%
% Determines number of unique permutations (nPerms) for vector x.
% Optionally, all permutations indices (pInds) are returned. If requested,
% permutations of the original input (Perms) are also returned.
%
% If k < nPerms, a random (but still unique) subset of k of permutations is
% returned.
%
% If k >= nPerms, a random (but still unique) subset of nPerms of permutations is
% returned. The original/identity permutation will be the first of these.
%
% Row or column vector x results in Perms being a [k length(x)] array,
% consistent with MATLAB's built-in perms. pInds is also [k length(x)].
%
% If first = true then the original/identity permutation will be the first of these.
% (first = false ... opposite case)
%
% Examples:
% uniqperms(1:7), factorial(7) % verify counts in simple case,
% uniqperms([1 1 2]), factorial(3)/prod(factorial([2 1])) % verify counts in nonunique case,
% [nPerms,pInds Perms] = uniqperms([1 1 1 2 2], 3))
% nPerms =
% 10
%
% pInds =
%
% 1 3 2 5 4
% 1 3 5 2 4
% 1 3 5 4 2
%
% Perms =
%
% 1 1 1 2 2
% 1 1 2 1 2
% 1 1 2 2 1
%
% Copyright 2018 Michal Kvasnicka
% UJV Rez, a.s.

Cita come

Michal (2024). Fast unique random permutations (https://www.mathworks.com/matlabcentral/fileexchange/67452-fast-unique-random-permutations), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2014b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Random Number Generation in Help Center e MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.2.0.0

Fix help description
...
Add examples to the help

1.0.0.0

fix summary typo