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


Java RealDistribution.sample方法代码示例

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


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

示例1: testPolynomialFit

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:SimpleCurveFitterTest.java

示例2: testFit

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:PolynomialFitterTest.java

示例3: testFit

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:PolynomialCurveFitterTest.java

示例4: getExponential

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public RandomNumberDistribution<Double> getExponential(
		final RandomNumberStream rng, final Number mean)
{
	final RealDistribution dist = new ExponentialDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			mean.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例5: getGamma

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public RandomNumberDistribution<Double> getGamma(
		final RandomNumberStream rng, final Number shape, final Number scale)
{
	final RealDistribution dist = new GammaDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			shape.doubleValue(), scale.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例6: getLevy

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public RandomNumberDistribution<Double> getLevy(
		final RandomNumberStream rng, final Number mu, final Number c)
{
	final RealDistribution dist = new LevyDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			mu.doubleValue(), c.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例7: getNormal

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public RandomNumberDistribution<Double> getNormal(
		final RandomNumberStream rng, final Number mean, final Number sd)
{
	final RealDistribution dist = new NormalDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			mean.doubleValue(), sd.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例8: getPareto

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
@Override
public RandomNumberDistribution<Double> getPareto(
		final RandomNumberStream rng, final Number scale, final Number shape)
{
	final RealDistribution dist = new ParetoDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			scale.doubleValue(), shape.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例9: getUniformReal

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的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();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例10: getSimulatedScores

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
public static List<List<Double>> getSimulatedScores(int[] n, List<RealDistribution> distributions){
	List<List<Double>> sample_sep=new ArrayList<List<Double>>();
	for(int i=0;i<n.length;i++){
		RealDistribution nd=distributions.get(i);
		List<Double> sample_curr=new ArrayList<Double>();
		for(double d:nd.sample(n[i])){
			sample_curr.add(d);
		}
		sample_sep.add(sample_curr);
	}
	return sample_sep;
}
 
开发者ID:boecker-lab,项目名称:passatuto,代码行数:13,代码来源:EMUtils.java

示例11: randomize

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * Adds some amount of random data to the given initializer.
 *
 * @param random Random variable distribution.
 * @param orig Original initializer.
 * @return an initializer whose {@link FeatureInitializer#value() value}
 * method will return {@code orig.value() + random.sample()}.
 */
public static FeatureInitializer randomize(final RealDistribution random,
                                           final FeatureInitializer orig) {
    return new FeatureInitializer() {
        /** {@inheritDoc} */
        public double value() {
            return orig.value() + random.sample();
        }
    };
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:FeatureInitializerFactory.java

示例12: generateSample

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * Generates a random sample of double values.
 * Sample size is random, between 10 and 100 and values are
 * uniformly distributed over [-100, 100].
 *
 * @return array of random double values
 */
private double[] generateSample() {
    final IntegerDistribution size = new UniformIntegerDistribution(10, 100);
    final RealDistribution randomData = new UniformRealDistribution(-100, 100);
    final int sampleSize = size.sample();
    final double[] out = randomData.sample(sampleSize);
    return out;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:15,代码来源:AggregateSummaryStatisticsTest.java

示例13: doDistributionTest

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
private void doDistributionTest(RealDistribution distribution) {
    double data[];

    data = distribution.sample(VERY_LARGE);
    doCalculatePercentile(50, data, 0.0001);
    doCalculatePercentile(95, data, 0.0001);

    data = distribution.sample(LARGE);
    doCalculatePercentile(50, data, 0.001);
    doCalculatePercentile(95, data, 0.001);

    data = distribution.sample(VERY_BIG);
    doCalculatePercentile(50, data, 0.001);
    doCalculatePercentile(95, data, 0.001);

    data = distribution.sample(BIG);
    doCalculatePercentile(50, data, 0.001);
    doCalculatePercentile(95, data, 0.001);

    data = distribution.sample(STANDARD);
    doCalculatePercentile(50, data, 0.005);
    doCalculatePercentile(95, data, 0.005);

    data = distribution.sample(MEDIUM);
    doCalculatePercentile(50, data, 0.005);
    doCalculatePercentile(95, data, 0.005);

    data = distribution.sample(NOMINAL);
    doCalculatePercentile(50, data, 0.01);
    doCalculatePercentile(95, data, 0.01);

    data = distribution.sample(SMALL);
    doCalculatePercentile(50, data, 0.01);
    doCalculatePercentile(95, data, 0.01);

    data = distribution.sample(TINY);
    doCalculatePercentile(50, data, 0.05);
    doCalculatePercentile(95, data, 0.05);

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

示例14: testPermutedArrayHash

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
/**
 * Make sure that permuted arrays do not hash to the same value.
 */
@Test
public void testPermutedArrayHash() {
    double[] original = new double[10];
    double[] permuted = new double[10];
    RandomDataGenerator random = new RandomDataGenerator();

    // Generate 10 distinct random values
    for (int i = 0; i < 10; i++) {
        final RealDistribution u = new UniformRealDistribution(i + 0.5, i + 0.75);
        original[i] = u.sample();
    }

    // Generate a random permutation, making sure it is not the identity
    boolean isIdentity = true;
    do {
        int[] permutation = random.nextPermutation(10, 10);
        for (int i = 0; i < 10; i++) {
            if (i != permutation[i]) {
                isIdentity = false;
            }
            permuted[i] = original[permutation[i]];
        }
    } while (isIdentity);

    // Verify that permuted array has different hash
    Assert.assertFalse(MathUtils.hash(original) == MathUtils.hash(permuted));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:31,代码来源:MathUtilsTest.java

示例15: substractDistributions

import org.apache.commons.math3.distribution.RealDistribution; //导入方法依赖的package包/类
private RealDistribution substractDistributions(RealDistribution left, RealDistribution right) {
	double[] leftSamples = left.sample(diffDistributionSampleCount);
	double[] rightSamples = left.sample(diffDistributionSampleCount);
	
	for (int i = 0; i < leftSamples.length; i++) {
		leftSamples[i] -= rightSamples[i];
	}
	
	return DistributionUtils.makeEmpirical(leftSamples);
}
 
开发者ID:D-iii-S,项目名称:spl-evaluation-java,代码行数:11,代码来源:DistributionLearningInterpretation.java


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