本文整理匯總了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;
}
示例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");
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}