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

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

Introduction

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

Prototype

public RandomDataGenerator(RandomGenerator rand) 

Source Link

Document

Construct a RandomDataGenerator using the supplied RandomGenerator as the source of (non-secure) random data.

Usage

From source file:com.cloudera.oryx.ml.param.RandomSearch.java

/**
 * @param ranges ranges of hyperparameters to try, one per hyperparameters
 * @param howMany how many combinations of hyperparameters to return
 * @return combinations of concrete hyperparameter values
 *///w  w w . j  a va  2  s  . c  om
static List<List<?>> chooseHyperParameterCombos(Collection<? extends HyperParamValues<?>> ranges, int howMany) {
    Preconditions.checkArgument(howMany > 0);

    int numParams = ranges.size();
    if (numParams == 0) {
        return Collections.singletonList(Collections.emptyList());
    }

    RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
    List<List<?>> allCombinations = new ArrayList<>(howMany);
    for (int i = 0; i < howMany; i++) {
        List<Object> combination = new ArrayList<>(numParams);
        for (HyperParamValues<?> range : ranges) {
            combination.add(range.getRandomValue(rdg));
        }
        allCombinations.add(combination);
    }

    return allCombinations;
}

From source file:com.arpnetworking.metrics.generator.name.SingleNameGenerator.java

/**
 * Public constructor./*from  w  ww .j av a  2 s  .  c  om*/
 *
 * @param generator Generator used to create the name.
 */
public SingleNameGenerator(final RandomGenerator generator) {
    _name = new RandomDataGenerator(generator).nextHexString(16);
}

From source file:com.arpnetworking.metrics.generator.name.NameSetGenerator.java

/**
 * Public constructor.//from   w  w  w .  jav a2s  .  co  m
 *
 * @param setSize Number of names in the set.
 * @param generator Generator used to create the name.
 */
public NameSetGenerator(final int setSize, final RandomGenerator generator) {
    final Set<String> names = Sets.newHashSetWithExpectedSize(setSize);
    _dataGenerator = new RandomDataGenerator(generator);
    while (names.size() < setSize) {
        names.add(_dataGenerator.nextHexString(16));
    }
    _names = Lists.newArrayList(names);
}

From source file:com.arpnetworking.metrics.generator.name.NameSetGenerator.java

/**
 * Public constructor.//from  ww  w  .  j  av  a 2s  .c  o m
 *
 * @param names The list of names to use.
 * @param generator Generator used to create the name.
 */
public NameSetGenerator(final Set<String> names, final RandomGenerator generator) {
    _dataGenerator = new RandomDataGenerator(generator);
    _names = Lists.newArrayList(names);
}

From source file:broadwick.rng.RNG.java

/**
 * Create a random number generator from a given generator using the current time as a seed.
 * @param gen the random number generator to use.
 *///from w w  w.jav a2 s  .c om
public RNG(final Generator gen) {
    if (gen.equals(Generator.MERSENNE)) {
        generator = new RandomDataGenerator(
                new MersenneTwister(System.currentTimeMillis() * Thread.currentThread().getId()));
        name = "Mersenne Twister";
    } else if (gen.equals(Generator.Well19937c)) {
        generator = new RandomDataGenerator(
                new Well19937c(System.currentTimeMillis() * Thread.currentThread().getId()));
        name = "Well19937c";
    } else if (gen.equals(Generator.Well44497b)) {
        generator = new RandomDataGenerator(
                new Well44497b(System.currentTimeMillis() * Thread.currentThread().getId()));
        name = "Well44497b";
    } else {
        // By default, the implementation provided in RandomDataImpl uses
        // the JDK-provided PRNG. Like most other PRNGs, the JDK generator
        // generates sequences of random numbers based on an initial
        // "seed value".
        generator = new RandomDataGenerator();
    }
}

From source file:com.cloudera.oryx.ml.param.GridSearch.java

/**
 * @param ranges ranges of hyperparameters to try, one per hyperparameters
 * @param howMany how many combinations of hyperparameters to return
 * @return combinations of concrete hyperparameter values. For example, for 5 parameters each
 *  with 3 values to try, the total number of combinations returned could be up to pow(3,5)
 *  or 243. The number could be less if the ranges do not actually have that many distinct
 *  values. If {@code howMany} is smaller than the total number of combinations, a random
 *  subset of all combinations are returned. The order is shuffled randomly. If no parameters
 *  are specified or {@code perParam} is 0, a single empty combination is returned.
 *///from  w  w  w.  java2s .  c om
static List<List<?>> chooseHyperParameterCombos(List<HyperParamValues<?>> ranges, int howMany) {
    // Put some reasonable upper limit on the number of combos
    Preconditions.checkArgument(howMany > 0 && howMany <= MAX_COMBOS);

    int numParams = ranges.size();
    int perParam = chooseValuesPerHyperParam(ranges, howMany);
    if (numParams == 0 || perParam == 0) {
        return Collections.singletonList(Collections.emptyList());
    }

    int howManyCombos = 1;
    List<List<?>> paramRanges = new ArrayList<>(numParams);
    for (HyperParamValues<?> range : ranges) {
        List<?> values = range.getTrialValues(perParam);
        paramRanges.add(values);
        howManyCombos *= values.size();
    }

    List<List<?>> allCombinations = new ArrayList<>(howManyCombos);
    for (int combo = 0; combo < howManyCombos; combo++) {
        List<Object> combination = new ArrayList<>(numParams);
        for (int param = 0; param < numParams; param++) {
            int whichValueToTry = combo;
            for (int i = 0; i < param; i++) {
                whichValueToTry /= paramRanges.get(i).size();
            }
            whichValueToTry %= paramRanges.get(param).size();
            combination.add(paramRanges.get(param).get(whichValueToTry));
        }
        allCombinations.add(combination);
    }

    if (howMany >= howManyCombos) {
        Collections.shuffle(allCombinations);
        return allCombinations;
    }
    RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
    int[] indices = rdg.nextPermutation(howManyCombos, howMany);
    List<List<?>> result = new ArrayList<>(indices.length);
    for (int i = 0; i < indices.length; i++) {
        result.add(allCombinations.get(i));
    }
    Collections.shuffle(result);
    return result;
}

From source file:com.milaboratory.core.alignment.BandedAlignerTest.java

@Test
public void testRandomGlobal() throws Exception {
    int its = its(100, 10000);
    RandomDataGenerator random = new RandomDataGenerator(new Well19937c());
    for (int i = 0; i < its; ++i) {
        NucleotideSequence seq1, seq2;/* w ww  . ja v a 2s . c  o  m*/
        seq1 = randomSequence(NucleotideSequence.ALPHABET, random, 10, 100);
        seq2 = randomSequence(NucleotideSequence.ALPHABET, random, 10, 100);
        Alignment<NucleotideSequence> alignment = BandedAligner.align(
                LinearGapAlignmentScoring.getNucleotideBLASTScoring(), seq1, seq2,
                random.nextInt(0, Math.min(seq1.size(), seq2.size()) - 1));
        assertAlignment(alignment, seq2);
    }
}

From source file:com.anhth12.lambda.ml.param.HyperParams.java

public static List<List<?>> chooseHyperParameterCombos(Collection<HyperParamValues<?>> ranges, int howMany,
        int perParam) {
    Preconditions.checkArgument(howMany > 0);
    Preconditions.checkArgument(perParam >= 0);

    int numParams = ranges.size();
    if (numParams == 0 || perParam == 0) {
        return Collections.<List<?>>singletonList(Collections.emptyList());
    }/*from w  ww  .ja  v  a  2 s .c o m*/

    // Put some reasonable upper limit on the number of combos
    Preconditions.checkArgument(Math.pow(perParam, numParams) <= MAX_COMBOS);

    int howManyCombos = 1;
    List<List<?>> paramRanges = new ArrayList<>(numParams);
    for (HyperParamValues<?> range : ranges) {
        List<?> values = range.getTrialValues(perParam);
        paramRanges.add(values);
        howManyCombos *= values.size();
    }

    List<List<?>> allCombinations = new ArrayList<>(howManyCombos);
    for (int combo = 0; combo < howManyCombos; combo++) {
        List<Object> combination = new ArrayList<>(numParams);
        for (int param = 0; param < numParams; param++) {
            int whichValueToTry = combo;
            for (int i = 0; i < param; i++) {
                whichValueToTry /= paramRanges.get(i).size();
            }
            whichValueToTry %= paramRanges.get(param).size();
            combination.add(paramRanges.get(param).get(whichValueToTry));
        }
        allCombinations.add(combination);
    }

    if (howMany >= howManyCombos) {
        Collections.shuffle(allCombinations);
        return allCombinations;
    }
    RandomDataGenerator rdg = new RandomDataGenerator(RandomManager.getRandom());
    int[] indices = rdg.nextPermutation(howManyCombos, howMany);
    List<List<?>> result = new ArrayList<>(indices.length);
    for (int i = 0; i < indices.length; i++) {
        result.add(allCombinations.get(i));
    }
    Collections.shuffle(result);
    return result;
}

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

/**
 * Create a distribution with the binary spots placed from min - max distance  
 * //from   ww w.  ja v a 2s.c  o m
 * @param size
 * @param depth
 * @param cellSize
 * @param pBinary
 * @param minBinaryDistance
 * @param maxBinaryDistance
 * @param randomGenerator
 */
public GridDistribution(int size, double depth, int cellSize, double pBinary, double minBinaryDistance,
        double maxBinaryDistance, RandomGenerator randomGenerator) {
    if (size < 1)
        throw new IllegalArgumentException("Size must be above zero");
    if (size < cellSize)
        throw new IllegalArgumentException("Size must be >= cell size");
    if (pBinary < 0 || pBinary > 1)
        throw new IllegalArgumentException("Probability must be between 0 and 1");
    if (maxBinaryDistance < 0)
        throw new IllegalArgumentException("Max distance must be positive");
    if (minBinaryDistance > maxBinaryDistance)
        throw new IllegalArgumentException("Min distance must be below max distance");
    if (randomGenerator == null)
        randomGenerator = new JDKRandomGenerator();

    this.randomGenerator = randomGenerator;
    this.dataGenerator = new RandomDataGenerator(randomGenerator);
    this.size = size;
    this.min = -depth / 2;
    this.depth = depth;
    this.cellSize = cellSize;
    this.pBinary = pBinary;
    this.minBinaryDistance = minBinaryDistance;
    this.maxBinaryDistance = maxBinaryDistance;

    nCellsPerRow = size / cellSize;
    nCells = nCellsPerRow * nCellsPerRow;
}

From source file:com.oltpbenchmark.benchmarks.smallworldbank.SWBankWorker.java

@SuppressWarnings("unchecked")
public SWBankWorker(BenchmarkModule benchmarkModule, int id) {
    super(benchmarkModule, id);

    exservice = Executors.newScheduledThreadPool(3);

    rdg = new RandomDataGenerator(new JDKRandomGenerator(id));
    // TODO: Get Dataset statistics:
    int noWorkers = benchmarkModule.getWorkloadConfiguration().getTerminals();
    tdp = benchmarkModule.getWorkloadConfiguration().getXmlConfig().getDouble("tdp");

    mddelay = benchmarkModule.getWorkloadConfiguration().getXmlConfig().getInt("mddelay");

    try {// ww w . ja  v a 2s.  c  om
        long _custIdMax = SWBankUtil.getCustIdMax(this.conn);
        long _acctIdMax = SWBankUtil.getAcctIdMax(this.conn);
        long custRange = _custIdMax / noWorkers;
        long acctRange = _acctIdMax / noWorkers;

        custIdMin = (id * custRange);
        custIdMax = custIdMin + custRange;

        acctIdMin = (id * acctRange);
        acctIdMax = acctIdMin + acctRange;

        LOG.info(String.format(
                "workerId=%d, custIdMin=%d, custIdMax=%d, custRange=%d,  "
                        + "acctIdMin=%d, acctIdMax=%d, acctRange=%d, tdp = %f ",
                id, custIdMin, custIdMax, custRange, acctIdMin, acctIdMax, acctRange, tdp));

    } catch (SQLException e) {
        // TODO: handle exception
        e.printStackTrace();
    }

    // parse specific properties of transaction types

}