You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/09/20 16:32:54 UTC

[commons-rng] 04/05: Added SharedStateSampler to the user guide.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 63483e7000af4720bdc458b8928b9430a8bcbf82
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Sep 20 17:17:02 2019 +0100

    Added SharedStateSampler to the user guide.
---
 src/site/apt/userguide/rng.apt | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt
index 5f43561..2a8e347 100644
--- a/src/site/apt/userguide/rng.apt
+++ b/src/site/apt/userguide/rng.apt
@@ -348,6 +348,27 @@ DiscreteSampler sampler = RejectionInversionZipfSampler.of(RandomSource.create(R
 int random = sampler.sample();
 +--------------------------+
 
+  * The <<<SharedStateSampler>>> interface allows creation of a copy of the sampler using a new
+    generator. The samplers share only their immutable state and can be used in parallel computations.
+
++--------------------------+
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.SharedStateDiscreteSampler;
+import org.apache.commons.rng.simple.RandomSource;
+
+RandomSource source = RandomSource.PCG_XSH_RR_32;
+
+double[] probabilities = {0.1, 0.2, 0.3, 0.4};
+SharedStateDiscreteSampler sampler1 = MarsagliaTsangWangDiscreteSampler.Enumerated.of(RandomSource.create(source),
+                                                                                      probabilities);
+
+// For use in parallel
+SharedStateDiscreteSampler sampler2 = sampler1.withUniformRandomProvider(RandomSource.create(source));
++--------------------------+
+
+    All samplers support the <<<SharedStateSampler>>> interface.
+
   * {{{../commons-rng-sampling/apidocs/org/apache/commons/rng/sampling/PermutationSampler.html}Permutation}},
     {{{../commons-rng-sampling/apidocs/org/apache/commons/rng/sampling/CollectionSampler.html}sampling from a <<<Collection>>>}}
     and shuffling utilities.