List of usage examples for org.apache.commons.math3.optim.nonlinear.scalar.gradient NonLinearConjugateGradientOptimizer NonLinearConjugateGradientOptimizer
public NonLinearConjugateGradientOptimizer(final Formula updateFormula, ConvergenceChecker<PointValuePair> checker)
From source file:com.itemanalysis.psychometrics.factoranalysis.WeightedLeastSquaresMethod.java
public double estimateParameters() { Sinv = new LUDecomposition(R).getSolver().getInverse(); WLSObjectiveFunction objectiveFunction = new WLSObjectiveFunction(); optimizer = new NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8)); solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(), objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(getStartValues())); computeFactorLoadings(solution.getPoint()); return solution.getValue(); }
From source file:com.itemanalysis.psychometrics.factoranalysis.GeneralizedLeastSquaresMethod.java
public double estimateParameters() { Sinv = new LUDecomposition(R).getSolver().getInverse(); GLSObjectiveFunction objectiveFunction = new GLSObjectiveFunction(); optimizer = new NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8)); solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(), objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(getStartValues())); computeFactorLoadings(solution.getPoint()); return solution.getValue(); }
From source file:com.itemanalysis.psychometrics.factoranalysis.MaximumLikelihoodMethod.java
public double estimateParameters() { MLObjectiveFunction objectiveFunction = new MLObjectiveFunction(); // System.out.println("START VALUES: " + Arrays.toString(getStartValues())); optimizer = new NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-8, 1e-8)); solution = optimizer.optimize(new MaxEval(1000), objectiveFunction.getObjectiveFunction(), objectiveFunction.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(getStartValues())); computeFactorLoadings(solution.getPoint()); return solution.getValue(); }
From source file:net.sf.tweety.math.opt.solver.ApacheCommonsNonLinearConjugateGradientOptimizer.java
@Override public Map<Variable, Term> solve(ConstraintSatisfactionProblem problem) throws GeneralMathException { // only optimization problems if (!(problem instanceof OptimizationProblem)) throw new IllegalArgumentException("Only optimization problems allowed for this solver."); OptimizationProblem p = (OptimizationProblem) problem; // no constraints allowed if (!p.isEmpty()) throw new IllegalArgumentException( "Only optimization problems without constraints allowed for this solver."); final Term target = p.getTargetFunction(); final List<Variable> vars = new ArrayList<Variable>(target.getVariables()); MultivariateFunction acTarget = new MultivariateFunction() { @Override/*from w w w . j a v a 2 s . c o m*/ public double value(double[] arg0) { return target.replaceAllTerms(arg0, vars).doubleValue(); } }; final Term[] targetGradient = new Term[vars.size()]; for (int i = 0; i < vars.size(); i++) targetGradient[i] = target.derive(vars.get(i)); MultivariateVectorFunction acTargetGradient = new MultivariateVectorFunction() { @Override public double[] value(double[] arg0) throws IllegalArgumentException { double[] result = new double[arg0.length]; for (int i = 0; i < arg0.length; i++) result[i] = targetGradient[i].replaceAllTerms(arg0, vars).doubleValue(); return result; } }; // create solver NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer( NonLinearConjugateGradientOptimizer.Formula.FLETCHER_REEVES, new SimplePointChecker<PointValuePair>(this.precision, this.precision)); double[] s = new double[vars.size()]; for (int i = 0; i < vars.size(); i++) s[i] = 0.5; PointValuePair val = optimizer.optimize(new ObjectiveFunction(acTarget), new ObjectiveFunctionGradient(acTargetGradient), new InitialGuess(s), p.getType() == OptimizationProblem.MAXIMIZE ? GoalType.MAXIMIZE : GoalType.MINIMIZE, new MaxEval(this.maxEval)); Map<Variable, Term> result = new HashMap<Variable, Term>(); for (int i = 0; i < vars.size(); i++) result.put(vars.get(i), new FloatConstant(val.getPoint()[i])); return result; }
From source file:uk.ac.diamond.scisoft.analysis.optimize.ApacheOptimizer.java
private MultivariateOptimizer createOptimizer() { SimplePointChecker<PointValuePair> checker = new SimplePointChecker<PointValuePair>(REL_TOL, ABS_TOL); switch (optimizer) { case CONJUGATE_GRADIENT: return new NonLinearConjugateGradientOptimizer(Formula.POLAK_RIBIERE, checker); case BOBYQA:// w w w. ja v a 2 s . c o m return new BOBYQAOptimizer(n + 2); case CMAES: return new CMAESOptimizer(MAX_ITER, 0., true, 0, 10, seed == null ? new Well19937c() : new Well19937c(seed), false, new SimplePointChecker<PointValuePair>(REL_TOL, ABS_TOL)); case POWELL: return new PowellOptimizer(REL_TOL, ABS_TOL, checker); case SIMPLEX_MD: case SIMPLEX_NM: return new SimplexOptimizer(checker); default: throw new IllegalStateException("Should not be called"); } }