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


Java ObjectiveFunction类代码示例

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


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

示例1: applyToNetwork

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Override
public double applyToNetwork(final MixedClearingNetwork network) {
   Preconditions.checkNotNull(network);
   final int dimension = network.getNumberOfEdges();
   
   final ResidualCostFunction aggregateCostFunction =
      super.getResidualScalarCostFunction(network);
   final RealVector
      start = new ArrayRealVector(network.getNumberOfEdges());
   start.set(1.0);                                       // Initial rate guess.
   
   final BOBYQAOptimizer optimizer = new BOBYQAOptimizer(2*dimension + 1, 1.2, 1.e-8);
   final PointValuePair result = optimizer.optimize(
      new MaxEval(maximumEvaluations),
      new ObjectiveFunction(aggregateCostFunction),
      GoalType.MINIMIZE,
      new SimpleBounds(new double[dimension], ArrayUtil.ones(dimension)),
      new InitialGuess(start.toArray())
      );
   
   final double residualCost = result.getValue();
   System.out.println("Network cleared: residual cost: " + residualCost + ".");
   
   return residualCost;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:26,代码来源:BoundedQuadraticEstimationClearingAlgorithm.java

示例2: findOptimum

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Override
public TreeMap<Double, TariffSpecification> findOptimum(TariffUtilityEstimate tariffUtilityEstimate,
    int NUM_RATES, int numEval) {
  
  double[] startingVertex = new double[NUM_RATES]; // start from the fixed-rate tariff's offset
  Arrays.fill(startingVertex, 0.0);
  
  PowellOptimizer optimizer = new PowellOptimizer(1e-3, 5);
  
  // needed since one optimization found positive 
  // charges (paying customer to consume...)
  double[][] boundaries = createBoundaries(NUM_RATES);
 
  final PointValuePair optimum
      = optimizer.optimize(
          new MaxEval(numEval),
          //new ObjectiveFunction(new MultivariateFunctionMappingAdapter(tariffUtilityEstimate, boundaries[0], boundaries[1])),
          new ObjectiveFunction(new OptimizerWrapperApacheObjective(tariffUtilityEstimate)),
          GoalType.MAXIMIZE,
          new InitialGuess(startingVertex)
          );
          
  TreeMap<Double, TariffSpecification> eval2TOUTariff = new TreeMap<Double, TariffSpecification>();
  eval2TOUTariff.put(optimum.getValue(), tariffUtilityEstimate.getCorrespondingSpec(optimum.getKey()));
  return eval2TOUTariff;
}
 
开发者ID:LARG,项目名称:TacTex,代码行数:27,代码来源:OptimizerWrapperApachePowell.java

示例3: optimize

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
/**
 * Optimizes parameters using the Nelder-Mead Method
 * @param initialGuess initial guess / state required for Nelder-Mead-Method
 * @param costFunction which defines that the Mean Squared Error has to be minimized
 * @return the optimized values
 */
private static double[] optimize(double[] initialGuess, MultivariateFunctionMappingAdapter costFunction) {
    double[] result;

    SimplexOptimizer optimizer = new SimplexOptimizer(simplexRelativeThreshold, simplexAbsoluteThreshold);

    PointValuePair unBoundedResult = optimizer.optimize(
            GoalType.MINIMIZE,
            new MaxIter(MAX_ALLOWED_NUMBER_OF_ITERATION),
            new MaxEval(MAX_ALLOWED_NUMBER_OF_EVALUATION),
            new InitialGuess(initialGuess),
            new ObjectiveFunction(costFunction),
            new NelderMeadSimplex(initialGuess.length));

    result = costFunction.unboundedToBounded(unBoundedResult.getPoint());
    return result;
}
 
开发者ID:lidox,项目名称:reaction-test,代码行数:23,代码来源:NelderMeadOptimizer.java

示例4: optimize

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的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

示例5: testMinimize1

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMinimize1() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-11, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { -3, 0 }),
                             new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xM, optimum.getPoint()[0], 4e-6);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXmYp, optimum.getValue(), 8e-13);
    Assert.assertTrue(optimizer.getEvaluations() > 120);
    Assert.assertTrue(optimizer.getEvaluations() < 150);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerMultiDirectionalTest.java

示例6: testMinimize2

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMinimize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-11, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 1, 0 }),
                             new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 2e-8);
    Assert.assertEquals(fourExtrema.yM, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXpYm, optimum.getValue(), 2e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 120);
    Assert.assertTrue(optimizer.getEvaluations() < 150);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerMultiDirectionalTest.java

示例7: testMaximize1

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMaximize1() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-11, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MAXIMIZE,
                             new InitialGuess(new double[] { -3.0, 0.0 }),
                             new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xM, optimum.getPoint()[0], 7e-7);
    Assert.assertEquals(fourExtrema.yM, optimum.getPoint()[1], 3e-7);
    Assert.assertEquals(fourExtrema.valueXmYm, optimum.getValue(), 2e-14);
    Assert.assertTrue(optimizer.getEvaluations() > 120);
    Assert.assertTrue(optimizer.getEvaluations() < 150);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerMultiDirectionalTest.java

示例8: testMaximize2

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMaximize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-15, 1e-30));
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(200),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MAXIMIZE,
                             new InitialGuess(new double[] { 1, 0 }),
                             new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 2e-8);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXpYp, optimum.getValue(), 2e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 180);
    Assert.assertTrue(optimizer.getEvaluations() < 220);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerMultiDirectionalTest.java

示例9: testMath283

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMath283() {
    // fails because MultiDirectional.iterateSimplex is looping forever
    // the while(true) should be replaced with a convergence check
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-14, 1e-14);
    final Gaussian2D function = new Gaussian2D(0, 0, 1);
    PointValuePair estimate = optimizer.optimize(new MaxEval(1000),
                                                 new ObjectiveFunction(function),
                                                 GoalType.MAXIMIZE,
                                                 new InitialGuess(function.getMaximumPosition()),
                                                 new MultiDirectionalSimplex(2));
    final double EPSILON = 1e-5;
    final double expectedMaximum = function.getMaximum();
    final double actualMaximum = estimate.getValue();
    Assert.assertEquals(expectedMaximum, actualMaximum, EPSILON);

    final double[] expectedPosition = function.getMaximumPosition();
    final double[] actualPosition = estimate.getPoint();
    Assert.assertEquals(expectedPosition[0], actualPosition[0], EPSILON );
    Assert.assertEquals(expectedPosition[1], actualPosition[1], EPSILON );
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:SimplexOptimizerMultiDirectionalTest.java

示例10: doTest

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
/**
 * @param func Function to optimize.
 * @param optimum Expected optimum.
 * @param init Starting point.
 * @param goal Minimization or maximization.
 * @param fTol Tolerance (relative error on the objective function) for
 * "Powell" algorithm.
 * @param pointTol Tolerance for checking that the optimum is correct.
 */
private void doTest(MultivariateFunction func,
                    double[] optimum,
                    double[] init,
                    GoalType goal,
                    double fTol,
                    double pointTol) {
    final PowellOptimizer optim = new PowellOptimizer(fTol, Math.ulp(1d));

    final PointValuePair result = optim.optimize(new MaxEval(1000),
                                                 new ObjectiveFunction(func),
                                                 goal,
                                                 new InitialGuess(init));
    final double[] point = result.getPoint();

    for (int i = 0, dim = optimum.length; i < dim; i++) {
        Assert.assertEquals("found[" + i + "]=" + point[i] + " value=" + result.getValue(),
                            optimum[i], point[i], pointTol);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:29,代码来源:PowellOptimizerTest.java

示例11: testMinimize1

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMinimize1() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { -3, 0 }),
                             new NelderMeadSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xM, optimum.getPoint()[0], 2e-7);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 2e-5);
    Assert.assertEquals(fourExtrema.valueXmYp, optimum.getValue(), 6e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 90);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerNelderMeadTest.java

示例12: testMinimize2

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMinimize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 1, 0 }),
                             new NelderMeadSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 5e-6);
    Assert.assertEquals(fourExtrema.yM, optimum.getPoint()[1], 6e-6);
    Assert.assertEquals(fourExtrema.valueXpYm, optimum.getValue(), 1e-11);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 90);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerNelderMeadTest.java

示例13: testMaximize1

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMaximize1() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MAXIMIZE,
                             new InitialGuess(new double[] { -3, 0 }),
                             new NelderMeadSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xM, optimum.getPoint()[0], 1e-5);
    Assert.assertEquals(fourExtrema.yM, optimum.getPoint()[1], 3e-6);
    Assert.assertEquals(fourExtrema.valueXmYm, optimum.getValue(), 3e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 90);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerNelderMeadTest.java

示例14: testMaximize2

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testMaximize2() {
    SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
    final FourExtrema fourExtrema = new FourExtrema();

    final PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             new ObjectiveFunction(fourExtrema),
                             GoalType.MAXIMIZE,
                             new InitialGuess(new double[] { 1, 0 }),
                             new NelderMeadSimplex(new double[] { 0.2, 0.2 }));
    Assert.assertEquals(fourExtrema.xP, optimum.getPoint()[0], 4e-6);
    Assert.assertEquals(fourExtrema.yP, optimum.getPoint()[1], 5e-6);
    Assert.assertEquals(fourExtrema.valueXpYp, optimum.getValue(), 7e-12);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 90);

    // Check that the number of iterations is updated (MATH-949).
    Assert.assertTrue(optimizer.getIterations() > 0);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerNelderMeadTest.java

示例15: testRosenbrock

import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; //导入依赖的package包/类
@Test
public void testRosenbrock() {

    Rosenbrock rosenbrock = new Rosenbrock();
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
    PointValuePair optimum
    = optimizer.optimize(new MaxEval(100),
                         new ObjectiveFunction(rosenbrock),
                         GoalType.MINIMIZE,
                         new InitialGuess(new double[] { -1.2, 1 }),
                            new NelderMeadSimplex(new double[][] {
                                    { -1.2,  1 },
                                    { 0.9, 1.2 },
                                    {  3.5, -2.3 } }));

    Assert.assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
    Assert.assertTrue(optimizer.getEvaluations() > 40);
    Assert.assertTrue(optimizer.getEvaluations() < 50);
    Assert.assertTrue(optimum.getValue() < 8e-4);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:SimplexOptimizerNelderMeadTest.java


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