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


Java PointValuePair.getPoint方法代码示例

本文整理汇总了Java中org.apache.commons.math3.optim.PointValuePair.getPoint方法的典型用法代码示例。如果您正苦于以下问题:Java PointValuePair.getPoint方法的具体用法?Java PointValuePair.getPoint怎么用?Java PointValuePair.getPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.optim.PointValuePair的用法示例。


在下文中一共展示了PointValuePair.getPoint方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrieveResults

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
private void retrieveResults(PointValuePair result) {
    int rows=suppliers.getValue();
    int cols=recipients.getValue();
    if (excessCheckbox.isSelected())
        cols++;
    double[] data=result.getPoint();
    for (int i = 0; i < rows; i++) {
        setVectorElement(excess,i,0);
    }
    for (int i = 0; i < data.length; i++) {
        int x=i%cols;
        int y=i/cols;
        if(x<recipients.getValue())
            setMatrixElement(this.result,y,x,data[i]);
        else
            setVectorElement(this.excess,y,data[i]);
    }
    double value=result.getValue();
    cost.setText(String.valueOf(value));
}
 
开发者ID:superdurszlak,项目名称:Transport-Production-Issue,代码行数:21,代码来源:Controller.java

示例2: solve

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Override
public void solve(double[] dir)
{
    /* Check the dimension of the vectorspace where lives dir */
    if (dir.length != d)
        throw new LinearProgrammingSolverException(dddirMessage);
    /* Update the constraints set of the simplex solver if modification */
    if (lcListModified)
    {
        List <LinearConstraint> lcList = new ArrayList <LinearConstraint>();
        int n = dirList.size();
        for (int i = 0 ; i < n ; i++) lcList.add(new LinearConstraint(dirList.get(i), Relationship.LEQ, valList.get(i)));
        lcSet = new LinearConstraintSet(lcList);
    }
    /* Evaluation */
    PointValuePair res = solver.optimize(new LinearObjectiveFunction(dir, 0), lcSet, GoalType.MAXIMIZE);
    /* Update the results and the flags */
    point = res.getPoint ();
    value = res.getSecond ();
    evaluated = true;
    lcListModified = false;
}
 
开发者ID:viryfrederic,项目名称:3plib,代码行数:23,代码来源:ACMLinearProgrammingSolver.java

示例3: testMath283

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的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

示例4: doTest

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的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

示例5: testMath293

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Test
public void testMath293() {
  LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 );
  Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
  constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0));
  constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0));
  constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0));
  constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0));
  constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0));

  SimplexSolver solver = new SimplexSolver();
  PointValuePair solution1 = solver.optimize(DEFAULT_MAX_ITER, f, new LinearConstraintSet(constraints),
                                             GoalType.MAXIMIZE, new NonNegativeConstraint(true));

  Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001);
  Assert.assertEquals(0.0, solution1.getPoint()[1], .0001);
  Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001);
  Assert.assertEquals(0.0, solution1.getPoint()[3], .0001);
  Assert.assertEquals(0.0, solution1.getPoint()[4], .0001);
  Assert.assertEquals(30.0, solution1.getPoint()[5], .0001);
  Assert.assertEquals(40.57143, solution1.getValue(), .0001);

  double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1];
  double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3];
  double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5];

  f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 );
  constraints = new ArrayList<LinearConstraint>();
  constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0));
  constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0));
  constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA));
  constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB));
  constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC));

  PointValuePair solution2 = solver.optimize(DEFAULT_MAX_ITER, f, new LinearConstraintSet(constraints),
                                             GoalType.MAXIMIZE, new NonNegativeConstraint(true));
  Assert.assertEquals(40.57143, solution2.getValue(), .0001);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:39,代码来源:SimplexSolverTest.java

示例6: validSolution

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
private static boolean validSolution(PointValuePair solution, List<LinearConstraint> constraints, double epsilon) {
    double[] vals = solution.getPoint();
    for (LinearConstraint c : constraints) {
        double[] coeffs = c.getCoefficients().toArray();
        double result = 0.0d;
        for (int i = 0; i < vals.length; i++) {
            result += vals[i] * coeffs[i];
        }
        
        switch (c.getRelationship()) {
        case EQ:
            if (!Precision.equals(result, c.getValue(), epsilon)) {
                return false;
            }
            break;
            
        case GEQ:
            if (Precision.compareTo(result, c.getValue(), epsilon) < 0) {
                return false;
            }
            break;
            
        case LEQ:
            if (Precision.compareTo(result, c.getValue(), epsilon) > 0) {
                return false;
            }
            break;
        }
    }
    
    return true;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:33,代码来源:SimplexSolverTest.java

示例7: run

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Override
public void run() throws Exception {
	// Let's find optimum for beta0, beta1, beta2
	NelderMeadSimplex optMethod = new NelderMeadSimplex(3);
	
	/*
	SimplexOptimizer optimizer = new SimplexOptimizer(1e-5, 1e-10);
	final PointValuePair optimum =
			optimizer.optimize(
				new MaxEval(150), 
                new ObjectiveFunction(this), 
                GoalType.MAXIMIZE, 
                new InitialGuess(new double[]{ Math.log(.6), Math.log(.2), Math.log(0.05) }), 
                optMethod);
	 */
     // new NelderMeadSimplex(new double[]{ 0.2, 0.2 }));
	
	/*
	SimplexOptimizer optimizer = new SimplexOptimizer(1e-5, 1e-10);
	final PointValuePair optimum =
			optimizer.optimize(
				new MaxEval(200), 
                new ObjectiveFunction(this), 
                GoalType.MAXIMIZE, 
                new InitialGuess(new double[]{ .6, .2, 0.05 }), 
                optMethod);
	*/
	
	
	//PowellOptimizer optimizer = new PowellOptimizer(1e-8, 1e-5, 1e-4, 1e-4);
	BOBYQAOptimizer optimizer = new BOBYQAOptimizer(2*3+1+2); // 2*point.length + 1+additional
	final PointValuePair optimum =
			optimizer.optimize(
				new MaxEval(150), 
                new ObjectiveFunction(this), 
                GoalType.MAXIMIZE, 
                new InitialGuess(new double[]{ 1.0, 1.0, 1.0 }),
                new SimpleBounds(new double[] { 0.0 , 0.0 , 0.0 },
                          new double[] { 3.5 , 3.5, 3.5 }));

	
	double[] point = optimum.getPoint();
	System.out.print("point= ");
	for(int i=0; i< point.length; i++) System.out.print("  "+ point[i]);
	System.out.println(" ");
	System.out.println("value = "+ optimum.getValue());
	
}
 
开发者ID:mrc-ide,项目名称:PhyDyn,代码行数:49,代码来源:PopModelParameterEstimation.java

示例8: process

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Override
public Data process(Data data) {

    if (initialRKey != null) {
        initialR = (double) data.get(initialRKey);
    }
    if (initialXKey != null) {
        initialX = (double) data.get(initialXKey);
    }
    if (initialYKey != null) {
        initialX = (double) data.get(initialYKey);
    }

    double[] photoncharge = (double[]) data.get(photonchargeKey);
    int[] cleaningPixel = (int[]) data.get(cleaningPixelKey);

    LightDistributionNegLogLikelihood negLnL = new LightDistributionNegLogLikelihood(photoncharge, cleaningPixel);
    ObjectiveFunction ob_negLnL = new ObjectiveFunction(negLnL);

    MaxEval maxEval = new MaxEval(50000);
    double[] initials = new double[]{
            initialR,
            initialX,
            initialY,
            initialSigma,
            initialRho,
            initialPhi,
            initialEps,
    };

    InitialGuess start_values = new InitialGuess(initials);
    PowellOptimizer optimizer = new PowellOptimizer(1e-4, 1e-2);

    double[] result_point = new double[initials.length];
    try {
        PointValuePair result = optimizer.optimize(ob_negLnL, GoalType.MINIMIZE, start_values, maxEval);
        result_point = result.getPoint();
    } catch (TooManyEvaluationsException e) {
        for (int i = 0; i < result_point.length; i++) {
            result_point[i] = Double.NaN;
        }
    }


    double r = result_point[0];
    double x = result_point[1];
    double y = result_point[2];
    double sigma = result_point[3];
    double rho = result_point[4];
    double phi = result_point[5];
    double eps = result_point[6];
    double[] test = new double[Constants.N_PIXELS];
    for (int pix = 0; pix < Constants.N_PIXELS; pix++) {
        test[pix] = negLnL.photon_expectance_pixel(pix, r, x, y, sigma, rho, phi, eps);
    }
    data.put("photon_expectance_fit", test);

    data.put(outputKey + "r", r);
    data.put(outputKey + "x", x);
    data.put(outputKey + "y", y);
    data.put(outputKey + "sigma", sigma);
    data.put(outputKey + "rho", rho);
    data.put(outputKey + "phi", phi);
    data.put(outputKey + "eps", eps);
    if (result_point[0] != Double.NaN) {
        data.put(outputKey + "circle", new EllipseOverlay(x, y, r, r, phi));
        data.put(outputKey + "circle_sigma1", new EllipseOverlay(x, y, r - sigma, r - sigma, phi));
        data.put(outputKey + "circle_sigma2", new EllipseOverlay(x, y, r + sigma, r + sigma, phi));
    } else {
        data.put(outputKey + "circle", new EllipseOverlay(500, 0, 1, 1, 0));
        data.put(outputKey + "circle_sigma1", new EllipseOverlay(500, 0, 1, 1, 0));
        data.put(outputKey + "circle_sigma2", new EllipseOverlay(500, 0, 1, 1, 0));
    }

    return data;
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:77,代码来源:LightDistributionFit.java

示例9: doOptimize

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws TooManyIterationsException,
           UnboundedSolutionException,
           NoFeasibleSolutionException {

    // reset the tableau to indicate a non-feasible solution in case
    // we do not pass phase 1 successfully
    if (solutionCallback != null) {
        solutionCallback.setTableau(null);
    }

    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           isRestrictedToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    // after phase 1, we are sure to have a feasible solution
    if (solutionCallback != null) {
        solutionCallback.setTableau(tableau);
    }

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }

    // check that the solution respects the nonNegative restriction in case
    // the epsilon/cutOff values are too large for the actual linear problem
    // (e.g. with very small constraint coefficients), the solver might actually
    // find a non-valid solution (with negative coefficients).
    final PointValuePair solution = tableau.getSolution();
    if (isRestrictedToNonNegative()) {
        final double[] coeff = solution.getPoint();
        for (int i = 0; i < coeff.length; i++) {
            if (Precision.compareTo(coeff[i], 0, epsilon) < 0) {
                throw new NoFeasibleSolutionException();
            }
        }
    }
    return solution;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:49,代码来源:SimplexSolver.java

示例10: testTwoSets

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Test
public void testTwoSets() {
    final double epsilon = 1.0e-7;
    LinearProblem problem = new LinearProblem(new double[][] {
            {  2,  1,   0,  4,       0, 0 },
            { -4, -2,   3, -7,       0, 0 },
            {  4,  1,  -2,  8,       0, 0 },
            {  0, -3, -12, -1,       0, 0 },
            {  0,  0,   0,  0, epsilon, 1 },
            {  0,  0,   0,  0,       1, 1 }
    }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2});

    final Preconditioner preconditioner
        = new Preconditioner() {
                public double[] precondition(double[] point, double[] r) {
                    double[] d = r.clone();
                    d[0] /=  72.0;
                    d[1] /=  30.0;
                    d[2] /= 314.0;
                    d[3] /= 260.0;
                    d[4] /= 2 * (1 + epsilon * epsilon);
                    d[5] /= 4.0;
                    return d;
                }
            };

    NonLinearConjugateGradientOptimizer optimizer
       = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                 new SimpleValueChecker(1e-13, 1e-13),
                                                 1e-7, 1e-7, 1,
                                                 preconditioner);

    PointValuePair optimum
        = optimizer.optimize(new MaxEval(100),
                             problem.getObjectiveFunction(),
                             problem.getObjectiveFunctionGradient(),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 0, 0, 0, 0, 0, 0 }));

    final double[] result = optimum.getPoint();
    final double[] expected = {3, 4, -1, -2, 1 + epsilon, 1 - epsilon};

    Assert.assertEquals(expected[0], result[0], 1.0e-7);
    Assert.assertEquals(expected[1], result[1], 1.0e-7);
    Assert.assertEquals(expected[2], result[2], 1.0e-9);
    Assert.assertEquals(expected[3], result[3], 1.0e-8);
    Assert.assertEquals(expected[4] + epsilon, result[4], 1.0e-6);
    Assert.assertEquals(expected[5] - epsilon, result[5], 1.0e-6);

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

示例11: testIllConditioned

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
@Test
public void testIllConditioned() {
    LinearProblem problem1 = new LinearProblem(new double[][] {
            { 10.0, 7.0,  8.0,  7.0 },
            {  7.0, 5.0,  6.0,  5.0 },
            {  8.0, 6.0, 10.0,  9.0 },
            {  7.0, 5.0,  9.0, 10.0 }
    }, new double[] { 32, 23, 33, 31 });
    NonLinearConjugateGradientOptimizer optimizer
        = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                  new SimpleValueChecker(1e-13, 1e-13),
                                                  1e-15, 1e-15, 1);
    PointValuePair optimum1
        = optimizer.optimize(new MaxEval(200),
                             problem1.getObjectiveFunction(),
                             problem1.getObjectiveFunctionGradient(),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 0, 1, 2, 3 }));
    Assert.assertEquals(1.0, optimum1.getPoint()[0], 1.0e-4);
    Assert.assertEquals(1.0, optimum1.getPoint()[1], 1.0e-3);
    Assert.assertEquals(1.0, optimum1.getPoint()[2], 1.0e-4);
    Assert.assertEquals(1.0, optimum1.getPoint()[3], 1.0e-4);

    LinearProblem problem2 = new LinearProblem(new double[][] {
            { 10.00, 7.00, 8.10, 7.20 },
            {  7.08, 5.04, 6.00, 5.00 },
            {  8.00, 5.98, 9.89, 9.00 },
            {  6.99, 4.99, 9.00, 9.98 }
    }, new double[] { 32, 23, 33, 31 });
    PointValuePair optimum2
        = optimizer.optimize(new MaxEval(200),
                             problem2.getObjectiveFunction(),
                             problem2.getObjectiveFunctionGradient(),
                             GoalType.MINIMIZE,
                             new InitialGuess(new double[] { 0, 1, 2, 3 }));

    final double[] result2 = optimum2.getPoint();
    final double[] expected2 = {-81, 137, -34, 22};

    Assert.assertEquals(expected2[0], result2[0], 2);
    Assert.assertEquals(expected2[1], result2[1], 4);
    Assert.assertEquals(expected2[2], result2[2], 1);
    Assert.assertEquals(expected2[3], result2[3], 1);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:45,代码来源:NonLinearConjugateGradientOptimizerTest.java

示例12: testFitAccuracyDependsOnBoundary

import org.apache.commons.math3.optim.PointValuePair; //导入方法依赖的package包/类
/**
 * Cf. MATH-867
 */
@Test
public void testFitAccuracyDependsOnBoundary() {
    final CMAESOptimizer optimizer
        = new CMAESOptimizer(30000, 0, true, 10,
                             0, new MersenneTwister(), false, null);
    final MultivariateFunction fitnessFunction = new MultivariateFunction() {
            public double value(double[] parameters) {
                final double target = 11.1;
                final double error = target - parameters[0];
                return error * error;
            }
        };

    final double[] start = { 1 };
 
    // No bounds.
    PointValuePair result = optimizer.optimize(new MaxEval(100000),
                                               new ObjectiveFunction(fitnessFunction),
                                               GoalType.MINIMIZE,
                                               SimpleBounds.unbounded(1),
                                               new CMAESOptimizer.PopulationSize(5),
                                               new CMAESOptimizer.Sigma(new double[] { 1e-1 }),
                                               new InitialGuess(start));
    final double resNoBound = result.getPoint()[0];

    // Optimum is near the lower bound.
    final double[] lower = { -20 };
    final double[] upper = { 5e16 };
    final double[] sigma = { 10 };
    result = optimizer.optimize(new MaxEval(100000),
                                new ObjectiveFunction(fitnessFunction),
                                GoalType.MINIMIZE,
                                new CMAESOptimizer.PopulationSize(5),
                                new CMAESOptimizer.Sigma(sigma),
                                new InitialGuess(start),
                                new SimpleBounds(lower, upper));
    final double resNearLo = result.getPoint()[0];

    // Optimum is near the upper bound.
    lower[0] = -5e16;
    upper[0] = 20;
    result = optimizer.optimize(new MaxEval(100000),
                                new ObjectiveFunction(fitnessFunction),
                                GoalType.MINIMIZE,
                                new CMAESOptimizer.PopulationSize(5),
                                new CMAESOptimizer.Sigma(sigma),
                                new InitialGuess(start),
                                new SimpleBounds(lower, upper));
    final double resNearHi = result.getPoint()[0];

    // System.out.println("resNoBound=" + resNoBound +
    //                    " resNearLo=" + resNearLo +
    //                    " resNearHi=" + resNearHi);

    // The two values currently differ by a substantial amount, indicating that
    // the bounds definition can prevent reaching the optimum.
    Assert.assertEquals(resNoBound, resNearLo, 1e-3);
    Assert.assertEquals(resNoBound, resNearHi, 1e-3);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:63,代码来源:CMAESOptimizerTest.java


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