本文整理汇总了Java中cern.jet.random.Uniform.nextDoubleFromTo方法的典型用法代码示例。如果您正苦于以下问题:Java Uniform.nextDoubleFromTo方法的具体用法?Java Uniform.nextDoubleFromTo怎么用?Java Uniform.nextDoubleFromTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.jet.random.Uniform
的用法示例。
在下文中一共展示了Uniform.nextDoubleFromTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPCA1
import cern.jet.random.Uniform; //导入方法依赖的package包/类
/**
* Generate some random 2d gaussian data with high variance
* in one dimension with a random rotation and check that the pca
* removes the rotation
*/
@Test
public void testPCA1() {
Uniform u = new Uniform(mt);
double stdx = 10;
double stdy = 1;
for (int i=0; i<10; i++) {
double rotation = u.nextDoubleFromTo(0, Math.PI);
Matrix m = makeData2d(1000, stdx, stdy, rotation);
pca.learnBasis(m);
assertTrue(
Math.abs(Math.cos(rotation) - pca.basis.get(0, 0)) < 0.1 ||
Math.abs(Math.cos(rotation - Math.PI) - pca.basis.get(0, 0)) < 0.1
);
Matrix projected = pca.project(m);
float [] xs = new float[projected.getRowDimension()];
float [] ys = new float[projected.getRowDimension()];
for (int j=0; j<projected.getRowDimension(); j++) {
xs[j] = (float) projected.get(j, 0);
ys[j] = (float) projected.get(j, 1);
}
assertEquals(FloatArrayStatsUtils.std(xs), stdx, 1.0);
assertEquals(FloatArrayStatsUtils.std(ys), stdy, 1.0);
}
}
示例2: doRandomTest
import cern.jet.random.Uniform; //导入方法依赖的package包/类
protected void doRandomTest(Uniform rnd) {
PointList pl = new PointList(
new Point2dImpl(-1,-1), new Point2dImpl(1,-1), new Point2dImpl(1,1), new Point2dImpl(-1,1)
);
double tx = rnd.nextDoubleFromTo(-100, 100);
double ty = rnd.nextDoubleFromTo(-100, 100);
double r = rnd.nextDoubleFromTo(-Math.PI, Math.PI);
double s = rnd.nextDoubleFromTo(0, 10);
Matrix tf = TransformUtilities.translateMatrix(tx, ty).times(TransformUtilities.scaleMatrix(s, s)).times(TransformUtilities.rotationMatrix(r));
PointList pl2 = pl.transform(tf);
float odist = ProcrustesAnalysis.computeProcrustesDistance(pl, pl2);
ProcrustesAnalysis pa = new ProcrustesAnalysis(pl);
Matrix patf = pa.align(pl2);
assertTrue(odist >= ProcrustesAnalysis.computeProcrustesDistance(pl, pl2));
for (int i=0; i<pl.points.size(); i++) {
assertEquals(pl.points.get(i).getX(), pl2.points.get(i).getX(), 0.0001);
assertEquals(pl.points.get(i).getY(), pl2.points.get(i).getY(), 0.0001);
}
Matrix tfInv = tf.inverse();
for (int i=0; i<3; i++) {
assertArrayEquals(tfInv.getArray()[i], patf.getArray()[i], 0.0001);
}
}
示例3: getRandomDoubleArray
import cern.jet.random.Uniform; //导入方法依赖的package包/类
/**
* Returns a two dimensional array of pseudorandom, uniformly
* distributed double values between min (inclusive) and
* max (exclusive), drawn from this random number generator's sequence.
* The generator is seeded with the time at which the method is called.
*
* @see cern.jet.random.Uniform
*
* @param rows number of rows
* @param cols number of cols
* @param min minimum value
* @param max maximum value
* @return 2d array of random doubles
*/
public static double [][] getRandomDoubleArray(int rows, int cols, double min, double max) {
Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
double [][] data = new double[rows][cols];
for (int r=0; r<rows; r++)
for (int c=0; c<cols; c++)
data[r][c] = rnd.nextDoubleFromTo(min, max);
return data;
}