1 /*
2 * Licensed to the Hipparchus project 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 Hipparchus project 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 * https://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.hipparchus.optim.nonlinear.vector.constrained;
18
19
20
21 import org.hipparchus.analysis.MultivariateFunction;
22 import org.hipparchus.linear.RealMatrix;
23 import org.hipparchus.linear.RealVector;
24 import org.hipparchus.linear.ArrayRealVector;
25
26 /** A MultivariateFunction that also has a defined gradient and Hessian.
27 * @since 3.1
28 */
29 public abstract class TwiceDifferentiableFunction implements MultivariateFunction {
30
31 /** Simple constructor.
32 */
33 public TwiceDifferentiableFunction() {
34 // nothing to do
35 }
36
37 /**
38 * Returns the dimensionality of the function domain.
39 * If dim() returns (n) then this function expects an n-vector as its input.
40 * @return the expected dimension of the function's domain
41 */
42 public abstract int dim();
43
44 /**
45 * Returns the value of this function at (x)
46 *
47 * @param x a point to evaluate this function at.
48 * @return the value of this function at (x)
49 */
50 public abstract double value(RealVector x);
51
52 /**
53 * Returns the gradient of this function at (x)
54 *
55 * @param x a point to evaluate this gradient at
56 * @return the gradient of this function at (x)
57 */
58 public abstract RealVector gradient(RealVector x);
59
60 /**
61 * The Hessian of this function at (x)
62 *
63 * @param x a point to evaluate this Hessian at
64 * @return the Hessian of this function at (x)
65 */
66 public abstract RealMatrix hessian(RealVector x);
67
68 /**
69 * Returns the value of this function at (x)
70 *
71 * @param x a point to evaluate this function at.
72 * @return the value of this function at (x)
73 */
74 @Override
75 public double value(final double[] x) {
76 return value(new ArrayRealVector(x, false));
77 }
78
79 /**
80 * Returns the gradient of this function at (x)
81 *
82 * @param x a point to evaluate this gradient at
83 * @return the gradient of this function at (x)
84 */
85 public RealVector gradient(final double[] x) {
86 return gradient(new ArrayRealVector(x, false));
87 }
88
89 /**
90 * The Hessian of this function at (x)
91 *
92 * @param x a point to evaluate this Hessian at
93 * @return the Hessian of this function at (x)
94 */
95 public RealMatrix hessian(final double[] x) {
96 return hessian(new ArrayRealVector(x, false));
97 }
98 }