org.apache.commons.math3.distribution.UniformIntegerDistribution Java Examples
The following examples show how to use
org.apache.commons.math3.distribution.UniformIntegerDistribution.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisHashLoadGenerator.java From yb-sample-apps with Apache License 2.0 | 6 votes |
public RedisHashLoadGenerator(String prefix, int numKeys, int numSubKeys, double keyZipfExp, double subkeyZipfExp, int numSubkeysPerWrite, int numSubkeysPerRead) { this.prefix = prefix; this.numKeys = numKeys; this.keyFreqDist = (keyZipfExp > 0 ? new ZipfDistribution(numKeys, keyZipfExp) : new UniformIntegerDistribution(1, numKeys)); printInfoAboutZifpian(numKeys, keyZipfExp, keyZipfExpThreshold); this.numSubKeys = numSubKeys; this.subkeyFreqDist = (subkeyZipfExp > 0 ? new ZipfDistribution(numSubKeys, subkeyZipfExp) : new UniformIntegerDistribution(1, numSubKeys)); printInfoAboutZifpian(numSubKeys, subkeyZipfExp, subkeyZipfExpThreshold); this.numSubkeysPerRead = numSubkeysPerRead; this.numSubkeysPerWrite = numSubkeysPerWrite; int numWrites = numKeys * (int)Math.ceil((double) numSubKeys / numSubkeysPerWrite); // Generates 0 ... (numWrites - 1). this.loadGenerator = new SimpleLoadGenerator(0, numWrites, -1); }
Example #2
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #3
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #4
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #5
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #6
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #7
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testWithInitialCapacity() { ResizableDoubleArray eDA2 = new ResizableDoubleArray(2); Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements()); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 1000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA2.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements()); eDA2.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations + 1 , eDA2.getNumElements() ); }
Example #8
Source File: UtilBenchmark.java From RoaringBitmap with Apache License 2.0 | 6 votes |
static BenchmarkData generate(int param, int howMany, int smallType, int bigType) { IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17), Short.MIN_VALUE, Short.MAX_VALUE); ClusteredDataGenerator cd = new ClusteredDataGenerator(); IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123), SMALLEST_ARRAY, BIGGEST_ARRAY / param); BenchmarkContainer[] smalls = new BenchmarkContainer[howMany]; BenchmarkContainer[] bigs = new BenchmarkContainer[howMany]; for (int i = 0; i < howMany; i++) { int smallSize = p.sample(); int bigSize = smallSize * param; char[] small = smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize); char[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize); smalls[i] = new BenchmarkContainer(small); bigs[i] = new BenchmarkContainer(big); } return new BenchmarkData(smalls, bigs); }
Example #9
Source File: BufferUtilBenchmark.java From RoaringBitmap with Apache License 2.0 | 6 votes |
static BenchmarkData generate(int param, int howMany, int smallType, int bigType) { IntegerDistribution ud = new UniformIntegerDistribution(new Well19937c(param + 17), Short.MIN_VALUE, Short.MAX_VALUE); ClusteredDataGenerator cd = new ClusteredDataGenerator(); IntegerDistribution p = new UniformIntegerDistribution(new Well19937c(param + 123), SMALLEST_ARRAY, BIGGEST_ARRAY / param); BenchmarkContainer[] smalls = new BenchmarkContainer[howMany]; BenchmarkContainer[] bigs = new BenchmarkContainer[howMany]; for (int i = 0; i < howMany; i++) { int smallSize = p.sample(); int bigSize = smallSize * param; char[] small = smallType == 0 ? generateUniform(ud, smallSize) : generateClustered(cd, smallSize); char[] big = bigType == 0 ? generateUniform(ud, bigSize) : generateClustered(cd, bigSize); smalls[i] = new BenchmarkContainer(small); bigs[i] = new BenchmarkContainer(big); } return new BenchmarkData(smalls, bigs); }
Example #10
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #11
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #12
Source File: IntegerParameterSpace.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public String toString() { if (distribution instanceof UniformIntegerDistribution) { return "IntegerParameterSpace(min=" + distribution.getSupportLowerBound() + ",max=" + distribution.getSupportUpperBound() + ")"; } else { return "IntegerParameterSpace(" + distribution + ")"; } }
Example #13
Source File: TestJson.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testParameterSpaceJson() throws Exception { List<ParameterSpace<?>> l = new ArrayList<>(); l.add(new FixedValue<>(1.0)); l.add(new FixedValue<>(1)); l.add(new FixedValue<>("string")); l.add(new ContinuousParameterSpace(-1, 1)); l.add(new ContinuousParameterSpace(new LogNormalDistribution(1, 1))); l.add(new ContinuousParameterSpace(new NormalDistribution(2, 0.01))); l.add(new DiscreteParameterSpace<>(1, 5, 7)); l.add(new DiscreteParameterSpace<>("first", "second", "third")); l.add(new IntegerParameterSpace(0, 10)); l.add(new IntegerParameterSpace(new UniformIntegerDistribution(0, 50))); l.add(new BooleanSpace()); for (ParameterSpace<?> ps : l) { String strJson = jsonMapper.writeValueAsString(ps); String strYaml = yamlMapper.writeValueAsString(ps); ParameterSpace<?> fromJson = jsonMapper.readValue(strJson, ParameterSpace.class); ParameterSpace<?> fromYaml = yamlMapper.readValue(strYaml, ParameterSpace.class); assertEquals(ps, fromJson); assertEquals(ps, fromYaml); } }
Example #14
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #15
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #16
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #17
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #18
Source File: UniformIntegerDistributionEvaluator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Object doWork(Object first, Object second) throws IOException{ if(null == first){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory))); } if(null == second){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory))); } Number lower = (Number)first; Number upper = (Number)second; return new UniformIntegerDistribution(lower.intValue(), upper.intValue()); }
Example #19
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #20
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #21
Source File: HashRangeGrouping.java From storm-solr with Apache License 2.0 | 5 votes |
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { this.targetTasks = targetTasks; int numTasks = targetTasks.size(); if (numTasks % numShards != 0) throw new IllegalArgumentException("Number of tasks ("+numTasks+") should be a multiple of the number of shards ("+numShards+")!"); this.tasksPerShard = numTasks/numShards; this.random = new UniformIntegerDistribution(0, tasksPerShard-1); CompositeIdRouter docRouter = new CompositeIdRouter(); this.ranges = docRouter.partitionRange(numShards, docRouter.fullRange()); }
Example #22
Source File: ShardGrouping.java From storm-solr with Apache License 2.0 | 5 votes |
public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { this.targetTasks = targetTasks; int numTasks = targetTasks.size(); int numShards = initShardInfo(); // setup for doing shard to task mapping if (numTasks % numShards != 0) throw new IllegalArgumentException("Number of tasks ("+numTasks+") should be a multiple of the number of shards ("+numShards+")!"); this.tasksPerShard = numTasks/numShards; this.random = new UniformIntegerDistribution(0, tasksPerShard-1); }
Example #23
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #24
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #25
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample of double values. * Sample size is random, between 10 and 100 and values are * uniformly distributed over [-100, 100]. * * @return array of random double values */ private double[] generateSample() { final IntegerDistribution size = new UniformIntegerDistribution(10, 100); final RealDistribution randomData = new UniformRealDistribution(-100, 100); final int sampleSize = size.sample(); final double[] out = randomData.sample(sampleSize); return out; }
Example #26
Source File: AggregateSummaryStatisticsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a partition of <sample> into up to 5 sequentially selected * subsamples with randomly selected partition points. * * @param sample array to partition * @return rectangular array with rows = subsamples */ private double[][] generatePartition(double[] sample) { final int length = sample.length; final double[][] out = new double[5][]; int cur = 0; // beginning of current partition segment int offset = 0; // end of current partition segment int sampleCount = 0; // number of segments defined for (int i = 0; i < 5; i++) { if (cur == length || offset == length) { break; } final int next; if (i == 4 || cur == length - 1) { next = length - 1; } else { next = (new UniformIntegerDistribution(cur, length - 1)).sample(); } final int subLength = next - cur + 1; out[i] = new double[subLength]; System.arraycopy(sample, offset, out[i], 0, subLength); cur = next + 1; sampleCount++; offset += subLength; } if (sampleCount < 5) { double[][] out2 = new double[sampleCount][]; for (int j = 0; j < sampleCount; j++) { final int curSize = out[j].length; out2[j] = new double[curSize]; System.arraycopy(out[j], 0, out2[j], 0, curSize); } return out2; } else { return out; } }
Example #27
Source File: ChangeFinder2DTest.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public void testSota5D() throws HiveException { final int DIM = 5; final int EXAMPLES = 20001; final Double[] x = new Double[DIM]; final List<Double> xList = Arrays.asList(x); Parameters params = new Parameters(); params.set(LossFunction.logloss); params.r1 = 0.01d; params.k = 10; params.T1 = 10; params.T2 = 10; PrimitiveObjectInspector oi = PrimitiveObjectInspectorFactory.javaDoubleObjectInspector; ListObjectInspector listOI = ObjectInspectorFactory.getStandardListObjectInspector(oi); final ChangeFinder2D cf = new ChangeFinder2D(params, listOI); final double[] outScores = new double[2]; RandomGenerator rng1 = new Well19937c(31L); final UniformIntegerDistribution uniform = new UniformIntegerDistribution(rng1, 0, 10); RandomGenerator rng2 = new Well19937c(41L); final PoissonDistribution poissonEvent = new PoissonDistribution(rng2, 1000.d, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); final StringBuilder buf = new StringBuilder(256); println("# time x0 x1 x2 x3 x4 mean0 mean1 mean2 mean3 mean4 outlier change"); FIN: for (int i = 0; i < EXAMPLES;) { int len = poissonEvent.sample(); double data[][] = new double[DIM][len]; double mean[] = new double[DIM]; double sd[] = new double[DIM]; for (int j = 0; j < DIM; j++) { mean[j] = uniform.sample() * 5.d; sd[j] = uniform.sample() / 10.d * 5.d + 1.d; if (i % 5 == 0) { mean[j] += 50.d; } NormalDistribution normDist = new NormalDistribution(new Well19937c(i + j), mean[j], sd[j]); data[j] = normDist.sample(len); data[j][len / (j + 2) + DIM % (j + 1)] = mean[j] + (j + 4) * sd[j]; } for (int j = 0; j < len; j++) { if (i >= EXAMPLES) { break FIN; } x[0] = data[0][j]; x[1] = data[1][j]; x[2] = data[2][j]; x[3] = data[3][j]; x[4] = data[4][j]; cf.update(xList, outScores); buf.append(i) .append(' ') .append(x[0].doubleValue()) .append(' ') .append(x[1].doubleValue()) .append(' ') .append(x[2].doubleValue()) .append(' ') .append(x[3].doubleValue()) .append(' ') .append(x[4].doubleValue()) .append(' ') .append(mean[0]) .append(' ') .append(mean[1]) .append(' ') .append(mean[2]) .append(' ') .append(mean[3]) .append(' ') .append(mean[4]) .append(' ') .append(outScores[0]) .append(' ') .append(outScores[1]); println(buf.toString()); StringUtils.clear(buf); i++; } } }
Example #28
Source File: UnivariateStatisticAbstractTest.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests consistency of weighted statistic computation. * For statistics that support weighted evaluation, this test case compares * the result of direct computation on an array with repeated values with * a weighted computation on the corresponding (shorter) array with each * value appearing only once but with a weight value equal to its multiplicity * in the repeating array. */ @Test public void testWeightedConsistency() { // See if this statistic computes weighted statistics // If not, skip this test UnivariateStatistic statistic = getUnivariateStatistic(); if (!(statistic instanceof WeightedEvaluation)) { return; } // Create arrays of values and corresponding integral weights // and longer array with values repeated according to the weights final int len = 10; // length of values array final double mu = 0; // mean of test data final double sigma = 5; // std dev of test data double[] values = new double[len]; double[] weights = new double[len]; // Fill weights array with random int values between 1 and 5 int[] intWeights = new int[len]; final IntegerDistribution weightDist = new UniformIntegerDistribution(1, 5); for (int i = 0; i < len; i++) { intWeights[i] = weightDist.sample(); weights[i] = intWeights[i]; } // Fill values array with random data from N(mu, sigma) // and fill valuesList with values from values array with // values[i] repeated weights[i] times, each i final RealDistribution valueDist = new NormalDistribution(mu, sigma); List<Double> valuesList = new ArrayList<Double>(); for (int i = 0; i < len; i++) { double value = valueDist.sample(); values[i] = value; for (int j = 0; j < intWeights[i]; j++) { valuesList.add(new Double(value)); } } // Dump valuesList into repeatedValues array int sumWeights = valuesList.size(); double[] repeatedValues = new double[sumWeights]; for (int i = 0; i < sumWeights; i++) { repeatedValues[i] = valuesList.get(i); } // Compare result of weighted statistic computation with direct computation // on array of repeated values WeightedEvaluation weightedStatistic = (WeightedEvaluation) statistic; TestUtils.assertRelativelyEquals(statistic.evaluate(repeatedValues), weightedStatistic.evaluate(values, weights, 0, values.length), 10E-12); // Check consistency of weighted evaluation methods Assert.assertEquals(weightedStatistic.evaluate(values, weights, 0, values.length), weightedStatistic.evaluate(values, weights), Double.MIN_VALUE); }
Example #29
Source File: RandomDataGenerator.java From astor with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public int nextInt(final int lower, final int upper) throws NumberIsTooLargeException { return new UniformIntegerDistribution(getRandomGenerator(), lower, upper).sample(); }
Example #30
Source File: ResizableDoubleArrayTest.java From astor with GNU General Public License v2.0 | 4 votes |
@Test public void testWithInitialCapacityAndExpansionFactor() { ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0, 3.5); Assert.assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() ); final IntegerDistribution randomData = new UniformIntegerDistribution(100, 3000); final int iterations = randomData.sample(); for( int i = 0; i < iterations; i++) { eDA3.addElement( i ); } Assert.assertEquals("Number of elements should be equal to " + iterations, iterations,eDA3.getNumElements()); eDA3.addElement( 2.0 ); Assert.assertEquals("Number of elements should be equals to " + (iterations +1), iterations +1, eDA3.getNumElements() ); Assert.assertEquals("Expansion factor should equal 3.0", 3.0f, eDA3.getExpansionFactor(), Double.MIN_VALUE); }