本文整理汇总了Java中org.apache.commons.math.random.RandomData类的典型用法代码示例。如果您正苦于以下问题:Java RandomData类的具体用法?Java RandomData怎么用?Java RandomData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RandomData类属于org.apache.commons.math.random包,在下文中一共展示了RandomData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNormalizer
import org.apache.commons.math.random.RandomData; //导入依赖的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);
}
示例2: testWithInitialCapacity
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
@Test
public void testWithInitialCapacity() {
ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements());
RandomData randomData = new RandomDataImpl();
int iterations = randomData.nextInt(100, 1000);
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() );
}
示例3: testNextInt
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
/**
* Run nextInt range for 10000. Time:9, Heap:0.0M
0: 44.8%
1: 31.42%
2: 16.7%
3: 5.54%
4: 1.31%
5: 0.2%
6: 0.03%
7: 0.0%
8: 0.0%
9: 0.0%
* @throws Exception
*/
@Test
public void testNextInt() throws Exception {
int max = 10000;
final int[] ratio1 = new int[10];
final RandomData commonRandom = new RandomDataImpl();
TestUtil.doPerform(new Runnable() {
public void run() {
int r = MathUtil.nextGaussionInt(0, 10);
ratio1[r]++;
}
}, "nextInt range", max);
printRatio(ratio1, max);
}
示例4: testNextGaussianDouble
import org.apache.commons.math.random.RandomData; //导入依赖的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]+"]");
}
示例5: testGetSortedValues
import org.apache.commons.math.random.RandomData; //导入依赖的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);
}
}
示例6: generateUserGUIDs
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
private List<String> generateUserGUIDs(final RandomData random, final int totalGUIDs, final int totalUniqueFirstParts) {
Set<String> firstParts = new HashSet<>(totalUniqueFirstParts, 1);
while (firstParts.size() < totalUniqueFirstParts) {
firstParts.add(randomHexString(random));
}
List<String> firstPartsList = new ArrayList<>(firstParts);
Set<String> guids = new HashSet<>(totalGUIDs, 1);
while (guids.size() < totalGUIDs) {
guids.add(firstPartsList.get(random.nextInt(0, totalUniqueFirstParts - 1)) + randomHexString(random));
}
return new ArrayList<>(guids);
}
示例7: generateSample
import org.apache.commons.math.random.RandomData; //导入依赖的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;
}
示例8: generatePartition
import org.apache.commons.math.random.RandomData; //导入依赖的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;
}
}
示例9: generateSample
import org.apache.commons.math.random.RandomData; //导入依赖的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;
}
示例10: generatePartition
import org.apache.commons.math.random.RandomData; //导入依赖的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;
}
}
示例11: testNextIntQ2
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
@Test
public void testNextIntQ2() throws Exception {
int loop = 10000;
final int min = 10;
final int max = 100;
final double q = 5;
final HashMap<Integer, Integer> countMap = new
HashMap<Integer, Integer>();
final RandomData commonRandom = new RandomDataImpl();
TestUtil.doPerform(new Runnable() {
public void run() {
int r = MathUtil.nextGaussionInt(min, max, q);
Integer count = countMap.get(r);
if ( count == null ) {
countMap.put(r, 1);
} else {
countMap.put(r, count+1);
}
}
}, "nextInt range 3.0", loop);
ArrayList<Integer> list = new ArrayList<Integer>(countMap.keySet());
Collections.sort(list);
for ( Integer in : list ) {
Integer value = countMap.get(in);
System.out.println(in+ "->"+value+" : " + (value*100.0/loop) + "%");
assertTrue(in.intValue() >= min);
}
}
示例12: RepeatingLSH
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
public RepeatingLSH(List<LSH> lshList) throws MathException
{
super(lshList.get(0).getDim(), lshList.get(0).getRandomGenerator());
this.lshList = lshList;
RandomGenerator rg = lshList.get(0).getRandomGenerator();
RandomData rd = new RandomDataImpl(rg);
/*
* Compute a random vector of lshList.size() with each component taken from U(0,10)
*/
randomVec = new ArrayRealVector(lshList.size());
for(int i = 0; i < randomVec.getDimension();++i)
{
randomVec.setEntry(i, rd.nextUniform(0, 10.0));
}
}
示例13: testSparseVectors
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
@Test
public void testSparseVectors() throws IOException, ParseException
{
RandomGenerator rg = new JDKRandomGenerator();
rg.setSeed(0);
RandomData rd = new RandomDataImpl(rg);
int n = 20;
List<RealVector> vectors = LSHTest.getVectors(rd, 1000, n);
PigTest test = createPigTestFromString(sparseVectorTest);
writeLinesToFile("input", getSparseLines(vectors));
test.runScript();
List<Tuple> neighbors = this.getLinesForAlias(test, "PTS");
Assert.assertEquals(neighbors.size(), n);
int idx = 0;
for(Tuple t : neighbors)
{
Assert.assertTrue(t.get(0) instanceof DataBag);
Assert.assertEquals(t.size(), 1);
RealVector interpreted = DataTypeUtil.INSTANCE.convert(t, 3);
RealVector original = vectors.get(idx);
Assert.assertEquals(original.getDimension(), interpreted.getDimension());
for(int i = 0;i < interpreted.getDimension();++i)
{
double originalField = original.getEntry(i);
double interpretedField = interpreted.getEntry(i);
Assert.assertTrue(Math.abs(originalField - interpretedField) < 1e-5);
}
idx++;
}
}
示例14: testL1UDFSparse
import org.apache.commons.math.random.RandomData; //导入依赖的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);
}
示例15: testL1UDF
import org.apache.commons.math.random.RandomData; //导入依赖的package包/类
@Test
public void testL1UDF() 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(l1Test);
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 L1.distance(v1, v2);
}
};
verifyPoints(neighbors, d, 1000);
}