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:MainClass.java

public static void main(String args[]) {

    Random generator = new Random();
    for (int i = 0; i < 10; i++) {
        System.out.println(generator.nextGaussian());
    }/*from w  w w .ja  v a 2 s  .co  m*/

}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random();

    // check next Gaussian value  
    System.out.println("Next Gaussian value: " + randomno.nextGaussian());
}

From source file:Random3.java

public static void main(String[] argv) {
    // java.util.Random methods are non-static, do need to construct Math
    //+/*from  w w w  . ja va  2  s.  c  om*/
    Random r = new Random();
    for (int i = 0; i < 10; i++)
        System.out.println("A gaussian random double is " + r.nextGaussian());
    //-
}

From source file:RandDemo.java

public static void main(String args[]) {
    Random r = new Random();
    double val;
    double sum = 0;
    int bell[] = new int[10];

    for (int i = 0; i < 100; i++) {
        val = r.nextGaussian();
        sum += val;
        double t = -2;
        for (int x = 0; x < 10; x++, t += 0.5)
            if (val < t) {
                bell[x]++;/* w  ww.  ja v  a 2s .  c  o  m*/
                break;
            }
    }
    System.out.println("Average of values: " + (sum / 100));

    for (int i = 0; i < 10; i++) {
        for (int x = bell[i]; x > 0; x--)
            System.out.print("*");
        System.out.println();
    }
}

From source file:poisondog.demo.StringDemo.java

public static void main(String[] args) {
    //      String temp=" command  para1 para2  ";
    //      System.out.println(temp.replaceAll("^\\s*\\S*\\s*", "").replaceAll("\\s*$", "") + "]]");

    Queue<Double> queue = new CircularFifoQueue<Double>(1000);
    List<Double> all = new LinkedList<Double>();
    List<Double> list = new ArrayList<Double>();
    double result = 0;
    double sum = 0;
    Random r = new Random();
    for (int i = 0; i < 10000; i++) {
        double g = r.nextGaussian() * 100 - 5;
        sum += g;//  w  ww.j  ava  2s . c  om
        if (g > 0)
            result++;
        if (i > 5000 && getRate(queue) < getRate(all) * .94)
            list.add(g);
        all.add(g);
        queue.add(g);
        //         if (queue.size() > 1000)
        //            queue.remove();

    }
    //      System.out.println(list.size());
    int count = 0;
    for (Double d : list) {
        if (d > 0)
            count++;
    }
    System.out.println("Origin Rate: " + (double) result / all.size());
    System.out.println("Origin Sum: " + sum);
    System.out.println("Upgrade Rate: " + (double) count / list.size());
    System.out.println("Upgrade Count: " + list.size());
    System.out.println("Upgrade Sum: " + getSum(list));
    System.out.println("Queue Count: " + queue.size());
}

From source file:Random4.java

public static void main(String[] argv) throws IOException {
    // java.util.Random methods are non-static, do need to construct Math
    Random r = new Random();
    PrintWriter file1 = new PrintWriter(new FileWriter("file1"));
    PrintWriter file2 = new PrintWriter(new FileWriter("file2"));
    for (int i = 0; i < 10000; i++) {
        file1.println(r.nextDouble());/*from  ww  w . ja v a  2s. c o m*/
        file2.println(r.nextGaussian());
    }
    file1.close();
    file2.close();
}

From source file:state.FindOutliers.java

public static void main(String[] args) throws Exception {

    final double threshold = args.length == 0 ? 2.0 : Double.parseDouble(args[0]);

    Topology t = new Topology("StandardDeviationFilter");

    final Random rand = new Random();

    // Produce a stream of random double values with a normal
    // distribution, mean 0.0 and standard deviation 1.
    TStream<Double> values = t.limitedSource(new Supplier<Double>() {
        private static final long serialVersionUID = 1L;

        @Override/*from  w  w  w.  ja va 2 s.co m*/
        public Double get() {
            return rand.nextGaussian();
        }

    }, 100000);

    /*
     * Filters the values based on calculating the mean and standard
     * deviation from the incoming data. In this case only outliers are
     * present in the output stream outliers. A outlier is defined as one
     * more than (threshold*standard deviation) from the mean.
     * 
     * This demonstrates an anonymous functional logic class that is
     * stateful. The two fields mean and sd maintain their values across
     * multiple invocations of the test method, that is for multiple tuples.
     * 
     * Note both Mean & StandardDeviation classes are serializable.
     */
    TStream<Double> outliers = values.filter(new Predicate<Double>() {

        private static final long serialVersionUID = 1L;
        private final Mean mean = new Mean();
        private final StandardDeviation sd = new StandardDeviation();

        @Override
        public boolean test(Double tuple) {
            mean.increment(tuple);
            sd.increment(tuple);

            double multpleSd = threshold * sd.getResult();
            double absMean = Math.abs(mean.getResult());
            double absTuple = Math.abs(tuple);

            return absTuple > absMean + multpleSd;
        }
    });

    outliers.print();

    StreamsContextFactory.getEmbedded().submit(t).get();
}

From source file:lambertmrev.LambertMRev.java

/**
 * @param args the command line arguments
 *//*from   w  w w  .  jav  a 2  s  .c o  m*/
public static void main(String[] args) {
    // Want to test the Lambert class so you can specify the number of revs for which to compute
    //System.out.print("this is the frames tutorial \n");
    try {
        Frame inertialFrame = FramesFactory.getEME2000();
        TimeScale utc = TimeScalesFactory.getTAI();
        AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc);
        double mu = 3.986004415e+14;

        double a = 24396159; // semi major axis in meters
        double e = 0.72831215; // eccentricity
        double i = Math.toRadians(7); // inclination
        double omega = Math.toRadians(180); // perigee argument
        double raan = Math.toRadians(261); // right ascension of ascending node
        double lM = 0; // mean anomaly

        Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame,
                initialDate, mu);
        //KeplerianPropagator kepler = new KeplerianPropagator(initialOrbit);

        // set geocentric positions
        Vector3D r1 = new Vector3D(-6.88999e3, 3.92763e4, 2.67053e3);
        Vector3D r2 = new Vector3D(-3.41458e4, 2.05328e4, 3.44315e3);
        Vector3D r1_site = new Vector3D(4.72599e3, 1.26633e3, 4.07799e3);
        Vector3D r2_site = new Vector3D(4.70819e3, 1.33099e3, 4.07799e3);

        // get the topocentric positions
        Vector3D top1 = Transform.geo2radec(r1.scalarMultiply(1000), r1_site.scalarMultiply(1000));
        Vector3D top2 = Transform.geo2radec(r2.scalarMultiply(1000), r2_site.scalarMultiply(1000));

        // time of flight in seconds
        double tof = 3 * 3600;

        // propagate to 0 and tof
        Lambert test = new Lambert();

        boolean cw = false;
        int multi_revs = 1;
        RealMatrix v1_mat;
        Random randomGenerator = new Random();

        PrintWriter out_a = new PrintWriter("out_java_a.txt");
        PrintWriter out_e = new PrintWriter("out_java_e.txt");
        PrintWriter out_rho1 = new PrintWriter("out_java_rho1.txt");
        PrintWriter out_rho2 = new PrintWriter("out_java_rho2.txt");

        // start the loop
        double A, Ecc, rho1, rho2, tof_hyp;

        long time1 = System.nanoTime();
        for (int ll = 0; ll < 1e6; ll++) {

            rho1 = top1.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top1.getZ() / 1000;
            rho2 = top2.getZ() / 1000 + 1e-3 * randomGenerator.nextGaussian() * top2.getZ() / 1000;
            //tof_hyp = FastMath.abs(tof + 0.1*3600 * randomGenerator.nextGaussian());
            // from topo to geo
            Vector3D r1_hyp = Transform.radec2geo(top1.getX(), top1.getY(), rho1, r1_site);
            Vector3D r2_hyp = Transform.radec2geo(top2.getX(), top2.getY(), rho2, r2_site);
            //            System.out.println(r1_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(r2_hyp.scalarMultiply(1000).getNorm());
            //            System.out.println(tof/3600);
            test.lambert_problem(r1_hyp.scalarMultiply(1000), r2_hyp.scalarMultiply(1000), tof, mu, cw,
                    multi_revs);

            v1_mat = test.get_v1();

            Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
            //            System.out.println(v1);
            PVCoordinates rv1 = new PVCoordinates(r1_hyp.scalarMultiply(1000), v1);
            Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
            A = orbit_out.getA();
            Ecc = orbit_out.getE();

            //            System.out.println(ll + " - " +A);
            out_a.println(A);
            out_e.println(Ecc);
            out_rho1.println(rho1);
            out_rho2.println(rho2);
        }
        long time2 = System.nanoTime();
        long timeTaken = time2 - time1;

        out_a.close();
        out_e.close();
        out_rho1.close();
        out_rho2.close();

        System.out.println("Time taken " + timeTaken / 1000 / 1000 + " milli secs");

        // get the truth
        test.lambert_problem(r1.scalarMultiply(1000), r2.scalarMultiply(1000), tof, mu, cw, multi_revs);
        v1_mat = test.get_v1();
        Vector3D v1 = new Vector3D(v1_mat.getEntry(0, 0), v1_mat.getEntry(0, 1), v1_mat.getEntry(0, 2));
        PVCoordinates rv1 = new PVCoordinates(r1.scalarMultiply(1000), v1);
        Orbit orbit_out = new KeplerianOrbit(rv1, inertialFrame, initialDate, mu);
        //System.out.println(orbit_out.getA());
    } catch (FileNotFoundException ex) {
        Logger.getLogger(LambertMRev.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override// w w w.  j av a  2  s .  com
        public void run() {
            Random r = new Random();
            int sampleSize = 1000;
            double[] data = new double[sampleSize];
            double[] xCategories = new double[sampleSize];
            String[] toolTipsLabels = new String[sampleSize];
            for (int i = 0; i < sampleSize; i++) {
                data[i] = Math.log((r.nextGaussian() * 1.5 + 10) * i + 50);
                xCategories[i] = Math.log(i + 50);
                toolTipsLabels[i] = String.valueOf(i);
            }

            String xLabel = "xLabel";
            String yLabel = "yLabel";
            //String yLabel = null;
            String graphTitle = "Graph Title";

            JFrame frame = new JFrame();
            ScatterGraph scatterGraph = new ScatterGraph(data, xCategories, toolTipsLabels, xLabel, yLabel,
                    graphTitle);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 500);
            frame.add(scatterGraph);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}

From source file:plugin.trackmate.tram.trackanalyzer.TrAM.java

/**
 * Unit test//w ww.j  a va  2 s  .  c  om
 */
public static void main(final String[] args) {
    final int numTracks = 500;
    final int numDiscontinuousTracks = 10;
    final int numTimePoints = 50;
    final int discontinuitySafeZoneWidth = 5;
    final String[] features = { "x", "y", "f1", "f2", "f3" };
    final double[] featureFluctuationScales = { 1, 1, 5, 10, 0.1 };
    final double relativeDiscontinuityScale = 9;

    final int numKnots = 6;

    // populate with Gaussian noise. Add discontinuities for the first ones
    final Random rnd = new Random();
    final List<Map<String, double[]>> allTrackData = new ArrayList<>();

    for (int i = 0; i < numTracks; ++i) {
        final Map<String, double[]> featureData = new HashMap<>(features.length);
        allTrackData.add(featureData);

        final boolean isDiscontinuous = i < numDiscontinuousTracks;
        final int discontinuityTimePoint = discontinuitySafeZoneWidth
                + rnd.nextInt(numTimePoints - 2 * discontinuitySafeZoneWidth);

        for (int j = 0; j < features.length; ++j) {
            final double[] data = new double[numTimePoints];
            for (int k = 0; k < numTimePoints; ++k)
                data[k] = featureFluctuationScales[j] * rnd.nextGaussian();

            // if discontinuous add a big jump
            if (isDiscontinuous)
                data[discontinuityTimePoint] += relativeDiscontinuityScale * featureFluctuationScales[j]
                        * rnd.nextGaussian();

            featureData.put(features[j], data); // save it
        }
    }

    final Map<String, Double> mad = computeMedianAbsoluteDifferences(allTrackData);
    System.out.println(mad); // sanity check

    final Map<String, String[]> euclidians = new HashMap<>();
    euclidians.put("XY", new String[] { "x", "y" });
    final TrAM tram = new TrAM(mad, numKnots, 0.5);
    final double[] tramValues = new double[numTracks];
    for (int trackNumber = 0; trackNumber < numTracks; ++trackNumber) {
        tramValues[trackNumber] = tram.computeTrAM(allTrackData.get(trackNumber), euclidians);

        // print out some of the discontinuous and an equal number of
        // continuous track TrAM values
        if (trackNumber < 2 * numDiscontinuousTracks)
            System.out.println(trackNumber + " " + tramValues[trackNumber]);
    }
}