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:org.jfree.chart.demo.selection.SelectionDemo4.java

/**
 * Creates a sample {@link HistogramDataset}.
 * /*from w  w w.jav a 2s . c  om*/
 * @return the dataset.
 */
private static IntervalXYDataset createDataset() {
    HistogramDataset dataset = new HistogramDataset("H1");
    double lower = 0.0;
    for (int i = 0; i < 100; i++) {
        double upper = (i + 1) / 10.0;
        HistogramBin bin = new HistogramBin(lower, upper, true, false);
        dataset.addBin(bin);
        lower = upper;
    }
    double[] values = new double[1000];
    Random generator = new Random(12345678L);
    for (int i = 0; i < 1000; i++) {
        values[i] = generator.nextGaussian() + 5;
    }
    dataset.addObservations(values);
    return dataset;
}

From source file:ml.shifu.shifu.core.binning.DynamicBinningTest.java

public static List<NumBinInfo> createNumBinInfos(int binCnt) {
    Random rd = new Random(System.currentTimeMillis());

    List<Double> thresholds = new ArrayList<Double>(binCnt - 1);
    for (int i = 0; i < binCnt - 1; i++) {
        thresholds.add(rd.nextGaussian() * 200);
    }/*from   ww  w . j  a  v a2s  .com*/

    Collections.sort(thresholds);

    List<NumBinInfo> binInfoList = NumBinInfo.constructNumBinfo(StringUtils.join(thresholds, ':'), ':');
    for (NumBinInfo binInfo : binInfoList) {
        if (rd.nextDouble() > 0.45) {
            int total = rd.nextInt() % 1000;
            int positive = (int) (total * rd.nextDouble());
            binInfo.setTotalInstCnt(total);
            binInfo.setPositiveInstCnt(positive);
        }
    }

    return binInfoList;
}

From source file:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a sample {@link HistogramDataset}.
 * //from   w ww  . j a  v a2 s .c  o m
 * @return the dataset.
 */
private static IntervalXYDataset createDataset() {
    SimpleHistogramDataset dataset = new SimpleHistogramDataset("H1");
    double lower = 0.0;
    for (int i = 0; i < 100; i++) {
        double upper = (i + 1) / 10.0;
        SimpleHistogramBin bin = new SimpleHistogramBin(lower, upper, true, false);
        dataset.addBin(bin);
        lower = upper;
    }
    double[] values = new double[1000];
    Random generator = new Random(12345678L);
    for (int i = 0; i < 1000; i++) {
        values[i] = generator.nextGaussian() + 5;
    }
    dataset.addObservations(values);
    return dataset;
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random array - one dimension//  w  w w. ja v a  2s  . co m
 *
 * @param n Array length
 * @return Result array
 */
public static Array randn(int n) {
    Array r = Array.factory(DataType.DOUBLE, new int[] { n });
    Random rd = new Random();
    for (int i = 0; i < r.getSize(); i++) {
        r.setDouble(i, rd.nextGaussian());
    }

    return r;
}

From source file:org.meteoinfo.math.RandomUtil.java

/**
 * Get random array//from  w w  w . java 2s .  c  o  m
 *
 * @param shape Shape
 * @return Array Result array
 */
public static Array randn(List<Integer> shape) {
    int[] ashape = new int[shape.size()];
    for (int i = 0; i < shape.size(); i++) {
        ashape[i] = shape.get(i);
    }
    Array a = Array.factory(DataType.DOUBLE, ashape);
    Random rd = new Random();
    for (int i = 0; i < a.getSize(); i++) {
        a.setDouble(i, rd.nextGaussian());
    }

    return a;
}

From source file:hivemall.utils.math.MathUtils.java

public static double gaussian(final double mean, final double stddev, @Nonnull final Random rnd) {
    return mean + (stddev * rnd.nextGaussian());
}

From source file:org.jfree.chart.demo.selection.SelectionDemo2.java

public static XYDataset createDataset() {
    Random rgen = new Random();
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int s = 0; s < 3; s++) {
        XYSeries series = new XYSeries("S" + s);
        for (int i = 0; i < 100; i++) {
            double x = rgen.nextGaussian() * 200;
            double y = rgen.nextGaussian() * 200;
            series.add(x, y);//from  w w  w. j  a v  a2  s  . c o m
        }
        dataset.addSeries(series);
    }
    return dataset;
}

From source file:org.jfree.chart.demo.ThumbnailDemo1.java

private static IntervalXYDataset createDataset5() {
    HistogramDataset histogramdataset = new HistogramDataset();
    double ad[] = new double[1000];
    Random random = new Random(0xbc614eL);
    for (int i = 0; i < 1000; i++)
        ad[i] = random.nextGaussian() + 5D;

    histogramdataset.addSeries("H1", ad, 100, 2D, 8D);
    ad = new double[1000];
    for (int j = 0; j < 1000; j++)
        ad[j] = random.nextGaussian() + 7D;

    histogramdataset.addSeries("H2", ad, 100, 4D, 10D);
    return histogramdataset;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo3.java

public static XYDataset createDataset() {
    String[] names = { "JFreeChart", "Eastwood", "Orson", "JCommon" };
    Random rgen = new Random();
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int s = 0; s < 4; s++) {
        XYSeries series = new XYSeries(names[s]);
        for (int i = 0; i < 5000; i++) {
            double x = rgen.nextGaussian() * 200;
            double y = rgen.nextGaussian() * 200;
            series.add(x, y);//from  ww w.  j a va 2 s.  c o m
        }
        dataset.addSeries(series);
    }
    return dataset;
}

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

public static void genTestData(int k) {
    PrintWriter writer;/*from  w  w  w .ja v a 2  s  . com*/
    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 meanLat = rnd.nextDouble() * 400.0;
            double meanLon = rnd.nextDouble() * 400.0;

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

                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();
    }
}