本文整理汇总了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);
}
}
示例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;
}
};
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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));
}