List of usage examples for org.apache.commons.math3.random RandomDataGenerator nextExponential
public double nextExponential(double mean) throws NotStrictlyPositiveException
Algorithm Description: Uses the Algorithm SA (Ahrens) from p.
From source file:gdsc.smlm.model.StandardFluorophoreSequenceModel.java
/** * Construct a new flourophore//from w w w . j a v a2s . c o m * * @param tAct * Average time for activation * @param id * The identifier * @param xyz * The [x,y,z] coordinates * @param tOn * Average on-state time * @param tOff * Average off-state time for the first dark state * @param tOff * Average off-state time for the second dark state * @param nBlinks * Average number of blinks int the first dark state (used for each burst between second dark states) * @param nBlinks2 * Average number of blinks into the second dark state * @param randomGenerator */ public StandardFluorophoreSequenceModel(double tAct, int id, double[] xyz, double tOn, double tOff, double tOff2, double nBlinks, double nBlinks2, boolean useGeometricBlinkingDistribution, RandomDataGenerator randomGenerator) { super(id, xyz); init(randomGenerator.nextExponential(tAct), tOn, tOff, tOff2, nBlinks, nBlinks2, useGeometricBlinkingDistribution, randomGenerator); }
From source file:com.siemens.industrialbenchmark.util.RandomNumberExpectedValueTest.java
@Test public void testExpectedValues() { long seed = 0; Random rand = new Random(seed); RandomDataGenerator randomData = new RandomDataGenerator(); double uniformAverage = 0.0; double binomialAverage = 0.0; double normalAverage = 0.0; double exponentialAverage = 0.0; for (int i = 0; i < 1e6; i++) { // set current seed randomData.reSeed(seed);/*from w ww . j a va2 s. c om*/ // draw random numbers double n = randomData.nextGaussian(0, 1); double u = randomData.nextUniform(0, 1); double b = randomData.nextBinomial(1, 0.5); double e = randomData.nextExponential(0.25); // average mean random number uniformAverage += (1. / (1. + i)) * (u - uniformAverage); binomialAverage += (1. / (1. + i)) * (b - binomialAverage); normalAverage += (1. / (1. + i)) * (n - normalAverage); exponentialAverage += (1. / (1. + i)) * (e - exponentialAverage); // draw new seed from global random generator seed = rand.nextLong(); } assertEquals(0.5, uniformAverage, 0.001); assertEquals(0.5, binomialAverage, 0.001); assertEquals(0.0, normalAverage, 0.001); assertEquals(0.25, exponentialAverage, 0.001); }
From source file:gdsc.smlm.model.StandardFluorophoreSequenceModel.java
private void init(double t, double tOn, double tOff, double tOff2, double nBlinks, double nBlinks2, boolean useGeometricBlinkingDistribution, RandomDataGenerator rand) { // Model two dark states: short and long. The second tOff and nBlinks is for the long dark state: ////w ww. jav a 2 s .c o m // ++-+-+++-+.................+-+--++-+................................+--+++-+ // // + = on // - = Short dark state // . = Long dark state // Note: 1+nBlinks is the number of on-states ArrayList<Double> sequence = new ArrayList<Double>(); // Perform a set number of long blinks int nLongBlinks = getBlinks(useGeometricBlinkingDistribution, rand, nBlinks2); for (int n = 0; n <= nLongBlinks; n++) { // For each burst between long blinks perform a number of short blinks int nShortBlinks = getBlinks(useGeometricBlinkingDistribution, rand, nBlinks); // Starts on the current time sequence.add(t); // Stops after the on-time t += rand.nextExponential(tOn); sequence.add(t); // Remaining bursts for (int i = 0; i < nShortBlinks; i++) { // Next burst starts after the short off-time t += rand.nextExponential(tOff); sequence.add(t); // Stops after the on-time t += rand.nextExponential(tOn); sequence.add(t); } // Add the long dark state if there are more bursts. t += rand.nextExponential(tOff2); } // Convert the sequence to the burst sequence array double[] burstSequence = new double[sequence.size()]; int c = 0; for (double time : sequence) burstSequence[c++] = time; setBurstSequence(burstSequence); }