Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E56D89FA3 for ; Thu, 8 Mar 2012 09:35:26 +0000 (UTC) Received: (qmail 87253 invoked by uid 500); 8 Mar 2012 09:35:26 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 86945 invoked by uid 500); 8 Mar 2012 09:35:24 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 86802 invoked by uid 99); 8 Mar 2012 09:35:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Mar 2012 09:35:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Mar 2012 09:35:20 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 666A8F699 for ; Thu, 8 Mar 2012 09:34:59 +0000 (UTC) Date: Thu, 8 Mar 2012 09:34:59 +0000 (UTC) From: "Alex Bertram (Commented) (JIRA)" To: issues@commons.apache.org Message-ID: <1678744776.38538.1331199299421.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1157671132.32254.1331111338038.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (MATH-764) New sample() API should accept RandomGenerator as parameter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MATH-764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13225109#comment-13225109 ] Alex Bertram commented on MATH-764: ----------------------------------- Hi Gilles, Specifying the RandomGenerator is pretty important for my use case: I am working on the renjin project, which is an implementation of the R language on the JVM that relies heavily on Commons Math. We need to be able to generate random values for specific distributions using the random number generator of the type and seed specified by the user. What i'm proposing would actually promote immutability and functional-style programming: The specific distribution classes would *not* implement Sampler, themselves, they would return a functor that implements Sampler. Here's a few examples {code:java} interface RealDistribution { /** * Factory method that returns a Sampler function object for this * distribution and the given {@code RandomGenerator} */ RealSampler createSampler(RandomGenerator rng); } interface RealSampler { double sample(); double[] sample(int sampleSize); } abstract class AbstractRealSampler implements RealSampler { RandomDataImpl randomData; AbstractRealSampler(RandomGenerator rng) { super(); this.randomData = new RandomDataImpl(rng); } double[] sample(int sampleSize) { // loop impl } void reseedRandomGenerator(long seed) { randomData.reSeed(); } } class AbstractRealDistribution implements RealDistribution { RealSampler createSampler(RandomGenerator rng) { return new AbstractRealSampler(rng) { public double sample() { return randomData.nextInversionDeviate(AbstractRealDistribution.this); } }; } final RealSampler createSampler() { return createSampler(DefaultRandomGeneratorFactory.create()); } } class ExponentialDistributionImpl extends AbstractRealDistribution { RealSampler createSampler(RandomGenerator rng) { return new AbstractSampler(rng) { double sample() { return randomData.nextExponential(); } } } } {code} > 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 > 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