当前位置: 首页>>代码示例>>Java>>正文


Java RandomDataImpl类代码示例

本文整理汇总了Java中org.apache.commons.math.random.RandomDataImpl的典型用法代码示例。如果您正苦于以下问题:Java RandomDataImpl类的具体用法?Java RandomDataImpl怎么用?Java RandomDataImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RandomDataImpl类属于org.apache.commons.math.random包,在下文中一共展示了RandomDataImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNormalizer

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
public void testNormalizer() {
	RandomData r = new RandomDataImpl();
	int size = 10000;
	short[] test = new short[size];

	for (int i = 0; i < size; i++) {
		test[i] = (short) r.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
	}

	double[] res = FrameUtil.normalize(test);

	double max = Double.MIN_VALUE;
	double min = Double.MAX_VALUE;
	for (int i = 0; i < res.length; i++) {
		max = res[i] > max ? max = res[i] : max;
		min = res[i] < min ? min = res[i] : min;
	}
	assertTrue(max <= 1.0d);
	assertTrue(min >= -1.0d);
}
 
开发者ID:mobilesec,项目名称:auth-client-demo-module-voice,代码行数:21,代码来源:FrameUtilTest.java

示例2: testGcdConsistency

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
public void testGcdConsistency() {
    int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131};
    ArrayList<Integer> primes = new ArrayList<Integer>();
    for (int i = 0; i < primeList.length; i++) {
        primes.add(Integer.valueOf(primeList[i]));
    }
    RandomDataImpl randomData = new RandomDataImpl();
    for (int i = 0; i < 20; i++) {
        Object[] sample = randomData.nextSample(primes, 4);
        int p1 = ((Integer) sample[0]).intValue();
        int p2 = ((Integer) sample[1]).intValue();
        int p3 = ((Integer) sample[2]).intValue();
        int p4 = ((Integer) sample[3]).intValue();
        int i1 = p1 * p2 * p3;
        int i2 = p1 * p2 * p4;
        int gcd = p1 * p2;
        assertEquals(gcd, MathUtils.gcd(i1, i2));
        long l1 = i1;
        long l2 = i2;
        assertEquals(gcd, MathUtils.gcd(l1, l2));
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:MathUtilsTest.java

示例3: testPermutedArrayHash

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * Make sure that permuted arrays do not hash to the same value.
 */
public void testPermutedArrayHash() {
    double[] original = new double[10];
    double[] permuted = new double[10];
    RandomDataImpl random = new RandomDataImpl();

    // Generate 10 distinct random values
    for (int i = 0; i < 10; i++) {
        original[i] = random.nextUniform(i + 0.5, i + 0.75);
    }

    // Generate a random permutation, making sure it is not the identity
    boolean isIdentity = true;
    do {
        int[] permutation = random.nextPermutation(10, 10);
        for (int i = 0; i < 10; i++) {
            if (i != permutation[i]) {
                isIdentity = false;
            }
            permuted[i] = original[permutation[i]];
        }
    } while (isIdentity);

    // Verify that permuted array has different hash
    assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:MathUtilsTest.java

示例4: testPermutedArrayHash

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * Make sure that permuted arrays do not hash to the same value.
 */
public void testPermutedArrayHash() {
    double[] original = new double[10];
    double[] permuted = new double[10];
    RandomDataImpl random = new RandomDataImpl();
    
    // Generate 10 distinct random values
    for (int i = 0; i < 10; i++) {
        original[i] = random.nextUniform(i + 0.5, i + 0.75);
    }
    
    // Generate a random permutation, making sure it is not the identity
    boolean isIdentity = true;
    do {
        int[] permutation = random.nextPermutation(10, 10);
        for (int i = 0; i < 10; i++) {
            if (i != permutation[i]) {
                isIdentity = false;
            }
            permuted[i] = original[permutation[i]];
        }
    } while (isIdentity);
    
    // Verify that permuted array has different hash
    assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:MathUtilsTest.java

示例5: testNextGaussianDouble

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * Run Uniform Random for 100000000. Time:29752, Heap:0.2576065M
 * Normal Distribution [1.9831936257114444E-9, 0.958216890674393]
 * Run Uniform Random for 100000. Time:25, Heap:0.0M
 * 
 * @throws Exception
 */
@Test
public void testNextGaussianDouble() throws Exception {
	int max = 100000;
	
	final RandomData commonRandom = new RandomDataImpl();
	final double[] result = new double[2];
	result[0] = Double.MAX_VALUE;
	result[1] = Double.MIN_NORMAL;
	TestUtil.doPerform(new Runnable() {
		public void run() {
			double r  = MathUtil.nextGaussionDouble();
			if ( result[0]>r ) {
				result[0] = r;
			}
			if ( result[1]<r ) {
				result[1] = r;
			}
		}
	}, "Uniform Random", max);
	
	System.out.println("Normal Distribution ["+result[0]+", "+result[1]+"]");
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:30,代码来源:MathUtilTest.java

示例6: testGetSortedValues

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
public void testGetSortedValues() {
    double[] test1 = {5,4,3,2,1};
    double[] test2 = {5,2,1,3,4,0};
    double[] test3 = {1};
    int[] testi = null;
    double[] test4 = null;
    RandomData rd = new RandomDataImpl();
    tstGetSortedValues(test1);
    tstGetSortedValues(test2);
    tstGetSortedValues(test3);
    for (int i = 0; i < 10; i++) {
        testi = rd.nextPermutation(10,6);
        test4 = new double[6];
        for (int j = 0; j < testi.length; j++) {
            test4[j] = (double) testi[j];
        }
        tstGetSortedValues(test4);
    }
    for (int i = 0; i < 10; i++) {
        testi = rd.nextPermutation(10,5);
        test4 = new double[5];
        for (int j = 0; j < testi.length; j++) {
            test4[j] = (double) testi[j];
        }
        tstGetSortedValues(test4);
    }        
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:28,代码来源:DescriptiveStatisticsAbstractTest.java

示例7: NaturalRanking

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * Create a NaturalRanking with the given TiesStrategy.
 *
 * @param tiesStrategy the TiesStrategy to use
 */
public NaturalRanking(TiesStrategy tiesStrategy) {
    super();
    this.tiesStrategy = tiesStrategy;
    nanStrategy = DEFAULT_NAN_STRATEGY;
    randomData = new RandomDataImpl();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:NaturalRanking.java

示例8: NaturalRanking

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * Create a NaturalRanking with the given NaNStrategy and TiesStrategy.
 *
 * @param nanStrategy NaNStrategy to use
 * @param tiesStrategy TiesStrategy to use
 */
public NaturalRanking(NaNStrategy nanStrategy, TiesStrategy tiesStrategy) {
    super();
    this.nanStrategy = nanStrategy;
    this.tiesStrategy = tiesStrategy;
    randomData = new RandomDataImpl();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:NaturalRanking.java

示例9: generatePartition

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * 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][];
    final RandomData randomData = new RandomDataImpl();
    int cur = 0;
    int offset = 0;
    int sampleCount = 0;
    for (int i = 0; i < 5; i++) {
        if (cur == length || offset == length) {
            break;
        }
        final int next = (i == 4 || cur == length - 1) ? length - 1 : randomData.nextInt(cur, length - 1);
        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;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:AggregateSummaryStatisticsTest.java

示例10: testL2UDF

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
@Test
public void testL2UDF() throws Exception
{
  setMemorySettings();
  RandomGenerator rg = new JDKRandomGenerator();
  rg.setSeed(0);
  RandomData rd = new RandomDataImpl(rg);
  int n = 1000;
  List<RealVector> vectors = LSHTest.getVectors(rd, 1000, n);
  PigTest test = createPigTestFromString(l2Test);
  writeLinesToFile("input", getLines(vectors));
  List<RealVector> queries = LSHTest.getVectors(rd, 1000, 10);
  writeLinesToFile("queries", getLines(queries));
  test.runScript();
  List<Tuple> neighbors = this.getLinesForAlias(test, "NEIGHBOR_CNT");
  Assert.assertEquals( queries.size(), neighbors.size() );
  for(long cnt : getCounts(neighbors))
  {
    Assert.assertTrue(cnt >= 3);
  }
  Distance d = new Distance()
  {

    @Override
    public double distance(RealVector v1, RealVector v2) {
      return L2.distance(v1, v2);
    }
    
  };
  verifyPoints(neighbors, d, 1000);
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:32,代码来源:LSHPigTest.java

示例11: reset

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
public void reset(int dim, double w) throws MathException
{
   RandomDataImpl dataSampler = new RandomDataImpl(rg);
   Sampler sampler = getSampler();      
   this.a = new double[dim];
   this.dim = dim;
   this.w = w;
   for(int i = 0;i < dim;++i)
   {
      a[i] = sampler.sample(dataSampler);
   }
   b = dataSampler.nextUniform(0, w);
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:14,代码来源:AbstractStableDistributionFunction.java

示例12: testL1UDFSparse

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
@Test
public void testL1UDFSparse() throws Exception
{
  
  setMemorySettings();
  RandomGenerator rg = new JDKRandomGenerator();
  rg.setSeed(0);
  RandomData rd = new RandomDataImpl(rg);
  int n = 1000;
  List<RealVector> vectors = LSHTest.getVectors(rd, 1000, n);
  PigTest test = createPigTestFromString(l1SparseTest);
  writeLinesToFile("input", getSparseLines(vectors));
  List<RealVector> queries = LSHTest.getVectors(rd, 1000, 10);
  writeLinesToFile("queries", getSparseLines(queries));
  test.runScript();
  List<Tuple> neighbors = this.getLinesForAlias(test, "NEIGHBOR_CNT");
  Assert.assertEquals( queries.size(), neighbors.size() );
  for(long cnt : getCounts(neighbors))
  {
    Assert.assertTrue(cnt >= 3);
  }
  Distance d = new Distance()
  {

    @Override
    public double distance(RealVector v1, RealVector v2) {
      return L1.distance(v1, v2);
    }
    
  };
  verifyPoints(neighbors, d, 1000);
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:33,代码来源:LSHPigTest.java

示例13: generateSample

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * 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 RandomData randomData = new RandomDataImpl();
    final int sampleSize = randomData.nextInt(10,100);
    double[] out = new double[sampleSize];
    for (int i = 0; i < out.length; i++) {
        out[i] = randomData.nextUniform(-100, 100);
    }
    return out;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:AggregateSummaryStatisticsTest.java

示例14: generatePartition

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * 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][];
    final RandomData randomData = new RandomDataImpl();
    int cur = 0;
    int offset = 0;
    int sampleCount = 0;
    for (int i = 0; i < 5; i++) {
        if (cur == length || offset == length) {
            break;
        }
        final int next = (i == 4 || cur == length - 1) ? length - 1 : randomData.nextInt(cur, length - 1);
        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;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:AggregateSummaryStatisticsTest.java

示例15: generateSample

import org.apache.commons.math.random.RandomDataImpl; //导入依赖的package包/类
/**
 * 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 RandomData randomData = new RandomDataImpl();
    final int sampleSize = randomData.nextInt(10,100);
    double[] out = new double[sampleSize];
    for (int i = 0; i < out.length; i++) {
        out[i] = randomData.nextUniform(-100, 100);
    }
    return out;     
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:AggregateSummaryStatisticsTest.java


注:本文中的org.apache.commons.math.random.RandomDataImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。