本文整理汇总了Java中ec.util.MersenneTwisterFast类的典型用法代码示例。如果您正苦于以下问题:Java MersenneTwisterFast类的具体用法?Java MersenneTwisterFast怎么用?Java MersenneTwisterFast使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MersenneTwisterFast类属于ec.util包,在下文中一共展示了MersenneTwisterFast类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
* Applies this function to the given argument.
*
* @param state the function argument
* @return the function result
*/
@Override
public PerTripIterativeDestinationStrategy apply(FishState state) {
MersenneTwisterFast random = state.getRandom();
NauticalMap map = state.getMap();
final DefaultBeamHillClimbing algorithm = new DefaultBeamHillClimbing(stepSize.apply(random).intValue(),
20);
return new PerTripIterativeDestinationStrategy(
new FavoriteDestinationStrategy(map, random), algorithm, 1d-stayingStillProbability.apply(random), 0d,
new HourlyProfitInTripObjective(), new Predicate<SeaTile>() {
@Override
public boolean test(SeaTile a) {
return true;
}
});
}
示例2: defaultParticleFilter
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
public static ParticleFilter<Double> defaultParticleFilter(
double min, double max, double drift,
int size, MersenneTwisterFast random)
{
return new ParticleFilter<>(
new Function<MersenneTwisterFast, Double>() {
@Override
public Double apply(MersenneTwisterFast mersenneTwisterFast) {
return mersenneTwisterFast.nextDouble() * (max - min) + min;
}
},
new Function<Double, Double>() {
@Override
public Double apply(Double previous) {
return Math.max(
Math.min(previous + random.nextGaussian()*drift,max),min);
}
},
size,random
);
}
示例3: ParticleFilterRegression
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
public ParticleFilterRegression(
double distanceNoise, double evidenceDeviation, double temporalDrift, int filterSizes,
NauticalMap map, MersenneTwisterFast random, double minValue, double maxValue) {
this.distanceNoise = distanceNoise;
this.evidenceDeviation = evidenceDeviation;
this.temporalDrift = temporalDrift;
this.filterSizes = filterSizes;
this.map = map;
this.random = random;
this.minValue = minValue;
this.maxValue = maxValue;
List<SeaTile> tiles = map.getAllSeaTilesExcludingLandAsList();
for(SeaTile tile : tiles)
filters.put(tile,ParticleFilter.defaultParticleFilter(minValue,
maxValue,
temporalDrift,
filterSizes,
random));
}
示例4: simpleSelection
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
@Test
public void simpleSelection() throws Exception {
SelectDoubleParameter parameter = new SelectDoubleParameter(new double[]{1,2,3});
//make sure they are all selected!
int first=0;
int second=0;
int third=0;
MersenneTwisterFast random = new MersenneTwisterFast();
for(int i=0; i<100;i++)
{
int result = parameter.apply(random).intValue();
if(result==1)
first++;
else if(result==2)
second++;
else if(result==3)
third++;
else
throw new AssertionError("Wrong!");
}
}
示例5: PseudoLogisticLogger
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
public PseudoLogisticLogger(
MapDiscretization discretization,
ObservationExtractor[] commonExtractors,
LogisticLog log,
Fisher fisher,
FishState state,
MersenneTwisterFast random) {
this.discretization = discretization;
//only model arms for which we have both at least a tile in the map AND is listed in the input file
switcher = new BanditSwitch(discretization.getNumberOfGroups(),
integer -> discretization.isValid(integer) );
ObservationExtractor[][] extractors = new ObservationExtractor[switcher.getNumberOfArms()][];
for(int arm = 0; arm<extractors.length; arm++)
extractors[arm] = commonExtractors;
this.inputter = new LogisticInputMaker(extractors, new Function<Integer, SeaTile>() {
@Override
public SeaTile apply(Integer arm) {
List<SeaTile> group = discretization.getGroup(switcher.getGroup(arm));
return group.get(random.nextInt(group.size()));
}
});
this.log = log;
this.fisher = fisher;
this.state = state;
}
示例6: generateLocal
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
* the carrying capacity is an average between the rocky and the sandy one depending on how rocky
* the tile is
* @param biology the global biology (species' list) object
* @param seaTile the sea-tile to populate
* @param random the randomizer
* @param mapHeightInCells height of the map
* @param mapWidthInCells width of the map
* @param map
*/
@Override
public LocalBiology generateLocal(
GlobalBiology biology, SeaTile seaTile, MersenneTwisterFast random, int mapHeightInCells,
int mapWidthInCells, NauticalMap map) {
if(seaTile.getAltitude() >=0)
return new EmptyLocalBiology();
else
{
int species = biology.getSize();
double carryingCapacityLevel =
(1-seaTile.getRockyPercentage()) * sandyCarryingCapacity.apply(random) +
seaTile.getRockyPercentage() * rockyCarryingCapacity.apply(random);
BiomassLocalBiology local = new BiomassLocalBiology(carryingCapacityLevel, species, random);
biologies.put(seaTile,local);
return local;
}
}
示例7: ParticleSwarmAlgorithm
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
public ParticleSwarmAlgorithm(
double inertia, double memoryWeight, double socialWeight, int dimensions,
Function<Fisher, T> getBestMemory,
CoordinateTransformer<T> transformers,
double[] velocityShocks,
MersenneTwisterFast random,
DoubleParameter[] initialVelocities) {
this.inertia = inertia;
this.memoryWeight = memoryWeight;
this.socialWeight = socialWeight;
this.dimensions = dimensions;
this.getBestMemory = getBestMemory;
this.transformers = transformers;
this.velocityShocks = velocityShocks;
currentCoordinates = new double[dimensions];
velocities = new double[dimensions];
for(int i=0; i<dimensions; i++)
{
velocities[i] = initialVelocities[i].apply(random);
}
}
示例8: beliefsFormCorrectly
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
@Test
public void beliefsFormCorrectly() throws Exception {
LinkedList<Particle<Double>> particles = new LinkedList<>();
particles.add(new Particle<>(3d));
particles.add(new Particle<>(3d));
particles.add(new Particle<>(4d));
particles.add(new Particle<>(5d));
Belief<Double> belief = new Belief<>(particles);
double[] summary = Belief.getSummaryStatistics(belief);
assertEquals(summary[0],3.75,.001);
assertEquals(summary[1],0.82916,.001);
LinkedList<Double> sample = belief.sample(new MersenneTwisterFast(), 100);
for(Double temp : sample)
assertTrue(temp==3 || temp==4 || temp==5);
}
示例9: buildPorts
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
* Create and add ports to map, return them as a list.
* Supposedly this is called during the early scenario setup. The map is built, the biology is built
* and the marketmap can be built.
*
* @param map the map to place ports in
* @param mapmakerRandom the randomizer
* @param marketFactory a function that returns the market associated with a location. We might refactor this at some point*
* @param model
* @param gasPriceMaker
* @return the list of ports that have been built and added to the map. It can be ignored.
*/
@Override
public List<Port> buildPorts(
NauticalMap map, MersenneTwisterFast mapmakerRandom, Function<SeaTile, MarketMap> marketFactory,
FishState model, GasPriceMaker gasPriceMaker) {
List<Port> toReturn = new ArrayList<>(ports.size());
for(Map.Entry<String,Coordinate> entry : ports.entrySet()) {
SeaTile location = map.getSeaTile((int) entry.getValue().x,
(int) entry.getValue().y);
Port newPort = new Port(entry.getKey(),
location,
marketFactory.apply(location),
//ports start with price = 0 because I assume the scenario will have its own rules for gas price
0
);
toReturn.add(newPort);
map.addPort(newPort);
}
return toReturn;
}
示例10: createsPortWhereYouWant
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
@Test
public void createsPortWhereYouWant() throws Exception
{
SimpleMapInitializer initializer = new SimpleMapInitializer(4, 4, 0, 0, 1, 10);
NauticalMap map = initializer.makeMap(new MersenneTwisterFast(),
new GlobalBiology(new Species("fake")),
mock(FishState.class));
OnePortInitializer ports = new OnePortInitializer(3,1);
ports.buildPorts(map, new MersenneTwisterFast(), mock(Function.class), mock(FishState.class),
new FixedGasPrice(2d ));
assertEquals(map.getPorts().size(),1);
assertEquals(map.getPorts().get(0).getGasPricePerLiter(),2d,.0001d);
assertEquals(map.getPorts().iterator().next().getLocation().getGridX(),3);
assertEquals(map.getPorts().iterator().next().getLocation().getGridY(),1);
}
示例11: move
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
* ask implementation how to move. This gets called iff there is a positive delta (that is, there are more fish here than there)
*
* @param species species moving!
* @param here departing point
* @param abundanceHere departing local biology
* @param there arriving point
* @param abundanceThere arriving local biology
* @param delta number of fish here - number of fish there (always positive or this isn't called)
* @param fishHere
* @param fishThere
* @param bin bin/age studied
* @param random
* @param subdivision
* @param biologyHere departing local biology
* @param biologyThere arriving local biology
*/
@Override
public void move(
Species species, SeaTile here, StructuredAbundance abundanceHere, SeaTile there,
StructuredAbundance abundanceThere, double delta, double fishHere, double fishThere, int bin,
MersenneTwisterFast random,
boolean rounding, int subdivision,
AbundanceBasedLocalBiology biologyHere,
AbundanceBasedLocalBiology biologyThere) {
//reweights
double weightHere = weights.get(biologyHere);
double weightThere = weights.get(biologyThere);
delta = ((fishHere * weightThere - fishThere * weightHere)/(weightHere+weightThere));
if(rounding)
delta=(int) delta;
super.move(species, here, abundanceHere, there, abundanceThere, delta, fishHere, fishThere, bin, random, rounding,
subdivision, biologyHere, biologyThere);
}
示例12: generateLocal
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
* this gets called for each tile by the map as the tile is created. Do not expect it to come in order
* @param biology the global biology (species' list) object
* @param seaTile the sea-tile to populate
* @param random the randomizer
* @param mapHeightInCells height of the map
* @param mapWidthInCells width of the map
* @param map
*/
@Override
public LocalBiology generateLocal(
GlobalBiology biology, SeaTile seaTile, MersenneTwisterFast random, int mapHeightInCells,
int mapWidthInCells, NauticalMap map) {
if (seaTile.getAltitude() >= 0)
return new EmptyLocalBiology();
else
{
int species = biology.getSize();
double carryingCapacityLevel = carryingCapacity.apply(random);
double minCapacity = minInitialCapacity.apply(random);
double maxCapacity = maxInitialCapacity.apply(random);
BiomassLocalBiology local = new BiomassLocalBiology(carryingCapacityLevel, species, random,
maxCapacity, minCapacity);
biologies.put(seaTile,local);
return local;
}
}
示例13: getValidSeatileFromGroup
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
public static SeaTile getValidSeatileFromGroup(
MersenneTwisterFast random, List<SeaTile> mapGroup, boolean respectMPA, Fisher fisher, FishState model,
boolean ignoreWastelands, final int maxAttempts) {
int attempts = 0;
SeaTile tile;
do {
tile =
mapGroup.get(random.nextInt(mapGroup.size()));
attempts++;
if(attempts > maxAttempts)
break;
}while (
(respectMPA && !fisher.isAllowedToFishHere(tile, model)) ||
(ignoreWastelands && !tile.isFishingEvenPossibleHere()));
if(attempts > maxAttempts) {
return null;
}
assert !respectMPA || fisher.isAllowedToFishHere(tile, model);
assert !ignoreWastelands || tile.isFishingEvenPossibleHere();
return tile;
}
示例14: randomRocky
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
@Test
public void randomRocky() throws Exception {
FishState state = MovingTest.generateSimple4x4Map();
when(state.getRandom()).thenReturn(new MersenneTwisterFast());
RockyRectangleMaker maker = new RandomRockyRectangles(
new FixedDoubleParameter(2),
new FixedDoubleParameter(2),
3);
RockyRectangle[] rockyRectangles = maker.buildRectangles(state.getRandom(), state.getMap());
assertEquals(rockyRectangles.length,3);
for(RockyRectangle rectangle : rockyRectangles) {
assertEquals(rectangle.getHeight(), 2);
assertEquals(rectangle.getWidth(), 2);
}
}
示例15: ExperimentSimulator
import ec.util.MersenneTwisterFast; //导入依赖的package包/类
/**
*
* @param seed random number generator seed
* @param N number of variables
* @param experimentAvailability experiment availability distribution
* @param experimentTime time of an experiment distribution
* @param a number of available experimenters
* @param m number of parallel slots per experimenter
* @param alg Parallel R&S algorithm
* @param initQueueSize initial size of the queue
*/
public ExperimentSimulator(long seed, int N, Distribution experimentAvailability, Distribution experimentTime, int a, int m, PRSalgorithm alg, int initQueueSize) {
super(new MersenneTwisterFast(seed));
this.seed = seed;
this.N = N;
this.alg = alg;
this.a = a;
this.m = m;
this.experimentTime = experimentTime;
this.experimentAvailability = experimentAvailability;
this.algName = alg.getClass().getName().substring(alg.getClass().getName().indexOf(".")+1, alg.getClass().getName().indexOf("_"))+
(alg instanceof HasMinMeasuresPerPoint?((HasMinMeasuresPerPoint)alg).getMinMeasuresPerPoint():"")+
(alg instanceof HasPreselection && ((HasPreselection)alg).getPreselectionDistance()>0?("p"+((HasPreselection)alg).getPreselectionDistance()):"");
this.experimentCalculationCount=0;
RandomStreamFactory rsf = new RandomStreamFactory(N*3, seed);
points = new RSpoint[N];
rsExperimentTimes = new RandomStream[N];
int rsExperimAvailaIds[] = new int[N];
int bestIx = 0;
for (int i=0;i<N;i++) {
points[i] = new RSpoint(rsf.getStream(i), i);
if (i>0 && points[i].u > points[bestIx].u) bestIx = i;
rsExperimentTimes[i] = rsf.getStream(N+i);
rsExperimAvailaIds[i] = 2*N+i;
}
bestN = bestIx;
rsExperimentAvalability = rsf.getStream(rsExperimAvailaIds);
workers = new ObservationWorker[a];
for (int j=0;j<a;j++) {
workers[j] = new ObservationWorker(m);
}
queue = new ObservationQueue(experimentAvailability, rsExperimentAvalability,initQueueSize);
stepAllocator = new StepAllocator();
log0();
}