[
https://issues.apache.org/jira/browse/MATH-1597?focusedWorklogId=621297&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-621297
]
ASF GitHub Bot logged work on MATH-1597:
----------------------------------------
Author: ASF GitHub Bot
Created on: 10/Jul/21 15:39
Start Date: 10/Jul/21 15:39
Worklog Time Spent: 10m
Work Description: amarlearning commented on a change in pull request #190:
URL: https://github.com/apache/commons-math/pull/190#discussion_r667349474
##########
File path:
commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/quasirandom/HaltonSequenceGenerator.java
##########
@@ -151,31 +159,44 @@ public HaltonSequenceGenerator(final int dimension, final
int[] bases, final int
* @param digit the j-th digit
* @return the scrambled digit
*/
- protected int scramble(final int i, final int j, final int b, final int
digit) {
+ protected long scramble(final int i, final int j, final int b, final long
digit) {
return weight != null ? (weight[i] * digit) % b : digit;
}
/**
- * Skip to the i-th point in the Halton sequence.
+ * jump to the i-th point in the Halton sequence.
* <p>
* This operation can be performed in O(1).
*
* @param index the index in the sequence to skip to
- * @return the i-th point in the Halton sequence
- * @throws org.apache.commons.math4.legacy.exception.NotPositiveException
NotPositiveException if index < 0
+ * @return the copy of this sequence
+ * @throws NotPositiveException if index < 0
*/
- public double[] skipTo(final int index) {
+ @Override
+ public LowDiscrepancySequence jump(final long index) throws
NotPositiveException {
+ if(index < 0) {
+ throw new NotPositiveException(index);
+ }
+ HaltonSequenceGenerator copy = this.copy();
+ copy.performJump(index);
+ return copy;
+ }
+
+ /**
+ * Do jump at the index.
+ * @param index
+ */
+ private void performJump(long index) {
count = index;
- return get();
}
/**
- * Returns the index i of the next point in the Halton sequence that will
be returned
- * by calling {@link #get()}.
- *
- * @return the index of the next point
+ * Private constructor avoid side effects.
+ * @return copy of HaltonSequenceGenerator
*/
- public int getNextIndex() {
- return count;
+ private HaltonSequenceGenerator copy() {
+ return new HaltonSequenceGenerator(this);
}
+
+
Review comment:
extra line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 621297)
Time Spent: 2.5h (was: 2h 20m)
> Low-discrepancy sequence
> ------------------------
>
> Key: MATH-1597
> URL: https://issues.apache.org/jira/browse/MATH-1597
> Project: Commons Math
> Issue Type: Sub-task
> Reporter: Gilles Sadowski
> Priority: Minor
> Fix For: 4.0
>
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> Two low-discrepancy sequences are implemented in Commons Math (in package
> {{o.a.c.math4.legacy.random}}:
> * {{SobolSequenceGenerator}}
> * {{HaltonSequenceGenerator}}
> They both provide several methods:
> * {{nextVector()}}
> * {{skipTo(int)}}
> * {{getNextIndex()}}
> of which only the first is part of their common API through the
> {{RandomVectorGenerator}}.
> I propose to create an interface that would better represent the specific
> concept (and avoid the confusion with pseudo-random generators):
> {code}
> public interface LowDiscrepancySequence extends Supplier<double[]> { /* ...
> */}
> {code}
> Thus, instead of class {{SobolSequenceGenerator}} we'd have:
> {code}
> public class SobolSequence implements LowDiscrepancySequence {
> // ...
> }
> {code}
> This functionality could be moved to a new {{o.a.c.m.legacy.quasirandom}}
> package (?).
> Method {{skipTo}} could be replaced with an API similar to Commons RNG
> {{JumpableUniformRandomProvider}} (?).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)