List of usage examples for org.apache.commons.math3.random RandomGenerator nextGaussian
double nextGaussian();
double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence. From source file:com.cloudera.oryx.common.random.RandomUtils.java
private static void doRandomUnitVector(float[] vector, RandomGenerator random) { int dimensions = vector.length; double total = 0.0; for (int i = 0; i < dimensions; i++) { double d = random.nextGaussian(); vector[i] = (float) d; total += d * d;/*from w w w .ja v a 2 s . co m*/ } float normalization = (float) FastMath.sqrt(total); for (int i = 0; i < dimensions; i++) { vector[i] /= normalization; } }
From source file:com.github.rinde.rinsim.core.model.rand.RandomModelTest.java
static void testUnmodifiable(RandomGenerator rng) { boolean fail = false; try {/*ww w . j a v a2 s. c om*/ rng.setSeed(0); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(new int[] { 0 }); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(123L); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; rng.nextBoolean(); rng.nextBytes(new byte[] {}); rng.nextDouble(); rng.nextFloat(); rng.nextGaussian(); rng.nextInt(); rng.nextInt(1); rng.nextLong(); }
From source file:com.anhth12.kafka.ulti.DefaultCSVDatumGenerator.java
@Override public Pair<String, String> generate(int id, RandomGenerator random) { return new Pair<>(Integer.toString(id), id + "," + random.nextInt(100) + ',' + random.nextBoolean() + ',' + random.nextGaussian()); }
From source file:gdsc.smlm.model.MoleculeModel.java
/** * Move the molecule using a random Gaussian shift with standard deviation of the given diffusion rate. * <p>/*from www . j av a 2 s. com*/ * Note: The array provided by {@link #getCoordinates()} is updated and returned. * * @param diffusionRate * @param random * @return The new coordinates */ public double[] move(double diffusionRate, RandomGenerator random) { double[] xyz = getCoordinates(); if (diffusionRate > 0) { for (int i = 0; i < 3; i++) { final double shift = random.nextGaussian() * diffusionRate; // Clip the movement //if (shift > 5*diffusionRate) // xyz[i] += 5*diffusionRate; //else xyz[i] += shift; } } return xyz; }
From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java
public void rebuildIndices() { if (projection == null) { RandomGenerator r = RandomManager.getSeededRandom(seed); this.projection = new double[dimensions * projectionBits]; for (int i = 0; i < projection.length; i++) { projection[i] = r.nextGaussian(); }/*w w w . j a va 2 s .c om*/ } indices.clear(); for (List<RealVector> px : points) { List<BitSet> indx = Lists.newArrayList(); for (RealVector aPx : px) { indx.add(index(aPx)); } indices.add(indx); } updated = false; }
From source file:gdsc.smlm.model.GaussianPSFModel.java
private double[] sample(final int n, final double mu, final double sigma) { final double[] x = new double[n]; final RandomGenerator random = rand.getRandomGenerator(); for (int i = 0; i < n; i++) { x[i] = sigma * random.nextGaussian() + mu; }/*from ww w .j a v a 2s . c o m*/ return x; }
From source file:gdsc.smlm.model.CompoundMoleculeModel.java
/** * Rotate the molecule using a random axis and a specified rotation angle. The rotation is around the * centre-of-mass.// w w w.j ava 2 s. com * * @param axis * The axis to rotate around * @param maxAngle * The maximum angle to rotate (in either direction) in degrees * @param random */ public void rotateRandomAxis(double angle, RandomGenerator random) { if (angle == 0 || getSize() < 2) return; if (this.mass == 0) checkMass(); double[] axis = new double[3]; for (int i = 0; i < 3; i++) { axis[i] = random.nextGaussian(); } rotateMolecules(axis, angle); }
From source file:gdsc.smlm.model.CompoundMoleculeModel.java
/** * Rotate the molecule using a random axis and a random rotation angle. The rotation is around the centre-of-mass. * //from w w w . j a v a2 s .c o m * @param maxAngle * The maximum angle to rotate (in either direction) in degrees * @param random */ public void rotateRandom(double maxAngle, RandomGenerator random) { if (maxAngle == 0 || getSize() < 2) return; if (this.mass == 0) checkMass(); double[] axis = new double[3]; for (int i = 0; i < 3; i++) { axis[i] = random.nextGaussian(); } final double angle = (-maxAngle + random.nextDouble() * 2.0 * maxAngle); if (angle == 0) return; rotateMolecules(axis, angle); }
From source file:edu.oregonstate.eecs.mcplan.domains.firegirl.FireGirlState.java
private double drawTemperature(final RandomGenerator rng, final int date) { // Re-scale standard normal return rng.nextGaussian() * Math.sqrt(params.temp_var) + tempMean(date); }
From source file:com.winterwell.maths.stats.algorithms.KalmanFilterTest.java
@Test public void testConstant() { // simulates a simple process with a constant state and no control input double constantValue = 10d; double measurementNoise = 0.1d; double processNoise = 1e-5d; // A = [ 1 ]//w w w . ja v a 2s . co m Matrix A = new Matrix1D(1); // no control input RealMatrix B = null; // H = [ 1 ] Matrix H = new Matrix1D(1); // x = [ 10 ] Vector x = new X(constantValue); // Q = [ 1e-5 ] Matrix Q = new Matrix1D(processNoise); // R = [ 0.1 ] Matrix R = new Matrix1D(measurementNoise); // ProcessModel pm // = new DefaultProcessModel(A, B, Q, // new ArrayRealVector(new double[] { constantValue }), null); // MeasurementModel mm = new DefaultMeasurementModel(H, R); KalmanFilter filter = new KalmanFilter(1, 1); filter.setTransitionMatrix(A); filter.setTransitionNoise(Q); filter.setEmissionMatrix(H); filter.setEmissionNoise(R); Assert.assertEquals(1, filter.getMeasurementDimension()); Assert.assertEquals(1, filter.getStateDimension()); MatrixUtils.equals(Q, filter.getTransitionNoise()); // // check the initial state // double[] expectedInitialState = new double[] { constantValue }; // assertVectorEquals(expectedInitialState, filter.getStateEstimation()); Gaussian hiddenState = new Gaussian(new X(constantValue), new Matrix1D(0)); Vector pNoise = new X(0); Vector mNoise = new X(0); RandomGenerator rand = new JDKRandomGenerator(); // iterate 60 steps for (int i = 0; i < 60; i++) { hiddenState = filter.predict(hiddenState, null); // Simulate the process pNoise.set(0, processNoise * rand.nextGaussian()); // x = A * x + p_noise x = MatrixUtils.apply(A, x).add(pNoise); // Simulate the measurement mNoise.set(0, measurementNoise * rand.nextGaussian()); // z = H * x + m_noise Vector z = MatrixUtils.apply(H, x).add(mNoise); hiddenState = filter.correct(hiddenState, z); // state estimate shouldn't be larger than measurement noise double diff = FastMath.abs(constantValue - hiddenState.getMean().get(0)); // System.out.println(diff); Assert.assertTrue(Precision.compareTo(diff, measurementNoise, 1e-6) < 0); } // error covariance should be already very low (< 0.02) Assert.assertTrue(Precision.compareTo(hiddenState.getCovar().get(0, 0), 0.02d, 1e-6) < 0); }