You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/05/26 17:59:04 UTC
svn commit: r1486422 - in /commons/proper/math/trunk/src: changes/changes.xml
test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java
Author: tn
Date: Sun May 26 15:59:03 2013
New Revision: 1486422
URL: http://svn.apache.org/r1486422
Log:
[MATH-977] Completed HaltonSequence generator, adding test.
Added:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java (with props)
Modified:
commons/proper/math/trunk/src/changes/changes.xml
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1486422&r1=1486421&r2=1486422&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Sun May 26 15:59:03 2013
@@ -51,6 +51,9 @@ If the output is not quite correct, chec
</properties>
<body>
<release version="x.y" date="TBD" description="TBD">
+ <action dev="tn" type="add" issue="MATH-977">
+ Added low-discrepancy random generator "HaltonSequenceGenerator".
+ </action>
<action dev="tn" type="add" issue="MATH-826" due-to="Sam Halliday">
Added low-discrepancy random generator "SobolSequenceGenerator".
</action>
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java?rev=1486422&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java Sun May 26 15:59:03 2013
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math3.random;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.math3.exception.DimensionMismatchException;
+import org.apache.commons.math3.exception.NullArgumentException;
+import org.apache.commons.math3.exception.OutOfRangeException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HaltonSequenceGeneratorTest {
+
+ private double[][] referenceValues = {
+ { 0.0, 0.0, 0.0 },
+ { 0.5, 0.6667, 0.6 },
+ { 0.25, 0.3333, 0.2 },
+ { 0.75, 0.2223, 0.8 },
+ { 0.125, 0.8888, 0.4 },
+ { 0.625, 0.5555, 0.12 },
+ { 0.375, 0.1111, 0.72 },
+ { 0.875, 0.7777, 0.32 },
+ { 0.0625, 0.4444, 0.92 },
+ { 0.5625, 0.0740, 0.52 }
+ };
+
+ private double[][] referenceValuesUnscrambled = {
+ { 0.0, 0.0 },
+ { 0.5, 0.3333 },
+ { 0.25, 0.6666 },
+ { 0.75, 0.1111 },
+ { 0.125, 0.4444 },
+ { 0.625, 0.7777 },
+ { 0.375, 0.2222 },
+ { 0.875, 0.5555 },
+ { 0.0625, 0.8888 },
+ { 0.5625, 0.0370 }
+ };
+
+ private HaltonSequenceGenerator generator;
+
+ @Before
+ public void setUp() {
+ generator = new HaltonSequenceGenerator(3);
+ }
+
+ @Test
+ public void test3DReference() {
+ for (int i = 0; i < referenceValues.length; i++) {
+ double[] result = generator.nextVector();
+ assertArrayEquals(referenceValues[i], result, 1e-3);
+ assertEquals(i + 1, generator.getNextIndex());
+ }
+ }
+
+ @Test
+ public void test2DUnscrambledReference() {
+ generator = new HaltonSequenceGenerator(2, new int[] {2, 3}, null);
+ for (int i = 0; i < referenceValuesUnscrambled.length; i++) {
+ double[] result = generator.nextVector();
+ assertArrayEquals(referenceValuesUnscrambled[i], result, 1e-3);
+ assertEquals(i + 1, generator.getNextIndex());
+ }
+ }
+
+ @Test
+ public void testConstructor() {
+ try {
+ new HaltonSequenceGenerator(0);
+ fail();
+ } catch (OutOfRangeException e) {
+ // expected
+ }
+
+ try {
+ new HaltonSequenceGenerator(41);
+ fail();
+ } catch (OutOfRangeException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testConstructor2() throws Exception{
+ try {
+ new HaltonSequenceGenerator(2, new int[] { 1 }, null);
+ fail();
+ } catch (OutOfRangeException e) {
+ // expected
+ }
+
+ try {
+ new HaltonSequenceGenerator(2, null, null);
+ fail();
+ } catch (NullArgumentException e) {
+ // expected
+ }
+
+ try {
+ new HaltonSequenceGenerator(2, new int[] { 1, 1 }, new int[] { 1 });
+ fail();
+ } catch (DimensionMismatchException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testSkip() {
+ double[] result = generator.skipTo(5);
+ assertArrayEquals(referenceValues[5], result, 1e-3);
+ assertEquals(6, generator.getNextIndex());
+
+ for (int i = 6; i < referenceValues.length; i++) {
+ result = generator.nextVector();
+ assertArrayEquals(referenceValues[i], result, 1e-3);
+ assertEquals(i + 1, generator.getNextIndex());
+ }
+ }
+
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java
------------------------------------------------------------------------------
svn:keywords = Id Revision HeadURL
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/random/HaltonSequenceGeneratorTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain