Example usage for java.util Random nextGaussian

List of usage examples for java.util Random nextGaussian

Introduction

In this page you can find the example usage for java.util Random nextGaussian.

Prototype

public synchronized double nextGaussian() 

Source Link

Document

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Usage

From source file:info.rmarcus.birkhoffvonneumann.MatrixUtils.java

public static double[] randomDirectionInNDSpace(Random r, int n) {
    double[] toR = new double[n];

    double sumSquared = 0.0;
    for (int i = 0; i < n; i++) {
        toR[i] = r.nextGaussian();
        sumSquared += Math.pow(toR[i], 2);
    }//from  w  w w  .j a  v  a2  s.  co m

    sumSquared = Math.sqrt(sumSquared);

    for (int i = 0; i < n; i++)
        toR[i] /= sumSquared;

    return toR;
}

From source file:com.oculusinfo.ml.spark.unsupervised.TestKMeans.java

public static void genTestData(int k) {
    PrintWriter writer;//from  ww  w  . j  a  va2s .  c  o  m
    try {
        writer = new PrintWriter("test.txt", "UTF-8");

        // each class size is equal 
        int classSize = 1000000 / k;

        double stdDev = 30.0;

        // generate k classes of data points using a normal distribution with random means and fixed std deviation
        for (int i = 0; i < k; i++) {
            Random rnd = new Random();

            double meanX = rnd.nextDouble() * 400.0;
            double meanY = rnd.nextDouble() * 400.0;

            // randomly generate a dataset of x, y points
            for (int j = 0; j < classSize; j++) {
                double x = rnd.nextGaussian() * stdDev + meanX;
                double y = rnd.nextGaussian() * stdDev + meanY;

                writer.println(x + "," + y);
            }
        }
        writer.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * data provider generator for aggregation-value tests
 * @return data/*from   ww w .  j  ava2 s .  com*/
 */
@DataProvider
public static Object[] aggregationvaluegenerate() {
    final Random l_random = new Random();

    return aggregationvaluetestcase(

            IntStream.range(0, 100).boxed().map(i -> l_random.nextGaussian()),

            Stream.of(CAverage.class, CSum.class, CMin.class, CMax.class),

            (i) -> i.mapToDouble(Number::doubleValue).average().getAsDouble(),
            (i) -> i.mapToDouble(Number::doubleValue).sum(),
            (i) -> i.mapToDouble(Number::doubleValue).min().getAsDouble(),
            (i) -> i.mapToDouble(Number::doubleValue).max().getAsDouble()

    ).toArray();
}

From source file:hivemall.mix.server.MixServerTest.java

private static void invokeClient(String groupId, int serverPort) throws InterruptedException {
    PredictionModel model = new DenseModel(16777216, false);
    model.configureClock();// ww w . java2s  .  c  om
    MixClient client = null;
    try {
        client = new MixClient(MixEventName.average, groupId, "localhost:" + serverPort, false, 2, model);
        model.configureMix(client, false);

        final Random rand = new Random(43);
        for (int i = 0; i < 100000; i++) {
            Integer feature = Integer.valueOf(rand.nextInt(100));
            float weight = (float) rand.nextGaussian();
            model.set(feature, new WeightValue(weight));
        }

        waitForMixed(model, 48000L, 10000L);

        long numMixed = model.getNumMixed();
        Assert.assertTrue("number of mix events: " + numMixed, numMixed > 0);
    } finally {
        IOUtils.closeQuietly(client);
    }

}

From source file:org.grouplens.lenskit.scored.RandomScoredIdListTest.java

@Parameterized.Parameters
public static Collection<Object[]> data() {
    Random rng = new Random();
    List<Object[]> idLists = Lists.newArrayListWithCapacity(TEST_COUNT);
    for (int test = 0; test < TEST_COUNT; test++) {
        int size = rng.nextInt(50);
        ImmutableList.Builder<ScoredId> ids = ImmutableList.builder();
        for (int i = 0; i < size; i++) {
            double v = rng.nextGaussian() + Math.PI;
            ScoredIdBuilder bld = new ScoredIdBuilder(i, v);
            if (rng.nextBoolean()) {
                bld.addChannel(VAL_SYM, Math.log(v));
            }//from  w  ww . ja va  2  s .co m
            if (rng.nextBoolean()) {
                bld.addChannel(STR_SYM, Double.toString(v));
            }
            ScoredId id = bld.build();
            ids.add(id);
        }
        idLists.add(new Object[] { ids.build() });
    }
    return idLists;
}

From source file:com.google.uzaygezen.core.hbase.HBaseQueryTest.java

/**
 * It may generate duplicates./*from  w w w.  j a  v  a 2  s  .c o m*/
 */
private static int[][] generateData(MultiDimensionalSpec spec, int n, Random rnd) {
    int[][] data = new int[n][spec.getBitsPerDimension().size()];
    for (int i = 0; i < n; ++i) {
        // int has 32 bits, which fits in each dimensions.
        for (int j = 0; j < spec.getBitsPerDimension().size(); ++j) {
            int bound = 1 << spec.getBitsPerDimension().get(j);
            double gauss = rnd.nextGaussian();
            // Std of 1024.
            int d = bound / 2 + (int) (gauss * (1 << (spec.getBitsPerDimension().get(j) / 2)) / 1024);
            if (d < 0) {
                d = 0;
            }
            if (d >= bound) {
                d = bound - 1;
            }
            data[i][j] = d;
        }
    }
    return data;
}

From source file:com.facebook.LinkBench.distributions.LogNormalDistribution.java

@Override
public long choose(Random rng) {
    long choice = (long) Math.round(FastMath.exp((rng.nextGaussian() * sigma) + mu));
    if (choice < min)
        return min;
    else if (choice >= max)
        return max - 1;
    else/*from   w  ww  .ja  va  2  s . com*/
        return choice;
}

From source file:com.mapr.synth.drive.GeoPoint.java

public GeoPoint nearby(double distance, Random rand) {
    distance = distance / Constants.EARTH_RADIUS_KM;
    double u = rand.nextGaussian();
    double v = rand.nextGaussian();
    return project(distance * u, distance * v);
}

From source file:scatterplot1k.JFreeScatter.java

/**
 * Populates the data array with random values.
 *//*from   ww  w  .j  a v a2 s.c om*/
private void populateData() {
    Random random = new Random();

    for (int i = 0; i < this.data[0].length; i++) {
        this.data[0][i] = (float) (random.nextGaussian() * 2.0);
        this.data[1][i] = (float) (random.nextGaussian() * 2.0);
    }
}

From source file:scatterplot1k.JFreeScatter2.java

private XYSeries populateData() {
    Random random = new Random();
    XYSeries series = new XYSeries("Gaussian");
    for (int i = 0; i < samplesCount; i++) {
        double x = random.nextGaussian() * 2.0;
        double y = random.nextGaussian() * 2.0;
        series.add(x, y);// w  w w . ja  va 2  s. co m
    }
    return series;
}