本文整理汇总了Java中ec.util.MersenneTwisterFast.nextGaussian方法的典型用法代码示例。如果您正苦于以下问题:Java MersenneTwisterFast.nextGaussian方法的具体用法?Java MersenneTwisterFast.nextGaussian怎么用?Java MersenneTwisterFast.nextGaussian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ec.util.MersenneTwisterFast
的用法示例。
在下文中一共展示了MersenneTwisterFast.nextGaussian方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tenOptions
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptions() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
SoftmaxBanditAlgorithm bandit = new SoftmaxBanditAlgorithm(
new BanditAverage(10, IterativeAverage::new), 20, .98);
for (int i = 0; i < 2000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
//sometimes it gets stuck at 8 rather than 9
assertTrue(bandit.getNumberOfObservations(9) + bandit.getNumberOfObservations(8)> 1000);
}
示例2: tenOptionsEMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsEMA() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
SoftmaxBanditAlgorithm bandit = new SoftmaxBanditAlgorithm(
new BanditAverage(10, () -> new ExponentialMovingAverage<>(.8)), 50, .975);
for (int i = 0; i < 1000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
assertTrue(bandit.getNumberOfObservations(9) > 500);
}
示例3: tenOptionsMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsMA() throws Exception
{
//About 1 out of 5000 trials fail
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
SoftmaxBanditAlgorithm bandit = new SoftmaxBanditAlgorithm(
new BanditAverage(10, () -> new MovingAverage<>(20)), 50, .975);
for (int i = 0; i < 1000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
assertTrue(bandit.getNumberOfObservations(9) > 500);
}
示例4: tenOptions
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptions() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
UCB1BanditAlgorithm bandit = new UCB1BanditAlgorithm(
-10,10,new BanditAverage(10, IterativeAverage::new)) ;
for (int i = 0; i < 10000; i++) { //notice how much slower this method is. It is being extremely cautious
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
assertTrue(bandit.getNumberOfObservations(9)>5000);
}
示例5: tenOptionsEMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsEMA() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
UCB1BanditAlgorithm bandit = new UCB1BanditAlgorithm(
-10,10,new BanditAverage(10, () -> new ExponentialMovingAverage<>(.8))) ;
for (int i = 0; i < 10000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
assertTrue(bandit.getNumberOfObservations(9)>4000);
}
示例6: tenOptionsMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsMA() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
UCB1BanditAlgorithm bandit = new UCB1BanditAlgorithm(
-10,10,new BanditAverage(10, () -> new MovingAverage<>(20))) ;
for (int i = 0; i < 10000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
System.out.println(bandit.getNumberOfObservations(9));
assertTrue(bandit.getNumberOfObservations(9)>5000);
}
示例7: tenOptions
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptions() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
EpsilonGreedyBanditAlgorithm bandit = new EpsilonGreedyBanditAlgorithm(
new BanditAverage(10, IterativeAverage::new)
, .2);
for (int i = 0; i < 1000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
bandit.setExplorationProbability(0);
assertEquals(9, bandit.chooseArm(random));
}
示例8: tenOptionsEMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsEMA() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
EpsilonGreedyBanditAlgorithm bandit = new EpsilonGreedyBanditAlgorithm(
new BanditAverage(10, () -> new ExponentialMovingAverage<>(.8))
, .2);
for (int i = 0; i < 1000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
bandit.setExplorationProbability(0);
assertEquals(9, bandit.chooseArm(random));
}
示例9: tenOptionsMA
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void tenOptionsMA() throws Exception
{
//option 10 is the best, you should pick it!
MersenneTwisterFast random = new MersenneTwisterFast();
EpsilonGreedyBanditAlgorithm bandit = new EpsilonGreedyBanditAlgorithm(
new BanditAverage(10, () -> new MovingAverage<>(20))
, .2);
for (int i = 0; i < 1000; i++) {
int arm = bandit.chooseArm(random);
double reward = random.nextGaussian() / 2 + arm;
bandit.observeReward(reward, arm);
}
//now you should be playing most
bandit.setExplorationProbability(0);
assertEquals(9, bandit.chooseArm(random));
}
示例10: NineBoxes
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
@Test
public void NineBoxes() throws Exception {
SimpleMapInitializer map = new SimpleMapInitializer(50, 50, 0, 0, 1, 10);
MersenneTwisterFast randomizer = new MersenneTwisterFast();
NauticalMap chart = map.makeMap(randomizer,
mock(GlobalBiology.class),
mock(FishState.class));
SquaresMapDiscretizer discretizer = new SquaresMapDiscretizer(2, 2);
MapDiscretization discretization = new MapDiscretization(discretizer);
discretization.discretize(chart);
BanditDestinationStrategy strategy = new BanditDestinationStrategy(
(Function<Integer, BanditAverage>) integer -> new BanditAverage(integer,
() -> new ExponentialMovingAverage<>(.5)),
banditAverage -> new EpsilonGreedyBanditAlgorithm(banditAverage,.1),
discretization,
new FavoriteDestinationStrategy(chart.getRandomBelowWaterLineSeaTile(randomizer)),
false, false);
//option 2 is the best, you should pick it!
for (int i = 0; i < 1000; i++) {
SeaTile tile = strategy.getFavoriteSpot();
int armPlayed = discretization.getGroup(tile);
double reward = -Math.pow(armPlayed-2,2)+randomizer.nextGaussian()/2;
strategy.choose(tile,reward,randomizer);
}
((EpsilonGreedyBanditAlgorithm) strategy.getAlgorithm()).setExplorationProbability(0);
assertEquals(2,strategy.getAlgorithm().chooseArm(randomizer));
}
示例11: apply
import ec.util.MersenneTwisterFast; //导入方法依赖的package包/类
/**
* Applies this function to the given argument.
*
* @param mersenneTwisterFast the function argument
* @return the function result
*/
@Override
public Double apply(MersenneTwisterFast mersenneTwisterFast) {
return mersenneTwisterFast.nextGaussian()*standardDeviation + mean;
}