View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.math3.optim.nonlinear.vector;
18  
19  import org.apache.commons.math3.analysis.MultivariateMatrixFunction;
20  import org.apache.commons.math3.optim.ConvergenceChecker;
21  import org.apache.commons.math3.optim.OptimizationData;
22  import org.apache.commons.math3.optim.PointVectorValuePair;
23  import org.apache.commons.math3.exception.TooManyEvaluationsException;
24  import org.apache.commons.math3.exception.DimensionMismatchException;
25  
26  /**
27   * Base class for implementing optimizers for multivariate vector
28   * differentiable functions.
29   * It contains boiler-plate code for dealing with Jacobian evaluation.
30   * It assumes that the rows of the Jacobian matrix iterate on the model
31   * functions while the columns iterate on the parameters; thus, the numbers
32   * of rows is equal to the dimension of the {@link Target} while the
33   * number of columns is equal to the dimension of the
34   * {@link org.apache.commons.math3.optim.InitialGuess InitialGuess}.
35   *
36   * @since 3.1
37   * @deprecated All classes and interfaces in this package are deprecated.
38   * The optimizers that were provided here were moved to the
39   * {@link org.apache.commons.math3.fitting.leastsquares} package
40   * (cf. MATH-1008).
41   */
42  @Deprecated
43  public abstract class JacobianMultivariateVectorOptimizer
44      extends MultivariateVectorOptimizer {
45      /**
46       * Jacobian of the model function.
47       */
48      private MultivariateMatrixFunction jacobian;
49  
50      /**
51       * @param checker Convergence checker.
52       */
53      protected JacobianMultivariateVectorOptimizer(ConvergenceChecker<PointVectorValuePair> checker) {
54          super(checker);
55      }
56  
57      /**
58       * Computes the Jacobian matrix.
59       *
60       * @param params Point at which the Jacobian must be evaluated.
61       * @return the Jacobian at the specified point.
62       */
63      protected double[][] computeJacobian(final double[] params) {
64          return jacobian.value(params);
65      }
66  
67      /**
68       * {@inheritDoc}
69       *
70       * @param optData Optimization data. In addition to those documented in
71       * {@link MultivariateVectorOptimizer#optimize(OptimizationData...)}
72       * MultivariateOptimizer}, this method will register the following data:
73       * <ul>
74       *  <li>{@link ModelFunctionJacobian}</li>
75       * </ul>
76       * @return {@inheritDoc}
77       * @throws TooManyEvaluationsException if the maximal number of
78       * evaluations is exceeded.
79       * @throws DimensionMismatchException if the initial guess, target, and weight
80       * arguments have inconsistent dimensions.
81       */
82      @Override
83      public PointVectorValuePair optimize(OptimizationData... optData)
84          throws TooManyEvaluationsException,
85                 DimensionMismatchException {
86          // Set up base class and perform computation.
87          return super.optimize(optData);
88      }
89  
90      /**
91       * Scans the list of (required and optional) optimization data that
92       * characterize the problem.
93       *
94       * @param optData Optimization data.
95       * The following data will be looked for:
96       * <ul>
97       *  <li>{@link ModelFunctionJacobian}</li>
98       * </ul>
99       */
100     @Override
101     protected void parseOptimizationData(OptimizationData... optData) {
102         // Allow base class to register its own data.
103         super.parseOptimizationData(optData);
104 
105         // The existing values (as set by the previous call) are reused if
106         // not provided in the argument list.
107         for (OptimizationData data : optData) {
108             if (data instanceof ModelFunctionJacobian) {
109                 jacobian = ((ModelFunctionJacobian) data).getModelFunctionJacobian();
110                 // If more data must be parsed, this statement _must_ be
111                 // changed to "continue".
112                 break;
113             }
114         }
115     }
116 }