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


Java RandomGenerator类代码示例

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


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

示例1: testDifference

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Test if two clusters are significantly different in the metrics we look at for balancing.
 *
 * @param orig the utilization matrix from the original cluster
 * @param optimized the utilization matrix from the optimized cluster
 * @return The P value that the various derived resources come from the same probability distribution.  The probability
 * that the null hypothesis is correct.
 */
public static double[] testDifference(double[][] orig, double[][] optimized) {
  int nResources = RawAndDerivedResource.values().length;
  if (orig.length != nResources) {
    throw new IllegalArgumentException("orig must have number of rows equal to RawAndDerivedResource.");
  }
  if (optimized.length != nResources) {
    throw new IllegalArgumentException("optimized must have number of rows equal to RawAndDerivedResource.");
  }
  if (orig[0].length != optimized[0].length) {
    throw new IllegalArgumentException("The number of brokers must be the same.");
  }

  double[] pValues = new double[orig.length];

  //TODO:  For small N we want to do statistical bootstrapping (not the same as bootstrapping data).
  for (int resourceIndex = 0; resourceIndex < nResources; resourceIndex++) {
    RandomGenerator rng = new MersenneTwister(0x5d11121018463324L);
    KolmogorovSmirnovTest kolmogorovSmirnovTest = new KolmogorovSmirnovTest(rng);
    pValues[resourceIndex] =
        kolmogorovSmirnovTest.kolmogorovSmirnovTest(orig[resourceIndex], optimized[resourceIndex]);
  }

  return pValues;
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:33,代码来源:AnalyzerUtils.java

示例2: PercentageDistro

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
@SuppressWarnings("checkstyle:innerassignment")
public PercentageDistro(RandomGenerator rng, LinkedHashMap<Integer, Integer> chances) {
    super(rng);
    this.chances = chances;

    chances.keySet().stream().max(Comparator.comparing(i -> i)).ifPresent(maxInt -> upper = maxInt);
    chances.keySet().stream().min(Comparator.comparing(i -> i)).ifPresent(minInt -> lower = minInt);

    chances = chances.entrySet().stream().sorted(Map.Entry.comparingByKey())
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));

    Integer totalPercent = chances.entrySet().stream().mapToInt(Map.Entry::getValue).sum();

    if (totalPercent != PERCENT_100) {
        throw new RuntimeException("Need to have 100% allocated");
    }

}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:19,代码来源:PercentageDistro.java

示例3: generate

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  String largeID = ALSUtilsTest.idToStringID(100 + id);
  String smallID = ALSUtilsTest.idToStringID(1 + id);
  if (id < 5) {
    return new Pair<>(Integer.toString(id),
                      largeID + "," + smallID + ",1," + System.currentTimeMillis());
  } else if (id < 9){
    return new Pair<>(Integer.toString(id),
                      smallID + "," + largeID + ",1," + System.currentTimeMillis());
  } else {
    // Delete
    return new Pair<>(Integer.toString(id),
                      smallID + "," + largeID + ",," + System.currentTimeMillis());
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:17,代码来源:MockALSInputGenerator.java

示例4: generate

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  if (id % 10 == 0) {
    PMML pmml = PMMLUtils.buildSkeletonPMML();
    AppPMMLUtils.addExtension(pmml, "features", 2);
    AppPMMLUtils.addExtension(pmml, "implicit", true);
    AppPMMLUtils.addExtensionContent(pmml, "XIDs", X.keySet());
    AppPMMLUtils.addExtensionContent(pmml, "YIDs", Y.keySet());
    return new Pair<>("MODEL", PMMLUtils.toString(pmml));
  } else {
    int xOrYID = id % 10;
    String xOrYIDString = ALSUtilsTest.idToStringID(id);
    String message;
    boolean isX = xOrYID >= 6;
    if (isX) {
      message = TextUtils.joinJSON(Arrays.asList(
          "X", xOrYIDString, X.get(xOrYIDString), A.get(xOrYIDString)));
    } else {
      message = TextUtils.joinJSON(Arrays.asList(
          "Y", xOrYIDString, Y.get(xOrYIDString), At.get(xOrYIDString)));
    }
    return new Pair<>("UP", message);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:25,代码来源:MockALSModelUpdateGenerator.java

示例5: start

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
public void start() throws InterruptedException {
  RandomGenerator random = RandomManager.getRandom();

  Properties props = ConfigUtils.keyValueToProperties(
      "bootstrap.servers", "localhost:" + kafkaPort,
      "key.serializer", "org.apache.kafka.common.serialization.StringSerializer",
      "value.serializer", "org.apache.kafka.common.serialization.StringSerializer",
      "compression.type", "gzip",
      "batch.size", 0,
      "acks", 1,
      "max.request.size", 1 << 26 // TODO
  );
  try (Producer<String,String> producer = new KafkaProducer<>(props)) {
    for (int i = 0; i < howMany; i++) {
      Pair<String,String> datum = datumGenerator.generate(i, random);
      ProducerRecord<String,String> record =
          new ProducerRecord<>(topic, datum.getFirst(), datum.getSecond());
      producer.send(record);
      log.debug("Sent datum {} = {}", record.key(), record.value());
      if (intervalMsec > 0) {
        Thread.sleep(intervalMsec);
      }
    }
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:26,代码来源:ProduceData.java

示例6: test1

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
@Test
public void test1() {

	IFeatureCollection<IFeature> featColl = ShapefileReader
			.read(getClass().getClassLoader().getResource("parcelDecomposition/parcelle.shp").toString());

	IPolygon pol = (IPolygon) FromGeomToSurface.convertGeom(featColl.get(0).getGeom()).get(0);

	double maximalArea = 100;
	double maximalWidth = 20;
	RandomGenerator rng = new MersenneTwister(42);
	double epsilon = 0;
	double noise = 10;

	OBBBlockDecomposition obb = new OBBBlockDecomposition(pol, maximalArea, maximalWidth, rng, epsilon, noise);
	try {
		IFeatureCollection<IFeature> featCOut = obb.decompParcel();
		assertNotNull(featCOut);
		assertTrue(! featCOut.isEmpty());
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		assertTrue(false);
	}

}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:27,代码来源:TestOBBBlockDecomposition.java

示例7: create_sampler

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
public Sampler<GraphConfiguration<ColorPoint>, BirthDeathModification<ColorPoint>> create_sampler(Parameters p,
    RandomGenerator rndg,
    DirectSampler<ColorPoint, GraphConfiguration<ColorPoint>, BirthDeathModification<ColorPoint>> ds) {

  KernelFactory<ColorPoint, GraphConfiguration<ColorPoint>, BirthDeathModification<ColorPoint>> kf = new KernelFactory<>();
  List<Kernel<GraphConfiguration<ColorPoint>, BirthDeathModification<ColorPoint>>> kernels = new ArrayList<>();
  ColorPointBuilder cpb = new ColorPointBuilder();
  // TODO Put the components ranges in the parameters
  ColourPointLightnessShift mL = new ColourPointLightnessShift(100d);
  ColourPointChromaShift mc = new ColourPointChromaShift(100d);
  ColourPointHueShift mh = new ColourPointHueShift(360d);

  kernels.add(kf.make_uniform_modification_kernel(rndg, cpb, mL, 1., "L"));
  kernels.add(kf.make_uniform_modification_kernel(rndg, cpb, mc, 1., "C"));
  kernels.add(kf.make_uniform_modification_kernel(rndg, cpb, mh, 1., "H"));

  Acceptance<SimpleTemperature> acceptance = new MetropolisAcceptance<>();
  Sampler<GraphConfiguration<ColorPoint>, BirthDeathModification<ColorPoint>> sampler = new GreenSampler<>(rndg, ds,
      acceptance, kernels);
  return sampler;
}
 
开发者ID:IGNF,项目名称:geoxygene-palettes,代码行数:22,代码来源:Extrapalettor.java

示例8: FDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates an F distribution.
 *
 * @param rng Random number generator.
 * @param numeratorDegreesOfFreedom Numerator degrees of freedom.
 * @param denominatorDegreesOfFreedom Denominator degrees of freedom.
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates.
 * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} or
 * {@code denominatorDegreesOfFreedom <= 0}.
 * @since 3.1
 */
public FDistribution(RandomGenerator rng,
                     double numeratorDegreesOfFreedom,
                     double denominatorDegreesOfFreedom,
                     double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (numeratorDegreesOfFreedom <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
                                               numeratorDegreesOfFreedom);
    }
    if (denominatorDegreesOfFreedom <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
                                               denominatorDegreesOfFreedom);
    }
    this.numeratorDegreesOfFreedom = numeratorDegreesOfFreedom;
    this.denominatorDegreesOfFreedom = denominatorDegreesOfFreedom;
    solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:FDistribution.java

示例9: LogNormalDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates a log-normal distribution.
 *
 * @param rng Random number generator.
 * @param scale Scale parameter of this distribution.
 * @param shape Shape parameter of this distribution.
 * @param inverseCumAccuracy Inverse cumulative probability accuracy.
 * @throws NotStrictlyPositiveException if {@code shape <= 0}.
 * @since 3.1
 */
public LogNormalDistribution(RandomGenerator rng,
                             double scale,
                             double shape,
                             double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }

    this.scale = scale;
    this.shape = shape;
    this.logShapePlusHalfLog2Pi = FastMath.log(shape) + 0.5 * FastMath.log(2 * FastMath.PI);
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:LogNormalDistribution.java

示例10: ParetoDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates a Pareto distribution.
 *
 * @param rng Random number generator.
 * @param scale Scale parameter of this distribution.
 * @param shape Shape parameter of this distribution.
 * @param inverseCumAccuracy Inverse cumulative probability accuracy.
 * @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}.
 */
public ParetoDistribution(RandomGenerator rng,
                          double scale,
                          double shape,
                          double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (scale <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
    }

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }

    this.scale = scale;
    this.shape = shape;
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:ParetoDistribution.java

示例11: TDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates a t distribution.
 *
 * @param rng Random number generator.
 * @param degreesOfFreedom Degrees of freedom.
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates
 * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
 * @since 3.1
 */
public TDistribution(RandomGenerator rng,
                     double degreesOfFreedom,
                     double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (degreesOfFreedom <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
                                               degreesOfFreedom);
    }
    this.degreesOfFreedom = degreesOfFreedom;
    solverAbsoluteAccuracy = inverseCumAccuracy;

    final double n = degreesOfFreedom;
    final double nPlus1Over2 = (n + 1) / 2;
    factor = Gamma.logGamma(nPlus1Over2) -
             0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) -
             Gamma.logGamma(n / 2);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:TDistribution.java

示例12: EnumeratedIntegerDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Create a discrete integer-valued distribution from the input data.  Values are assigned
 * mass based on their frequency.
 *
 * @param rng random number generator used for sampling
 * @param data input dataset
 * @since 3.6
 */
public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] data) {
    super(rng);
    final Map<Integer, Integer> dataMap = new HashMap<Integer, Integer>();
    for (int value : data) {
        Integer count = dataMap.get(value);
        if (count == null) {
            count = 0;
        }
        dataMap.put(value, ++count);
    }
    final int massPoints = dataMap.size();
    final double denom = data.length;
    final int[] values = new int[massPoints];
    final double[] probabilities = new double[massPoints];
    int index = 0;
    for (Entry<Integer, Integer> entry : dataMap.entrySet()) {
        values[index] = entry.getKey();
        probabilities[index] = entry.getValue().intValue() / denom;
        index++;
    }
    innerDistribution = new EnumeratedDistribution<Integer>(rng, createDistribution(values, probabilities));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:EnumeratedIntegerDistribution.java

示例13: ZipfDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates a Zipf distribution.
 *
 * @param rng Random number generator.
 * @param numberOfElements Number of elements.
 * @param exponent Exponent.
 * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0}
 * or {@code exponent <= 0}.
 * @since 3.1
 */
public ZipfDistribution(RandomGenerator rng,
                        int numberOfElements,
                        double exponent)
    throws NotStrictlyPositiveException {
    super(rng);

    if (numberOfElements <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION,
                                               numberOfElements);
    }
    if (exponent <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.EXPONENT,
                                               exponent);
    }

    this.numberOfElements = numberOfElements;
    this.exponent = exponent;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:ZipfDistribution.java

示例14: BinomialDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Creates a binomial distribution.
 *
 * @param rng Random number generator.
 * @param trials Number of trials.
 * @param p Probability of success.
 * @throws NotPositiveException if {@code trials < 0}.
 * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
 * @since 3.1
 */
public BinomialDistribution(RandomGenerator rng,
                            int trials,
                            double p) {
    super(rng);

    if (trials < 0) {
        throw new NotPositiveException(LocalizedFormats.NUMBER_OF_TRIALS,
                                       trials);
    }
    if (p < 0 || p > 1) {
        throw new OutOfRangeException(p, 0, 1);
    }

    probabilityOfSuccess = p;
    numberOfTrials = trials;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:27,代码来源:BinomialDistribution.java

示例15: EnumeratedRealDistribution

import org.apache.commons.math3.random.RandomGenerator; //导入依赖的package包/类
/**
 * Create a discrete real-valued distribution from the input data.  Values are assigned
 * mass based on their frequency.
 *
 * @param rng random number generator used for sampling
 * @param data input dataset
 * @since 3.6
 */
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) {
    super(rng);
    final Map<Double, Integer> dataMap = new HashMap<Double, Integer>();
    for (double value : data) {
        Integer count = dataMap.get(value);
        if (count == null) {
            count = 0;
        }
        dataMap.put(value, ++count);
    }
    final int massPoints = dataMap.size();
    final double denom = data.length;
    final double[] values = new double[massPoints];
    final double[] probabilities = new double[massPoints];
    int index = 0;
    for (Entry<Double, Integer> entry : dataMap.entrySet()) {
        values[index] = entry.getKey();
        probabilities[index] = entry.getValue().intValue() / denom;
        index++;
    }
    innerDistribution = new EnumeratedDistribution<Double>(rng, createDistribution(values, probabilities));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:EnumeratedRealDistribution.java


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