View source: R/partitionsSample.R
| partitionsSample | R Documentation | 
Generate a specific (lexicographically) or random sample of partitions/compositions of a number.
 Produce results in parallel using the Parallel or nThreads arguments.
GMP support allows for exploration of cases where the number of partitions/compositions is large.
partitionsSample(v, m = NULL, ...)
compositionsSample(v, m = NULL, ...)
## Default S3 method:
partitionsSample(
    v, m = NULL, repetition = FALSE, freqs = NULL, target = NULL,
    n = NULL, sampleVec = NULL, seed = NULL,
    nThreads = NULL, namedSample = FALSE, ...
)
## Default S3 method:
compositionsSample(
    v, m = NULL, repetition = FALSE, freqs = NULL, target = NULL,
    weak = FALSE, n = NULL, sampleVec = NULL, seed = NULL,
    nThreads = NULL, namedSample = FALSE, ...
)
## S3 method for class 'table'
partitionsSample(
    v, m = NULL, target = NULL, n = NULL,
    sampleVec = NULL, seed = NULL, nThreads = NULL, namedSample = FALSE, ...
)
## S3 method for class 'table'
compositionsSample(
    v, m = NULL, target = NULL, weak = FALSE, n = NULL,
    sampleVec = NULL, seed = NULL, nThreads = NULL, namedSample = FALSE, ...
)
| v | Source vector. If  | 
| m | Width of the partition. If  | 
| ... | Further arguments passed to methods. | 
| repetition | Logical value indicating whether partitions/compositions should be with or without repetition. The default is  | 
| freqs | A vector of frequencies used for producing all partitions of a multiset of  | 
| target | Number to be partitioned. If  | 
| weak | (Compositions only) Logical flag indicating whether to allow terms of the sequence to be zero. | 
| n | Number of partitions/compositions to return. The default is  | 
| sampleVec | A vector of numbers representing the lexicographical partitions/compositions to return. Accepts vectors of class  | 
| seed | Random seed initialization. The default is  | 
| nThreads | Specific number of threads to be used. The default is  | 
| namedSample | Logical flag. If  | 
These algorithms rely on efficiently generating the n^{th} lexicographical partition. This is the process of unranking.
A matrix is returned with each row containing a vector of length m.
partitionsSample is not available for the following cases:
 With standard multisets. If zero is the only element with a non-trivial multiplicity, sampling is allowed (e.g. partitionsSample(0:100, freqs = c(100, rep(1, 100)), n = 2))
 If the source vector is not isomorphic to 1:length(v) (e.g. v = c(1, 4, 6, 7, 8)).
n and sampleVec cannot both be NULL.
Joseph Wood
partitionsSample(100, 10, n = 5)
partitionsSample(100, 10, seed = 42, n = 5, target = 200)
## retrieve specific results (lexicographically)
partitionsCount(100, 10, TRUE, target = 500)
## [1] 175591757896
partitionsSample(100, 10, TRUE, target = 500,
                 sampleVec = c(1, 1000, 175591757896))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.