当前位置: 首页>>代码示例>>Java>>正文


Java RandomDataGenerator类代码示例

本文整理汇总了Java中org.apache.commons.math3.random.RandomDataGenerator的典型用法代码示例。如果您正苦于以下问题:Java RandomDataGenerator类的具体用法?Java RandomDataGenerator怎么用?Java RandomDataGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RandomDataGenerator类属于org.apache.commons.math3.random包,在下文中一共展示了RandomDataGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: chooseHyperParameterCombos

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
/**
 * @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
 */
static List<List<?>> chooseHyperParameterCombos(List<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;
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:26,代码来源:RandomSearch.java

示例2: SetPointGenerator

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
/**
 Constructor with given seed and properties file
 * @param seed The seed for the random number generator 
 * @param aProperties The properties file to parse 
 * @throws PropertiesException
 */
public SetPointGenerator(long seed, Properties aProperties)
		throws PropertiesException {

	mIsStationary = aProperties.containsKey("STATIONARY_SETPOINT");
	if (mIsStationary) {
		mSetPoint = PropertiesUtil.getFloat (aProperties, "STATIONARY_SETPOINT", true);			
		Preconditions.checkArgument(mSetPoint >= 0.0f && mSetPoint <= 100.0f, "setpoint must be in range [0, 100]");
	}
	MAX_CHANGE_RATE_PER_STEP_SETPOINT = PropertiesUtil.getFloat(aProperties, "MAX_CHANGE_RATE_PER_STEP_SETPOINT", true);
	MAX_SEQUENCE_LENGTH = PropertiesUtil.getInt(aProperties, "MAX_SEQUENCE_LENGTH", true);
	MINSETPOINT = PropertiesUtil.getFloat(aProperties, "SetPoint_MIN", true);
	MAXSETPOINT = PropertiesUtil.getFloat(aProperties, "SetPoint_MAX", true);
	SETPOINT_STEP_SIZE = PropertiesUtil.getFloat(aProperties, "SETPOINT_STEP_SIZE", true);
	
	this.mRandom = new RandomDataGenerator();
	this.mRandom.reSeed(seed);
	defineNewSequence();
}
 
开发者ID:siemens,项目名称:industrialbenchmark,代码行数:25,代码来源:SetPointGenerator.java

示例3: addRandomTile

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public void addRandomTile(RandomDataGenerator random) {
	List<Integer> emptyLocations = new ArrayList<>();
	for (int location = 0; location < SIZE * SIZE; location++) {
		if (getValue(location) == 0) {
			emptyLocations.add(location);
		}
	}

	Integer randomEmptyLocation = RandomUtils.pickRandom(emptyLocations, random);
	boolean isFour = (random.nextUniform(0, 1, true) < RANDOM_FOUR_PROB);
	if (isFour) {
		setValue(randomEmptyLocation, 2);
	} else {
		setValue(randomEmptyLocation, 1);
	}
}
 
开发者ID:wjaskowski,项目名称:2048-gecco-2015-competition,代码行数:17,代码来源:State2048.java

示例4: playGame

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public Pair<Integer, Integer> playGame(Player2048 player, RandomDataGenerator random) {
	int sumRewards = 0;

	State2048 state = sampleInitialStateDistribution(random);
	List<Action2048> actions = getPossibleActions(state);
	while (!actions.isEmpty()) {
		Action2048 action = player.chooseAction(state, actions);
		Transition<State2048, Action2048> transition = computeTransition(state, action);
		sumRewards += transition.getReward();
		
		state = getNextState(transition.getAfterState(), random);
		actions = getPossibleActions(state);
	}

	return new Pair<>(sumRewards, state.getMaxTile());
}
 
开发者ID:wjaskowski,项目名称:2048-gecco-2015-competition,代码行数:17,代码来源:Game2048.java

示例5: sample

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
/**
 * Returns a sample without replacement. Complexity: O(m). This is an iterative implementation of the Floyd's random
 * sampling algorithm (cf. http://dl.acm.org/citation.cfm?id=315746&dl=ACM&coll=DL). It's much faster than the other
 * implementations, especially for small <code>m</code> and large <code>Lists</code>.
 */
public static <T> List<T> sample(List<T> items, int m, RandomDataGenerator random) {
	Preconditions.checkArgument(items.size() >= m, "Sample size cannot be greater than list size!");
	final IntDoubleLinkedSet indices = new IntDoubleLinkedSet();
	final List<T> res = new ArrayList<>(m);
	final int n = items.size();
	for (int i = n - m; i < n; i++) {
		int pos = nextInt(0, i, random);
		if (indices.contains(pos)) {
			indices.add(i);
			res.add(items.get(i));
		} else {
			indices.add(pos);
			res.add(items.get(pos));
		}
	}
	return res;
}
 
开发者ID:wjaskowski,项目名称:2048-gecco-2015-competition,代码行数:23,代码来源:RandomUtils.java

示例6: main

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public static void main(String[] args) {
	if (args.length != 5) {
		System.err.println(usage());
		System.exit(1);
	}
	try {
		final Supplier<Agent> AGENT = createAgentFactoryByReflection(new File(args[0]), args[1]);
		final int REPEATS = Integer.parseInt(args[2]);
		final Duration ACTION_TIME_LIMIT = Duration.ofNanos((int) (Double.parseDouble(args[3]) * 1000 * 1000));
		final long RANDOM_SEED = Long.parseLong(args[4]);

		RandomDataGenerator random = new RandomDataGenerator(new MersenneTwister(RANDOM_SEED));
		MultipleGamesResult result = new Game(ACTION_TIME_LIMIT).playMultiple(AGENT, REPEATS, random);
		System.out.println(result.toCvsRow());

	} catch (Exception e) {
		System.err.println(e.toString());
		System.err.println();
		System.err.println(usage());
		System.exit(1);
	}
}
 
开发者ID:wjaskowski,项目名称:2048-gecco-2015-competition,代码行数:23,代码来源:AgentEvaluation.java

示例7: testGcdConsistency

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
@Test
public void testGcdConsistency() {
    int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131};
    ArrayList<Integer> primes = new ArrayList<Integer>();
    for (int i = 0; i < primeList.length; i++) {
        primes.add(Integer.valueOf(primeList[i]));
    }
    RandomDataGenerator randomData = new RandomDataGenerator();
    for (int i = 0; i < 20; i++) {
        Object[] sample = randomData.nextSample(primes, 4);
        int p1 = ((Integer) sample[0]).intValue();
        int p2 = ((Integer) sample[1]).intValue();
        int p3 = ((Integer) sample[2]).intValue();
        int p4 = ((Integer) sample[3]).intValue();
        int i1 = p1 * p2 * p3;
        int i2 = p1 * p2 * p4;
        int gcd = p1 * p2;
        Assert.assertEquals(gcd, ArithmeticUtils.gcd(i1, i2));
        long l1 = i1;
        long l2 = i2;
        Assert.assertEquals(gcd, ArithmeticUtils.gcd(l1, l2));
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:ArithmeticUtilsTest.java

示例8: randomNormal

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public static double randomNormal(RandomDataGenerator rnd, final double min, final double max, final double variance) {
	double value;
	
	if (min == max)
		return min;
	
	if (variance == 0.0) {
		value = rnd.nextUniform(min, max);
	} else {
		do {
			value = rnd.nextGaussian((max + min)/2, variance);
		} while (value < min || value > max);
	}
	
	return value;
}
 
开发者ID:gmarciani,项目名称:opmap,代码行数:17,代码来源:GMath.java

示例9: randomNormalLong

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public static long randomNormalLong(RandomDataGenerator rnd, final double min, final double max, final double variance) {
	long value;
	
	if (min == max)
		return FastMath.round(min);
	
	if (variance == 0.0) {
		value = FastMath.round(rnd.nextUniform(min, max));
	} else {
		do {
			value = FastMath.round(rnd.nextGaussian((max + min)/2, variance));
		} while (value < min || value > max);
		
	}
	
	return value;
}
 
开发者ID:gmarciani,项目名称:opmap,代码行数:18,代码来源:GMath.java

示例10: randomNormalInt

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public static int randomNormalInt(RandomDataGenerator rnd, final double min, final double max, final double variance) {
	int value;
	
	if (min == max)
		return (int) FastMath.round(min);
	
	if (variance == 0.0) {
		value = (int) FastMath.round(rnd.nextUniform(min, max));
	} else {
		do {
			value = (int) FastMath.round(rnd.nextGaussian((max + min)/2, variance));
		} while (value < min || value > max);
	}
	
	return value;
}
 
开发者ID:gmarciani,项目名称:opmap,代码行数:17,代码来源:GMath.java

示例11: sampleDataset

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
private static XYDataset sampleDataset() {		
RandomDataGenerator rnd = new RandomDataGenerator();		
      
      XYSeries series1 = new XYSeries("First");
      XYSeries series2 = new XYSeries("Second");
      XYSeries series3 = new XYSeries("Third");
      
      for (int input = 100; input <= 1000; input+=100) {
      	double value = rnd.nextUniform(100, 1000000);
      	series1.add(input, value);
      	series2.add(input, value * 10);
      	series3.add(input, value * 100);
      }

      XYSeriesCollection dataset = new XYSeriesCollection();
      dataset.addSeries(series1);
      dataset.addSeries(series2);
      dataset.addSeries(series3);
              
      return dataset;        
  }
 
开发者ID:gmarciani,项目名称:opmap,代码行数:22,代码来源:TestLinePlot.java

示例12: normalDouble

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
@Test
public void normalDouble() {
	double min = 10.0;
	double max = 100.0;
	double var = 1.0;
	double value;
	int reps = 10000000;
	RandomDataGenerator rnd = new RandomDataGenerator();
	
	for (int rep = 1; rep <= reps; rep++) {
		value = GMath.randomNormal(rnd, min, max, var);
		if (rep%100000 == 0)
			System.out.println(rep);
		if (value < min || value > max) fail("Random value outside interval: " + value + " (rep:" + rep + ")");
	}
}
 
开发者ID:gmarciani,项目名称:opmap,代码行数:17,代码来源:Random.java

示例13: normalInt

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
@Test
public void normalInt() {
	double min = 10.0;
	double max = 100.0;
	double var = 1.0;
	double value;
	int reps = 10000000;
	RandomDataGenerator rnd = new RandomDataGenerator();
	
	for (int rep = 1; rep <= reps; rep++) {
		value = GMath.randomNormalInt(rnd, min, max, var);
		if (rep%100000 == 0)
			System.out.println(rep);
		if (value < min || value > max) fail("Random value outside interval: " + value + " (rep:" + rep + ")");
	}
}
 
开发者ID:gmarciani,项目名称:opmap,代码行数:17,代码来源:Random.java

示例14: iteratorPerformanceTestList

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
private static long iteratorPerformanceTestList(final int curTest) {
    final Instant start = new Instant();
    for (int i = 0; i < COUNT_LOOPS; i++) {
        final List<Long> list = new ArrayList<Long>(COUNT_RAND);
        final RandomDataGenerator r = new RandomDataGenerator(RandomGenerators.newDefaultRandom());
        for (long ilong = 0L; ilong < COUNT_RAND; ilong++) {
            list.add(r.nextLong(Long.MIN_VALUE, Long.MAX_VALUE));
        }
        final Iterator<Long> iterator = list.iterator();
        while (iterator.hasNext()) {
            iterator.next().hashCode();
            iterator.remove();
        }
    }
    return start.longValue();
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:17,代码来源:BufferingIteratorRemoveTest.java

示例15: generateRandomPx

import org.apache.commons.math3.random.RandomDataGenerator; //导入依赖的package包/类
public static void generateRandomPx(double[][] px, RandomDataGenerator r,boolean verbose) {
double sum;
for (int a = 0; a < px.length; a++) {
    sum = 0.0;
    for (int v = 0; v < px[a].length; v++) {
	px[a][v] = r.nextGamma(1.0,1.0);
	sum += px[a][v];
    }
    // normalizing
    for (int v = 0; v < px[a].length; v++) {
	px[a][v] /= sum;
	 
    }
    if(verbose)System.out.println("p(x_" + a + ")=" + Arrays.toString(px[a]));
}

   }
 
开发者ID:fpetitjean,项目名称:ConceptDriftGenerator,代码行数:18,代码来源:CategoricalDriftGenerator.java


注:本文中的org.apache.commons.math3.random.RandomDataGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。