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


Java RandomGenerator.nextDouble方法代码示例

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


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

示例1: inputBroadcast

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public void inputBroadcast( RandomGenerator r , 
		CarmaSystem system,
		CarmaComponent sender, 
		int action, 
		CarmaPredicate predicate,
		Object value ) {
	if (predicate.satisfy(system.now(),store)) {
		WeightedStructure<Activity> enabledInputs = new ComposedWeightedStructure<Activity>();
		double missingProbability = 1.0;
		for (CarmaProcess p : processes) {//TODO: fix this!
			WeightedStructure<Activity> foo = p.doReceiveBroadcast(system, sender.store , action, value );
			missingProbability = missingProbability*(1-foo.getTotalWeight());
			enabledInputs = enabledInputs.add(foo);
		}
		double select = r.nextDouble()*(enabledInputs.getTotalWeight()+missingProbability);
		if (select<enabledInputs.getTotalWeight()) {
			enabledInputs.select(select).getElement().execute(r);
		} 
	}
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:CarmaComponent.java

示例2: testRandom

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testRandom() {
    final RandomGenerator random = new Well1024a(0xd015982e9f31ee04l);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        List<Vector3D> support = new ArrayList<Vector3D>();
        for (int j = 0; j < 5; ++j) {
            support.add(new Vector3D(1.0, refCenter, refRadius, new Vector3D(sr.nextVector())));
        }
        EnclosingBall<Euclidean3D, Vector3D> sphere = new SphereGenerator().ballOnSupport(support);
        Assert.assertEquals(0.0, refCenter.distance(sphere.getCenter()), 4e-7 * refRadius);
        Assert.assertEquals(refRadius, sphere.getRadius(), 1e-7 * refRadius);
    }
    
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:SphereGeneratorTest.java

示例3: testRandom

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testRandom() {
    final RandomGenerator random = new Well1024a(0x12faa818373ffe90l);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(2, random);
    for (int i = 0; i < 500; ++i) {
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector2D refCenter = new Vector2D(d, new Vector2D(sr.nextVector()));
        List<Vector2D> support = new ArrayList<Vector2D>();
        for (int j = 0; j < 3; ++j) {
            support.add(new Vector2D(1.0, refCenter, refRadius, new Vector2D(sr.nextVector())));
        }
        EnclosingBall<Euclidean2D, Vector2D> disk = new DiskGenerator().ballOnSupport(support);
        Assert.assertEquals(0.0, refCenter.distance(disk.getCenter()), 3e-9 * refRadius);
        Assert.assertEquals(refRadius, disk.getRadius(), 7e-10 * refRadius);
    }
    
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:DiskGeneratorTest.java

示例4: generateAllelicCount

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
protected static AllelicCount generateAllelicCount(final double minorFraction, final SimpleInterval position,
                                                   final RandomGenerator rng, final GammaDistribution biasGenerator, final double outlierProbability) {
    final int numReads = 100;
    final double bias = biasGenerator.sample();

    //flip a coin to decide alt minor (alt fraction = minor fraction) or ref minor (alt fraction = 1 - minor fraction)
    final double altFraction =  rng.nextDouble() < 0.5 ? minorFraction : 1 - minorFraction;

    //the probability of an alt read is the alt fraction modified by the bias or, in the case of an outlier, random
    final double pAlt = rng.nextDouble() < outlierProbability ? rng.nextDouble()
            : altFraction / (altFraction + (1 - altFraction) * bias);

    final int numAltReads = new BinomialDistribution(rng, numReads, pAlt).sample();
    final int numRefReads = numReads - numAltReads;
    return new AllelicCount(position, numAltReads, numRefReads);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:17,代码来源:AlleleFractionSegmenterUnitTest.java

示例5: chooseEndpoint

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
Endpoint chooseEndpoint(RandomGenerator random) {
  double p = random.nextDouble();
  int i = 0;
  while (i < cumulativeProbs.length && p >= cumulativeProbs[i]) {
    i++;
  }
  return endpoints[i];
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:9,代码来源:Endpoints.java

示例6: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  List<String> elements = new ArrayList<>(numberOfDimensions);
  for (int i = 0; i < numberOfDimensions; i++) {
    double d = random.nextDouble();
    elements.add(Double.toString(d));
  }
  return new Pair<>(Integer.toString(id), TextUtils.joinDelimited(elements, ','));
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:10,代码来源:RandomKMeansDataGenerator.java

示例7: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  List<String> elements = new ArrayList<>(n + 2);
  elements.add(Integer.toString(id));
  boolean positive = true;
  for (int i = 0; i < n; i++) {
    double d = random.nextDouble();
    if (d < 0.5) {
      positive = false;
    }
    elements.add(Double.toString(d));
  }
  elements.add(Boolean.toString(positive));
  return new Pair<>(Integer.toString(id), TextUtils.joinDelimited(elements, ','));
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:16,代码来源:RandomCategoricalRDFDataGenerator.java

示例8: generate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public Pair<String, String> generate(int id, RandomGenerator random) {
  boolean positive = id % 2 != 0;
  String target = positive ? "banana" : "apple";
  // 10% chance of wrong predictor
  String predictor = (positive ^ (random.nextDouble() < 0.1)) ? "yellow" : "red";
  return new Pair<>(null, predictor + "," + target);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:9,代码来源:MockRDFClassificationInputGenerator.java

示例9: testRandomState

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Ignore
@Test
public void testRandomState() {
  RandomGenerator generator = RandomManager.getRandom();
  double unseededValue = generator.nextDouble();
  RandomManager.useTestSeed();
  double seededValue = generator.nextDouble();
  assertNotEquals(unseededValue, seededValue);
  assertEquals(seededValue, RandomManager.getRandom().nextDouble());
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:11,代码来源:RandomManagerRandomTest.java

示例10: binomial

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Generates a binomial distributed number using
 * the given rng
 *
 * @param rng
 * @param n
 * @param p
 * @return
 */
public static int binomial(RandomGenerator rng, int n, double p) {
    if ((p < 0) || (p > 1)) {
        return 0;
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (rng.nextDouble() < p) {
            c++;
        }
    }
    return c;
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:22,代码来源:MathUtils.java

示例11: mate

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Helper for {@link #crossover(Chromosome, Chromosome)}. Performs the actual crossover.
 *
 * @param first the first chromosome
 * @param second the second chromosome
 * @return the pair of new chromosomes that resulted from the crossover
 * @throws DimensionMismatchException if the length of the two chromosomes is different
 */
private ChromosomePair mate(final AbstractListChromosome<T> first,
                            final AbstractListChromosome<T> second) throws DimensionMismatchException {
    final int length = first.getLength();
    if (length != second.getLength()) {
        throw new DimensionMismatchException(second.getLength(), length);
    }

    // array representations of the parents
    final List<T> parent1Rep = first.getRepresentation();
    final List<T> parent2Rep = second.getRepresentation();
    // and of the children
    final List<T> child1Rep = new ArrayList<T>(length);
    final List<T> child2Rep = new ArrayList<T>(length);

    final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();

    for (int index = 0; index < length; index++) {

        if (random.nextDouble() < ratio) {
            // swap the bits -> take other parent
            child1Rep.add(parent2Rep.get(index));
            child2Rep.add(parent1Rep.get(index));
        } else {
            child1Rep.add(parent1Rep.get(index));
            child2Rep.add(parent2Rep.get(index));
        }
    }

    return new ChromosomePair(first.newFixedLengthChromosome(child1Rep),
                              second.newFixedLengthChromosome(child2Rep));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:40,代码来源:UniformCrossover.java

示例12: algorithmBB

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
 * Returns one sample using Cheng's BB algorithm, when both &alpha; and &beta; are greater than 1.
 * @param random random generator to use
 * @param a0 distribution first shape parameter (&alpha;)
 * @param a min(&alpha;, &beta;) where &alpha;, &beta; are the two distribution shape parameters
 * @param b max(&alpha;, &beta;) where &alpha;, &beta; are the two distribution shape parameters
 * @return sampled value
 */
private static double algorithmBB(RandomGenerator random,
                                  final double a0,
                                  final double a,
                                  final double b) {
    final double alpha = a + b;
    final double beta = FastMath.sqrt((alpha - 2.) / (2. * a * b - alpha));
    final double gamma = a + 1. / beta;

    double r;
    double w;
    double t;
    do {
        final double u1 = random.nextDouble();
        final double u2 = random.nextDouble();
        final double v = beta * (FastMath.log(u1) - FastMath.log1p(-u1));
        w = a * FastMath.exp(v);
        final double z = u1 * u1 * u2;
        r = gamma * v - 1.3862944;
        final double s = a + r - w;
        if (s + 2.609438 >= 5 * z) {
            break;
        }

        t = FastMath.log(z);
        if (s >= t) {
            break;
        }
    } while (r + alpha * (FastMath.log(alpha) - FastMath.log(b + w)) < t);

    w = FastMath.min(w, Double.MAX_VALUE);
    return Precision.equals(a, a0) ? w / (b + w) : b / (b + w);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:41,代码来源:BetaDistribution.java

示例13: sample

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public double sample(final RandomGenerator rng, final Function<Double, Double> logPDF) {
    Utils.nonNull(rng);
    Utils.nonNull(logPDF);
    final AbstractRealDistribution normal = new NormalDistribution(rng, 0, 1);
    final double proposal = xCurrent + stepSize * normal.sample();
    final double acceptanceProbability = (proposal < lowerBound || upperBound < proposal) ? 0
            : Math.min(1, Math.exp(logPDF.apply(proposal) - logPDF.apply(xCurrent)));

    //adjust stepSize larger/smaller to decrease/increase the acceptance rate
    final double correctionFactor = (acceptanceProbability - optimalAcceptanceRate) * adjustmentRate * (timeScale / (timeScale + iteration));
    stepSize *= Math.exp(correctionFactor);
    iteration++;
    return rng.nextDouble() < acceptanceProbability ? proposal : xCurrent;
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:15,代码来源:AdaptiveMetropolisSampler.java

示例14: makeBlobs

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd,
                                       double min, double max, boolean shuffle, RandomGenerator random) {

    NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9);

    double range = max - min;
    Vector2D[] centerPoints = new Vector2D[centers];
    for (int i = 0; i < centers; i++) {
        double x = random.nextDouble() * range + min;
        double y = random.nextDouble() * range + min;
        centerPoints[i] = new Vector2D(x, y);
    }
    
    int[] nSamplesPerCenter = new int[centers];
    int count = samples / centers;
    Arrays.fill(nSamplesPerCenter, count);
    
    for (int i = 0; i < samples % centers; i++) {
        nSamplesPerCenter[i]++;
    }
    
    List<Vector2D> points = new ArrayList<Vector2D>();
    for (int i = 0; i < centers; i++) {
        for (int j = 0; j < nSamplesPerCenter[i]; j++) {
            Vector2D point = new Vector2D(dist.sample(), dist.sample());
            points.add(point.add(centerPoints[i]));
        }
    }
    
    if (shuffle) {
        Collections.shuffle(points, new RandomAdaptor(random));
    }

    return points;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:36,代码来源:ClusterAlgorithmComparison.java

示例15: testTransform

import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Test
public void testTransform() {
    RandomGenerator random = new Well1024a(0x16992fc4294bf2f1l);
    UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {

        Rotation r = new Rotation(new Vector3D(sphRandom.nextVector()),
                                  FastMath.PI * random.nextDouble());
        Transform<Sphere2D, Sphere1D> t = Circle.getTransform(r);

        S2Point  p = new S2Point(new Vector3D(sphRandom.nextVector()));
        S2Point tp = (S2Point) t.apply(p);
        Assert.assertEquals(0.0, r.applyTo(p.getVector()).distance(tp.getVector()), 1.0e-10);

        Circle  c = new Circle(new Vector3D(sphRandom.nextVector()), 1.0e-10);
        Circle tc = (Circle) t.apply(c);
        Assert.assertEquals(0.0, r.applyTo(c.getPole()).distance(tc.getPole()),   1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getXAxis()).distance(tc.getXAxis()), 1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getYAxis()).distance(tc.getYAxis()), 1.0e-10);
        Assert.assertEquals(c.getTolerance(), ((Circle) t.apply(c)).getTolerance(), 1.0e-10);

        SubLimitAngle  sub = new LimitAngle(new S1Point(MathUtils.TWO_PI * random.nextDouble()),
                                            random.nextBoolean(), 1.0e-10).wholeHyperplane();
        Vector3D psub = c.getPointAt(((LimitAngle) sub.getHyperplane()).getLocation().getAlpha());
        SubLimitAngle tsub = (SubLimitAngle) t.apply(sub, c, tc);
        Vector3D ptsub = tc.getPointAt(((LimitAngle) tsub.getHyperplane()).getLocation().getAlpha());
        Assert.assertEquals(0.0, r.applyTo(psub).distance(ptsub), 1.0e-10);

    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:31,代码来源:CircleTest.java


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