本文整理汇总了Java中java.util.Random.nextGaussian方法的典型用法代码示例。如果您正苦于以下问题:Java Random.nextGaussian方法的具体用法?Java Random.nextGaussian怎么用?Java Random.nextGaussian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Random
的用法示例。
在下文中一共展示了Random.nextGaussian方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: salesRateAdjustment
import java.util.Random; //导入方法依赖的package包/类
private static double salesRateAdjustment(long time, Random random){
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
double x = cal.get(Calendar.DAY_OF_YEAR);
//if you graph out this rate equation you will see two peaks and two troughs with some valleys
//but summed over 365 days it will add up to zero so the sales rate adjustement, if averaged over a year period (365 days)
//will be zero. Basically this is to simulate the ups and downs in sales in a year
double rate = (-1.0/3.0) * Math.sin(x * ((4.0 * Math.PI)/365.0)) - (1.0/13.0) * Math.sin(x *(32.0 * Math.PI)/365.0);
double noise = (10 + random.nextGaussian())/10;
if (Math.abs(noise) < 2.0){
rate = rate * noise;
}
return rate;
}
示例2: createNoisySeasonalData
import java.util.Random; //导入方法依赖的package包/类
double[] createNoisySeasonalData(int length, int period, double seasonalAmplitude, double trendSlope,
double noiseSigma, long seed) {
this.seed = seed;
Random rand = new Random(seed);
double[] y = new double[length];
double dx = 2 * Math.PI / period;
for (int i = 0; i < length; ++i) {
double x = i * dx;
double e = noiseSigma * rand.nextGaussian();
y[i] = trendSlope * x + seasonalAmplitude * Math.sin(x) + e;
}
return y;
}
示例3: createDoubleArrayGaussian
import java.util.Random; //导入方法依赖的package包/类
public static double[] createDoubleArrayGaussian(int size) {
Random rand = new Random(0);
double[] array = new double[size];
for (int i = 0; i < size; ++i) {
array[i] = rand.nextGaussian();
}
return array;
}
示例4: createArguments
import java.util.Random; //导入方法依赖的package包/类
public double[] createArguments(Random random) {
double[] args = new double[coordinates.length];
for (int i = 0; i < args.length; i++) {
args[i] = coordinates[i] + random.nextGaussian() * sigmas[i];
}
return args;
}
示例5: initWeights
import java.util.Random; //导入方法依赖的package包/类
@Override
public DMatrix initWeights(int outputSize, int inputSize)
{
Random rand = new Random();
double[][] values = new double[inputSize][outputSize];
for(double[] row : values)
{
for(int j = 0; j < outputSize; j++)
{
row[j] = rand.nextGaussian();
}
}
return new DMatrix(values);
}
示例6: getH1nH2
import java.util.Random; //导入方法依赖的package包/类
public void getH1nH2(){
double price = 0.0;
alpha = 2.0/(100.0 + 1.0);
alphaWeight = Math.exp(-alpha);
runner = new Runner[runner.length];
for( int i = 0; i < runner.length; ++i ){
runner[i] = new Runner(0.025/100.0 + 0.05/100.0*(double)i, 0.025/100.0 + 0.05/100.0*(double)i, price, "JustFake");
runner[i].type = (i%2 == 0 ? 1 : -1);
prevState[i] = (runner[i].type == 1 ? 1 : 0);
}
double total1 = 0.0, total2 = 0.0;
Random rand = new Random(1);
double dt = 1.0/Math.sqrt(1000000.0);
double sigma = 0.25; // 25%
for( int i = 0; i < 100000000; ++i ){
price += sigma*dt*rand.nextGaussian();
for( int j= 0; j < runner.length; ++j ){
if( Math.abs(runner[j].run(price)) == 1 ){ // this is OK for simulated prices
double myProbs = getProbs(j);
total1 = total1*alphaWeight + (1.0 - alphaWeight)*(-Math.log(myProbs));
total2 = total2*alphaWeight + (1.0 - alphaWeight)*Math.pow(Math.log(myProbs), 2.0);
}
}
}
H1 = total1;
H2 = total2 - H1*H1;
System.out.println("H1:" + H1 + " H2:" + H2);
}
示例7: testNextGaussian
import java.util.Random; //导入方法依赖的package包/类
/**
* Repeated calls to nextGaussian produce at least two distinct results
*/
public void testNextGaussian() {
Random r = new Random();
double f = r.nextGaussian();
int i = 0;
while (i < NCALLS && r.nextGaussian() == f)
++i;
assertTrue(i < NCALLS);
}
示例8: testOneDimensionalPosition
import java.util.Random; //导入方法依赖的package包/类
@Test
public void testOneDimensionalPosition() {
final String name = "pos";
final int index = 4;
final double pos = -79.0;
mockIterator.next = new MapPosition(name, index, pos);
Random random = new Random(RANDOM_SEED);
double expectedPos = pos + random.nextGaussian() * STD_DEV;
IPosition expected = new MapPosition(name, index, expectedPos);
IPosition actual = randomOffsetDecorator.next();
assertEquals(expected, actual);
}
示例9: getRandomNumberAroundSomething
import java.util.Random; //导入方法依赖的package包/类
public static int getRandomNumberAroundSomething(Random generator, int center, int deviation)
{
if (center == 0)
return 0;
if (deviation == 0)
return center;
double val = generator.nextGaussian();
// first we scale to account for the standard deviation we need
// here we just use half of the average
// val *= center * 0.5;
val *= deviation;
// Shift it to the center we want
val += center;
// make any possible negative value, positive
val = (val < 0) ? -val : val;
// and if 0 make it 1
//val = (val == 0) ? 1 : val;
// if less than 1 make it 1
val = (val < 1) ? 1 : val;
return (int) val;
}
示例10: dispenserNukes
import java.util.Random; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void dispenserNukes(BlockTransformEvent event) {
BlockState oldState = event.getOldState();
if(oldState instanceof Dispenser &&
this.properties.dispenserNukeLimit > 0 &&
this.properties.dispenserNukeMultiplier > 0 &&
event.getCause() instanceof EntityExplodeEvent) {
EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
Dispenser dispenser = (Dispenser) oldState;
int tntLimit = Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier);
int tntCount = 0;
for(ItemStack stack : dispenser.getInventory().contents()) {
if(stack != null && stack.getType() == Material.TNT) {
int transfer = Math.min(stack.getAmount(), tntLimit - tntCount);
if(transfer > 0) {
stack.setAmount(stack.getAmount() - transfer);
tntCount += transfer;
}
}
}
tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier);
for(int i = 0; i < tntCount; i++) {
TNTPrimed tnt = this.getMatch().getWorld().spawn(BlockUtils.base(dispenser), TNTPrimed.class);
tnt.setFuseTicks(10 + this.getMatch().getRandom().nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining
Random random = this.getMatch().getRandom();
Vector velocity = new Vector(random.nextGaussian(), random.nextGaussian(), random.nextGaussian()); // uniform random direction
velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble());
tnt.setVelocity(velocity);
callPrimeEvent(tnt, explodeEvent.getEntity(), false);
}
}
}
示例11: resetFilter
import java.util.Random; //导入方法依赖的package包/类
@Override
public void resetFilter() {
filter = new ParticleFilter(dynamic, measurement, average);
Random r = new Random();
for(int i = 0; i < particlesCount; i++) {
// double x = (chip.getSizeX()/2) * (r.nextDouble()*2 - 1) + chip.getSizeX()/2;
// double y = (chip.getSizeX()/2) * (r.nextDouble()*2 - 1) + chip.getSizeX()/2;
double x = r.nextGaussian() + startPositionX;
double y = r.nextGaussian() + startPositionY;
filter.addParticle(new SimpleParticle(x, y));
}
}
示例12: generateSinusFunctions
import java.util.Random; //导入方法依赖的package包/类
/**
* Generates a new sinus function attribute for all given attribute peaks. Since the frequency
* cannot be calculated exactly (leakage, aliasing), several new attribute may be added for each
* peak. These additional attributes are randomly chosen (uniformly in epsilon range, uniformly
* without nu, gaussian with epsilon as standard deviation)
*/
public void generateSinusFunctions(ExampleSet exampleSet, List<AttributePeak> attributes, Random random)
throws GenerationException {
if (attributes.size() > 0) {
Collections.sort(attributes);
double totalMaxEvidence = attributes.get(0).getEvidence();
Iterator<AttributePeak> a = attributes.iterator();
while (a.hasNext()) {
AttributePeak ae = a.next();
if (ae.getEvidence() > MIN_EVIDENCE * totalMaxEvidence) {
for (int i = 0; i < attributesPerPeak; i++) {
double frequency = ae.getFrequency();
switch (adaptionType) {
case UNIFORMLY:
if (attributesPerPeak != 1) {
frequency = (double) i / (double) (attributesPerPeak - 1) * 2.0d * epsilon * frequency
+ (frequency - epsilon * frequency);
}
break;
case UNIFORMLY_WITHOUT_NU:
if (attributesPerPeak != 1) {
frequency = (double) i / (double) (attributesPerPeak - 1) * 2.0d * epsilon
+ (frequency - epsilon);
}
break;
case GAUSSIAN:
frequency = random.nextGaussian() * epsilon + frequency;
break;
}
// frequency constant
List frequencyResult = generateAttribute(exampleSet, new ConstantGenerator(frequency));
// scaling with frequency
FeatureGenerator scale = new BasicArithmeticOperationGenerator(
BasicArithmeticOperationGenerator.PRODUCT);
scale.setArguments(new Attribute[] { (Attribute) frequencyResult.get(0), ae.getAttribute() });
List scaleResult = generateAttribute(exampleSet, scale);
// calc sin
FeatureGenerator sin = new TrigonometricFunctionGenerator(TrigonometricFunctionGenerator.SINUS);
sin.setArguments(new Attribute[] { (Attribute) scaleResult.get(0) });
List<Attribute> sinResult = generateAttribute(exampleSet, sin);
for (Attribute attribute : sinResult) {
exampleSet.getAttributes().addRegular(attribute);
}
}
}
}
}
}
示例13: spawnBaby
import java.util.Random; //导入方法依赖的package包/类
/**
* Spawns a baby animal of the same type.
*/
private void spawnBaby()
{
EntityAgeable entityageable = this.theAnimal.createChild(this.targetMate);
if (entityageable != null)
{
EntityPlayer entityplayer = this.theAnimal.getPlayerInLove();
if (entityplayer == null && this.targetMate.getPlayerInLove() != null)
{
entityplayer = this.targetMate.getPlayerInLove();
}
if (entityplayer != null)
{
entityplayer.triggerAchievement(StatList.animalsBredStat);
if (this.theAnimal instanceof EntityCow)
{
entityplayer.triggerAchievement(AchievementList.breedCow);
}
}
this.theAnimal.setGrowingAge(6000);
this.targetMate.setGrowingAge(6000);
this.theAnimal.resetInLove();
this.targetMate.resetInLove();
entityageable.setGrowingAge(-24000);
entityageable.setLocationAndAngles(this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, 0.0F, 0.0F);
this.theWorld.spawnEntityInWorld(entityageable);
Random random = this.theAnimal.getRNG();
for (int i = 0; i < 7; ++i)
{
double d0 = random.nextGaussian() * 0.02D;
double d1 = random.nextGaussian() * 0.02D;
double d2 = random.nextGaussian() * 0.02D;
double d3 = random.nextDouble() * (double)this.theAnimal.width * 2.0D - (double)this.theAnimal.width;
double d4 = 0.5D + random.nextDouble() * (double)this.theAnimal.height;
double d5 = random.nextDouble() * (double)this.theAnimal.width * 2.0D - (double)this.theAnimal.width;
this.theWorld.spawnParticle(EnumParticleTypes.HEART, this.theAnimal.posX + d3, this.theAnimal.posY + d4, this.theAnimal.posZ + d5, d0, d1, d2, new int[0]);
}
if (this.theWorld.getGameRules().getBoolean("doMobLoot"))
{
this.theWorld.spawnEntityInWorld(new EntityXPOrb(this.theWorld, this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, random.nextInt(7) + 1));
}
}
}
示例14: bench
import java.util.Random; //导入方法依赖的package包/类
public static void bench() {
Random r = new Random();
RandomFloat rf = new RandomFloat();
Stopwatch sw = new Stopwatch();
int nf;
float sum;
double rate;
for(int ntrial=0; ntrial<3; ++ntrial) {
System.out.println();
System.out.println("java.util.Random:");
sw.restart();
sum = 0.0f;
for(nf=0; sw.time()<1.0; ++nf)
sum += r.nextFloat();
sw.stop();
rate = nf/sw.time();
System.out.println(" uniform: float/s="+rate+" sum="+sum);
sw.restart();
sum = 0.0f;
for(nf=0; sw.time()<1.0; ++nf)
sum += (float)r.nextGaussian();
sw.stop();
rate = nf/sw.time();
System.out.println(" normal: float/s="+rate+" sum="+sum);
System.out.println();
System.out.println("edu.mines.jtk.util.RandomFloat:");
sw.restart();
sum = 0.0f;
for(nf=0; sw.time()<1.0; ++nf)
sum += rf.uniform();
sw.stop();
rate = nf/sw.time();
System.out.println(" uniform: float/s="+rate+" sum="+sum);
sw.restart();
sum = 0.0f;
for(nf=0; sw.time()<1.0; ++nf)
sum += rf.normal();
sw.stop();
rate = nf/sw.time();
System.out.println(" normal: float/s="+rate+" sum="+sum);
}
}
示例15: spawnBaby
import java.util.Random; //导入方法依赖的package包/类
/**
* Spawns a baby animal of the same type.
*/
private void spawnBaby()
{
EntityAgeable entityageable = this.theAnimal.createChild(this.targetMate);
final net.minecraftforge.event.entity.living.BabyEntitySpawnEvent event = new net.minecraftforge.event.entity.living.BabyEntitySpawnEvent(theAnimal, targetMate, entityageable);
final boolean cancelled = net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
entityageable = event.getChild();
if (cancelled) {
//Reset the "inLove" state for the animals
this.theAnimal.setGrowingAge(6000);
this.targetMate.setGrowingAge(6000);
this.theAnimal.resetInLove();
this.targetMate.resetInLove();
return;
}
if (entityageable != null)
{
EntityPlayer entityplayer = this.theAnimal.getPlayerInLove();
if (entityplayer == null && this.targetMate.getPlayerInLove() != null)
{
entityplayer = this.targetMate.getPlayerInLove();
}
if (entityplayer != null)
{
entityplayer.addStat(StatList.ANIMALS_BRED);
if (this.theAnimal instanceof EntityCow)
{
entityplayer.addStat(AchievementList.BREED_COW);
}
}
this.theAnimal.setGrowingAge(6000);
this.targetMate.setGrowingAge(6000);
this.theAnimal.resetInLove();
this.targetMate.resetInLove();
entityageable.setGrowingAge(-24000);
entityageable.setLocationAndAngles(this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, 0.0F, 0.0F);
this.theWorld.spawnEntityInWorld(entityageable);
Random random = this.theAnimal.getRNG();
for (int i = 0; i < 7; ++i)
{
double d0 = random.nextGaussian() * 0.02D;
double d1 = random.nextGaussian() * 0.02D;
double d2 = random.nextGaussian() * 0.02D;
double d3 = random.nextDouble() * (double)this.theAnimal.width * 2.0D - (double)this.theAnimal.width;
double d4 = 0.5D + random.nextDouble() * (double)this.theAnimal.height;
double d5 = random.nextDouble() * (double)this.theAnimal.width * 2.0D - (double)this.theAnimal.width;
this.theWorld.spawnParticle(EnumParticleTypes.HEART, this.theAnimal.posX + d3, this.theAnimal.posY + d4, this.theAnimal.posZ + d5, d0, d1, d2, new int[0]);
}
if (this.theWorld.getGameRules().getBoolean("doMobLoot"))
{
this.theWorld.spawnEntityInWorld(new EntityXPOrb(this.theWorld, this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, random.nextInt(7) + 1));
}
}
}