Fast unique random permutations

バージョン 1.2.0.0 (2.82 KB) 作成者: Michal
Fast random sample (without replacement) from unique permutations of an integer vector
ダウンロード: 28
更新 2018/5/24

ライセンスの表示

%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.

引用

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

MATLAB リリースの互換性
作成: R2014b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.2.0.0

Fix help description
...
Add examples to the help

1.0.0.0

fix summary typo