本文整理汇总了Java中org.uncommons.maths.random.MersenneTwisterRNG类的典型用法代码示例。如果您正苦于以下问题:Java MersenneTwisterRNG类的具体用法?Java MersenneTwisterRNG怎么用?Java MersenneTwisterRNG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MersenneTwisterRNG类属于org.uncommons.maths.random包,在下文中一共展示了MersenneTwisterRNG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public static void main(String[] args) {
NetworkCandidateFactory candidateFactory = new NetworkCandidateFactory(100);
NetworkFitnessEvaluator fitnessEvaluator = new NetworkFitnessEvaluator();
NetworkMutationOperator networkMutationOperator = new NetworkMutationOperator();
SelectionStrategy<Object> selectionStrategy = new RouletteWheelSelection();
EvolutionEngine<NetworkGeneticExpression> engine = new GenerationalEvolutionEngine<>(
candidateFactory,
networkMutationOperator,
fitnessEvaluator,
selectionStrategy,
new MersenneTwisterRNG());
engine.addEvolutionObserver(new EvolutionObserver<NetworkGeneticExpression>()
{
public void populationUpdate(PopulationData<? extends NetworkGeneticExpression> data)
{
System.out.printf("Generation %d: best candidate fitness: %s\n",
data.getGenerationNumber(),
data.getBestCandidateFitness());
}
});
NetworkGeneticExpression result = engine.evolve(500, 3, new GenerationCount(50000));
//System.out.println(result);
}
示例2: reset
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
/**
* Resets all static fields to default values
*/
public static void reset() {
Settings s = new Settings(MOVEMENT_MODEL_NS);
int seed = s.contains(RNG_SEED) ? s.getInt(RNG_SEED) : RandomNumberGeneratorDefaultSeed;
RandomNumberGenerator = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(seed));
}
示例3: getOrderingInstance
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
static RandomOrder getOrderingInstance() {
if (singletonInstance == null) {
singletonInstance = new RandomOrder();
RandomGenerator = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(RandomGeneratorSeed));
}
return singletonInstance;
}
示例4: MessagePriorityGenerator
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public MessagePriorityGenerator(Settings s) {
long seed = s.contains(PRIORITY_RANDOMIZER_SEED_S) ?
s.getInt(PRIORITY_RANDOMIZER_SEED_S) : DEF_RANDOM_PRIORITY_GENERATOR_SEED;
this.randomPriorityGenerator = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(seed));
if (!s.contains(MESSAGE_PRIORITY_SLOT_S)) {
this.prioritySlotRanges = new double[DEFAULT_PRIORITY_SLOT_RANGES.length];
System.arraycopy(DEFAULT_PRIORITY_SLOT_RANGES, 0, prioritySlotRanges, 0,
DEFAULT_PRIORITY_SLOT_RANGES.length);
}
else {
double tempVals[] = s.getCsvDoubles(MESSAGE_PRIORITY_SLOT_S);
// Check consistency of the array of doubles containing the priority ranges
for (int i = 0; i < tempVals.length; i++) {
if ((tempVals[i] <= 0.0) || (tempVals[i] >= 1.0)) {
throw new SimError("Found invalid value in the " + MESSAGE_PRIORITY_SLOT_S +
" entry of the settings file");
}
else if ((i != 0) && (tempVals[i] <= tempVals[i-1])) {
throw new SimError("Found an out of order value in the " + MESSAGE_PRIORITY_SLOT_S +
" entry of the settings file");
}
}
// OK! Proceed with copying it
this.prioritySlotRanges = new double[tempVals.length + 2];
this.prioritySlotRanges[0] = 0.0;
this.prioritySlotRanges[prioritySlotRanges.length - 1] = 1.0;
System.arraycopy(tempVals, 0, this.prioritySlotRanges, 1, tempVals.length);
Message.MAX_PRIORITY_LEVEL = Math.max(Message.MAX_PRIORITY_LEVEL,
this.prioritySlotRanges.length - 2);
}
}
示例5: initSettings
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
/**
* Initializes settings fields that can be configured using Settings class
*/
private void initSettings() {
Settings s = new Settings(SETTINGS_NS);
boolean randomizeUpdates = DEF_RANDOMIZE_UPDATES;
if (s.contains(RANDOMIZE_UPDATES_S)) {
randomizeUpdates = s.getBoolean(RANDOMIZE_UPDATES_S);
}
if (randomizeUpdates) {
// creates the update order array that can be shuffled
updateOrder = new ArrayList<DTNHost>(hosts);
if (s.contains(RANDOMIZE_UPDATES_SEED_S)) {
RANDOM_UPDATE_ORDER_SEED = s.getInt(RANDOMIZE_UPDATES_SEED_S);
}
UPDATE_ORDER_RANDOMIZER = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(RANDOM_UPDATE_ORDER_SEED));
}
else { // null pointer means "don't randomize"
updateOrder = null;
}
if (s.contains(CELL_SIZE_MULT_S)) {
conCellSizeMult = s.getInt(CELL_SIZE_MULT_S);
}
else {
conCellSizeMult = DEF_CON_CELL_SIZE_MULT;
}
// check that values are within limits
if (conCellSizeMult < 2) {
throw new SettingsError("Too small value (" + conCellSizeMult +
") for " + SETTINGS_NS + "." + CELL_SIZE_MULT_S);
}
}
示例6: map
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public void map(IntWritable key,
Text value,
OutputCollector<LongWritable, VectorWritable> output,
Reporter reporter) throws IOException {
try {
MersenneTwisterRNG rng = new MersenneTwisterRNG();
//create gussian generators based on seeds
GaussianGenerator[] gg = new GaussianGenerator[dimension];
String[] numbers = value.toString().split("\t");
int i = 0;
long numSamples = Long.parseLong(numbers[i++]);
for (int d = 0; d < dimension; d++) {
double mean = Double.parseDouble(numbers[i++]);
double std = Double.parseDouble(numbers[i++]);
LOG.info("dimension=" + d + ": mean=" + mean + ", std=" + std);
gg[d] = new GaussianGenerator(mean, std, rng);
}
//generate samples
double[] vec = new double[dimension];
for (long count = 0; count < numSamples; count++) {
for (int d = 0; d < dimension; d++)
vec[d] = gg[d].nextValue();
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
output.collect(new LongWritable(count), new VectorWritable(p));
reporter.setStatus(Long.toString(count + 1) + " samples generated");
reporter.incrCounter(HiBench.Counters.BYTES_DATA_GENERATED,
8 + p.getNumNondefaultElements() * 8);
}
} catch (Exception e) {
LOG.warn("Exception in GussianSampleGenerator.MapClass");
e.printStackTrace();
}
}
示例7: buildRandom
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
private Random buildRandom() {
if (testSeed) {
return new MersenneTwisterRNG(STANDARD_SEED);
} else if (fixedSeed == null) {
return new MersenneTwisterRNG();
} else {
return new MersenneTwisterRNG(RandomUtils.longSeedtoBytes(fixedSeed));
}
}
示例8: buildRandom
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
private Random buildRandom() {
if (testSeed) {
return new MersenneTwisterRNG(STANDARD_SEED);
} else if (fixedSeed == null) {
return new MersenneTwisterRNG();
} else {
return new MersenneTwisterRNG(RandomUtils.longSeedtoBytes(fixedSeed));
}
}
示例9: PseudoNoise
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public PseudoNoise(Seed seed) {
this.seed = (ClonableSeed)seed;
this.random = new MersenneTwisterRNG(this.seed.bytes);
int count = this.seed.count;
this.seed.count = 0;
while (this.seed.count < count) {
nextDouble();
}
}
示例10: map
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public void map( IntWritable key,
Text value,
OutputCollector<LongWritable,VectorWritable> output,
Reporter reporter) throws IOException {
try {
MersenneTwisterRNG rng = new MersenneTwisterRNG();
//create gussian generators based on seeds
GaussianGenerator [] gg = new GaussianGenerator [dimension];
String[] numbers = value.toString().split("\t");
int i = 0;
long numSamples = Long.parseLong(numbers[i++]);
for (int d = 0; d< dimension; d++) {
double mean = Double.parseDouble(numbers[i++]);
double std = Double.parseDouble(numbers[i++]);
LOG.info("dimension="+d+": mean="+mean+", std="+std);
gg[d] = new GaussianGenerator(mean,std,rng);
}
//generate samples
double [] vec = new double[dimension];
for(long count = 0; count <numSamples; count++){
for(int d = 0; d<dimension ; d++)
vec[d] = gg[d].nextValue();
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
output.collect(new LongWritable(count), new VectorWritable(p));
reporter.setStatus(Long.toString(count+1)+" samples generated");
}
} catch (Exception e) {
LOG.warn("Exception in GussianSampleGenerator.MapClass");
e.printStackTrace();
}
}
示例11: configure
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
@Override
protected void configure() {
install(new FactoryModuleBuilder()
.implement(WorkEngine.class, ListWorkEngine.class)
.build(ListWorkEngineFactory.class));
bind(Random.class).to(MersenneTwisterRNG.class);
bind(Stopwatch.class).annotatedWith(Names.named("serverDuration")).to(Stopwatch.class)
.in(Singleton.class);
bind(AtomicLong.class).annotatedWith(Names.named("jtaWorkerWorkTime")).to(AtomicLong.class)
.in(Singleton.class);
bind(AtomicLong.class).annotatedWith(Names.named("jtaWorkerSleepTime")).to(AtomicLong.class)
.in(Singleton.class);
bind(Settings.class).toProvider(SettingsProvider.class).in(Singleton.class);
}
示例12: MessageEventGenerator
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
/**
* Constructor, initializes the interval between events,
* and the size of messages generated, as well as number
* of hosts in the network.
* @param s Settings for this generator.
*/
public MessageEventGenerator(Settings s) {
this.sizeRange = s.getCsvInts(MESSAGE_SIZE_S);
this.msgInterval = s.getCsvInts(MESSAGE_INTERVAL_S);
this.hostRange = s.getCsvInts(HOST_RANGE_S, 2);
this.idPrefix = s.getSetting(MESSAGE_ID_PREFIX_S);
if (s.contains(MESSAGE_TIME_S)) {
this.msgTime = s.getCsvDoubles(MESSAGE_TIME_S, 2);
}
else {
this.msgTime = null;
}
if (s.contains(TO_HOST_RANGE_S)) {
this.toHostRange = s.getCsvInts(TO_HOST_RANGE_S, 2);
}
else {
this.toHostRange = null;
}
/* if prefix is unique, so will be the rng's sequence */
//this.rng = new Random(idPrefix.hashCode());
//this.rng = new Random(System.currentTimeMillis());
if (s.contains(MESSAGE_GENERATOR_RANDOMIZER_SEED_S)) {
randomSeed = s.getInt(MESSAGE_GENERATOR_RANDOMIZER_SEED_S);
}
this.randomNumberGenerator = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(randomSeed));
if (this.sizeRange.length == 1) {
/* convert single value to range with 0 length */
this.sizeRange = new int[] {this.sizeRange[0], this.sizeRange[0]};
}
else {
s.assertValidRange(this.sizeRange, MESSAGE_SIZE_S);
}
if (this.msgInterval.length == 1) {
this.msgInterval = new int[] {this.msgInterval[0], this.msgInterval[0]};
}
else {
s.assertValidRange(this.msgInterval, MESSAGE_INTERVAL_S);
}
s.assertValidRange(this.hostRange, HOST_RANGE_S);
if (this.hostRange[1] - this.hostRange[0] < 2) {
if (this.toHostRange == null) {
throw new SettingsError("Host range must contain at least two "
+ "nodes unless toHostRange is defined");
}
else if ((this.toHostRange[0] == this.hostRange[0]) &&
(this.toHostRange[1] == this.hostRange[1])) {
// XXX: teemuk: Since (X,X) == (X,X+1) in drawHostAddress() there's
// still a boundary condition that can cause an infinite loop.
throw new SettingsError("If to and from host ranges contain " +
"only one host, they can't be the equal");
}
}
messagePriorityGenerator = new MessagePriorityGenerator(s);
/* calculate the first event's time */
this.nextEventsTime = ((this.msgTime != null) ? this.msgTime[0] : 0) +
this.msgInterval[0] + (this.msgInterval[0] == this.msgInterval[1] ?
0 : this.randomNumberGenerator.nextInt(this.msgInterval[1] - this.msgInterval[0]));
}
示例13: reset
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
/**
* Resets the static fields of the class
*/
public static void reset() {
nextAddress = 0;
RandomGenerator = new MersenneTwisterRNG(
SeedGeneratorHelper.get16BytesSeedFromValue(RandomGeneratorSeed));
}
示例14: GaussianSampleGenerator
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public GaussianSampleGenerator() {
rng = new MersenneTwisterRNG();
}
示例15: produceInitialCentroids
import org.uncommons.maths.random.MersenneTwisterRNG; //导入依赖的package包/类
public int produceInitialCentroids(int numClusters, List<Vector> iCentroids) throws Exception {
MersenneTwisterRNG rng = new MersenneTwisterRNG();
int numMax = (numSamples >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : ((int) numSamples);
DiscreteUniformGenerator dug = new DiscreteUniformGenerator(1, numMax, rng);
ArrayList<Integer> indexes = new ArrayList<Integer>(numClusters);
for (int i = 0; i < numClusters; i++) {
//check duplications
while (true) {
Integer v = dug.nextValue();
int j;
for (j = 0; j < indexes.size(); j++)
if (indexes.get(j) == v) break;
if (j == indexes.size()) break;
}
indexes.add(dug.nextValue());
}
BufferedReader in = new BufferedReader(new FileReader(dataFile));
int line = 0;
double[] vec = new double[dimension];
String s;
while ((s = in.readLine()) != null) {
line++;
if (indexes.size() == 0) break;
for (int i = 0; i < indexes.size(); i++) {
if (line == indexes.get(i)) {
LOG.info("found line " + String.valueOf(line));
String[] elements = s.split(",");
for (int d = 0; d < dimension; d++) {
vec[d] = Double.parseDouble(elements[d + 1]);
}
Vector p = new RandomAccessSparseVector(dimension);
p.assign(vec);
iCentroids.add(p);
indexes.remove(i);
break;
}
}
}
in.close();
//dump centroids
LOG.info("Dumping " + iCentroids.size() + " centroids..");
for (int i = 0; i < iCentroids.size(); i++) {
LOG.info("Centroid :" + (iCentroids.get(i).asFormatString()));
}
return iCentroids.size();
}