本文整理汇总了Java中org.apache.commons.math.MathException类的典型用法代码示例。如果您正苦于以下问题:Java MathException类的具体用法?Java MathException怎么用?Java MathException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MathException类属于org.apache.commons.math包,在下文中一共展示了MathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSignificance
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Computes the significance of the difference between two correlations.
* @see org.tud.sir.util.statistics.Significance.testCorrelations
*/
public static double getSignificance(double correlation1, double correlation2, int n1, int n2) throws MathException {
// transform to Fisher Z-values
double zv1 = FisherZTransformation.transform(correlation1);
double zv2 = FisherZTransformation.transform(correlation2);
// difference of the Z-values
double zDifference = (zv1 - zv2) / Math.sqrt(2d) / Math.sqrt( (double)1/(n1-3) + (double)1/(n2-3));
// get p value from the complementary error function
double p = Erf.erfc( Math.abs(zDifference));
return p;
}
示例2: generatePixelSignature
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Computes the relative probability of receiving a photon at the pixel.
* @param pixelX The pixel's x-position.
* @param pixelY The pixel's y-position.
* @return The probability of a photon hitting this pixel.
* @throws org.apache.commons.math.MathException
*/
@Override
public double generatePixelSignature(int pixelX, int pixelY)
throws MathException {
final double sigma_0 = this.FWHM / 2.3548;
final double zR = 2 * sigma_0 / this.numericalAperture; // Rayleigh range
// Add the offset from the stage's position to the emitter's z-values
double z;
z = this.eZ + this.stageDisplacement;
double sigma = sigma_0 * sqrt(1 + (z/ zR) * (z / zR));
double denom = sqrt(2.0)*sigma;
return 0.25 *(Erf.erf((pixelX - this.eX + 0.5)/denom) -
Erf.erf((pixelX - this.eX - 0.5)/denom)) *
(Erf.erf((pixelY - this.eY + 0.5)/denom) -
Erf.erf((pixelY - this.eY - 0.5)/denom));
}
示例3: computePhiMeasure
import org.apache.commons.math.MathException; //导入依赖的package包/类
public synchronized Double computePhiMeasure(long now) {
if (latestHeartbeatMs == -1 || descriptiveStatistics.getN() < minimumSamples) {
return null;
}
long delta = now - latestHeartbeatMs;
try {
double probability;
if (distribution.equals("normal")) {
double standardDeviation = descriptiveStatistics.getStandardDeviation();
standardDeviation = standardDeviation < 0.1 ? 0.1 : standardDeviation;
probability = new NormalDistributionImpl(descriptiveStatistics.getMean(), standardDeviation).cumulativeProbability(delta);
} else {
probability = new ExponentialDistributionImpl(descriptiveStatistics.getMean()).cumulativeProbability(delta);
}
final double eps = 1e-12;
if (1 - probability < eps) {
probability = 1.0;
}
return -1.0d * Math.log10(1.0d - probability);
} catch (MathException | IllegalArgumentException e) {
LOGGER.debug(e);
return null;
}
}
示例4: fst
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Perform the FST algorithm (including inverse).
*
* @param f the real data array to be transformed
* @return the real transformed array
* @throws MathException if any math-related errors occur
* @throws IllegalArgumentException if any parameters are invalid
*/
protected double[] fst(double f[]) throws MathException,
IllegalArgumentException {
double A, B, x[], F[] = new double[f.length];
FastFourierTransformer.verifyDataSet(f);
if (f[0] != 0.0) {
throw new IllegalArgumentException
("The first element is not zero: " + f[0]);
}
int N = f.length;
if (N == 1) { // trivial case
F[0] = 0.0;
return F;
}
// construct a new array and perform FFT on it
x = new double[N];
x[0] = 0.0;
x[N >> 1] = 2.0 * f[N >> 1];
for (int i = 1; i < (N >> 1); i++) {
A = Math.sin(i * Math.PI / N) * (f[i] + f[N-i]);
B = 0.5 * (f[i] - f[N-i]);
x[i] = A + B;
x[N-i] = A - B;
}
FastFourierTransformer transformer = new FastFourierTransformer();
Complex y[] = transformer.transform(x);
// reconstruct the FST result for the original array
F[0] = 0.0;
F[1] = 0.5 * y[0].getReal();
for (int i = 1; i < (N >> 1); i++) {
F[2*i] = -y[i].getImaginary();
F[2*i+1] = y[i].getReal() + F[2*i-1];
}
return F;
}
示例5: SimpleNoiseDistribution
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Constructor.
*
* @param peakList the peak list
*
* @throws MathException thrown if a math error occurs
*/
public SimpleNoiseDistribution(HashMap<Double, Peak> peakList) throws MathException {
ArrayList<Double> intensitiesLog = new ArrayList<Double>(peakList.size());
for (Peak peak : peakList.values()) {
double log = FastMath.log10(peak.intensity);
intensitiesLog.add(log);
}
Collections.sort(intensitiesLog);
intensityLogDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistributionFromSortedList(intensitiesLog);
orderedBins = new int[nBins - 1];
pLog = new double[nBins - 1];
binSize = 1.0 / nBins;
for (int i = 1; i < nBins; i++) {
double p = binSize * i;
double x = intensityLogDistribution.getValueAtDescendingCumulativeProbability(p);
orderedBins[i - 1] = (int) FastMath.pow(10, x);
pLog[i - 1] = FastMath.log10(p);
}
}
示例6: testExpm1Function2
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Test of solver for the exponential function using solve2().
* <p>
* It takes 25 to 50 iterations for the last two tests to converge.
*/
public void testExpm1Function2() throws MathException {
UnivariateRealFunction f = new Expm1Function();
MullerSolver solver = new MullerSolver(f);
double min, max, expected, result, tolerance;
min = -1.0; max = 2.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(min, max);
assertEquals(expected, result, tolerance);
min = -20.0; max = 10.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(min, max);
assertEquals(expected, result, tolerance);
min = -50.0; max = 100.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve2(min, max);
assertEquals(expected, result, tolerance);
}
示例7: testConstants
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* tests the value of a constant polynomial.
*
* <p>value of this is 2.5 everywhere.</p>
*/
public void testConstants() throws MathException {
double[] c = { 2.5 };
PolynomialFunction f = new PolynomialFunction( c );
// verify that we are equal to c[0] at several (nonsymmetric) places
assertEquals( f.value( 0.0), c[0], tolerance );
assertEquals( f.value( -1.0), c[0], tolerance );
assertEquals( f.value( -123.5), c[0], tolerance );
assertEquals( f.value( 3.0), c[0], tolerance );
assertEquals( f.value( 456.89), c[0], tolerance );
assertEquals(f.degree(), 0);
assertEquals(f.derivative().value(0), 0, tolerance);
assertEquals(f.polynomialDerivative().derivative().value(0), 0, tolerance);
}
示例8: testLargeMeanCumulativeProbability
import org.apache.commons.math.MathException; //导入依赖的package包/类
public void testLargeMeanCumulativeProbability() {
PoissonDistribution dist = new PoissonDistributionImpl(1.0);
double mean = 1.0;
while (mean <= 10000000.0) {
dist.setMean(mean);
double x = mean * 2.0;
double dx = x / 10.0;
while (x >= 0) {
try {
dist.cumulativeProbability(x);
} catch (MathException ex) {
fail("mean of " + mean + " and x of " + x + " caused " + ex.getMessage());
}
x -= dx;
}
mean *= 10.0;
}
}
示例9: testLargeMeanInverseCumulativeProbability
import org.apache.commons.math.MathException; //导入依赖的package包/类
public void testLargeMeanInverseCumulativeProbability() {
PoissonDistribution dist = new PoissonDistributionImpl(1.0);
double mean = 1.0;
while (mean <= 10000000.0) {
dist.setMean(mean);
double p = 0.1;
double dp = p;
while (p < 1.0) {
try {
dist.inverseCumulativeProbability(p);
} catch (MathException ex) {
fail("mean of " + mean + " and p of " + p + " caused " + ex.getMessage());
}
p += dp;
}
mean *= 10.0;
}
}
示例10: findDifferentia
import org.apache.commons.math.MathException; //导入依赖的package包/类
public List<InferredClassDefinition> findDifferentia(OWLClass child, OWLClass parent, OWLClass diffClassRoot) throws UnknownOWLClassException, MathException {
List<InferredClassDefinition> results = new Vector<InferredClassDefinition>();
LOG.info("Finding: "+child+" against "+parent);
for (OWLClass differentiaClass : sim.getReasoner()
.getSubClasses(diffClassRoot, false).getFlattened()) {
//LOG.info(" Testing: "+enrichedClass);
if (differentiaClass.isBottomEntity()) {
continue;
}
if (sim.getNumElementsForAttribute(differentiaClass) == 0) {
LOG.info("Skipping: "+differentiaClass);
continue;
}
InferredClassDefinition r = calculateGenusDifferentiaEnrichment(child, parent,
differentiaClass);
if (r != null)
results.add(r);
}
Collections.sort(results);
return results;
}
示例11: cumulativeProbability
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* For this distribution, X, this method returns P(X ≤ x).
* @param x the value at which the PDF is evaluated.
* @return PDF for this distribution.
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(int x) throws MathException {
double ret;
if (x < 0) {
ret = 0.0;
} else if (x >= getNumberOfTrials()) {
ret = 1.0;
} else {
ret =
1.0 - Beta.regularizedBeta(
getProbabilityOfSuccess(),
x + 1.0,
getNumberOfTrials() - x);
}
return ret;
}
示例12: exhaustiveTestOnGO
import org.apache.commons.math.MathException; //导入依赖的package包/类
@Test
public void exhaustiveTestOnGO() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, MathException {
/*
ParserWrapper pw = new ParserWrapper();
sourceOntol = pw.parseOBO(getResourceIRIString("go-subset-t1.obo"));
g = new OWLGraphWrapper(sourceOntol);
IRI vpIRI = g.getOWLObjectPropertyByIdentifier("GOTESTREL:0000001").getIRI();
TableToAxiomConverter ttac = new TableToAxiomConverter(g);
ttac.config.axiomType = AxiomType.CLASS_ASSERTION;
ttac.config.property = vpIRI;
ttac.config.isSwitchSubjectObject = true;
ttac.parse("src/test/resources/simplegaf-t1.txt");
OWLPrettyPrinter pp = new OWLPrettyPrinter(g);
AutomaticSimPreProcessor pproc = new AutomaticSimPreProcessor();
pproc.setInputOntology(sourceOntol);
pproc.setOutputOntology(sourceOntol);
pproc.preprocess();
*/
}
示例13: testQuantileCM
import org.apache.commons.math.MathException; //导入依赖的package包/类
private static void testQuantileCM(double y, double shape, double scale) {
long time = System.currentTimeMillis();
double value = 0;
try {
for (int i = 0; i < 1000; i++) {
value = (new org.apache.commons.math.distribution.GammaDistributionImpl(shape, scale)).inverseCumulativeProbability(y);
}
value = (new org.apache.commons.math.distribution.GammaDistributionImpl(shape, scale)).inverseCumulativeProbability(y);
} catch (MathException e) {
e.printStackTrace();
}
long elapsed = System.currentTimeMillis() - time;
System.out.println("commons.maths inverseCDF, "+ y +", for shape=" + shape + ", scale=" + scale
+ " : " + value + ", time=" + elapsed + "ms");
}
示例14: testExpm1Function
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Test of solver for the exponential function.
*/
public void testExpm1Function() throws MathException {
UnivariateRealFunction f = new Expm1Function();
UnivariateRealSolver solver = new RiddersSolver(f);
double min, max, expected, result, tolerance;
min = -1.0; max = 2.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
min = -20.0; max = 10.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
min = -50.0; max = 100.0; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
}
示例15: testQuinticFunction
import org.apache.commons.math.MathException; //导入依赖的package包/类
/**
* Test of solver for the quintic function.
*/
public void testQuinticFunction() throws MathException {
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new MullerSolver(f);
double min, max, expected, result, tolerance;
min = -0.4; max = 0.2; expected = 0.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
min = 0.75; max = 1.5; expected = 1.0;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
min = -0.9; max = -0.2; expected = -0.5;
tolerance = Math.max(solver.getAbsoluteAccuracy(),
Math.abs(expected * solver.getRelativeAccuracy()));
result = solver.solve(min, max);
assertEquals(expected, result, tolerance);
}