本文整理汇总了Java中org.apache.commons.math3.distribution.UniformRealDistribution类的典型用法代码示例。如果您正苦于以下问题:Java UniformRealDistribution类的具体用法?Java UniformRealDistribution怎么用?Java UniformRealDistribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UniformRealDistribution类属于org.apache.commons.math3.distribution包,在下文中一共展示了UniformRealDistribution类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPolynomialFit
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
@Test
public void testPolynomialFit() {
final Random randomizer = new Random(53882150042L);
final RealDistribution rng = new UniformRealDistribution(-100, 100);
rng.reseedRandomGenerator(64925784252L);
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
final PolynomialFunction f = new PolynomialFunction(coeff);
// Collect data from a known polynomial.
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < 100; i++) {
final double x = rng.sample();
obs.add(x, f.value(x) + 0.1 * randomizer.nextGaussian());
}
final ParametricUnivariateFunction function = new PolynomialFunction.Parametric();
// Start fit from initial guesses that are far from the optimal values.
final SimpleCurveFitter fitter
= SimpleCurveFitter.create(function,
new double[] { -1e20, 3e15, -5e25 });
final double[] best = fitter.fit(obs.toList());
TestUtils.assertEquals("best != coeff", coeff, best, 2e-2);
}
示例2: RandomCirclePointGenerator
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
/**
* @param x Abscissa of the circle center.
* @param y Ordinate of the circle center.
* @param radius Radius of the circle.
* @param xSigma Error on the x-coordinate of the circumference points.
* @param ySigma Error on the y-coordinate of the circumference points.
* @param seed RNG seed.
*/
public RandomCirclePointGenerator(double x,
double y,
double radius,
double xSigma,
double ySigma,
long seed) {
final RandomGenerator rng = new Well44497b(seed);
this.radius = radius;
cX = new NormalDistribution(rng, x, xSigma,
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
cY = new NormalDistribution(rng, y, ySigma,
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
tP = new UniformRealDistribution(rng, 0, MathUtils.TWO_PI,
UniformRealDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
示例3: testFit
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
@Test
public void testFit() {
final RealDistribution rng = new UniformRealDistribution(-100, 100);
rng.reseedRandomGenerator(64925784252L);
final LevenbergMarquardtOptimizer optim = new LevenbergMarquardtOptimizer();
final PolynomialFitter fitter = new PolynomialFitter(optim);
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
final PolynomialFunction f = new PolynomialFunction(coeff);
// Collect data from a known polynomial.
for (int i = 0; i < 100; i++) {
final double x = rng.sample();
fitter.addObservedPoint(x, f.value(x));
}
// Start fit from initial guesses that are far from the optimal values.
final double[] best = fitter.fit(new double[] { -1e-20, 3e15, -5e25 });
TestUtils.assertEquals("best != coeff", coeff, best, 1e-12);
}
示例4: testFit
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
@Test
public void testFit() {
final RealDistribution rng = new UniformRealDistribution(-100, 100);
rng.reseedRandomGenerator(64925784252L);
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
final PolynomialFunction f = new PolynomialFunction(coeff);
// Collect data from a known polynomial.
final WeightedObservedPoints obs = new WeightedObservedPoints();
for (int i = 0; i < 100; i++) {
final double x = rng.sample();
obs.add(x, f.value(x));
}
// Start fit from initial guesses that are far from the optimal values.
final PolynomialCurveFitter fitter
= PolynomialCurveFitter.create(0).withStartPoint(new double[] { -1e-20, 3e15, -5e25 });
final double[] best = fitter.fit(obs.toList());
TestUtils.assertEquals("best != coeff", coeff, best, 1e-12);
}
示例5: makeInitializers
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
/**
* Creates the features' initializers: an approximate circle around the
* barycentre of the cities.
*
* @return an array containing the two initializers.
*/
private FeatureInitializer[] makeInitializers() {
// Barycentre.
final double[] centre = barycentre(cities);
// Largest distance from centre.
final double radius = 0.5 * largestDistance(centre[0], centre[1], cities);
final double omega = 2 * Math.PI / numberOfNeurons;
final UnivariateFunction h1 = new HarmonicOscillator(radius, omega, 0);
final UnivariateFunction h2 = new HarmonicOscillator(radius, omega, 0.5 * Math.PI);
final UnivariateFunction f1 = FunctionUtils.add(h1, new Constant(centre[0]));
final UnivariateFunction f2 = FunctionUtils.add(h2, new Constant(centre[1]));
final RealDistribution u
= new UniformRealDistribution(random, -0.05 * radius, 0.05 * radius);
return new FeatureInitializer[] {
FeatureInitializerFactory.randomize(u, FeatureInitializerFactory.function(f1, 0, 1)),
FeatureInitializerFactory.randomize(u, FeatureInitializerFactory.function(f2, 0, 1))
};
}
示例6: getUniformReal
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Double> getUniformReal(
final RandomNumberStream rng, final Number lower, final Number upper)
{
final RealDistribution dist = new UniformRealDistribution(
RandomNumberStream.Util.asCommonsRandomGenerator(rng),
lower.doubleValue(), upper.doubleValue());
return new RandomNumberDistribution<Double>()
{
@Override
public Double draw()
{
return dist.sample();
}
};
}
示例7: testAssignement
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
@Test
public void testAssignement()
{
int dc = 10;
int hs = 20;
UniformRealDistribution urd = new UniformRealDistribution(0, 1);
int[] dist = DistributionAssignment.getAssignmentArray(dc, hs, urd);
// check the length of the returned array
Assert.assertEquals(dc, dist.length);
int sum = 0;
for (int i=0; i<dist.length; i++)
sum += dist[i];
Assert.assertEquals(hs, sum);
}
示例8: BM
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
public BM(int numClusters, int dimension, long randomSeed) {
this.numClusters = numClusters;
this.dimension = dimension;
this.distributions = new BernoulliDistribution[numClusters][dimension];
this.mixtureCoefficients = new double[numClusters];
Arrays.fill(mixtureCoefficients,1.0/numClusters);
this.logMixtureCoefficients = new double[numClusters];
Arrays.fill(logMixtureCoefficients,Math.log(1.0/numClusters));
Random random = new Random(randomSeed);
RandomGenerator randomGenerator = RandomGeneratorFactory.createRandomGenerator(random);
UniformRealDistribution uniform = new UniformRealDistribution(randomGenerator, 0.25,0.75);
for (int k=0;k<numClusters;k++){
for (int d=0;d<dimension;d++){
double p = uniform.sample();
distributions[k][d] = new BernoulliDistribution(p);
}
}
this.logClusterConditioinalForEmpty = new double[numClusters];
updateLogClusterConditioinalForEmpty();
this.names = new ArrayList<>(dimension);
for (int d=0;d<dimension;d++){
names.add(""+d);
}
}
示例9: genUniform
import org.apache.commons.math3.distribution.UniformRealDistribution; //导入依赖的package包/类
private static List<Double> genUniform(DoubleGenerator dg, int size) {
UniformRealDistribution ud = new UniformRealDistribution(dg.start, dg.end);
List<Double> output = new ArrayList<>(size);
for (int i = 0; i < size; ++i) {
output.add(ud.sample());
}
return output;
}