Example usage for org.apache.commons.math3.random JDKRandomGenerator JDKRandomGenerator

List of usage examples for org.apache.commons.math3.random JDKRandomGenerator JDKRandomGenerator

Introduction

In this page you can find the example usage for org.apache.commons.math3.random JDKRandomGenerator JDKRandomGenerator.

Prototype

JDKRandomGenerator

Source Link

Usage

From source file:com.fpuna.preproceso.TestApacheMathLibDemo.java

/**
 * @param args//from   w w w. j  a va  2s .co  m
 */
public static void main(String[] args) {

    RandomGenerator randomGenerator = new JDKRandomGenerator();
    System.out.println(randomGenerator.nextInt());
    System.out.println(randomGenerator.nextDouble());

    /**
     * Descriptive Statistics like MEAN,GP,SD,MAX
    *
     */
    DescriptiveStatistics stats = new DescriptiveStatistics();
    stats.addValue(1);
    stats.addValue(2);
    stats.addValue(3);
    stats.addValue(4);
    stats.addValue(5);
    stats.addValue(6);
    stats.addValue(7);
    System.out.print("Mean : " + stats.getMean() + "\n");
    System.out.print("Standard deviation : " + stats.getStandardDeviation() + "\n");
    System.out.print("Max : " + stats.getMax() + "\n");

    /**
     * Complex number format a+bi
    *
     */
    Complex c1 = new Complex(1, 2);
    Complex c2 = new Complex(2, 3);
    System.out.print("Absolute of c1 " + c1.abs() + "\n");
    System.out.print("Addition : " + (c1.add(c2)) + "\n");
}

From source file:net.liuxuan.temp.filterTest.java

public static void main(String[] args) {
    double constantVoltage = 10d;
    double measurementNoise = 0.1d;
    double processNoise = 1e-5d;

    // A = [ 1 ]//from w  ww.j a  v  a2s .  c o  m
    RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d });
    // B = null
    RealMatrix B = null;
    // H = [ 1 ]
    RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d });
    // x = [ 10 ]
    RealVector x = new ArrayRealVector(new double[] { constantVoltage });
    // Q = [ 1e-5 ]
    RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise });
    // P = [ 1 ]
    RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1d });
    // R = [ 0.1 ]
    RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise });

    ProcessModel pm = new DefaultProcessModel(A, B, Q, x, P0);
    MeasurementModel mm = new DefaultMeasurementModel(H, R);
    KalmanFilter filter = new KalmanFilter(pm, mm);

    // process and measurement noise vectors
    RealVector pNoise = new ArrayRealVector(1);
    RealVector mNoise = new ArrayRealVector(1);

    RandomGenerator rand = new JDKRandomGenerator();
    // iterate 60 steps
    for (int i = 0; i < 60; i++) {
        filter.predict();

        // simulate the process
        //            pNoise.setEntry(0, processNoise * rand.nextGaussian());
        pNoise.setEntry(0, Math.sin(Math.PI * 2 * i / 6));
        //            System.out.println("============");
        //            System.out.println(Math.sin(Math.PI*2*i/6));

        // x = A * x + p_noise
        x = A.operate(x).add(pNoise);
        // simulate the measurement
        //            mNoise.setEntry(0, measurementNoise * rand.nextGaussian());
        mNoise.setEntry(0, 0);

        // z = H * x + m_noise
        RealVector z = H.operate(x).add(mNoise);
        filter.correct(z);

        double voltage = filter.getStateEstimation()[0];
        System.out.println(voltage);

        // state estimate shouldn't be larger than the measurement noise
        double diff = Math.abs(x.getEntry(0) - filter.getStateEstimation()[0]);
        System.out.println("diff = " + diff);

    }
}

From source file:fr.inria.zenith.randomWalk.RandomWalkTsG.java

public static String[] randomWalk(int length) {
    NormalDistribution n = new NormalDistribution(new JDKRandomGenerator(), 0, 1); //mean 0 std 1 variance 1
    String[] ts = new String[length];
    double[] tstemp = new double[length];
    double[] e = new double[length - 1];

    for (int i = 0; i < e.length; i++) {
        e[i] = n.sample();//  www .j a v a2s. c o m
    }
    ts[0] = "0.0";
    for (int i = 1; i < length; i++) {
        ts[i] = (tstemp[i] = tstemp[i - 1] + e[i - 1]) + "";
    }
    return ts;
}

From source file:cz.cuni.mff.d3s.spl.utils.DistributionUtils.java

/** Create empirical distribution from given samples.
 * /*w w  w  .j  a v  a 2  s.  c  o  m*/
 * @param samples Samples (does not need to be distinct) to use.
 * @return Empirical distribution built from the samples.
 */
public static EmpiricalDistribution makeEmpirical(double[] samples) {
    /* Be deterministic for now. */
    RandomGenerator gen = new JDKRandomGenerator();
    gen.setSeed(0);

    EmpiricalDistribution result = new EmpiricalDistribution(samples.length / 10 + 1, gen);
    result.load(samples);

    return result;
}

From source file:fi.smaa.common.RandomUtil.java

public static RandomUtil createWithFixedSeed() {
    JDKRandomGenerator engine = new JDKRandomGenerator();
    engine.setSeed(666);/* w  w w.java  2 s  . co  m*/
    return new RandomUtil(engine);
}

From source file:io.fabric8.example.calculator.http.GeneratorTest.java

@Test
public void testGenerator() throws Exception {

    RandomGenerator rg = new JDKRandomGenerator();
    double[] array = new double[10];

    for (int i = 0; i < array.length; i++) {
        array[i] = rg.nextDouble();/*from   w  ww .  ja va  2  s  . c o  m*/
    }

    final ObjectMapper mapper = new ObjectMapper();
    System.out.println(mapper.writeValueAsString(array));
}

From source file:io.yields.math.framework.data.RandomIntGenerator.java

public RandomIntGenerator() {
    this(new CommonsMathIntegerRandomSequence(new JDKRandomGenerator()));
}

From source file:io.yields.math.framework.data.RandomDoubleGenerator.java

public RandomDoubleGenerator() {
    this(new CommonsMathDoubleRandomSequence(new JDKRandomGenerator()));
}

From source file:gdsc.smlm.model.SphericalDistribution.java

public SphericalDistribution(double radius, RandomGenerator randomGenerator) {
    if (randomGenerator == null)
        randomGenerator = new JDKRandomGenerator();
    if (radius < 0)
        throw new IllegalArgumentException("Radius must be positive: {0}");
    this.radius = radius;
    this.r2 = radius * radius;
    this.range = 2 * radius;
    this.randomGenerator = randomGenerator;
}

From source file:io.fabric8.example.stddev.http.StdDevProcessorTest.java

@Test
public void testProcess() throws Exception {
    RandomGenerator rg = new JDKRandomGenerator();
    double[] array = new double[10];
    ObjectMapper objectMapper = new ObjectMapper();
    for (int i = 0; i < array.length; i++) {
        array[i] = rg.nextDouble();// w w w.j  av  a  2s  . c  o m
    }
    String body = objectMapper.writeValueAsString(array);
    SummaryStatistics summaryStatistics = new SummaryStatistics();
    List<Double> list = new ObjectMapper().readValue(body, List.class);
    for (Double value : list) {
        summaryStatistics.addValue(value);
    }
    String stdDev = Double.toString(summaryStatistics.getStandardDeviation());

    resultEndpoint.expectedBodiesReceived(stdDev);

    template.sendBody(body);

    resultEndpoint.assertIsSatisfied();
}