commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Bertram (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-764) New sample() API should accept RandomGenerator as parameter
Date Wed, 30 May 2012 12:16:24 GMT

    [ https://issues.apache.org/jira/browse/MATH-764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13285615#comment-13285615
] 

Alex Bertram commented on MATH-764:
-----------------------------------

I think since the sample() method is already part of the 3.0 API, it might be better to just
leave it alone as a convenience method and have a separate set of interfaces/classes that
sample from distributions: e.g. InversionSampler which would accept a Distribution and RandomData
arguments to the constructor. I think that adding a RandomData instance as additional state
to the Distribution classes would really add a new "responsibility" to the Distribution classes
that muddies the API. 

Basically for the Renjin project we need to solve two concrete problems:

1) Given an arbitrary Distribution and an arbitrary random number generator provided by the
R developer, create a new Sampler object that can sample values from the distribution. This
makes it possible to cleanly implement R's large number of distribution-related built-in functions.

2) Provide specialized Sampler objects for certain distributions in order to be consistent
with the original C-R implementation. While InversionSampler would be used most of the time,
we have ported some of the specialized sampling algorithms for some of the more exotic distributions
and would like to hide them behind a Sampler interface. Hence the desire to cleanly separate
the Distribution, RandomData, and Sampler classes: a given distribution can have multiple
sampling implementations, which each need to be paramaterized by the random number generator.

We can of course add this hierarchy to Renjin core and leave commons math alone, but I really
like the idea of pushing as much of the pure math stuff into Commons Math and keeping Renjin
focused on the R-language interpretration.

I will draft and post a new patch shortly.

Alex


                
> New sample() API should accept RandomGenerator as parameter
> -----------------------------------------------------------
>
>                 Key: MATH-764
>                 URL: https://issues.apache.org/jira/browse/MATH-764
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.0
>            Reporter: Alex Bertram
>         Attachments: sampler-refactor.diff
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> This may come to late as I know the 3.0 release is nearing completion, but I had some
concerns about the new sample() method on the math3 RealDistribution interface. 
> Specifically, there doesn't seem to be a way to supply a random generator to the sampler.
Perhaps it would be better to have a factory method on the RealDistribution interface that
accepted a RandomGenerator and returns an instance of some new interface, Sampler, which contains
the sample() methods. 
> That is:
> interface RealDistribution {
>     Sampler createSampler(RandomGenerator generator);
>     Sample createSampler(); // uses default RandomGenerator
> }
> interface Sampler {
>     double sample();
>     double[] sample(int sampleSize);
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message