public void testHalton() { //("Testing Halton sequences..."); List <double> point; double tolerance = 1.0e-15; // testing "high" dimensionality int dimensionality = (int)SobolRsg.PPMT_MAX_DIM; HaltonRsg rsg = new HaltonRsg(dimensionality, 0, false, false); int points = 100, i, k; for (i = 0; i < points; i++) { point = rsg.nextSequence().value; if (point.Count != dimensionality) { Assert.Fail("Halton sequence generator returns " + " a sequence of wrong dimensionality: " + point.Count + " instead of " + dimensionality) ; } } // testing first and second dimension (van der Corput sequence) double[] vanderCorputSequenceModuloTwo = { // first cycle (zero excluded) 0.50000, // second cycle 0.25000, 0.75000, // third cycle 0.12500, 0.62500, 0.37500, 0.87500, // fourth cycle 0.06250, 0.56250, 0.31250, 0.81250, 0.18750, 0.68750, 0.43750, 0.93750, // fifth cycle 0.03125, 0.53125, 0.28125, 0.78125, 0.15625, 0.65625, 0.40625, 0.90625, 0.09375, 0.59375, 0.34375, 0.84375, 0.21875, 0.71875, 0.46875, 0.96875, }; dimensionality = 1; rsg = new HaltonRsg(dimensionality, 0, false, false); points = (int)(Math.Pow(2.0, 5)) - 1; // five cycles for (i = 0; i < points; i++) { point = rsg.nextSequence().value; double error = Math.Abs(point[0] - vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail(i + 1 + " draw (" + /*QL_FIXED*/ +point[0] + ") in 1-D Halton sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } double[] vanderCorputSequenceModuloThree = { // first cycle (zero excluded) 1.0 / 3, 2.0 / 3, // second cycle 1.0 / 9, 4.0 / 9, 7.0 / 9, 2.0 / 9, 5.0 / 9, 8.0 / 9, // third cycle 1.0 / 27, 10.0 / 27, 19.0 / 27, 4.0 / 27, 13.0 / 27, 22.0 / 27, 7.0 / 27, 16.0 / 27, 25.0 / 27, 2.0 / 27, 11.0 / 27, 20.0 / 27, 5.0 / 27, 14.0 / 27, 23.0 / 27, 8.0 / 27, 17.0 / 27, 26.0 / 27 }; dimensionality = 2; rsg = new HaltonRsg(dimensionality, 0, false, false); points = (int)(Math.Pow(3.0, 3)) - 1; // three cycles of the higher dimension for (i = 0; i < points; i++) { point = rsg.nextSequence().value; double error = Math.Abs(point[0] - vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail("First component of " + i + 1 + " draw (" + /*QL_FIXED*/ +point[0] + ") in 2-D Halton sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } error = Math.Abs(point[1] - vanderCorputSequenceModuloThree[i]); if (error > tolerance) { Assert.Fail("Second component of " + i + 1 + " draw (" + /*QL_FIXED*/ +point[1] + ") in 2-D Halton sequence is not in the " + "van der Corput sequence modulo three: " + "it should have been " + vanderCorputSequenceModuloThree[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } // testing homogeneity properties dimensionality = 33; rsg = new HaltonRsg(dimensionality, 0, false, false); SequenceStatistics stat = new SequenceStatistics(dimensionality); List <double> mean; //, stdev, variance, skewness, kurtosis; k = 0; int j; for (j = 1; j < 5; j++) { // five cycle points = (int)(Math.Pow(2.0, j)) - 1; // base 2 for (; k < points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); double error = Math.Abs(mean[0] - 0.5); if (error > tolerance) { Assert.Fail("First dimension mean (" + /*QL_FIXED*/ +mean[0] + ") at the end of the " + j + 1 + " cycle in Halton sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } // reset generator and gaussianstatistics rsg = new HaltonRsg(dimensionality, 0, false, false); stat.reset(dimensionality); k = 0; for (j = 1; j < 3; j++) { // three cycle points = (int)(Math.Pow(3.0, j)) - 1; // base 3 for (; k < points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); double error = Math.Abs(mean[1] - 0.5); if (error > tolerance) { Assert.Fail("Second dimension mean (" + /*QL_FIXED*/ +mean[1] + ") at the end of the " + j + 1 + " cycle in Halton sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } }
public void testSobol() { //("Testing Sobol sequences up to dimension " // + PPMT_MAX_DIM + "..."); List<double> point; double tolerance = 1.0e-15; // testing max dimensionality int dimensionality =(int)SobolRsg.PPMT_MAX_DIM; ulong seed = 123456; SobolRsg rsg=new SobolRsg(dimensionality, seed); int points = 100, i; for (i=0; i<points; i++) { point = rsg.nextSequence().value; if (point.Count!=dimensionality) { Assert.Fail("Sobol sequence generator returns "+ " a sequence of wrong dimensionality: " + point.Count + " instead of " + dimensionality); } } // testing homogeneity properties dimensionality = 33; seed = 123456; rsg = new SobolRsg(dimensionality, seed); SequenceStatistics stat=new SequenceStatistics(dimensionality); List<double> mean; int k = 0; for (int j=1; j<5; j++) { // five cycle points = (int)(Utils.Pow(2.0, j)-1); // base 2 for (; k<points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); for (i=0; i<dimensionality; i++) { double error = Math.Abs(mean[i]-0.5); if (error > tolerance) { Assert.Fail(i+1 + " dimension: " // + QL_FIXED + "mean (" + mean[i] + ") at the end of the " + j+1 + " cycle in Sobol sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } } // testing first dimension (van der Corput sequence) double[] vanderCorputSequenceModuloTwo= { // first cycle (zero excluded) 0.50000, // second cycle 0.75000, 0.25000, // third cycle 0.37500, 0.87500, 0.62500, 0.12500, // fourth cycle 0.18750, 0.68750, 0.93750, 0.43750, 0.31250, 0.81250, 0.56250, 0.06250, // fifth cycle 0.09375, 0.59375, 0.84375, 0.34375, 0.46875, 0.96875, 0.71875, 0.21875, 0.15625, 0.65625, 0.90625, 0.40625, 0.28125, 0.78125, 0.53125, 0.03125 }; dimensionality = 1; rsg = new SobolRsg(dimensionality); points = (int)(Utils.Pow(2.0, 5))-1; // five cycles for (i=0; i<points; i++) { point = rsg.nextSequence().value; double error =Math.Abs(point[0]-vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail(i+1 + " draw (" //+ QL_FIXED + point[0] + ") in 1-D Sobol sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } }
public void testSobol() { //("Testing Sobol sequences up to dimension " // + PPMT_MAX_DIM + "..."); List <double> point; double tolerance = 1.0e-15; // testing max dimensionality int dimensionality = (int)SobolRsg.PPMT_MAX_DIM; ulong seed = 123456; SobolRsg rsg = new SobolRsg(dimensionality, seed); int points = 100, i; for (i = 0; i < points; i++) { point = rsg.nextSequence().value; if (point.Count != dimensionality) { Assert.Fail("Sobol sequence generator returns " + " a sequence of wrong dimensionality: " + point.Count + " instead of " + dimensionality); } } // testing homogeneity properties dimensionality = 33; seed = 123456; rsg = new SobolRsg(dimensionality, seed); SequenceStatistics stat = new SequenceStatistics(dimensionality); List <double> mean; int k = 0; for (int j = 1; j < 5; j++) // five cycle { points = (int)(Utils.Pow(2.0, j) - 1); // base 2 for (; k < points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); for (i = 0; i < dimensionality; i++) { double error = Math.Abs(mean[i] - 0.5); if (error > tolerance) { Assert.Fail(i + 1 + " dimension: " // + QL_FIXED + "mean (" + mean[i] + ") at the end of the " + j + 1 + " cycle in Sobol sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } } // testing first dimension (van der Corput sequence) double[] vanderCorputSequenceModuloTwo = { // first cycle (zero excluded) 0.50000, // second cycle 0.75000, 0.25000, // third cycle 0.37500, 0.87500, 0.62500, 0.12500, // fourth cycle 0.18750, 0.68750, 0.93750, 0.43750, 0.31250, 0.81250, 0.56250, 0.06250, // fifth cycle 0.09375, 0.59375, 0.84375, 0.34375, 0.46875, 0.96875, 0.71875, 0.21875, 0.15625, 0.65625, 0.90625, 0.40625, 0.28125, 0.78125, 0.53125, 0.03125 }; dimensionality = 1; rsg = new SobolRsg(dimensionality); points = (int)(Utils.Pow(2.0, 5)) - 1; // five cycles for (i = 0; i < points; i++) { point = rsg.nextSequence().value; double error = Math.Abs(point[0] - vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail(i + 1 + " draw (" //+ QL_FIXED + point[0] + ") in 1-D Sobol sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } }
public void testHalton() { //("Testing Halton sequences..."); List<double> point; double tolerance = 1.0e-15; // testing "high" dimensionality int dimensionality = (int)SobolRsg.PPMT_MAX_DIM; HaltonRsg rsg = new HaltonRsg(dimensionality, 0, false, false); int points = 100, i, k; for (i = 0; i < points; i++) { point = rsg.nextSequence().value; if (point.Count != dimensionality) { Assert.Fail("Halton sequence generator returns "+ " a sequence of wrong dimensionality: " + point.Count + " instead of " + dimensionality) ; } } // testing first and second dimension (van der Corput sequence) double[] vanderCorputSequenceModuloTwo = { // first cycle (zero excluded) 0.50000, // second cycle 0.25000, 0.75000, // third cycle 0.12500, 0.62500, 0.37500, 0.87500, // fourth cycle 0.06250, 0.56250, 0.31250, 0.81250, 0.18750, 0.68750, 0.43750, 0.93750, // fifth cycle 0.03125, 0.53125, 0.28125, 0.78125, 0.15625, 0.65625, 0.40625, 0.90625, 0.09375, 0.59375, 0.34375, 0.84375, 0.21875, 0.71875, 0.46875, 0.96875, }; dimensionality = 1; rsg = new HaltonRsg(dimensionality, 0, false, false); points = (int) (Math.Pow(2.0, 5)) - 1; // five cycles for (i = 0; i < points; i++) { point = rsg.nextSequence().value; double error = Math.Abs(point[0] - vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail(i + 1 + " draw (" + /*QL_FIXED*/ + point[0] + ") in 1-D Halton sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } double[] vanderCorputSequenceModuloThree = { // first cycle (zero excluded) 1.0/3, 2.0/3, // second cycle 1.0/9, 4.0/9, 7.0/9, 2.0/9, 5.0/9, 8.0/9, // third cycle 1.0/27, 10.0/27, 19.0/27, 4.0/27, 13.0/27, 22.0/27, 7.0/27, 16.0/27, 25.0/27, 2.0/27, 11.0/27, 20.0/27, 5.0/27, 14.0/27, 23.0/27, 8.0/27, 17.0/27, 26.0/27 }; dimensionality = 2; rsg = new HaltonRsg(dimensionality, 0, false, false); points = (int) (Math.Pow(3.0, 3)) - 1; // three cycles of the higher dimension for (i = 0; i < points; i++) { point = rsg.nextSequence().value; double error = Math.Abs(point[0] - vanderCorputSequenceModuloTwo[i]); if (error > tolerance) { Assert.Fail("First component of " + i + 1 + " draw (" + /*QL_FIXED*/ + point[0] + ") in 2-D Halton sequence is not in the " + "van der Corput sequence modulo two: " + "it should have been " + vanderCorputSequenceModuloTwo[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } error = Math.Abs(point[1] - vanderCorputSequenceModuloThree[i]); if (error > tolerance) { Assert.Fail("Second component of " + i + 1 + " draw (" + /*QL_FIXED*/ + point[1] + ") in 2-D Halton sequence is not in the " + "van der Corput sequence modulo three: " + "it should have been " + vanderCorputSequenceModuloThree[i] //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } // testing homogeneity properties dimensionality = 33; rsg = new HaltonRsg(dimensionality, 0, false, false); SequenceStatistics stat = new SequenceStatistics(dimensionality); List<double> mean; //, stdev, variance, skewness, kurtosis; k = 0; int j; for (j = 1; j < 5; j++) { // five cycle points = (int) (Math.Pow(2.0, j)) - 1; // base 2 for (; k < points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); double error = Math.Abs(mean[0] - 0.5); if (error > tolerance) { Assert.Fail("First dimension mean (" + /*QL_FIXED*/ + mean[0] + ") at the end of the " + j + 1 + " cycle in Halton sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } // reset generator and gaussianstatistics rsg = new HaltonRsg(dimensionality, 0, false, false); stat.reset(dimensionality); k = 0; for (j = 1; j < 3; j++) { // three cycle points = (int) (Math.Pow(3.0, j)) - 1; // base 3 for (; k < points; k++) { point = rsg.nextSequence().value; stat.add(point); } mean = stat.mean(); double error = Math.Abs(mean[1] - 0.5); if (error > tolerance) { Assert.Fail("Second dimension mean (" + /*QL_FIXED*/ + mean[1] + ") at the end of the " + j + 1 + " cycle in Halton sequence is not " + 0.5 //+ QL_SCIENTIFIC + " (error = " + error + ")"); } } }