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


Java NormalDistribution类代码示例

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


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

示例1: testRandomDataNormalDistribution

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
@Test
public void testRandomDataNormalDistribution() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        RealMatrix s = checkAEqualPTPt(m);
        checkSchurForm(s);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:SchurTransformerTest.java

示例2: solveLognormalNewsvendor

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
public static Newsvendor solveLognormalNewsvendor (final double price, final double cost, final double mu, final double sigma) {
	final NormalDistribution dist1 = new NormalDistribution();
	final double cv = sigma/mu;
	final double nu = Math.log(mu)-Math.log(Math.sqrt(1+cv*cv));
	final double tau = Math.sqrt(Math.log(1+cv*cv));
	final LogNormalDistribution dist2 = new LogNormalDistribution(nu,tau);
	return new Newsvendor(price,cost) {{
		_safetyfactor = dist1.inverseCumulativeProbability((price-cost)/price);
		_quantity = Math.exp(nu+tau*_safetyfactor);
		_profit = (price-cost)*mu - price*mu*dist1.cumulativeProbability(tau-_safetyfactor)+cost*mu;
	}
	@Override
	public double getProfit(double quantity) {
		double lostSales = quantity*(1-dist2.cumulativeProbability(quantity))-Math.exp(nu+tau*tau/2)*dist1.cumulativeProbability((nu+tau*tau-Math.log(quantity))/tau);
		return _price*mu -_cost*quantity + _price*lostSales;
	}
	};
}
 
开发者ID:loehndorf,项目名称:scengen,代码行数:19,代码来源:Newsvendor.java

示例3: test

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/**
 * Testing code...
 * @param args
 */
public static void test() {
	final NormalDistribution dist_1 = new NormalDistribution(-1,1);
	final NormalDistribution dist0 = new NormalDistribution(0,1);
	final NormalDistribution dist1 = new NormalDistribution(1,1);
	final UnivariateFunction F = new UnivariateFunction() {				
		@Override
		public double value(double x) {
			double val = dist_1.cumulativeProbability(x)*dist0.cumulativeProbability(x)*dist1.cumulativeProbability(x);
			return val;
		}
	};
	double v;
	long t = System.currentTimeMillis();
	v = calculateEV_KG(F);
    System.out.println("calculateEV_KG "+v+" "+(System.currentTimeMillis()-t));
}
 
开发者ID:pszufe,项目名称:pkg,代码行数:21,代码来源:CalculateEv.java

示例4: calculateAsymptoticPValue

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/**
 * @param Wmin smallest Wilcoxon signed rank value
 * @param N number of subjects (corresponding to x.length)
 * @return two-sided asymptotic p-value
 */
private double calculateAsymptoticPValue(final double Wmin, final int N) {

    final double ES = (double) (N * (N + 1)) / 4.0;

    /* Same as (but saves computations):
     * final double VarW = ((double) (N * (N + 1) * (2*N + 1))) / 24;
     */
    final double VarS = ES * ((double) (2 * N + 1) / 6.0);

    // - 0.5 is a continuity correction
    final double z = (Wmin - ES - 0.5) / FastMath.sqrt(VarS);

    // No try-catch or advertised exception because args are valid
    // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
    final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);

    return 2*standardNormal.cumulativeProbability(z);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:WilcoxonSignedRankTest.java

示例5: calculateAsymptoticPValue

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/**
 * @param Umin smallest Mann-Whitney U value
 * @param n1 number of subjects in first sample
 * @param n2 number of subjects in second sample
 * @return two-sided asymptotic p-value
 * @throws ConvergenceException if the p-value can not be computed
 * due to a convergence error
 * @throws MaxCountExceededException if the maximum number of
 * iterations is exceeded
 */
private double calculateAsymptoticPValue(final double Umin,
                                         final int n1,
                                         final int n2)
    throws ConvergenceException, MaxCountExceededException {

    /* long multiplication to avoid overflow (double not used due to efficiency
     * and to avoid precision loss)
     */
    final long n1n2prod = (long) n1 * n2;

    // http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation
    final double EU = n1n2prod / 2.0;
    final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0;

    final double z = (Umin - EU) / FastMath.sqrt(VarU);

    // No try-catch or advertised exception because args are valid
    // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
    final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);

    return 2 * standardNormal.cumulativeProbability(z);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:MannWhitneyUTest.java

示例6: createInterval

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;

    final double factor = 1.0 / (1 + (1.0 / numberOfTrials) * zSquared);
    final double modifiedSuccessRatio = mean + (1.0 / (2 * numberOfTrials)) * zSquared;
    final double difference = z *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean) +
                                            (1.0 / (4 * FastMath.pow(numberOfTrials, 2)) * zSquared));

    final double lowerBound = factor * (modifiedSuccessRatio - difference);
    final double upperBound = factor * (modifiedSuccessRatio + difference);
    return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:20,代码来源:WilsonScoreInterval.java

示例7: rerankPermutation

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
@Override
public int[] rerankPermutation(Recommendation<U, I> recommendation, int maxLength) {
    List<Tuple2od<I>> items = recommendation.getItems();
    int M = items.size();
    int N = min(maxLength, M);

    if (variance == 0.0) {
        return getBasePerm(N);
    }
    
    NormalDistribution dist = new NormalDistribution(0.0, sqrt(variance));

    IntDoubleTopN topN = new IntDoubleTopN(N);
    for (int i = 0; i < M; i++) {
        topN.add(M - i, log(i + 1) + dist.sample());
    }
    topN.sort();

    return topN.stream()
            .mapToInt(e -> M - e.v1)
            .toArray();

}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:24,代码来源:DitheringReranker.java

示例8: makeCircles

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) {
    if (factor < 0 || factor > 1) {
        throw new IllegalArgumentException();
    }
    
    NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9);

    List<Vector2D> points = new ArrayList<Vector2D>();
    double range = 2.0 * FastMath.PI;
    double step = range / (samples / 2.0 + 1);
    for (double angle = 0; angle < range; angle += step) {
        Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle));
        Vector2D innerCircle = outerCircle.scalarMultiply(factor);
        
        points.add(outerCircle.add(generateNoiseVector(dist)));
        points.add(innerCircle.add(generateNoiseVector(dist)));
    }
    
    if (shuffle) {
        Collections.shuffle(points, new RandomAdaptor(random));
    }

    return points;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:ClusterAlgorithmComparison.java

示例9: makeMoons

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
public static List<Vector2D> makeMoons(int samples, boolean shuffle, double noise, RandomGenerator random) {
    NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9);

    int nSamplesOut = samples / 2;
    int nSamplesIn = samples - nSamplesOut;
    
    List<Vector2D> points = new ArrayList<Vector2D>();
    double range = FastMath.PI;
    double step = range / (nSamplesOut / 2.0);
    for (double angle = 0; angle < range; angle += step) {
        Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle));
        points.add(outerCircle.add(generateNoiseVector(dist)));
    }

    step = range / (nSamplesIn / 2.0);
    for (double angle = 0; angle < range; angle += step) {
        Vector2D innerCircle = new Vector2D(1 - FastMath.cos(angle), 1 - FastMath.sin(angle) - 0.5);
        points.add(innerCircle.add(generateNoiseVector(dist)));
    }
    
    if (shuffle) {
        Collections.shuffle(points, new RandomAdaptor(random));
    }

    return points;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:ClusterAlgorithmComparison.java

示例10: RandomCirclePointGenerator

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

示例11: testStoredVsDirect

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
@Test
public void testStoredVsDirect() {
    final RandomGenerator rand= new JDKRandomGenerator();
    rand.setSeed(Long.MAX_VALUE);
    for (final int sampleSize:sampleSizes) {
        final double[] data = new NormalDistribution(rand,4000, 50)
                            .sample(sampleSize);
        for (final double p:new double[] {50d,95d}) {
            for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
                reset(p, e);
                final Percentile pStoredData = getUnivariateStatistic();
                pStoredData.setData(data);
                final double storedDataResult=pStoredData.evaluate();
                pStoredData.setData(null);
                final Percentile pDirect = getUnivariateStatistic();
                Assert.assertEquals("Sample="+sampleSize+",P="+p+" e="+e,
                        storedDataResult,
                        pDirect.evaluate(data),0d);
            }
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:PercentileTest.java

示例12: testNextGaussian

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/** test failure modes and distribution of nextGaussian() */
@Test
public void testNextGaussian() {
    try {
        randomData.nextGaussian(0, 0);
        Assert.fail("zero sigma -- MathIllegalArgumentException expected");
    } catch (MathIllegalArgumentException ex) {
        // ignored
    }
    double[] quartiles = TestUtils.getDistributionQuartiles(new NormalDistribution(0,1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextGaussian(0, 1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:RandomDataGeneratorTest.java

示例13: testRandomDataNormalDistribution

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
@Test
public void testRandomDataNormalDistribution() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        RealMatrix h = checkAEqualPHPt(m);
        checkHessenbergForm(h);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:HessenbergTransformerTest.java

示例14: testNormalDistributionUnsymmetricMatrix

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
@Test
@Ignore
public void testNormalDistributionUnsymmetricMatrix() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        checkUnsymmetricMatrix(m);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:EigenDecompositionTest.java

示例15: macKinnonP

import org.apache.commons.math3.distribution.NormalDistribution; //导入依赖的package包/类
/**
 * Returns MacKinnonP's approximate p-value for the given test statistic.
 *
 * MacKinnonP, J.G. 1994 "Approximate Asymptotic Distribution Functions for Unit-Root and Cointegration Tests."
 * Journal of Business & Economics Statistics, 12.2, 167-76.
 *
 * @param testStat
 *            "T-value" from an Augmented Dickey-Fuller regression.
 * @param regressionMethod
 *            The method of regression that was used. Following MacKinnonP's notation, this can be "c" for constant,
 *            "nc" for no constant, "ct" for constant and trend, and "ctt" for constant, trend, and trend-squared.
 * @param n
 *            The number of series believed to be I(1). For (Augmented) Dickey-Fuller n = 1.
 * @return The p-value for the ADF statistic using MacKinnonP 1994.
 */
public static double macKinnonP(final double testStat, final RegressionMethod regressionMethod, final int n) {
    final double[] maxStat = ADF_TAU_MAX.get(regressionMethod);
    if (testStat > maxStat[n - 1]) {
        return 1.0;
    }
    final double[] minStat = ADF_TAU_MIN.get(regressionMethod);
    if (testStat < minStat[n - 1]) {
        return 0.0;
    }
    final double[] starStat = ADF_TAU_STAR.get(regressionMethod);
    final double[] tauCoef;
    if (testStat <= starStat[n - 1]) {
        tauCoef = ADF_TAU_SMALLP.get(regressionMethod)[n - 1];
    } else {
        tauCoef = ADF_TAU_LARGEP.get(regressionMethod)[n - 1];
    }
    return new NormalDistribution().cumulativeProbability(polyVal(tauCoef, testStat));
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:34,代码来源:MacKinnonP.java


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