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:50 UTC

[commons-rng] branch master updated (e34eb81 -> 819e121)

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

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


    from e34eb81  Renamed JSF generators to JenkinsSmallFast.
     new fc12fde  Changed user guide sampler examples to use factory constructors
     new a106d3d  Added JumpableUniformRandomProvider to the user guide.
     new f9c5c12  Added ListSampler to the user guide.
     new 63483e7  Added SharedStateSampler to the user guide.
     new 819e121  Add LongJumpable and Jumpable interfaces to user guide library layout.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/site/apt/userguide/rng.apt | 73 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 69 insertions(+), 4 deletions(-)


[commons-rng] 01/05: Changed user guide sampler examples to use factory constructors

Posted by ah...@apache.org.
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 fc12fdebfa9f60bfaf6e99a232dccb4c8cccf57a
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Sep 20 16:36:40 2019 +0100

    Changed user guide sampler examples to use factory constructors
---
 src/site/apt/userguide/rng.apt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt
index 1b018f6..5b2589a 100644
--- a/src/site/apt/userguide/rng.apt
+++ b/src/site/apt/userguide/rng.apt
@@ -311,8 +311,8 @@ import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
 import org.apache.commons.rng.sampling.distribution.GaussianSampler;
 import org.apache.commons.rng.sampling.distribution.MarsagliaNormalizedGaussianSampler;
 
-ContinuousSampler sampler = new GaussianSampler(new MarsagliaNormalizedGaussianSampler(RandomSource.create(RandomSource.MT_64)),
-                                                45.6, 2.3);
+ContinuousSampler sampler = GaussianSampler.of(MarsagliaNormalizedGaussianSampler.of(RandomSource.create(RandomSource.MT_64)),
+                                               45.6, 2.3);
 double random = sampler.sample();
 +--------------------------+
 
@@ -320,8 +320,8 @@ double random = sampler.sample();
 import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
 import org.apache.commons.rng.sampling.distribution.RejectionInversionZipfSampler;
 
-DiscreteSampler sampler = new RejectionInversionZipfSampler(RandomSource.create(RandomSource.ISAAC),
-                                                            5, 1.2);
+DiscreteSampler sampler = RejectionInversionZipfSampler.of(RandomSource.create(RandomSource.ISAAC),
+                                                           5, 1.2);
 int random = sampler.sample();
 +--------------------------+
 


[commons-rng] 02/05: Added JumpableUniformRandomProvider to the user guide.

Posted by ah...@apache.org.
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 a106d3dcb77e3d954ce744144c063a45b5fb095a
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Sep 20 16:53:39 2019 +0100

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

diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt
index 5b2589a..622c2ce 100644
--- a/src/site/apt/userguide/rng.apt
+++ b/src/site/apt/userguide/rng.apt
@@ -302,6 +302,29 @@ RestorableUniformRandomProvider rngNew = RandomSource.create(source); // New RNG
 rngNew.restoreState(stateNew);
 +--------------------------+
 
+  * The <<<JumpableUniformRandomProvider>>> interface allows creation of a copy of the generator and
+    advances the state of the current generator a large number of steps in a single jump. This can
+    be used to create a set of generators that will not overlap in their output sequence for the
+    length of the jump for use in parallel computations.
+
++--------------------------+
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.JumpableUniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+
+RandomSource source = RandomSource.XO_RO_SHI_RO_128_SS; // Known to be jumpable.
+
+JumpableUniformRandomProvider master = (JumpableUniformRandomProvider) RandomSource.create(source);
+
+// For use in parallel
+UniformRandomProvider[] rngs = new UniformRandomProvider[10];
+for (int i = 0; i < rngs.length; i++) {
+    rngs[i] = master.jump();
+}
++--------------------------+
+
+    In the above example, the source is known to implement the <<<JumpableUniformRandomProvider>>> interface.
+    Not all generators support this functionality.
 
   * Generation of {{{./dist_density_approx.html}random deviates}} for various
     {{{../commons-rng-sampling/apidocs/org/apache/commons/rng/sampling/distribution/package-summary.html}distributions}}.


[commons-rng] 05/05: Add LongJumpable and Jumpable interfaces to user guide library layout.

Posted by ah...@apache.org.
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 819e121487db2f88f142b251875fe1a15708b479
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Sep 20 17:18:10 2019 +0100

    Add LongJumpable and Jumpable interfaces to user guide library layout.
---
 src/site/apt/userguide/rng.apt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt
index 2a8e347..c330c1e 100644
--- a/src/site/apt/userguide/rng.apt
+++ b/src/site/apt/userguide/rng.apt
@@ -429,6 +429,9 @@ ListSampler.shuffle(rng, list)
   * Interfaces <<<RestorableUniformRandomProvider>>> and <<<RandomProviderState>>>
     provide the "save/restore" API.
 
+  * Interfaces <<<JumpableUniformRandomProvider>>> and <<<LongJumpableUniformRandomProvider>>>
+    provide the "copy and jump" API for parallel computations.
+
   []
 
 


[commons-rng] 03/05: Added ListSampler to the user guide.

Posted by ah...@apache.org.
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 f9c5c12919d62e948aff925837af9ec037639e87
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Sep 20 17:03:32 2019 +0100

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

diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt
index 622c2ce..5f43561 100644
--- a/src/site/apt/userguide/rng.apt
+++ b/src/site/apt/userguide/rng.apt
@@ -376,6 +376,24 @@ CollectionSampler<String> sampler = new CollectionSampler<String>(RandomSource.c
 String word = sampler.sample();
 +--------------------------+
 
++--------------------------+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ListSampler;
+
+List<String> list = Arrays.asList("Apache", "Commons", "RNG");
+
+UniformRandomProvider rng = RandomSource.create(RandomSource.PCG_XSH_RS_32);
+
+// Get 2 random items
+int k = 2;
+List<String> sample = ListSampler.sample(rng, list, k);
+
+// Shuffle the list
+ListSampler.shuffle(rng, list)
++--------------------------+
+
   []
 
 


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

Posted by ah...@apache.org.
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.