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


Java RealDistribution类代码示例

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


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

示例1: mainTest

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
public static void mainTest() throws Exception{
	int maxIterations=10000;

	List<List<Double>> sample_sep=EMUtils.getSimulatedScores(new int[]{1000,2000},Arrays.asList(new RealDistribution[]{
			new BetaDistribution(2,2),
			new BetaDistribution(5,1)
	}));

	//		List<List<Double>> sample_sep=EMUtils.getSimulatedScores(new int[]{1000,2000},Arrays.asList(new RealDistribution[]{
	//				new GammaDistribution(2,2),
	//				new GammaDistribution(7.5,1)
	//		}));
	List<Double> values=new ArrayList<Double>();
	List<InterfaceMLDistribution> distributions=new ArrayList<InterfaceMLDistribution>();
	for(List<Double> s:sample_sep){
		values.addAll(s);			
		distributions.add(new MLBetaDistribution(false, 0));
		//			distributions.add(new MLGammaDistribution(false, 0));
	}

	Sample sample=new Sample(values, null, null);
	//		EM em=new EM(sample, distributions, maxIterations, minChangeLikelihood);
	EM em=new EM(sample, distributions, maxIterations, Double.NEGATIVE_INFINITY);
	EMResult r=em.doEM(true);
	System.out.println(r.likelihood);
}
 
开发者ID:boecker-lab,项目名称:passatuto,代码行数:27,代码来源:EMMain.java

示例2: test

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
public void test(RealRng rng, RealDistribution distribution) {
    SequenceTransformer[] transformers = SequenceTransformer.values();

    try {
        for (TestStatistic testStatistic : Collections.singleton(TestStatistic.ANDERSON_DARLING)) {
            Map<SequenceTransformer, Double> result = runTwoLevelTest(rng, distribution, testStatistic, transformers);

            for (SequenceTransformer transformer : transformers) {
                assertThat(result, hasEntry(is(transformer), greaterThanOrEqualTo(0.001)));
            }

        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:komiya-atsushi,项目名称:fast-rng-java,代码行数:17,代码来源:TwoLevelTester.java

示例3: kolmogorovSmirnovStatistic

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
/**
 * Computes the one-sample Kolmogorov-Smirnov test statistic, \(D_n=\sup_x |F_n(x)-F(x)|\) where
 * \(F\) is the distribution (cdf) function associated with {@code distribution}, \(n\) is the
 * length of {@code data} and \(F_n\) is the empirical distribution that puts mass \(1/n\) at
 * each of the values in {@code data}.
 *
 * @param distribution reference distribution
 * @param data sample being evaluated
 * @return Kolmogorov-Smirnov statistic \(D_n\)
 * @throws InsufficientDataException if {@code data} does not have length at least 2
 * @throws NullArgumentException if {@code data} is null
 */
public double kolmogorovSmirnovStatistic(RealDistribution distribution, double[] data) {
    checkArray(data);
    final int n = data.length;
    final double nd = n;
    final double[] dataCopy = new double[n];
    System.arraycopy(data, 0, dataCopy, 0, n);
    Arrays.sort(dataCopy);
    double d = 0d;
    for (int i = 1; i <= n; i++) {
        final double yi = distribution.cumulativeProbability(dataCopy[i - 1]);
        final double currD = FastMath.max(yi - (i - 1) / nd, i / nd - yi);
        if (currD > d) {
            d = currD;
        }
    }
    return d;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:KolmogorovSmirnovTest.java

示例4: cumulativeProbability

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>Algorithm description:<ol>
 * <li>Find the bin B that x belongs to.</li>
 * <li>Compute P(B) = the mass of B and P(B-) = the combined mass of the bins below B.</li>
 * <li>Compute K(B) = the probability mass of B with respect to the within-bin kernel
 * and K(B-) = the kernel distribution evaluated at the lower endpoint of B</li>
 * <li>Return P(B-) + P(B) * [K(x) - K(B-)] / K(B) where
 * K(x) is the within-bin kernel distribution function evaluated at x.</li></ol>
 * If K is a constant distribution, we return P(B-) + P(B) (counting the full
 * mass of B).</p>
 *
 * @since 3.1
 */
public double cumulativeProbability(double x) {
    if (x < min) {
        return 0d;
    } else if (x >= max) {
        return 1d;
    }
    final int binIndex = findBin(x);
    final double pBminus = pBminus(binIndex);
    final double pB = pB(binIndex);
    final RealDistribution kernel = k(x);
    if (kernel instanceof ConstantRealDistribution) {
        if (x < kernel.getNumericalMean()) {
            return pBminus;
        } else {
            return pBminus + pB;
        }
    }
    final double[] binBounds = getUpperBounds();
    final double kB = kB(binIndex);
    final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];
    final double withinBinCum =
        (kernel.cumulativeProbability(x) -  kernel.cumulativeProbability(lower)) / kB;
    return pBminus + pB * withinBinCum;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:40,代码来源:EmpiricalDistribution.java

示例5: cumulativeProbability

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>Algorithm description:<ol>
 * <li>Find the bin B that x belongs to.</li>
 * <li>Compute P(B) = the mass of B and P(B-) = the combined mass of the bins below B.</li>
 * <li>Compute K(B) = the probability mass of B with respect to the within-bin kernel
 * and K(B-) = the kernel distribution evaluated at the lower endpoint of B</li>
 * <li>Return P(B-) + P(B) * [K(x) - K(B-)] / K(B) where
 * K(x) is the within-bin kernel distribution function evaluated at x.</li></ol></p>
 *
 * @since 3.1
 */
public double cumulativeProbability(double x) {
    if (x < min) {
        return 0d;
    } else if (x >= max) {
        return 1d;
    }
    final int binIndex = findBin(x);
    final double pBminus = pBminus(binIndex);
    final double pB = pB(binIndex);
    final double[] binBounds = getUpperBounds();
    final double kB = kB(binIndex);
    final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];
    final RealDistribution kernel = k(x);
    final double withinBinCum =
        (kernel.cumulativeProbability(x) -  kernel.cumulativeProbability(lower)) / kB;
    return pBminus + pB * withinBinCum;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:31,代码来源:EmpiricalDistribution.java

示例6: addPDFSeries

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
public static void addPDFSeries(Chart chart, RealDistribution distribution, String desc, int lowerBound, int upperBound) {
    // generates Log data
    List<Number> xData = new ArrayList<Number>();
    List<Number> yData = new ArrayList<Number>();
    int samples = 100;
    double stepSize = (upperBound - lowerBound) / (double) samples;
    for (double x = lowerBound; x <= upperBound; x += stepSize) {
        try {
            double density = distribution.density(x);
            if (! Double.isInfinite(density) && ! Double.isNaN(density)) {
                xData.add(x);
                yData.add(density);
            }
        } catch (Exception e) {
            // ignore
            // some distributions may reject certain values depending on the parameter settings
        }
    }

    Series series = chart.addSeries(desc, xData, yData);
    series.setMarker(SeriesMarker.NONE);
    series.setLineStyle(new BasicStroke(1.2f));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:RealDistributionComparison.java

示例7: addCDFSeries

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
public static void addCDFSeries(Chart chart, RealDistribution distribution, String desc, int lowerBound, int upperBound) {
    // generates Log data
    List<Number> xData = new ArrayList<Number>();
    List<Number> yData = new ArrayList<Number>();
    int samples = 100;
    double stepSize = (upperBound - lowerBound) / (double) samples;
    for (double x = lowerBound; x <= upperBound; x += stepSize) {
      double density = distribution.cumulativeProbability(x);
      if (! Double.isInfinite(density) && ! Double.isNaN(density)) {
          xData.add(x);
          yData.add(density);
      }
    }

    Series series = chart.addSeries(desc, xData, yData);
    series.setMarker(SeriesMarker.NONE);
    series.setLineStyle(new BasicStroke(1.2f));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:RealDistributionComparison.java

示例8: 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

示例9: 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

示例10: 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

示例11: makeInitializers

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

示例12: makeCumulativeTestValues

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
@Override
public double[] makeCumulativeTestValues() {
    /* 
     * Bins should be [0, 10], (10, 20], ..., (9990, 10000]
     * Kernels should be N(4.5, 3.02765), N(14.5, 3.02765)...
     * Each bin should have mass 10/10000 = .001
     */
    final double[] testPoints = getCumulativeTestPoints();
    final double[] cumValues = new double[testPoints.length];
    final EmpiricalDistribution empiricalDistribution = (EmpiricalDistribution) makeDistribution();
    final double[] binBounds = empiricalDistribution.getUpperBounds();
    for (int i = 0; i < testPoints.length; i++) {
        final int bin = findBin(testPoints[i]);
        final double lower = bin == 0 ? empiricalDistribution.getSupportLowerBound() :
            binBounds[bin - 1];
        final double upper = binBounds[bin];
        // Compute bMinus = sum or mass of bins below the bin containing the point
        // First bin has mass 11 / 10000, the rest have mass 10 / 10000.
        final double bMinus = bin == 0 ? 0 : (bin - 1) * binMass + firstBinMass;
        final RealDistribution kernel = findKernel(lower, upper);
        final double withinBinKernelMass = kernel.cumulativeProbability(lower, upper);
        final double kernelCum = kernel.cumulativeProbability(lower, testPoints[i]);
        cumValues[i] = bMinus + (bin == 0 ? firstBinMass : binMass) * kernelCum/withinBinKernelMass;
    }
    return cumValues;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:EmpiricalDistributionTest.java

示例13: makeDensityTestValues

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
@Override
public double[] makeDensityTestValues() {
    final double[] testPoints = getCumulativeTestPoints();
    final double[] densityValues = new double[testPoints.length];
    final EmpiricalDistribution empiricalDistribution = (EmpiricalDistribution) makeDistribution();
    final double[] binBounds = empiricalDistribution.getUpperBounds();
    for (int i = 0; i < testPoints.length; i++) {
        final int bin = findBin(testPoints[i]);
        final double lower = bin == 0 ? empiricalDistribution.getSupportLowerBound() :
            binBounds[bin - 1];
        final double upper = binBounds[bin];
        final RealDistribution kernel = findKernel(lower, upper);
        final double withinBinKernelMass = kernel.cumulativeProbability(lower, upper);
        final double density = kernel.density(testPoints[i]);
        densityValues[i] = density * (bin == 0 ? firstBinMass : binMass) / withinBinKernelMass;   
    }
    return densityValues;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:EmpiricalDistributionTest.java

示例14: testDensityIntegrals

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
/** 
 * Modify test integration bounds from the default. Because the distribution
 * has discontinuities at bin boundaries, integrals spanning multiple bins
 * will face convergence problems.  Only test within-bin integrals and spans
 * across no more than 3 bin boundaries.
 */
@Override
@Test
public void testDensityIntegrals() {
    final RealDistribution distribution = makeDistribution();
    final double tol = 1.0e-9;
    final BaseAbstractUnivariateIntegrator integrator =
        new IterativeLegendreGaussIntegrator(5, 1.0e-12, 1.0e-10);
    final UnivariateFunction d = new UnivariateFunction() {
        public double value(double x) {
            return distribution.density(x);
        }
    };
    final double[] lower = {0, 5, 1000, 5001, 9995};
    final double[] upper = {5, 12, 1030, 5010, 10000};
    for (int i = 1; i < 5; i++) {
        Assert.assertEquals(
                distribution.cumulativeProbability( 
                        lower[i], upper[i]),
                        integrator.integrate(
                                1000000, // Triangle integrals are very slow to converge
                                d, lower[i], upper[i]), tol);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:30,代码来源:EmpiricalDistributionTest.java

示例15: boostrapEmpirical

import org.apache.commons.math3.distribution.RealDistribution; //导入依赖的package包/类
private RealDistribution boostrapEmpirical(DataSnapshot data, double shift) {
	List<BenchmarkRun> runs = new ArrayList<>(data.getRunCount());
	for (BenchmarkRun run : data.getRuns()) {
		runs.add(run);
	}
	
	int runCount = runs.size();
	
	double[] runMeans = new double[runCount * bootstrapSizeInnerMeans];
	int startIndex = 0;
	for (int i = 0; i < runCount; i++, startIndex += bootstrapSizeInnerMeans) {
		double[] samples = BenchmarkRunUtils.toDoubleArray(runs.get(i));
		bootstrapWithMean(samples, samples.length, bootstrapSizeInnerMeans, runMeans, startIndex);
	}
	
	double[] finalSamples = new double[bootstrapSizeOuterMeans];
	bootstrapWithMean(runMeans, runs.size(), bootstrapSizeOuterMeans, finalSamples, 0);
	
	for (int i = 0; i < finalSamples.length; i++) {
		finalSamples[i] += shift;
	}
	
	return DistributionUtils.makeEmpirical(finalSamples);
}
 
开发者ID:D-iii-S,项目名称:spl-evaluation-java,代码行数:25,代码来源:DistributionLearningInterpretation.java


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