/** Generate a random scalar with null mean and unit standard deviation. * <p>The number generated is uniformly distributed between -&sqrt;(3) * and +&sqrt;(3).</p> * @return a random scalar with null mean and unit standard deviation */ public double nextNormalizedDouble() { return SQRT3 * (2 * generator.nextDouble() - 1.0); }
/** * {@inheritDoc} */ public synchronized double nextDouble() { return wrapped.nextDouble(); }
@Override public double nextDouble() { return random.nextDouble(); }
/** {@inheritDoc} */ @Override public double sample() { final double u = random.nextDouble(); return u * upper + (1 - u) * lower; } }
/** * Returns the next pseudorandom, uniformly distributed * <code>double</code> value between <code>0.0</code> and * <code>1.0</code> from this random number generator's sequence. * * @return the next pseudorandom, uniformly distributed * <code>double</code> value between <code>0.0</code> and * <code>1.0</code> from this random number generator's sequence */ @Override public double nextDouble() { return randomGenerator.nextDouble(); }
/** * Generates a random integer between the specified numbers * * @param begin the begin of the interval * @param end the end of the interval * @return an int between begin and end */ public static int randomNumberBetween(double begin, double end, RandomGenerator rng) { if (begin > end) throw new IllegalArgumentException("Begin must not be less than end"); return (int) begin + (int) (rng.nextDouble() * ((end - begin) + 1)); }
@Override public T sample() { final double randomValue = random.nextDouble(); Integer valueIndex = probabilityRanges.floorEntry(randomValue).getValue(); return normalizedPmf.get(valueIndex).getFirst(); } }
Endpoint chooseEndpoint(RandomGenerator random) { double p = random.nextDouble(); int i = 0; while (i < cumulativeProbs.length && p >= cumulativeProbs[i]) { i++; } return endpoints[i]; }
/** * Initialize the membership matrix with random values. */ private void initializeMembershipMatrix() { for (int i = 0; i < points.size(); i++) { for (int j = 0; j < k; j++) { membershipMatrix[i][j] = random.nextDouble(); } membershipMatrix[i] = MathArrays.normalizeArray(membershipMatrix[i], 1.0); } }
/** {@inheritDoc} */ @Override public double sample() { final double n = random.nextDouble(); return scale / FastMath.pow(n, 1 / shape); } }
/** * {@inheritDoc} * * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method</a>. */ public int sample() { return inverseCumulativeProbability(random.nextDouble()); }
/** * {@inheritDoc} * * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method. * </a> */ public double sample() { return inverseCumulativeProbability(random.nextDouble()); }
@Override public double nextDouble() { return getRandomGenerator().nextDouble(); }
/** * Generates a representation corresponding to a random permutation of * length l which can be passed to the RandomKey constructor. * * @param l length of the permutation * @return representation of a random permutation */ public static final List<Double> randomPermutation(final int l) { List<Double> repr = new ArrayList<Double>(l); for (int i=0; i<l; i++) { repr.add(GeneticAlgorithm.getRandomGenerator().nextDouble()); } return repr; }
private Chromosome rouletteWheel(final List<Chromosome> chromosomes, final double totalFitness) { double rnd = (GeneticAlgorithm.getRandomGenerator().nextDouble() * totalFitness); double runningScore = 0; for (Chromosome o : chromosomes) { if (rnd >= runningScore && rnd <= runningScore + o.getFitness()) { return o; } runningScore += o.getFitness(); } return null; } }
@Override public Pair<String, String> generate(int id, RandomGenerator random) { boolean positive = id % 2 != 0; String target = positive ? "banana" : "apple"; // 10% chance of wrong predictor String predictor = (positive ^ (random.nextDouble() < 0.1)) ? "yellow" : "red"; return new Pair<>(null, predictor + "," + target); }
/** * {@inheritDoc} * * @throws MathIllegalArgumentException if <code>original</code> is not a {@link RandomKey} instance */ public Chromosome mutate(final Chromosome original) throws MathIllegalArgumentException { if (!(original instanceof RandomKey<?>)) { throw new MathIllegalArgumentException(LocalizedFormats.RANDOMKEY_MUTATION_WRONG_CLASS, original.getClass().getSimpleName()); } RandomKey<?> originalRk = (RandomKey<?>) original; List<Double> repr = originalRk.getRepresentation(); int rInd = GeneticAlgorithm.getRandomGenerator().nextInt(repr.size()); List<Double> newRepr = new ArrayList<Double> (repr); newRepr.set(rInd, GeneticAlgorithm.getRandomGenerator().nextDouble()); return originalRk.newFixedLengthChromosome(newRepr); }
@Override public Pair<String,String> generate(int id, RandomGenerator random) { List<String> elements = new ArrayList<>(numberOfDimensions); for (int i = 0; i < numberOfDimensions; i++) { double d = random.nextDouble(); elements.add(Double.toString(d)); } return new Pair<>(Integer.toString(id), TextUtils.joinDelimited(elements, ',')); } }
@Override public Pair<String,String> generate(int id, RandomGenerator random) { List<String> elements = new ArrayList<>(n + 2); elements.add(Integer.toString(id)); boolean positive = true; for (int i = 0; i < n; i++) { double d = random.nextDouble(); if (d < 0.5) { positive = false; } elements.add(Double.toString(d)); } elements.add(Boolean.toString(positive)); return new Pair<>(Integer.toString(id), TextUtils.joinDelimited(elements, ',')); }
@Ignore @Test public void testRandomState() { RandomGenerator generator = RandomManager.getRandom(); double unseededValue = generator.nextDouble(); RandomManager.useTestSeed(); double seededValue = generator.nextDouble(); assertNotEquals(unseededValue, seededValue); assertEquals(seededValue, RandomManager.getRandom().nextDouble()); }