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


Java ConvergenceException类代码示例

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


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

示例1: generate

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
/** {@inheritDoc} */
public ConvexHull2D generate(final Collection<Vector2D> points)
        throws NullArgumentException, ConvergenceException {
    // check for null points
    MathUtils.checkNotNull(points);

    Collection<Vector2D> hullVertices = null;
    if (points.size() < 2) {
        hullVertices = points;
    } else {
        hullVertices = findHullVertices(points);
    }

    try {
        return new ConvexHull2D(hullVertices.toArray(new Vector2D[hullVertices.size()]),
                                tolerance);
    } catch (MathIllegalArgumentException e) {
        // the hull vertices may not form a convex hull if the tolerance value is to large
        throw new ConvergenceException();
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:22,代码来源:AbstractConvexHullGenerator2D.java

示例2: calculateAsymptoticPValue

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的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

示例3: value

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
/**
 * Returns the first Bessel function, \(J_{order}(x)\).
 *
 * @param order Order of the Bessel function
 * @param x Argument
 * @return Value of the Bessel function of the first kind, \(J_{order}(x)\)
 * @throws MathIllegalArgumentException if {@code x} is too large relative to {@code order}
 * @throws ConvergenceException if the algorithm fails to converge
 */
public static double value(double order, double x)
    throws MathIllegalArgumentException, ConvergenceException {
    final int n = (int) order;
    final double alpha = order - n;
    final int nb = n + 1;
    final BesselJResult res = rjBesl(x, alpha, nb);

    if (res.nVals >= nb) {
        return res.vals[n];
    } else if (res.nVals < 0) {
        throw new MathIllegalArgumentException(LocalizedFormats.BESSEL_FUNCTION_BAD_ARGUMENT,order, x);
    } else if (FastMath.abs(res.vals[res.nVals - 1]) < 1e-100) {
        return res.vals[n]; // underflow; return value (will be zero)
    }
    throw new ConvergenceException(LocalizedFormats.BESSEL_FUNCTION_FAILED_CONVERGENCE, order, x);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:BesselJ.java

示例4: testNonInvertible

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@Test
public void testNonInvertible() throws Exception {
    try {
        LinearProblem problem = new LinearProblem(new double[][]{
                {1, 2, -3},
                {2, 1, 3},
                {-3, 0, -9}
        }, new double[]{1, 1, 1});

        optimizer.optimize(problem.getBuilder().build());

        fail(optimizer);
    } catch (ConvergenceException e) {
        //expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java

示例5: checkUnsolvableProblem

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
private void checkUnsolvableProblem(MultivariateVectorOptimizer optimizer,
                                    boolean solvable) {
    Random randomizer = new Random(1248788532l);
    for (int degree = 0; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(optimizer);

        // reusing the same point over and over again does not bring
        // information, the problem cannot be solved in this case for
        // degrees greater than 1 (but one point is sufficient for
        // degree 0)
        for (double x = -1.0; x < 1.0; x += 0.01) {
            fitter.addObservedPoint(1.0, 0.0, p.value(0.0));
        }

        try {
            final double[] init = new double[degree + 1];
            fitter.fit(init);
            Assert.assertTrue(solvable || (degree == 0));
        } catch(ConvergenceException e) {
            Assert.assertTrue((! solvable) && (degree > 0));
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:PolynomialFitterTest.java

示例6: checkUnsolvableProblem

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
private void checkUnsolvableProblem(boolean solvable) {
    final Random randomizer = new Random(1248788532l);

    for (int degree = 0; degree < 10; ++degree) {
        final PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
        final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);
        final WeightedObservedPoints obs = new WeightedObservedPoints();
        // reusing the same point over and over again does not bring
        // information, the problem cannot be solved in this case for
        // degrees greater than 1 (but one point is sufficient for
        // degree 0)
        for (double x = -1.0; x < 1.0; x += 0.01) {
            obs.add(1.0, 0.0, p.value(0.0));
        }

        try {
            fitter.fit(obs.toList());
            Assert.assertTrue(solvable || (degree == 0));
        } catch(ConvergenceException e) {
            Assert.assertTrue((! solvable) && (degree > 0));
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:PolynomialCurveFitterTest.java

示例7: testConvergenceException

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@Test(expected=ConvergenceException.class)
public void testConvergenceException() {
    final Collection<Vector2D> points = new ArrayList<Vector2D>();

    points.add(new Vector2D(1, 1));
    points.add(new Vector2D(1, 5));
    points.add(new Vector2D(0, 7));
    points.add(new Vector2D(1, 10));
    points.add(new Vector2D(1, 20));
    points.add(new Vector2D(20, 20));
    points.add(new Vector2D(20, 40));
    points.add(new Vector2D(40, 1));

    @SuppressWarnings("unused")
    final ConvexHull2D hull = new MonotoneChain(true, 2).generate(points);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:MonotoneChainTest.java

示例8: testMath199

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@[email protected]
public void testMath199() {
    try {
        QuadraticProblem problem = new QuadraticProblem();
        problem.addPoint (0, -3.182591015485607);
        problem.addPoint (1, -2.5581184967730577);
        problem.addPoint (2, -2.1488478161387325);
        problem.addPoint (3, -1.9122489313410047);
        problem.addPoint (4, 1.7785661310051026);
        LevenbergMarquardtOptimizer optimizer
            = new LevenbergMarquardtOptimizer(100, 1e-10, 1e-10, 1e-10, 0);
        optimizer.optimize(100, problem,
                           new double[] { 0, 0, 0, 0, 0 },
                           new double[] { 0.0, 4.4e-323, 1.0, 4.4e-323, 0.0 },
                           new double[] { 0, 0, 0 });
        Assert.fail("an exception should have been thrown");
    } catch (ConvergenceException ee) {
        // expected behavior
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:LevenbergMarquardtOptimizerTest.java

示例9: checkUnsolvableProblem

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
private void checkUnsolvableProblem(DifferentiableMultivariateVectorOptimizer optimizer,
                                    boolean solvable) {
    Random randomizer = new Random(1248788532l);
    for (int degree = 0; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(optimizer);

        // reusing the same point over and over again does not bring
        // information, the problem cannot be solved in this case for
        // degrees greater than 1 (but one point is sufficient for
        // degree 0)
        for (double x = -1.0; x < 1.0; x += 0.01) {
            fitter.addObservedPoint(1.0, 0.0, p.value(0.0));
        }

        try {
            final double[] init = new double[degree + 1];
            fitter.fit(init);
            Assert.assertTrue(solvable || (degree == 0));
        } catch(ConvergenceException e) {
            Assert.assertTrue((! solvable) && (degree > 0));
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:PolynomialFitterTest.java

示例10: testNonInvertible

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@Test(expected=ConvergenceException.class)
public void testNonInvertible() throws Exception {

    LinearProblem problem = new LinearProblem(new double[][] {
            {  1, 2, -3 },
            {  2, 1,  3 },
            { -3, 0, -9 }
    }, new double[] { 1, 1, 1 });

    AbstractLeastSquaresOptimizer optimizer = createOptimizer();

    optimizer.optimize(new MaxEval(100),
                       problem.getModelFunction(),
                       problem.getModelFunctionJacobian(),
                       problem.getTarget(),
                       new Weight(new double[] { 1, 1, 1 }),
                       new InitialGuess(new double[] { 0, 0, 0 }));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:AbstractLeastSquaresOptimizerAbstractTest.java

示例11: testMath199

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@Test
public void testMath199() {
    try {
        QuadraticProblem problem = new QuadraticProblem();
        problem.addPoint (0, -3.182591015485607);
        problem.addPoint (1, -2.5581184967730577);
        problem.addPoint (2, -2.1488478161387325);
        problem.addPoint (3, -1.9122489313410047);
        problem.addPoint (4, 1.7785661310051026);
        LevenbergMarquardtOptimizer optimizer
            = new LevenbergMarquardtOptimizer(100, 1e-10, 1e-10, 1e-10, 0);
        optimizer.optimize(100, problem,
                           new double[] { 0, 0, 0, 0, 0 },
                           new double[] { 0.0, 4.4e-323, 1.0, 4.4e-323, 0.0 },
                           new double[] { 0, 0, 0 });
        Assert.fail("an exception should have been thrown");
    } catch (ConvergenceException ee) {
        // expected behavior
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:LevenbergMarquardtOptimizerTest.java

示例12: solve

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        final Pair<RealMatrix, RealVector> normalEquation =
                computeNormalMatrix(jacobian, residuals);
        final RealMatrix normal = normalEquation.getFirst();
        final RealVector jTr = normalEquation.getSecond();
        return new CholeskyDecomposition(
                normal, SINGULARITY_THRESHOLD, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(jTr);
    } catch (NonPositiveDefiniteMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:17,代码来源:GaussNewtonOptimizer.java

示例13: cluster

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
/**
 * Runs the K-means++ clustering algorithm.
 *
 * @param points the points to cluster
 * @return a list of clusters containing the points
 * @throws MathIllegalArgumentException if the data points are null or the number
 *   of clusters is larger than the number of data points
 * @throws ConvergenceException if an empty cluster is encountered and the
 *   underlying {@link KMeansPlusPlusClusterer} has its
 *   {@link KMeansPlusPlusClusterer.EmptyClusterStrategy} is set to {@code ERROR}.
 */
@Override
public List<CentroidCluster<T>> cluster(final Collection<T> points)
    throws MathIllegalArgumentException, ConvergenceException {

    // at first, we have not found any clusters list yet
    List<CentroidCluster<T>> best = null;
    double bestVarianceSum = Double.POSITIVE_INFINITY;

    // do several clustering trials
    for (int i = 0; i < numTrials; ++i) {

        // compute a clusters list
        List<CentroidCluster<T>> clusters = clusterer.cluster(points);

        // compute the variance of the current list
        final double varianceSum = evaluator.score(clusters);

        if (evaluator.isBetterScore(varianceSum, bestVarianceSum)) {
            // this one is the best we have found so far, remember it
            best            = clusters;
            bestVarianceSum = varianceSum;
        }

    }

    // return the best clusters list found
    return best;

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:41,代码来源:MultiKMeansPlusPlusClusterer.java

示例14: getPointFromLargestVarianceCluster

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
/**
 * Get a random point from the {@link Cluster} with the largest distance variance.
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 */
private T getPointFromLargestVarianceCluster(final Collection<CentroidCluster<T>> clusters)
        throws ConvergenceException {

    double maxVariance = Double.NEGATIVE_INFINITY;
    Cluster<T> selected = null;
    for (final CentroidCluster<T> cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            // compute the distance variance of the current cluster
            final Clusterable center = cluster.getCenter();
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center));
            }
            final double variance = stat.getResult();

            // select the cluster with the largest variance
            if (variance > maxVariance) {
                maxVariance = variance;
                selected = cluster;
            }

        }
    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return selectedPoints.remove(random.nextInt(selectedPoints.size()));

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:43,代码来源:KMeansPlusPlusClusterer.java

示例15: getPointFromLargestNumberCluster

import org.apache.commons.math3.exception.ConvergenceException; //导入依赖的package包/类
/**
 * Get a random point from the {@link Cluster} with the largest number of points
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 */
private T getPointFromLargestNumberCluster(final Collection<? extends Cluster<T>> clusters)
        throws ConvergenceException {

    int maxNumber = 0;
    Cluster<T> selected = null;
    for (final Cluster<T> cluster : clusters) {

        // get the number of points of the current cluster
        final int number = cluster.getPoints().size();

        // select the cluster with the largest number of points
        if (number > maxNumber) {
            maxNumber = number;
            selected = cluster;
        }

    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return selectedPoints.remove(random.nextInt(selectedPoints.size()));

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:36,代码来源:KMeansPlusPlusClusterer.java


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