You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex D Herbert (JIRA)" <ji...@apache.org> on 2019/05/09 21:14:00 UTC
[jira] [Created] (RNG-102) SharedStateSampler interface
Alex D Herbert created RNG-102:
----------------------------------
Summary: SharedStateSampler interface
Key: RNG-102
URL: https://issues.apache.org/jira/browse/RNG-102
Project: Commons RNG
Issue Type: New Feature
Components: sampling
Affects Versions: 1.3
Reporter: Alex D Herbert
Nearly all the samplers in the library compute data during construction that is immutable. In most cases the data is small in size but could be large (e.g. a discrete probability sampler with a stored cumulative probability table). To build another sampler with the same parameters will have to re-compute this state. The only difference between the two samplers is the random generator.
Reusing this state to create a duplicate generator is an advantage for lower construction cost and will save memory. This can be done using a generic interface:
{code:java}
public interface SharedStateSampler<R> {
R withUniformRandomProvider(UniformRandomProvider rng);
}
{code}
R is expected to be a sampler of some type, e.g.
{code:java}
public class CollectionSampler<T>
implements SharedStateSampler<CollectionSampler<T>> {
// ...
public CollectionSampler<T>
withUniformRandomProvider(UniformRandomProvider rng) {
return /* new instance that shares the immutable state */;
}
}
{code}
An example application would be to create a single sampler to be duplicated across threads for parallel computation using a unique RNG per thread.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)