You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/02/25 22:49:42 UTC
[14/18] [math] Remove deprecated optimization package.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateOptimizer.java b/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateOptimizer.java
deleted file mode 100644
index 8af7c47..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateOptimizer.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MaxCountExceededException;
-import org.apache.commons.math4.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.optimization.BaseMultivariateOptimizer;
-import org.apache.commons.math4.optimization.ConvergenceChecker;
-import org.apache.commons.math4.optimization.GoalType;
-import org.apache.commons.math4.optimization.InitialGuess;
-import org.apache.commons.math4.optimization.OptimizationData;
-import org.apache.commons.math4.optimization.PointValuePair;
-import org.apache.commons.math4.optimization.SimpleBounds;
-import org.apache.commons.math4.optimization.SimpleValueChecker;
-import org.apache.commons.math4.util.Incrementor;
-
-/**
- * Base class for implementing optimizers for multivariate scalar functions.
- * This base class handles the boiler-plate methods associated to thresholds,
- * evaluations counting, initial guess and simple bounds settings.
- *
- * @param <FUNC> Type of the objective function to be optimized.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 2.2
- */
-@Deprecated
-public abstract class BaseAbstractMultivariateOptimizer<FUNC extends MultivariateFunction>
- implements BaseMultivariateOptimizer<FUNC> {
- /** Evaluations counter. */
- protected final Incrementor evaluations = new Incrementor();
- /** Convergence checker. */
- private ConvergenceChecker<PointValuePair> checker;
- /** Type of optimization. */
- private GoalType goal;
- /** Initial guess. */
- private double[] start;
- /** Lower bounds. */
- private double[] lowerBound;
- /** Upper bounds. */
- private double[] upperBound;
- /** Objective function. */
- private MultivariateFunction function;
-
- /**
- * Simple constructor with default settings.
- * The convergence check is set to a {@link SimpleValueChecker}.
- * @deprecated See {@link SimpleValueChecker#SimpleValueChecker()}
- */
- @Deprecated
- protected BaseAbstractMultivariateOptimizer() {
- this(new SimpleValueChecker());
- }
- /**
- * @param checker Convergence checker.
- */
- protected BaseAbstractMultivariateOptimizer(ConvergenceChecker<PointValuePair> checker) {
- this.checker = checker;
- }
-
- /** {@inheritDoc} */
- public int getMaxEvaluations() {
- return evaluations.getMaximalCount();
- }
-
- /** {@inheritDoc} */
- public int getEvaluations() {
- return evaluations.getCount();
- }
-
- /** {@inheritDoc} */
- public ConvergenceChecker<PointValuePair> getConvergenceChecker() {
- return checker;
- }
-
- /**
- * Compute the objective function value.
- *
- * @param point Point at which the objective function must be evaluated.
- * @return the objective function value at the specified point.
- * @throws TooManyEvaluationsException if the maximal number of
- * evaluations is exceeded.
- */
- protected double computeObjectiveValue(double[] point) {
- try {
- evaluations.incrementCount();
- } catch (MaxCountExceededException e) {
- throw new TooManyEvaluationsException(e.getMax());
- }
- return function.value(point);
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated As of 3.1. Please use
- * {@link #optimize(int,MultivariateFunction,GoalType,OptimizationData[])}
- * instead.
- */
- @Deprecated
- public PointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
- double[] startPoint) {
- return optimizeInternal(maxEval, f, goalType, new InitialGuess(startPoint));
- }
-
- /**
- * 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.
- * @since 3.1
- */
- public PointValuePair optimize(int maxEval,
- FUNC f,
- GoalType goalType,
- OptimizationData... optData) {
- return optimizeInternal(maxEval, f, goalType, optData);
- }
-
- /**
- * Optimize an objective function.
- *
- * @param f Objective function.
- * @param goalType Type of optimization goal: either
- * {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}.
- * @param startPoint Start point for optimization.
- * @param maxEval Maximum number of function evaluations.
- * @return the point/value pair giving the optimal value for objective
- * function.
- * @throws org.apache.commons.math4.exception.DimensionMismatchException
- * if the start point dimension is wrong.
- * @throws org.apache.commons.math4.exception.TooManyEvaluationsException
- * if the maximal number of evaluations is exceeded.
- * @throws org.apache.commons.math4.exception.NullArgumentException if
- * any argument is {@code null}.
- * @deprecated As of 3.1. Please use
- * {@link #optimize(int,MultivariateFunction,GoalType,OptimizationData[])}
- * instead.
- */
- @Deprecated
- protected PointValuePair optimizeInternal(int maxEval, FUNC f, GoalType goalType,
- double[] startPoint) {
- return optimizeInternal(maxEval, f, goalType, new InitialGuess(startPoint));
- }
-
- /**
- * 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();
- }
-
- /**
- * Scans the list of (required and optional) optimization data that
- * characterize the problem.
- *
- * @param optData Optimization data. The following data will be looked for:
- * <ul>
- * <li>{@link InitialGuess}</li>
- * <li>{@link SimpleBounds}</li>
- * </ul>
- */
- private void parseOptimizationData(OptimizationData... optData) {
- // The existing values (as set by the previous call) are reused if
- // not provided in the argument list.
- for (OptimizationData data : optData) {
- if (data instanceof InitialGuess) {
- start = ((InitialGuess) data).getInitialGuess();
- continue;
- }
- if (data instanceof SimpleBounds) {
- final SimpleBounds bounds = (SimpleBounds) data;
- lowerBound = bounds.getLower();
- upperBound = bounds.getUpper();
- continue;
- }
- }
- }
-
- /**
- * @return the optimization type.
- */
- public GoalType getGoalType() {
- return goal;
- }
-
- /**
- * @return the initial guess.
- */
- public double[] getStartPoint() {
- return start == null ? null : start.clone();
- }
- /**
- * @return the lower bounds.
- * @since 3.1
- */
- public double[] getLowerBound() {
- return lowerBound == null ? null : lowerBound.clone();
- }
- /**
- * @return the upper bounds.
- * @since 3.1
- */
- public double[] getUpperBound() {
- return upperBound == null ? null : upperBound.clone();
- }
-
- /**
- * Perform the bulk of the optimization algorithm.
- *
- * @return the point/value pair giving the optimal value of the
- * objective function.
- */
- protected abstract PointValuePair doOptimize();
-
- /**
- * Check parameters consistency.
- */
- private void checkParameters() {
- if (start != null) {
- final int dim = start.length;
- if (lowerBound != null) {
- if (lowerBound.length != dim) {
- throw new DimensionMismatchException(lowerBound.length, dim);
- }
- for (int i = 0; i < dim; i++) {
- final double v = start[i];
- final double lo = lowerBound[i];
- if (v < lo) {
- throw new NumberIsTooSmallException(v, lo, true);
- }
- }
- }
- if (upperBound != null) {
- if (upperBound.length != dim) {
- throw new DimensionMismatchException(upperBound.length, dim);
- }
- for (int i = 0; i < dim; i++) {
- final double v = start[i];
- final double hi = upperBound[i];
- if (v > hi) {
- throw new NumberIsTooLargeException(v, hi, true);
- }
- }
- }
-
- // If the bounds were not specified, the allowed interval is
- // assumed to be [-inf, +inf].
- if (lowerBound == null) {
- lowerBound = new double[dim];
- for (int i = 0; i < dim; i++) {
- lowerBound[i] = Double.NEGATIVE_INFINITY;
- }
- }
- if (upperBound == null) {
- upperBound = new double[dim];
- for (int i = 0; i < dim; i++) {
- upperBound[i] = Double.POSITIVE_INFINITY;
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateSimpleBoundsOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateSimpleBoundsOptimizer.java b/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateSimpleBoundsOptimizer.java
deleted file mode 100644
index d179202..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateSimpleBoundsOptimizer.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.optimization.BaseMultivariateOptimizer;
-import org.apache.commons.math4.optimization.BaseMultivariateSimpleBoundsOptimizer;
-import org.apache.commons.math4.optimization.ConvergenceChecker;
-import org.apache.commons.math4.optimization.GoalType;
-import org.apache.commons.math4.optimization.InitialGuess;
-import org.apache.commons.math4.optimization.PointValuePair;
-import org.apache.commons.math4.optimization.SimpleBounds;
-
-/**
- * Base class for implementing optimizers for multivariate scalar functions,
- * subject to simple bounds: The valid range of the parameters is an interval.
- * The interval can possibly be infinite (in one or both directions).
- * This base class handles the boiler-plate methods associated to thresholds
- * settings, iterations and evaluations counting.
- *
- * @param <FUNC> Type of the objective function to be optimized.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 3.0
- * @deprecated As of 3.1 since the {@link BaseAbstractMultivariateOptimizer
- * base class} contains similar functionality.
- */
-@Deprecated
-public abstract class BaseAbstractMultivariateSimpleBoundsOptimizer<FUNC extends MultivariateFunction>
- extends BaseAbstractMultivariateOptimizer<FUNC>
- implements BaseMultivariateOptimizer<FUNC>,
- BaseMultivariateSimpleBoundsOptimizer<FUNC> {
- /**
- * Simple constructor with default settings.
- * The convergence checker is set to a
- * {@link org.apache.commons.math4.optimization.SimpleValueChecker}.
- *
- * @see BaseAbstractMultivariateOptimizer#BaseAbstractMultivariateOptimizer()
- * @deprecated See {@link org.apache.commons.math4.optimization.SimpleValueChecker#SimpleValueChecker()}
- */
- @Deprecated
- protected BaseAbstractMultivariateSimpleBoundsOptimizer() {}
-
- /**
- * @param checker Convergence checker.
- */
- protected BaseAbstractMultivariateSimpleBoundsOptimizer(ConvergenceChecker<PointValuePair> checker) {
- super(checker);
- }
-
- /** {@inheritDoc} */
- @Override
- public PointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
- double[] startPoint) {
- return super.optimizeInternal(maxEval, f, goalType,
- new InitialGuess(startPoint));
- }
-
- /** {@inheritDoc} */
- public PointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
- double[] startPoint,
- double[] lower, double[] upper) {
- return super.optimizeInternal(maxEval, f, goalType,
- new InitialGuess(startPoint),
- new SimpleBounds(lower, upper));
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateVectorOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateVectorOptimizer.java b/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateVectorOptimizer.java
deleted file mode 100644
index ccca86e..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/BaseAbstractMultivariateVectorOptimizer.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import org.apache.commons.math4.analysis.MultivariateVectorFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MaxCountExceededException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.math4.optimization.BaseMultivariateVectorOptimizer;
-import org.apache.commons.math4.optimization.ConvergenceChecker;
-import org.apache.commons.math4.optimization.InitialGuess;
-import org.apache.commons.math4.optimization.OptimizationData;
-import org.apache.commons.math4.optimization.PointVectorValuePair;
-import org.apache.commons.math4.optimization.SimpleVectorValueChecker;
-import org.apache.commons.math4.optimization.Target;
-import org.apache.commons.math4.optimization.Weight;
-import org.apache.commons.math4.util.Incrementor;
-
-/**
- * Base class for implementing optimizers for multivariate scalar functions.
- * This base class handles the boiler-plate methods associated to thresholds
- * settings, iterations and evaluations counting.
- *
- * @param <FUNC> the type of the objective function to be optimized
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 3.0
- */
-@Deprecated
-public abstract class BaseAbstractMultivariateVectorOptimizer<FUNC extends MultivariateVectorFunction>
- implements BaseMultivariateVectorOptimizer<FUNC> {
- /** Evaluations counter. */
- protected final Incrementor evaluations = new Incrementor();
- /** Convergence checker. */
- private ConvergenceChecker<PointVectorValuePair> checker;
- /** Target value for the objective functions at optimum. */
- private double[] target;
- /** Weight matrix. */
- private RealMatrix weightMatrix;
- /** Weight for the least squares cost computation.
- * @deprecated
- */
- @Deprecated
- private double[] weight;
- /** Initial guess. */
- private double[] start;
- /** Objective function. */
- private FUNC function;
-
- /**
- * Simple constructor with default settings.
- * The convergence check is set to a {@link SimpleVectorValueChecker}.
- * @deprecated See {@link SimpleVectorValueChecker#SimpleVectorValueChecker()}
- */
- @Deprecated
- protected BaseAbstractMultivariateVectorOptimizer() {
- this(new SimpleVectorValueChecker());
- }
- /**
- * @param checker Convergence checker.
- */
- protected BaseAbstractMultivariateVectorOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
- this.checker = checker;
- }
-
- /** {@inheritDoc} */
- public int getMaxEvaluations() {
- return evaluations.getMaximalCount();
- }
-
- /** {@inheritDoc} */
- public int getEvaluations() {
- return evaluations.getCount();
- }
-
- /** {@inheritDoc} */
- public ConvergenceChecker<PointVectorValuePair> getConvergenceChecker() {
- return checker;
- }
-
- /**
- * Compute the objective function value.
- *
- * @param point Point at which the objective function must be evaluated.
- * @return the objective function value at the specified point.
- * @throws TooManyEvaluationsException if the maximal number of evaluations is
- * exceeded.
- */
- protected double[] computeObjectiveValue(double[] point) {
- try {
- evaluations.incrementCount();
- } catch (MaxCountExceededException e) {
- throw new TooManyEvaluationsException(e.getMax());
- }
- return function.value(point);
- }
-
- /** {@inheritDoc}
- *
- * @deprecated As of 3.1. Please use
- * {@link #optimize(int,MultivariateVectorFunction,OptimizationData[])}
- * instead.
- */
- @Deprecated
- public PointVectorValuePair optimize(int maxEval, FUNC f, double[] t, double[] w,
- double[] startPoint) {
- return optimizeInternal(maxEval, f, t, w, startPoint);
- }
-
- /**
- * Optimize an objective function.
- *
- * @param maxEval Allowed number of evaluations of the objective function.
- * @param f Objective function.
- * @param optData Optimization data. The following data will be looked for:
- * <ul>
- * <li>{@link Target}</li>
- * <li>{@link Weight}</li>
- * <li>{@link InitialGuess}</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.
- * @throws DimensionMismatchException if the initial guess, target, and weight
- * arguments have inconsistent dimensions.
- *
- * @since 3.1
- */
- protected PointVectorValuePair optimize(int maxEval,
- FUNC f,
- OptimizationData... optData)
- throws TooManyEvaluationsException,
- DimensionMismatchException {
- return optimizeInternal(maxEval, f, optData);
- }
-
- /**
- * Optimize an objective function.
- * Optimization is considered to be a weighted least-squares minimization.
- * The cost function to be minimized is
- * <code>∑weight<sub>i</sub>(objective<sub>i</sub> - target<sub>i</sub>)<sup>2</sup></code>
- *
- * @param f Objective function.
- * @param t Target value for the objective functions at optimum.
- * @param w Weights for the least squares cost computation.
- * @param startPoint Start point for optimization.
- * @return the point/value pair giving the optimal value for objective
- * function.
- * @param maxEval Maximum number of function evaluations.
- * @throws org.apache.commons.math4.exception.DimensionMismatchException
- * if the start point dimension is wrong.
- * @throws org.apache.commons.math4.exception.TooManyEvaluationsException
- * if the maximal number of evaluations is exceeded.
- * @throws org.apache.commons.math4.exception.NullArgumentException if
- * any argument is {@code null}.
- * @deprecated As of 3.1. Please use
- * {@link #optimizeInternal(int,MultivariateVectorFunction,OptimizationData[])}
- * instead.
- */
- @Deprecated
- protected PointVectorValuePair optimizeInternal(final int maxEval, final FUNC f,
- final double[] t, final double[] w,
- final double[] startPoint) {
- // Checks.
- if (f == null) {
- throw new NullArgumentException();
- }
- if (t == null) {
- throw new NullArgumentException();
- }
- if (w == null) {
- throw new NullArgumentException();
- }
- if (startPoint == null) {
- throw new NullArgumentException();
- }
- if (t.length != w.length) {
- throw new DimensionMismatchException(t.length, w.length);
- }
-
- return optimizeInternal(maxEval, f,
- new Target(t),
- new Weight(w),
- new InitialGuess(startPoint));
- }
-
- /**
- * Optimize an objective function.
- *
- * @param maxEval Allowed number of evaluations of the objective function.
- * @param f Objective function.
- * @param optData Optimization data. The following data will be looked for:
- * <ul>
- * <li>{@link Target}</li>
- * <li>{@link Weight}</li>
- * <li>{@link InitialGuess}</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.
- * @throws DimensionMismatchException if the initial guess, target, and weight
- * arguments have inconsistent dimensions.
- *
- * @since 3.1
- */
- protected PointVectorValuePair optimizeInternal(int maxEval,
- FUNC f,
- OptimizationData... optData)
- throws TooManyEvaluationsException,
- DimensionMismatchException {
- // Set internal state.
- evaluations.setMaximalCount(maxEval);
- evaluations.resetCount();
- function = f;
- // Retrieve other settings.
- parseOptimizationData(optData);
- // Check input consistency.
- checkParameters();
- // Allow subclasses to reset their own internal state.
- setUp();
- // Perform computation.
- return doOptimize();
- }
-
- /**
- * Gets the initial values of the optimized parameters.
- *
- * @return the initial guess.
- */
- public double[] getStartPoint() {
- return start.clone();
- }
-
- /**
- * Gets the weight matrix of the observations.
- *
- * @return the weight matrix.
- * @since 3.1
- */
- public RealMatrix getWeight() {
- return weightMatrix.copy();
- }
- /**
- * Gets the observed values to be matched by the objective vector
- * function.
- *
- * @return the target values.
- * @since 3.1
- */
- public double[] getTarget() {
- return target.clone();
- }
-
- /**
- * Gets the objective vector function.
- * Note that this access bypasses the evaluation counter.
- *
- * @return the objective vector function.
- * @since 3.1
- */
- protected FUNC getObjectiveFunction() {
- return function;
- }
-
- /**
- * Perform the bulk of the optimization algorithm.
- *
- * @return the point/value pair giving the optimal value for the
- * objective function.
- */
- protected abstract PointVectorValuePair doOptimize();
-
- /**
- * @return a reference to the {@link #target array}.
- * @deprecated As of 3.1.
- */
- @Deprecated
- protected double[] getTargetRef() {
- return target;
- }
- /**
- * @return a reference to the {@link #weight array}.
- * @deprecated As of 3.1.
- */
- @Deprecated
- protected double[] getWeightRef() {
- return weight;
- }
-
- /**
- * Method which a subclass <em>must</em> override whenever its internal
- * state depend on the {@link OptimizationData input} parsed by this base
- * class.
- * It will be called after the parsing step performed in the
- * {@link #optimize(int,MultivariateVectorFunction,OptimizationData[])
- * optimize} method and just before {@link #doOptimize()}.
- *
- * @since 3.1
- */
- protected void setUp() {
- // XXX Temporary code until the new internal data is used everywhere.
- final int dim = target.length;
- weight = new double[dim];
- for (int i = 0; i < dim; i++) {
- weight[i] = weightMatrix.getEntry(i, i);
- }
- }
-
- /**
- * Scans the list of (required and optional) optimization data that
- * characterize the problem.
- *
- * @param optData Optimization data. The following data will be looked for:
- * <ul>
- * <li>{@link Target}</li>
- * <li>{@link Weight}</li>
- * <li>{@link InitialGuess}</li>
- * </ul>
- */
- private void parseOptimizationData(OptimizationData... optData) {
- // The existing values (as set by the previous call) are reused if
- // not provided in the argument list.
- for (OptimizationData data : optData) {
- if (data instanceof Target) {
- target = ((Target) data).getTarget();
- continue;
- }
- if (data instanceof Weight) {
- weightMatrix = ((Weight) data).getWeight();
- continue;
- }
- if (data instanceof InitialGuess) {
- start = ((InitialGuess) data).getInitialGuess();
- continue;
- }
- }
- }
-
- /**
- * Check parameters consistency.
- *
- * @throws DimensionMismatchException if {@link #target} and
- * {@link #weightMatrix} have inconsistent dimensions.
- */
- private void checkParameters() {
- if (target.length != weightMatrix.getColumnDimension()) {
- throw new DimensionMismatchException(target.length,
- weightMatrix.getColumnDimension());
- }
- }
-}