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


Java TooManyEvaluationsException类代码示例

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


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

示例1: doSolve

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected double doSolve()
    throws TooManyEvaluationsException {
    final double startValue = getStartValue();
    final double absoluteAccuracy = getAbsoluteAccuracy();

    double x0 = startValue;
    double x1;
    while (true) {
        final DerivativeStructure y0 = computeObjectiveValueAndDerivative(x0);
        x1 = x0 - (y0.getValue() / y0.getPartialDerivative(1));
        if (FastMath.abs(x1 - x0) <= absoluteAccuracy) {
            return x1;
        }

        x0 = x1;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:22,代码来源:NewtonRaphsonSolver.java

示例2: optimizeInternal

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * Optimize an objective function.
 *
 * @param maxEval Allowed number of evaluations of the objective function.
 * @param f Objective function.
 * @param goalType Optimization type.
 * @param optData Optimization data. The following data will be looked for:
 * <ul>
 *  <li>{@link InitialGuess}</li>
 *  <li>{@link SimpleBounds}</li>
 * </ul>
 * @return the point/value pair giving the optimal value of the objective
 * function.
 * @throws TooManyEvaluationsException if the maximal number of
 * evaluations is exceeded.
 * @since 3.1
 */
protected PointValuePair optimizeInternal(int maxEval,
                                          FUNC f,
                                          GoalType goalType,
                                          OptimizationData... optData)
    throws TooManyEvaluationsException {
    // Set internal state.
    evaluations.setMaximalCount(maxEval);
    evaluations.resetCount();
    function = f;
    goal = goalType;
    // Retrieve other settings.
    parseOptimizationData(optData);
    // Check input consistency.
    checkParameters();
    // Perform computation.
    return doOptimize();
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:35,代码来源:BaseAbstractMultivariateOptimizer.java

示例3: doIntegrate

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected double doIntegrate()
    throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {

    double oldt = stage(this, 0);
    incrementCount();
    while (true) {
        final int i = getIterations();
        final double t = stage(this, i);
        if (i >= getMinimalIterationCount()) {
            final double delta = FastMath.abs(t - oldt);
            final double rLimit =
                getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
            if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
                return t;
            }
        }
        oldt = t;
        incrementCount();
    }

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

示例4: stage

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * Compute the n-th stage integral of midpoint rule.
 * This function should only be called by API <code>integrate()</code> in the package.
 * To save time it does not verify arguments - caller does.
 * <p>
 * The interval is divided equally into 2^n sections rather than an
 * arbitrary m sections because this configuration can best utilize the
 * already computed values.</p>
 *
 * @param n the stage of 1/2 refinement. Must be larger than 0.
 * @param previousStageResult Result from the previous call to the
 * {@code stage} method.
 * @param min Lower bound of the integration interval.
 * @param diffMaxMin Difference between the lower bound and upper bound
 * of the integration interval.
 * @return the value of n-th stage integral
 * @throws TooManyEvaluationsException if the maximal number of evaluations
 * is exceeded.
 */
private double stage(final int n,
                     double previousStageResult,
                     double min,
                     double diffMaxMin)
    throws TooManyEvaluationsException {

    // number of new points in this stage
    final long np = 1L << (n - 1);
    double sum = 0;

    // spacing between adjacent new points
    final double spacing = diffMaxMin / np;

    // the first new point
    double x = min + 0.5 * spacing;
    for (long i = 0; i < np; i++) {
        sum += computeObjectiveValue(x);
        x += spacing;
    }
    // add the new sum to previously calculated result
    return 0.5 * (previousStageResult + sum * spacing);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:42,代码来源:MidPointIntegrator.java

示例5: stage

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * Compute the n-th stage integral.
 * @param n number of steps
 * @return the value of n-th stage integral
 * @throws TooManyEvaluationsException if the maximum number of evaluations
 * is exceeded.
 */
private double stage(final int n)
    throws TooManyEvaluationsException {

    // set up the step for the current stage
    final double step     = (getMax() - getMin()) / n;
    final double halfStep = step / 2.0;

    // integrate over all elementary steps
    double midPoint = getMin() + halfStep;
    double sum = 0.0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < abscissas.length; ++j) {
            sum += weights[j] * computeObjectiveValue(midPoint + halfStep * abscissas[j]);
        }
        midPoint += step;
    }

    return halfStep * sum;

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

示例6: doSolve

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected double doSolve()
    throws TooManyEvaluationsException {
    final double startValue = getStartValue();
    final double absoluteAccuracy = getAbsoluteAccuracy();

    double x0 = startValue;
    double x1;
    while (true) {
        x1 = x0 - (computeObjectiveValue(x0) / computeDerivativeObjectiveValue(x0));
        if (FastMath.abs(x1 - x0) <= absoluteAccuracy) {
            return x1;
        }

        x0 = x1;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:21,代码来源:NewtonSolver.java

示例7: optimize

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * Optimizes the circuit to the given ys vector
 * 
 * @param ys
 *            complex scattering parameters to which the model is optimized
 */
public void optimize(Complex[] ys) {
	// shorten parameters to optimize
	shortParameters = MCUtil.shortenParam(circuitType, parameters);
	errorFunction = new MCErrorSum(ys, this);
	optimum = null;
	try {
		optimum = optimizer.optimize(new MaxEval(10000), new ObjectiveFunction(errorFunction), GoalType.MINIMIZE,
				new InitialGuess(shortParameters), new NelderMeadSimplex(optStep));
		parameters = MCUtil.topo2Param(circuitType, optimum.getPoint());
	} catch (TooManyEvaluationsException ex) {
		// This exception can be ignored. If max eval is reached, the recent
		// parameters are stored
		// and no null pointer can appear
		parameters = new double[] { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
	}
	// save new parameters
}
 
开发者ID:noah95,项目名称:ezrlc,代码行数:24,代码来源:MCEqCircuit.java

示例8: stage

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/**
 * Compute the n-th stage integral.
 *
 * @param n Number of steps.
 * @return the value of n-th stage integral.
 * @throws TooManyEvaluationsException if the maximum number of evaluations
 * is exceeded.
 */
private double stage(final int n)
    throws TooManyEvaluationsException {
    // Function to be integrated is stored in the base class.
    final UnivariateFunction f = new UnivariateFunction() {
            public double value(double x)
                throws MathIllegalArgumentException, TooManyEvaluationsException {
                return computeObjectiveValue(x);
            }
        };

    final double min = getMin();
    final double max = getMax();
    final double step = (max - min) / n;

    double sum = 0;
    for (int i = 0; i < n; i++) {
        // Integrate over each sub-interval [a, b].
        final double a = min + i * step;
        final double b = a + step;
        final GaussIntegrator g = FACTORY.legendreHighPrecision(numberOfPoints, a, b);
        sum += g.integrate(f);
    }

    return sum;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:34,代码来源:IterativeLegendreGaussIntegrator.java

示例9: doIntegrate

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected double doIntegrate()
    throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {

    double oldt = stage(this, 0);
    iterations.incrementCount();
    while (true) {
        final int i = iterations.getCount();
        final double t = stage(this, i);
        if (i >= getMinimalIterationCount()) {
            final double delta = FastMath.abs(t - oldt);
            final double rLimit =
                getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5;
            if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) {
                return t;
            }
        }
        oldt = t;
        iterations.incrementCount();
    }

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

示例10: testMaxEvaluations

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
@Test
public void testMaxEvaluations() throws Exception {
    try{
    CircleVectorial circle = new CircleVectorial();
    circle.addPoint( 30.0,  68.0);
    circle.addPoint( 50.0,  -6.0);
    circle.addPoint(110.0, -20.0);
    circle.addPoint( 35.0,  15.0);
    circle.addPoint( 45.0,  97.0);

    LeastSquaresProblem lsp = builder(circle)
            .checkerPair(new SimpleVectorValueChecker(1e-30, 1e-30))
            .maxIterations(Integer.MAX_VALUE)
            .start(new double[]{98.680, 47.345})
            .build();

    optimizer.optimize(lsp);

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

示例11: testMaxEvaluations

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
@Test(expected=TooManyEvaluationsException.class)
public void testMaxEvaluations() throws Exception {
    CircleVectorial circle = new CircleVectorial();
    circle.addPoint( 30.0,  68.0);
    circle.addPoint( 50.0,  -6.0);
    circle.addPoint(110.0, -20.0);
    circle.addPoint( 35.0,  15.0);
    circle.addPoint( 45.0,  97.0);

    GaussNewtonOptimizer optimizer
        = new GaussNewtonOptimizer(new SimpleVectorValueChecker(1.0e-30, 1.0e-30));

    optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 },
                       new double[] { 1, 1, 1, 1, 1 },
                       new double[] { 98.680, 47.345 });
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:GaussNewtonOptimizerTest.java

示例12: minpackTest

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
private void minpackTest(MinpackFunction function, boolean exceptionExpected) {
      LevenbergMarquardtOptimizer optimizer
          = new LevenbergMarquardtOptimizer(FastMath.sqrt(2.22044604926e-16),
                                            FastMath.sqrt(2.22044604926e-16),
                                            2.22044604926e-16);
//      Assert.assertTrue(function.checkTheoreticalStartCost(optimizer.getRMS()));
      try {
          PointVectorValuePair optimum =
              optimizer.optimize(400 * (function.getN() + 1), function,
                                 function.getTarget(), function.getWeight(),
                                 function.getStartPoint());
          Assert.assertFalse(exceptionExpected);
          function.checkTheoreticalMinCost(optimizer.getRMS());
          function.checkTheoreticalMinParams(optimum);
      } catch (TooManyEvaluationsException e) {
          Assert.assertTrue(exceptionExpected);
      }
  }
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:19,代码来源:MinpackTest.java

示例13: testSinMin

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(200, f, GoalType.MINIMIZE, 4, 5).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 50);
    Assert.assertEquals(200, optimizer.getMaxEvaluations());
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(200, f, GoalType.MINIMIZE, 1, 5).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 100);
    Assert.assertTrue(optimizer.getEvaluations() >= 15);
    try {
        optimizer.optimize(10, f, GoalType.MINIMIZE, 4, 5);
        Assert.fail("an exception should have been thrown");
    } catch (TooManyEvaluationsException fee) {
        // expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:BrentOptimizerTest.java

示例14: testSinMin

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
@Test
public void testSinMin() {
    UnivariateFunction f = new Sin();
    UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(new MaxEval(200),
                                                            new UnivariateObjectiveFunction(f),
                                                            GoalType.MINIMIZE,
                                                            new SearchInterval(4, 5)).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 50);
    Assert.assertEquals(200, optimizer.getMaxEvaluations());
    Assert.assertEquals(3 * Math.PI / 2, optimizer.optimize(new MaxEval(200),
                                                            new UnivariateObjectiveFunction(f),
                                                            GoalType.MINIMIZE,
                                                            new SearchInterval(1, 5)).getPoint(), 1e-8);
    Assert.assertTrue(optimizer.getEvaluations() <= 100);
    Assert.assertTrue(optimizer.getEvaluations() >= 15);
    try {
        optimizer.optimize(new MaxEval(10),
                           new UnivariateObjectiveFunction(f),
                           GoalType.MINIMIZE,
                           new SearchInterval(4, 5));
        Assert.fail("an exception should have been thrown");
    } catch (TooManyEvaluationsException fee) {
        // expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:BrentOptimizerTest.java

示例15: testQuinticMax

import org.apache.commons.math3.exception.TooManyEvaluationsException; //导入依赖的package包/类
@Test
public void testQuinticMax() {
    // The quintic function has zeros at 0, +-0.5 and +-1.
    // The function has a local maximum at 0.27195613.
    UnivariateFunction f = new QuinticFunction();
    UnivariateOptimizer optimizer = new BrentOptimizer(1e-12, 1e-14);
    Assert.assertEquals(0.27195613, optimizer.optimize(new MaxEval(100),
                                                       new UnivariateObjectiveFunction(f),
                                                       GoalType.MAXIMIZE,
                                                       new SearchInterval(0.2, 0.3)).getPoint(), 1e-8);
    try {
        optimizer.optimize(new MaxEval(5),
                           new UnivariateObjectiveFunction(f),
                           GoalType.MAXIMIZE,
                           new SearchInterval(0.2, 0.3));
        Assert.fail("an exception should have been thrown");
    } catch (TooManyEvaluationsException miee) {
        // expected
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:BrentOptimizerTest.java


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