當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。