skfolio.utils.stats.sample_unique_subsets#
- skfolio.utils.stats.sample_unique_subsets(n, k, n_subsets, random_state=None)[source]#
Generate unique k-element subsets from a universe of size n using combinatorial unranking.
Each subset is drawn without replacement (elements within subset are distinct) and no subset is repeated across draws. Ranks are sampled uniformly without replacement over [0, C(n, k)).
Time complexity: O(n_subsets * k) Space complexity: O(n_subsets * k)
- Parameters:
- nint
Universe size.
- kint
Subset size (0 <= k <= n).
- n_subsetsint
Number of distinct subsets to generate (0 <= n_subsets <= C(n, k)).
- random_stateint, RandomState instance or None, default=None
Seed or random state to ensure reproducibility.
- Returns:
- subsetsndarray of shape (n_subsets, k)
2D integer array of shape (n_subsets, k) where each row is a sorted k-combination.
- Raises:
- ValueError
If any parameters are out of valid ranges.