diff --git a/adapter-cqld4/pom.xml b/adapter-cqld4/pom.xml
index a7a10ec9d..fb63c0fab 100644
--- a/adapter-cqld4/pom.xml
+++ b/adapter-cqld4/pom.xml
@@ -140,48 +140,6 @@
- * Classes implementing this interface will often be singletons.
- *
- * The additive identity is the element e0 of the field such that
- * for all elements a of the field, the equalities a + e0 =
- * e0 + a = a hold.
- *
- * The multiplicative identity is the element e1 of the field such that
- * for all elements a of the field, the equalities a × e1 =
- * e1 × a = a hold.
- *
- * The functions in the argument list are composed sequentially, in the
- * given order. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
- * The functions in the argument list are composed sequentially, in the
- * given order. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
- * The interval is divided equally into {@code n} sections and sample points
- * are taken from {@code min} to {@code max - (max - min) / n}; therefore
- * {@code f} is not sampled at the upper bound {@code max}.
- * This method handle the case with one free parameter and several derivatives.
- * For the case with several free parameters and only first order derivatives,
- * see {@link #toDifferentiable(MultivariateFunction, MultivariateVectorFunction)}.
- * There are no direct support for intermediate cases, with several free parameters
- * and order 2 or more derivatives, as is would be difficult to specify all the
- * cross derivatives.
- *
- * Note that the derivatives are expected to be computed only with respect to the
- * raw parameter x of the base function, i.e. they are df/dx, df2/dx2, ...
- * Even if the built function is later used in a composition like f(sin(t)), the provided
- * derivatives should not apply the composition with sine and its derivatives by
- * themselves. The composition will be done automatically here and the result will properly
- * contain f(sin(t)), df(sin(t))/dt, df2(sin(t))/dt2 despite the
- * provided derivatives functions know nothing about the sine function.
- *
- * This method handle the case with several free parameters and only first order derivatives.
- * For the case with one free parameter and several derivatives,
- * see {@link #toDifferentiable(UnivariateFunction, UnivariateFunction...)}.
- * There are no direct support for intermediate cases, with several free parameters
- * and order 2 or more derivatives, as is would be difficult to specify all the
- * cross derivatives.
- *
- * Note that the gradient is expected to be computed only with respect to the
- * raw parameter x of the base function, i.e. it is df/dx1, df/dx2, ...
- * Even if the built function is later used in a composition like f(sin(t), cos(t)), the provided
- * gradient should not apply the composition with sine or cosine and their derivative by
- * itself. The composition will be done automatically here and the result will properly
- * contain f(sin(t), cos(t)), df(sin(t), cos(t))/dt despite the provided derivatives functions
- * know nothing about the sine or cosine functions.
- *
- * This converter is only a convenience method. Beware computing only one derivative does
- * not save any computation as the original function will really be called under the hood.
- * The derivative will be extracted from the full {@link DerivativeStructure} result.
- *
- * This converter is only a convenience method. Beware computing only one derivative does
- * not save any computation as the original function will really be called under the hood.
- * The derivative will be extracted from the full {@link DerivativeStructure} result.
- *
- * When a user-defined function encounters an error during
- * evaluation, the {@link #value(RealFieldElement) value} method should throw a
- * user-defined unchecked exception.
- * The following code excerpt shows the recommended way to do that using
- * a root solver as an example, but the same construct is applicable to
- * ODE integrators or optimizers.
- *
- *
- * As shown, the exception is local to the user's code and it is guaranteed
- * that Apache Commons Math will not catch it.
- * When a user-defined function encounters an error during
- * evaluation, the {@link #value(double) value} method should throw a
- * user-defined unchecked exception.
- * The following code excerpt shows the recommended way to do that using
- * a root solver as an example, but the same construct is applicable to
- * ODE integrators or optimizers. This class implements the computation rules described in Dan Kalman's paper Doubly
- * Recursive Multivariate Automatic Differentiation, Mathematics Magazine, vol. 75,
- * no. 3, June 2002. However, in order to avoid performances bottlenecks, the recursive
- * rules are "compiled" once in an unfold form. This class does this recursion unrolling
- * and stores the computation rules as simple loops with pre-computed indirection arrays.
- * This class maps all derivative computation into single dimension arrays that hold the
- * value and partial derivatives. The class does not hold these arrays, which remains under
- * the responsibility of the caller. For each combination of number of free parameters and
- * derivation order, only one compiler is necessary, and this compiler will be used to
- * perform computations on all arrays provided to it, which can represent hundreds or
- * thousands of different parameters kept together with all their partial derivatives.
- *
- * The arrays on which compilers operate contain only the partial derivatives together
- * with the 0th derivative, i.e. the value. The partial derivatives are stored in
- * a compiler-specific order, which can be retrieved using methods {@link
- * #getPartialDerivativeIndex(int...) getPartialDerivativeIndex} and {@link
- * #getPartialDerivativeOrders(int)}. The value is guaranteed to be stored as the first element
- * (i.e. the {@link #getPartialDerivativeIndex(int...) getPartialDerivativeIndex} method returns
- * 0 when called with 0 for all derivation orders and {@link #getPartialDerivativeOrders(int)
- * getPartialDerivativeOrders} returns an array filled with 0 when called with 0 as the index).
- *
- * Note that the ordering changes with number of parameters and derivation order. For example
- * given 2 parameters x and y, df/dy is stored at index 2 when derivation order is set to 1 (in
- * this case the array has three elements: f, df/dx and df/dy). If derivation order is set to
- * 2, then df/dy will be stored at index 3 (in this case the array has six elements: f, df/dx,
- * df/dxdx, df/dy, df/dxdy and df/dydy).
- *
- * Given this structure, users can perform some simple operations like adding, subtracting
- * or multiplying constants and negating the elements by themselves, knowing if they want to
- * mutate their array or create a new array. These simple operations are not provided by
- * the compiler. The compiler provides only the more complex operations between several arrays.
- * This class is mainly used as the engine for scalar variable {@link DerivativeStructure}.
- * It can also be used directly to hold several variables in arrays for more complex data
- * structures. User can for example store a vector of n variables depending on three x, y
- * and z free parameters in one array as follows: Then in another function, user can perform some operations on all elements stored
- * in the single array, such as a simple product of all variables:
- * This indirection array contains the indices of all elements
- * except derivatives for last derivation order.
- *
- * This indirection array contains the indices of all pairs of elements
- * involved when computing a multiplication. This allows a straightforward
- * loop-based multiplication (see {@link #multiply(double[], int, double[], int, double[], int)}).
- *
- * This indirection array contains the indices of all sets of elements
- * involved when computing a composition. This allows a straightforward
- * loop-based composition (see {@link #compose(double[], int, double[], double[], int)}).
- *
- * If all orders are set to 0, then the 0th order derivative
- * is returned, which is the value of the function.
- * The indices of derivatives are between 0 and {@link #getSize() getSize()} - 1.
- * Their specific order is fixed for a given compiler, but otherwise not
- * publicly specified. There are however some simple cases which have guaranteed
- * indices:
- *
- * This method is the inverse of method {@link #getPartialDerivativeOrders(int)}
- *
- * This method is the inverse of {@link #getPartialDerivativeIndex(int...)}.
- *
- * This number includes the single 0 order derivative element, which is
- * guaranteed to be stored in the first element of the array.
- * This class is the workhorse of the differentiation package. This class is an implementation of the extension to Rall's
- * numbers described in Dan Kalman's paper Doubly
- * Recursive Multivariate Automatic Differentiation, Mathematics Magazine, vol. 75,
- * no. 3, June 2002. Rall's numbers are an extension to the real numbers used
- * throughout mathematical expressions; they hold the derivative together with the
- * value of a function. Dan Kalman's derivative structures hold all partial derivatives
- * up to any specified order, with respect to any number of free parameters. Rall's
- * numbers therefore can be seen as derivative structures for order one derivative and
- * one free parameter, and real numbers can be seen as derivative structures with zero
- * order derivative and no free parameters. {@link DerivativeStructure} instances can be used directly thanks to
- * the arithmetic operators to the mathematical functions provided as
- * methods by this class (+, -, *, /, %, sin, cos ...). Implementing complex expressions by hand using these classes is
- * a tedious and error-prone task but has the advantage of having no limitation
- * on the derivation order despite not requiring users to compute the derivatives by
- * themselves. Implementing complex expression can also be done by developing computation
- * code using standard primitive double values and to use {@link
- * UnivariateFunctionDifferentiator differentiators} to create the {@link
- * DerivativeStructure}-based instances. This method is simpler but may be limited in
- * the accuracy and derivation orders and may be computationally intensive (this is
- * typically the case for {@link FiniteDifferencesDifferentiator finite differences
- * differentiator}. Instances of this class are guaranteed to be immutable. Instances built using this constructor are considered
- * to be the free variables with respect to which differentials
- * are computed. As such, their differential with respect to
- * themselves is +1.
- * This method is a convenience factory method, it simply calls
- * {@code new DerivativeStructure(getFreeParameters(), getOrder(), c)}
- *
- * For double numbers of the form 2x, the unbiased
- * exponent is exactly x.
- *
- * Derivative structures are considered equal if they have the same number
- * of free parameters, the same derivation order, and the same derivatives.
- *
- * This class creates some wrapper objects around regular
- * {@link UnivariateFunction univariate functions} (or {@link
- * UnivariateVectorFunction univariate vector functions} or {@link
- * UnivariateMatrixFunction univariate matrix functions}). These
- * wrapper objects compute derivatives in addition to function
- * values.
- *
- * The wrapper objects work by calling the underlying function on
- * a sampling grid around the current point and performing polynomial
- * interpolation. A finite differences scheme with n points is
- * theoretically able to compute derivatives up to order n-1, but
- * it is generally better to have a slight margin. The step size must
- * also be small enough in order for the polynomial approximation to
- * be good in the current point neighborhood, but it should not be too
- * small because numerical instability appears quickly (there are several
- * differences of close points). Choosing the number of points and
- * the step size is highly problem dependent.
- *
- * As an example of good and bad settings, lets consider the quintic
- * polynomial function {@code f(x) = (x-1)*(x-0.5)*x*(x+0.5)*(x+1)}.
- * Since it is a polynomial, finite differences with at least 6 points
- * should theoretically recover the exact same polynomial and hence
- * compute accurate derivatives for any order. However, due to numerical
- * errors, we get the following results for a 7 points finite differences
- * for abscissae in the [-10, 10] range:
- *
- * This example shows that the small step size is really bad, even simply
- * for second order derivative!
- * Beware that wrong settings for the finite differences differentiator
- * can lead to highly unstable and inaccurate results, especially for
- * high derivation orders. Using very small step sizes is often a
- * bad idea.
- *
- * When the independent variable is bounded (tLower < t < tUpper), the sampling
- * points used for differentiation will be adapted to ensure the constraint holds
- * even near the boundaries. This means the sample will not be centered anymore in
- * these cases. At an extreme case, computing derivatives exactly at the lower bound
- * will lead the sample to be entirely on the right side of the derivation point.
- *
- * Note that the boundaries are considered to be excluded for function evaluation.
- *
- * Beware that wrong settings for the finite differences differentiator
- * can lead to highly unstable and inaccurate results, especially for
- * high derivation orders. Using very small step sizes is often a
- * bad idea.
- *
- * Evaluation is done using divided differences.
- * The returned object cannot compute derivatives to arbitrary orders. The
- * value function will throw a {@link NumberIsTooLargeException} if the requested
- * derivation order is larger or equal to the number of points.
- * The returned object cannot compute derivatives to arbitrary orders. The
- * value function will throw a {@link NumberIsTooLargeException} if the requested
- * derivation order is larger or equal to the number of points.
- * The returned object cannot compute derivatives to arbitrary orders. The
- * value function will throw a {@link NumberIsTooLargeException} if the requested
- * derivation order is larger or equal to the number of points.
- *
- * The vectorial components of the function represent the derivatives
- * with respect to each function parameters.
- *
- * The rows iterate on the model functions while the columns iterate on the parameters; thus,
- * the numbers of rows is equal to the dimension of the underlying function vector
- * value and the number of columns is equal to the number of free parameters of
- * the underlying function.
- *
- * This class plays a similar role to {@link DerivativeStructure}, with
- * a focus on efficiency when dealing with large number of independent variables
- * and most computation depend only on a few of them, and when only first derivative
- * is desired. When these conditions are met, this class should be much faster than
- * {@link DerivativeStructure} and use less memory.
- *
- * This method is designed to be faster when used multiple times in a loop.
- *
- * The instance is changed here, in order to not change the
- * instance the {@link #add(SparseGradient)} method should
- * be used.
- *
- * This method is designed to be faster when used multiple times in a loop.
- *
- * The instance is changed here, in order to not change the
- * instance the {@link #add(SparseGradient)} method should
- * be used.
- *
- * Sparse gradients are considered equal if they have the same value
- * and the same derivatives.
- * This interface represents a simple function which computes
- * both the value and the first derivative of a mathematical function.
- * The derivative is computed with respect to the input variable. {@link UnivariateDifferentiableFunction} classes compute both the
- * value and the first derivative of the function.
- * This package holds the main interfaces and basic building block classes
- * dealing with differentiation.
- * The core class is {@link org.apache.commons.math4.analysis.differentiation.DerivativeStructure
- * DerivativeStructure} which holds the value and the differentials of a function. This class
- * handles some arbitrary number of free parameters and arbitrary differentiation order. It is used
- * both as the input and the output type for the {@link
- * org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction
- * UnivariateDifferentiableFunction} interface. Any differentiable function should implement this
- * interface.
- *
- * The {@link org.apache.commons.math4.analysis.differentiation.UnivariateFunctionDifferentiator
- * UnivariateFunctionDifferentiator} interface defines a way to differentiate a simple {@link
- * org.apache.commons.math4.analysis.UnivariateFunction UnivariateFunction} and get a {@link
- * org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction
- * UnivariateDifferentiableFunction}.
- *
- * Similar interfaces also exist for multivariate functions and for vector or matrix valued functions.
- *
- * The Taylor series for sinc even order derivatives are:
- * {@code
+ * [To redirect Truffle log output to a file use one of the following options:
+ * * '--log.file=
+ */
@Test
public void testBasicOperations() {
GraalJsEvaluator
- *
- *
- * @param y a value
- * @return sqrt(this2 +y2)
- * @exception DimensionMismatchException if number of free parameters or orders are inconsistent
- */
- T hypot(T y)
- throws DimensionMismatchException;
-
- /** {@inheritDoc} */
- @Override
- T reciprocal();
-
- /** Square root.
- * @return square root of the instance
- */
- T sqrt();
-
- /** Cubic root.
- * @return cubic root of the instance
- */
- T cbrt();
-
- /** Nth root.
- * @param n order of the root
- * @return nth root of the instance
- */
- T rootN(int n);
-
- /** Power operation.
- * @param p power to apply
- * @return thisp
- */
- T pow(double p);
-
- /** Integer power operation.
- * @param n power to apply
- * @return thisn
- */
- T pow(int n);
-
- /** Power operation.
- * @param e exponent
- * @return thise
- * @exception DimensionMismatchException if number of free parameters or orders are inconsistent
- */
- T pow(T e)
- throws DimensionMismatchException;
-
- /** Exponential.
- * @return exponential of the instance
- */
- T exp();
-
- /** Exponential minus 1.
- * @return exponential minus one of the instance
- */
- T expm1();
-
- /** Natural logarithm.
- * @return logarithm of the instance
- */
- T log();
-
- /** Shifted natural logarithm.
- * @return logarithm of one plus the instance
- */
- T log1p();
-
- /** Base 10 logarithm.
- * @return base 10 logarithm of the instance
- * @since 4.0
- */
- T log10();
-
- /** Cosine operation.
- * @return cos(this)
- */
- T cos();
-
- /** Sine operation.
- * @return sin(this)
- */
- T sin();
-
- /** Tangent operation.
- * @return tan(this)
- */
- T tan();
-
- /** Arc cosine operation.
- * @return acos(this)
- */
- T acos();
-
- /** Arc sine operation.
- * @return asin(this)
- */
- T asin();
-
- /** Arc tangent operation.
- * @return atan(this)
- */
- T atan();
-
- /** Two arguments arc tangent operation.
- * @param x second argument of the arc tangent
- * @return atan2(this, x)
- * @exception DimensionMismatchException if number of free parameters or orders are inconsistent
- */
- T atan2(T x)
- throws DimensionMismatchException;
-
- /** Hyperbolic cosine operation.
- * @return cosh(this)
- */
- T cosh();
-
- /** Hyperbolic sine operation.
- * @return sinh(this)
- */
- T sinh();
-
- /** Hyperbolic tangent operation.
- * @return tanh(this)
- */
- T tanh();
-
- /** Inverse hyperbolic cosine operation.
- * @return acosh(this)
- */
- T acosh();
-
- /** Inverse hyperbolic sine operation.
- * @return asin(this)
- */
- T asinh();
-
- /** Inverse hyperbolic tangent operation.
- * @return atanh(this)
- */
- T atanh();
-
- /**
- * Compute a linear combination.
- * @param a Factors.
- * @param b Factors.
- * @return Σi ai bi
.
- * @throws DimensionMismatchException if arrays dimensions don't match
- * @since 3.2
- */
- T linearCombination(T[] a, T[] b)
- throws DimensionMismatchException;
-
- /**
- * Compute a linear combination.
- * @param a Factors.
- * @param b Factors.
- * @return Σi ai bi
.
- * @throws DimensionMismatchException if arrays dimensions don't match
- * @since 3.2
- */
- T linearCombination(double[] a, T[] b)
- throws DimensionMismatchException;
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @return a1×b1 +
- * a2×b2
- * @see #linearCombination(Object, Object, Object, Object, Object, Object)
- * @see #linearCombination(Object, Object, Object, Object, Object, Object, Object, Object)
- * @since 3.2
- */
- T linearCombination(T a1, T b1, T a2, T b2);
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @return a1×b1 +
- * a2×b2
- * @see #linearCombination(double, Object, double, Object, double, Object)
- * @see #linearCombination(double, Object, double, Object, double, Object, double, Object)
- * @since 3.2
- */
- T linearCombination(double a1, T b1, double a2, T b2);
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @param a3 first factor of the third term
- * @param b3 second factor of the third term
- * @return a1×b1 +
- * a2×b2 + a3×b3
- * @see #linearCombination(Object, Object, Object, Object)
- * @see #linearCombination(Object, Object, Object, Object, Object, Object, Object, Object)
- * @since 3.2
- */
- T linearCombination(T a1, T b1, T a2, T b2, T a3, T b3);
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @param a3 first factor of the third term
- * @param b3 second factor of the third term
- * @return a1×b1 +
- * a2×b2 + a3×b3
- * @see #linearCombination(double, Object, double, Object)
- * @see #linearCombination(double, Object, double, Object, double, Object, double, Object)
- * @since 3.2
- */
- T linearCombination(double a1, T b1, double a2, T b2, double a3, T b3);
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @param a3 first factor of the third term
- * @param b3 second factor of the third term
- * @param a4 first factor of the third term
- * @param b4 second factor of the third term
- * @return a1×b1 +
- * a2×b2 + a3×b3 +
- * a4×b4
- * @see #linearCombination(Object, Object, Object, Object)
- * @see #linearCombination(Object, Object, Object, Object, Object, Object)
- * @since 3.2
- */
- T linearCombination(T a1, T b1, T a2, T b2, T a3, T b3, T a4, T b4);
-
- /**
- * Compute a linear combination.
- * @param a1 first factor of the first term
- * @param b1 second factor of the first term
- * @param a2 first factor of the second term
- * @param b2 second factor of the second term
- * @param a3 first factor of the third term
- * @param b3 second factor of the third term
- * @param a4 first factor of the third term
- * @param b4 second factor of the third term
- * @return a1×b1 +
- * a2×b2 + a3×b3 +
- * a4×b4
- * @see #linearCombination(double, Object, double, Object)
- * @see #linearCombination(double, Object, double, Object, double, Object)
- * @since 3.2
- */
- T linearCombination(double a1, T b1, double a2, T b2, double a3, T b3, double a4, T b4);
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/BivariateFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/BivariateFunction.java
deleted file mode 100644
index 49ca2102a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/BivariateFunction.java
+++ /dev/null
@@ -1,35 +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.analysis;
-
-/**
- * An interface representing a bivariate real function.
- *
- * @since 2.1
- */
-public interface BivariateFunction {
- /**
- * Compute the value for the function.
- *
- * @param x Abscissa for which the function value should be computed.
- * @param y Ordinate for which the function value should be computed.
- * @return the value.
- */
- double value(double x, double y);
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/FunctionUtils.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/FunctionUtils.java
deleted file mode 100644
index 6c5487937..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/FunctionUtils.java
+++ /dev/null
@@ -1,544 +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.analysis;
-
-import org.apache.commons.numbers.arrays.LinearCombination;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.MultivariateDifferentiableFunction;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.analysis.function.Identity;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Utilities for manipulating function objects.
- *
- * @since 3.0
- */
-public class FunctionUtils {
- /**
- * Class only contains static methods.
- */
- private FunctionUtils() {}
-
- /**
- * Composes functions.
- *
- *
- * @param combiner Combiner function.
- * @param f Function.
- * @param initialValue Initial value.
- * @return a collector function.
- */
- public static MultivariateFunction collector(final BivariateFunction combiner,
- final UnivariateFunction f,
- final double initialValue) {
- return new MultivariateFunction() {
- /** {@inheritDoc} */
- @Override
- public double value(double[] point) {
- double result = combiner.value(initialValue, f.value(point[0]));
- for (int i = 1; i < point.length; i++) {
- result = combiner.value(result, f.value(point[i]));
- }
- return result;
- }
- };
- }
-
- /**
- * Returns a MultivariateFunction h(x[]) defined by
- * h(x[]) = combiner(...combiner(combiner(initialValue,f(x[0])),f(x[1]))...),f(x[x.length-1]))
- *
- *
- * @param combiner Combiner function.
- * @param initialValue Initial value.
- * @return a collector function.
- */
- public static MultivariateFunction collector(final BivariateFunction combiner,
- final double initialValue) {
- return collector(combiner, new Identity(), initialValue);
- }
-
- /**
- * Creates a unary function by fixing the first argument of a binary function.
- *
- * @param f Binary function.
- * @param fixed value to which the first argument of {@code f} is set.
- * @return the unary function h(x) = f(fixed, x)
- */
- public static UnivariateFunction fix1stArgument(final BivariateFunction f,
- final double fixed) {
- return new UnivariateFunction() {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return f.value(fixed, x);
- }
- };
- }
- /**
- * Creates a unary function by fixing the second argument of a binary function.
- *
- * @param f Binary function.
- * @param fixed value to which the second argument of {@code f} is set.
- * @return the unary function h(x) = f(x, fixed)
- */
- public static UnivariateFunction fix2ndArgument(final BivariateFunction f,
- final double fixed) {
- return new UnivariateFunction() {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return f.value(x, fixed);
- }
- };
- }
-
- /**
- * Samples the specified univariate real function on the specified interval.
- *
- * h(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1])
- *
- * private static class LocalException extends RuntimeException {
- * // The x value that caused the problem.
- * private final SomeFieldType x;
- *
- * public LocalException(SomeFieldType x) {
- * this.x = x;
- * }
- *
- * public double getX() {
- * return x;
- * }
- * }
- *
- * private static class MyFunction implements FieldUnivariateFunction<SomeFieldType> {
- * public SomeFieldType value(SomeFieldType x) {
- * SomeFieldType y = hugeFormula(x);
- * if (somethingBadHappens) {
- * throw new LocalException(x);
- * }
- * return y;
- * }
- * }
- *
- * public void compute() {
- * try {
- * solver.solve(maxEval, new MyFunction(a, b, c), min, max);
- * } catch (LocalException le) {
- * // Retrieve the x value.
- * }
- * }
- *
- *
- * private static class LocalException extends RuntimeException {
- * // The x value that caused the problem.
- * private final double x;
- *
- * public LocalException(double x) {
- * this.x = x;
- * }
- *
- * public double getX() {
- * return x;
- * }
- * }
- *
- * private static class MyFunction implements UnivariateFunction {
- * public double value(double x) {
- * double y = hugeFormula(x);
- * if (somethingBadHappens) {
- * throw new LocalException(x);
- * }
- * return y;
- * }
- * }
- *
- * public void compute() {
- * try {
- * solver.solve(maxEval, new MyFunction(a, b, c), min, max);
- * } catch (LocalException le) {
- * // Retrieve the x value.
- * }
- * }
- *
- *
- * As shown, the exception is local to the user's code and it is guaranteed
- * that Apache Commons Math will not catch it.
- *
- */
-public interface UnivariateFunction {
- /**
- * Compute the value of the function.
- *
- * @param x Point at which the function value should be computed.
- * @return the value of the function.
- * @throws IllegalArgumentException when the activated method itself can
- * ascertain that a precondition, specified in the API expressed at the
- * level of the activated method, has been violated.
- * When Commons Math throws an {@code IllegalArgumentException}, it is
- * usually the consequence of checking the actual parameters passed to
- * the method.
- */
- double value(double x);
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateMatrixFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateMatrixFunction.java
deleted file mode 100644
index a364cb70c..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateMatrixFunction.java
+++ /dev/null
@@ -1,33 +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.analysis;
-
-/**
- * An interface representing a univariate matrix function.
- *
- * @since 2.0
- */
-public interface UnivariateMatrixFunction {
-
- /**
- * Compute the value for the function.
- * @param x the point for which the function value should be computed
- * @return the value
- */
- double[][] value(double x);
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateVectorFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateVectorFunction.java
deleted file mode 100644
index c836ecb28..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/UnivariateVectorFunction.java
+++ /dev/null
@@ -1,33 +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.analysis;
-
-/**
- * An interface representing a univariate vectorial function.
- *
- * @since 2.0
- */
-public interface UnivariateVectorFunction {
-
- /**
- * Compute the value for the function.
- * @param x the point for which the function value should be computed
- * @return the value
- */
- double[] value(double x);
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
deleted file mode 100644
index 03898ac82..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/differentiation/DSCompiler.java
+++ /dev/null
@@ -1,1834 +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.analysis.differentiation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.commons.numbers.arrays.LinearCombination;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.MathInternalError;
-import org.apache.commons.math4.exception.NotPositiveException;
-import org.apache.commons.math4.exception.NumberIsTooLargeException;
-import org.apache.commons.numbers.combinatorics.FactorialDouble;
-import org.apache.commons.math4.util.FastMath;
-
-/** Class holding "compiled" computation rules for derivative structures.
- *
- * // parameter 0 is x, parameter 1 is y, parameter 2 is z
- * int parameters = 3;
- * DSCompiler compiler = DSCompiler.getCompiler(parameters, order);
- * int size = compiler.getSize();
- *
- * // pack all elements in a single array
- * double[] array = new double[n * size];
- * for (int i = 0; i < n; ++i) {
- *
- * // we know value is guaranteed to be the first element
- * array[i * size] = v[i];
- *
- * // we don't know where first derivatives are stored, so we ask the compiler
- * array[i * size + compiler.getPartialDerivativeIndex(1, 0, 0) = dvOnDx[i][0];
- * array[i * size + compiler.getPartialDerivativeIndex(0, 1, 0) = dvOnDy[i][0];
- * array[i * size + compiler.getPartialDerivativeIndex(0, 0, 1) = dvOnDz[i][0];
- *
- * // we let all higher order derivatives set to 0
- *
- * }
- *
- *
- * // compute the product of all elements
- * double[] product = new double[size];
- * prod[0] = 1.0;
- * for (int i = 0; i < n; ++i) {
- * double[] tmp = product.clone();
- * compiler.multiply(tmp, 0, array, i * size, product, 0);
- * }
- *
- * // value
- * double p = product[0];
- *
- * // first derivatives
- * double dPdX = product[compiler.getPartialDerivativeIndex(1, 0, 0)];
- * double dPdY = product[compiler.getPartialDerivativeIndex(0, 1, 0)];
- * double dPdZ = product[compiler.getPartialDerivativeIndex(0, 0, 1)];
- *
- * // cross derivatives (assuming order was at least 2)
- * double dPdXdX = product[compiler.getPartialDerivativeIndex(2, 0, 0)];
- * double dPdXdY = product[compiler.getPartialDerivativeIndex(1, 1, 0)];
- * double dPdXdZ = product[compiler.getPartialDerivativeIndex(1, 0, 1)];
- * double dPdYdY = product[compiler.getPartialDerivativeIndex(0, 2, 0)];
- * double dPdYdZ = product[compiler.getPartialDerivativeIndex(0, 1, 1)];
- * double dPdZdZ = product[compiler.getPartialDerivativeIndex(0, 0, 2)];
- *
- * @see DerivativeStructure
- * @since 3.1
- */
-public class DSCompiler {
- /** Cache for factorials. */
- private static FactorialDouble FACTORIAL = FactorialDouble.create().withCache(30);
-
- /** Array of all compilers created so far. */
- private static AtomicReference
- *
- *
- *
- *
- * @param x a value
- * @param y a value
- * @return sqrt(x2 +y2)
- * @exception DimensionMismatchException if number of free parameters
- * or orders do not match
- * @since 3.2
- */
- public static DerivativeStructure hypot(final DerivativeStructure x, final DerivativeStructure y)
- throws DimensionMismatchException {
- return x.hypot(y);
- }
-
- /** Compute composition of the instance by a univariate function.
- * @param f array of value and derivatives of the function at
- * the current point (i.e. [f({@link #getValue()}),
- * f'({@link #getValue()}), f''({@link #getValue()})...]).
- * @return f(this)
- * @exception DimensionMismatchException if the number of derivatives
- * in the array is not equal to {@link #getOrder() order} + 1
- */
- public DerivativeStructure compose(final double ... f)
- throws DimensionMismatchException {
- if (f.length != getOrder() + 1) {
- throw new DimensionMismatchException(f.length, getOrder() + 1);
- }
- final DerivativeStructure result = new DerivativeStructure(compiler);
- compiler.compose(data, 0, f, result.data, 0);
- return result;
- }
-
- /** {@inheritDoc} */
- @Override
- public DerivativeStructure reciprocal() {
- final DerivativeStructure result = new DerivativeStructure(compiler);
- compiler.pow(data, 0, -1, result.data, 0);
- return result;
- }
-
- /** {@inheritDoc}
- * @since 3.2
- */
- @Override
- public DerivativeStructure sqrt() {
- return rootN(2);
- }
-
- /** {@inheritDoc}
- * @since 3.2
- */
- @Override
- public DerivativeStructure cbrt() {
- return rootN(3);
- }
-
- /** {@inheritDoc}
- * @since 3.2
- */
- @Override
- public DerivativeStructure rootN(final int n) {
- final DerivativeStructure result = new DerivativeStructure(compiler);
- compiler.rootN(data, 0, n, result.data, 0);
- return result;
- }
-
- /** {@inheritDoc} */
- @Override
- public Field
- *
- *
- *
- *
- * @param x a value
- * @param y a value
- * @return sqrt(x2 +y2)
- */
- public static SparseGradient hypot(final SparseGradient x, final SparseGradient y) {
- return x.hypot(y);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient reciprocal() {
- return new SparseGradient(1.0 / value, -1.0 / (value * value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient sqrt() {
- final double sqrt = FastMath.sqrt(value);
- return new SparseGradient(sqrt, 0.5 / sqrt, derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient cbrt() {
- final double cbrt = FastMath.cbrt(value);
- return new SparseGradient(cbrt, 1.0 / (3 * cbrt * cbrt), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient rootN(final int n) {
- if (n == 2) {
- return sqrt();
- } else if (n == 3) {
- return cbrt();
- } else {
- final double root = FastMath.pow(value, 1.0 / n);
- return new SparseGradient(root, 1.0 / (n * FastMath.pow(root, n - 1)), derivatives);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient pow(final double p) {
- return new SparseGradient(FastMath.pow(value, p), p * FastMath.pow(value, p - 1), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient pow(final int n) {
- if (n == 0) {
- return getField().getOne();
- } else {
- final double valueNm1 = FastMath.pow(value, n - 1);
- return new SparseGradient(value * valueNm1, n * valueNm1, derivatives);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient pow(final SparseGradient e) {
- return log().multiply(e).exp();
- }
-
- /** Compute ax where a is a double and x a {@link SparseGradient}
- * @param a number to exponentiate
- * @param x power to apply
- * @return ax
- */
- public static SparseGradient pow(final double a, final SparseGradient x) {
- if (a == 0) {
- if (x.value == 0) {
- return x.compose(1.0, Double.NEGATIVE_INFINITY);
- } else if (x.value < 0) {
- return x.compose(Double.NaN, Double.NaN);
- } else {
- return x.getField().getZero();
- }
- } else {
- final double ax = FastMath.pow(a, x.value);
- return new SparseGradient(ax, ax * FastMath.log(a), x.derivatives);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient exp() {
- final double e = FastMath.exp(value);
- return new SparseGradient(e, e, derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient expm1() {
- return new SparseGradient(FastMath.expm1(value), FastMath.exp(value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient log() {
- return new SparseGradient(FastMath.log(value), 1.0 / value, derivatives);
- }
-
- /** Base 10 logarithm.
- * @return base 10 logarithm of the instance
- */
- @Override
- public SparseGradient log10() {
- return new SparseGradient(FastMath.log10(value), 1.0 / (FastMath.log(10.0) * value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient log1p() {
- return new SparseGradient(FastMath.log1p(value), 1.0 / (1.0 + value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient cos() {
- return new SparseGradient(FastMath.cos(value), -FastMath.sin(value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient sin() {
- return new SparseGradient(FastMath.sin(value), FastMath.cos(value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient tan() {
- final double t = FastMath.tan(value);
- return new SparseGradient(t, 1 + t * t, derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient acos() {
- return new SparseGradient(FastMath.acos(value), -1.0 / FastMath.sqrt(1 - value * value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient asin() {
- return new SparseGradient(FastMath.asin(value), 1.0 / FastMath.sqrt(1 - value * value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient atan() {
- return new SparseGradient(FastMath.atan(value), 1.0 / (1 + value * value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient atan2(final SparseGradient x) {
-
- // compute r = sqrt(x^2+y^2)
- final SparseGradient r = multiply(this).add(x.multiply(x)).sqrt();
-
- final SparseGradient a;
- if (x.value >= 0) {
-
- // compute atan2(y, x) = 2 atan(y / (r + x))
- a = divide(r.add(x)).atan().multiply(2);
-
- } else {
-
- // compute atan2(y, x) = +/- pi - 2 atan(y / (r - x))
- final SparseGradient tmp = divide(r.subtract(x)).atan().multiply(-2);
- a = tmp.add(tmp.value <= 0 ? -FastMath.PI : FastMath.PI);
-
- }
-
- // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
- a.value = FastMath.atan2(value, x.value);
-
- return a;
-
- }
-
- /** Two arguments arc tangent operation.
- * @param y first argument of the arc tangent
- * @param x second argument of the arc tangent
- * @return atan2(y, x)
- */
- public static SparseGradient atan2(final SparseGradient y, final SparseGradient x) {
- return y.atan2(x);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient cosh() {
- return new SparseGradient(FastMath.cosh(value), FastMath.sinh(value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient sinh() {
- return new SparseGradient(FastMath.sinh(value), FastMath.cosh(value), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient tanh() {
- final double t = FastMath.tanh(value);
- return new SparseGradient(t, 1 - t * t, derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient acosh() {
- return new SparseGradient(FastMath.acosh(value), 1.0 / FastMath.sqrt(value * value - 1.0), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient asinh() {
- return new SparseGradient(FastMath.asinh(value), 1.0 / FastMath.sqrt(value * value + 1.0), derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient atanh() {
- return new SparseGradient(FastMath.atanh(value), 1.0 / (1.0 - value * value), derivatives);
- }
-
- /** Convert radians to degrees, with error of less than 0.5 ULP
- * @return instance converted into degrees
- */
- public SparseGradient toDegrees() {
- return new SparseGradient(FastMath.toDegrees(value), FastMath.toDegrees(1.0), derivatives);
- }
-
- /** Convert degrees to radians, with error of less than 0.5 ULP
- * @return instance converted into radians
- */
- public SparseGradient toRadians() {
- return new SparseGradient(FastMath.toRadians(value), FastMath.toRadians(1.0), derivatives);
- }
-
- /** Evaluate Taylor expansion of a sparse gradient.
- * @param delta parameters offsets (Δx, Δy, ...)
- * @return value of the Taylor expansion at x + Δx, y + Δy, ...
- */
- public double taylor(final double ... delta) {
- double y = value;
- for (int i = 0; i < delta.length; ++i) {
- y += delta[i] * getDerivative(i);
- }
- return y;
- }
-
- /** Compute composition of the instance by a univariate function.
- * @param f0 value of the function at (i.e. f({@link #getValue()}))
- * @param f1 first derivative of the function at
- * the current point (i.e. f'({@link #getValue()}))
- * @return f(this)
- */
- public SparseGradient compose(final double f0, final double f1) {
- return new SparseGradient(f0, f1, derivatives);
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final SparseGradient[] a,
- final SparseGradient[] b)
- throws DimensionMismatchException {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = a[0].getField().getZero();
- for (int i = 0; i < a.length; ++i) {
- out = out.add(a[i].multiply(b[i]));
- }
-
- // recompute an accurate value, taking care of cancellations
- final double[] aDouble = new double[a.length];
- for (int i = 0; i < a.length; ++i) {
- aDouble[i] = a[i].getValue();
- }
- final double[] bDouble = new double[b.length];
- for (int i = 0; i < b.length; ++i) {
- bDouble[i] = b[i].getValue();
- }
- out.value = LinearCombination.value(aDouble, bDouble);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final double[] a, final SparseGradient[] b) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = b[0].getField().getZero();
- for (int i = 0; i < a.length; ++i) {
- out = out.add(b[i].multiply(a[i]));
- }
-
- // recompute an accurate value, taking care of cancellations
- final double[] bDouble = new double[b.length];
- for (int i = 0; i < b.length; ++i) {
- bDouble[i] = b[i].getValue();
- }
- out.value = LinearCombination.value(a, bDouble);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1,
- final SparseGradient a2, final SparseGradient b2) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = a1.multiply(b1).add(a2.multiply(b2));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1.value, b1.value, a2.value, b2.value);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final double a1, final SparseGradient b1,
- final double a2, final SparseGradient b2) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = b1.multiply(a1).add(b2.multiply(a2));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1, b1.value, a2, b2.value);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1,
- final SparseGradient a2, final SparseGradient b2,
- final SparseGradient a3, final SparseGradient b3) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1.value, b1.value,
- a2.value, b2.value,
- a3.value, b3.value);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final double a1, final SparseGradient b1,
- final double a2, final SparseGradient b2,
- final double a3, final SparseGradient b3) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1, b1.value,
- a2, b2.value,
- a3, b3.value);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final SparseGradient a1, final SparseGradient b1,
- final SparseGradient a2, final SparseGradient b2,
- final SparseGradient a3, final SparseGradient b3,
- final SparseGradient a4, final SparseGradient b4) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = a1.multiply(b1).add(a2.multiply(b2)).add(a3.multiply(b3)).add(a4.multiply(b4));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1.value, b1.value,
- a2.value, b2.value,
- a3.value, b3.value,
- a4.value, b4.value);
-
- return out;
-
- }
-
- /** {@inheritDoc} */
- @Override
- public SparseGradient linearCombination(final double a1, final SparseGradient b1,
- final double a2, final SparseGradient b2,
- final double a3, final SparseGradient b3,
- final double a4, final SparseGradient b4) {
-
- // compute a simple value, with all partial derivatives
- SparseGradient out = b1.multiply(a1).add(b2.multiply(a2)).add(b3.multiply(a3)).add(b4.multiply(a4));
-
- // recompute an accurate value, taking care of cancellations
- out.value = LinearCombination.value(a1, b1.value,
- a2, b2.value,
- a3, b3.value,
- a4, b4.value);
-
- return out;
-
- }
-
- /**
- * Test for the equality of two sparse gradients.
- * ex-1
function.
- *
- * @since 3.0
- */
-public class Expm1 implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.expm1(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.expm1();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Floor.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Floor.java
deleted file mode 100644
index 1ecd5d72a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Floor.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * {@code floor} function.
- *
- * @since 3.0
- */
-public class Floor implements UnivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.floor(x);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Gaussian.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Gaussian.java
deleted file mode 100644
index 08dcac0d4..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Gaussian.java
+++ /dev/null
@@ -1,252 +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.analysis.function;
-
-import java.util.Arrays;
-
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.numbers.core.Precision;
-
-/**
- *
- * Gaussian function.
- *
- * @since 3.0
- */
-public class Gaussian implements UnivariateDifferentiableFunction {
- /** Mean. */
- private final double mean;
- /** Inverse of the standard deviation. */
- private final double is;
- /** Inverse of twice the square of the standard deviation. */
- private final double i2s2;
- /** Normalization factor. */
- private final double norm;
-
- /**
- * Gaussian with given normalization factor, mean and standard deviation.
- *
- * @param norm Normalization factor.
- * @param mean Mean.
- * @param sigma Standard deviation.
- * @throws NotStrictlyPositiveException if {@code sigma <= 0}.
- */
- public Gaussian(double norm,
- double mean,
- double sigma)
- throws NotStrictlyPositiveException {
- if (sigma <= 0) {
- throw new NotStrictlyPositiveException(sigma);
- }
-
- this.norm = norm;
- this.mean = mean;
- this.is = 1 / sigma;
- this.i2s2 = 0.5 * is * is;
- }
-
- /**
- * Normalized gaussian with given mean and standard deviation.
- *
- * @param mean Mean.
- * @param sigma Standard deviation.
- * @throws NotStrictlyPositiveException if {@code sigma <= 0}.
- */
- public Gaussian(double mean,
- double sigma)
- throws NotStrictlyPositiveException {
- this(1 / (sigma * FastMath.sqrt(2 * Math.PI)), mean, sigma);
- }
-
- /**
- * Normalized gaussian with zero mean and unit standard deviation.
- */
- public Gaussian() {
- this(0, 1);
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return value(x - mean, norm, i2s2);
- }
-
- /**
- * Parametric function where the input array contains the parameters of
- * the Gaussian, ordered as follows:
- *
- *
- */
- public static class Parametric implements ParametricUnivariateFunction {
- /**
- * Computes the value of the Gaussian at {@code x}.
- *
- * @param x Value for which the function must be computed.
- * @param param Values of norm, mean and standard deviation.
- * @return the value of the function.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
- */
- @Override
- public double value(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- validateParameters(param);
-
- final double diff = x - param[1];
- final double i2s2 = 1 / (2 * param[2] * param[2]);
- return Gaussian.value(diff, param[0], i2s2);
- }
-
- /**
- * Computes the value of the gradient at {@code x}.
- * The components of the gradient vector are the partial
- * derivatives of the function with respect to each of the
- * parameters (norm, mean and standard deviation).
- *
- * @param x Value at which the gradient must be computed.
- * @param param Values of norm, mean and standard deviation.
- * @return the gradient vector at {@code x}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
- */
- @Override
- public double[] gradient(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- validateParameters(param);
-
- final double norm = param[0];
- final double diff = x - param[1];
- final double sigma = param[2];
- final double i2s2 = 1 / (2 * sigma * sigma);
-
- final double n = Gaussian.value(diff, 1, i2s2);
- final double m = norm * n * 2 * i2s2 * diff;
- final double s = m * diff / sigma;
-
- return new double[] { n, m, s };
- }
-
- /**
- * Validates parameters to ensure they are appropriate for the evaluation of
- * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
- * methods.
- *
- * @param param Values of norm, mean and standard deviation.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- * @throws NotStrictlyPositiveException if {@code param[2]} is negative.
- */
- private void validateParameters(double[] param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- if (param == null) {
- throw new NullArgumentException();
- }
- if (param.length != 3) {
- throw new DimensionMismatchException(param.length, 3);
- }
- if (param[2] <= 0) {
- throw new NotStrictlyPositiveException(param[2]);
- }
- }
- }
-
- /**
- * @param xMinusMean {@code x - mean}.
- * @param norm Normalization factor.
- * @param i2s2 Inverse of twice the square of the standard deviation.
- * @return the value of the Gaussian at {@code x}.
- */
- private static double value(double xMinusMean,
- double norm,
- double i2s2) {
- return norm * FastMath.exp(-xMinusMean * xMinusMean * i2s2);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t)
- throws DimensionMismatchException {
-
- final double u = is * (t.getValue() - mean);
- double[] f = new double[t.getOrder() + 1];
-
- // the nth order derivative of the Gaussian has the form:
- // dn(g(x)/dxn = (norm / s^n) P_n(u) exp(-u^2/2) with u=(x-m)/s
- // where P_n(u) is a degree n polynomial with same parity as n
- // P_0(u) = 1, P_1(u) = -u, P_2(u) = u^2 - 1, P_3(u) = -u^3 + 3 u...
- // the general recurrence relation for P_n is:
- // P_n(u) = P_(n-1)'(u) - u P_(n-1)(u)
- // as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array
- final double[] p = new double[f.length];
- p[0] = 1;
- final double u2 = u * u;
- double coeff = norm * FastMath.exp(-0.5 * u2);
- if (coeff <= Precision.SAFE_MIN) {
- Arrays.fill(f, 0.0);
- } else {
- f[0] = coeff;
- for (int n = 1; n < f.length; ++n) {
-
- // update and evaluate polynomial P_n(x)
- double v = 0;
- p[n] = -p[n - 1];
- for (int k = n; k >= 0; k -= 2) {
- v = v * u2 + p[k];
- if (k > 2) {
- p[k - 2] = (k - 1) * p[k - 1] - p[k - 3];
- } else if (k == 2) {
- p[0] = p[1];
- }
- }
- if ((n & 0x1) == 1) {
- v *= u;
- }
-
- coeff *= is;
- f[n] = coeff * v;
-
- }
- }
-
- return t.compose(f);
-
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/HarmonicOscillator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/HarmonicOscillator.java
deleted file mode 100644
index 6207d007a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/HarmonicOscillator.java
+++ /dev/null
@@ -1,176 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- *
- * simple harmonic oscillator function.
- *
- * @since 3.0
- */
-public class HarmonicOscillator implements UnivariateDifferentiableFunction {
- /** Amplitude. */
- private final double amplitude;
- /** Angular frequency. */
- private final double omega;
- /** Phase. */
- private final double phase;
-
- /**
- * Harmonic oscillator function.
- *
- * @param amplitude Amplitude.
- * @param omega Angular frequency.
- * @param phase Phase.
- */
- public HarmonicOscillator(double amplitude,
- double omega,
- double phase) {
- this.amplitude = amplitude;
- this.omega = omega;
- this.phase = phase;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return value(omega * x + phase, amplitude);
- }
-
- /**
- * Parametric function where the input array contains the parameters of
- * the harmonic oscillator function, ordered as follows:
- *
- *
- */
- public static class Parametric implements ParametricUnivariateFunction {
- /**
- * Computes the value of the harmonic oscillator at {@code x}.
- *
- * @param x Value for which the function must be computed.
- * @param param Values of norm, mean and standard deviation.
- * @return the value of the function.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- */
- @Override
- public double value(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
- return HarmonicOscillator.value(x * param[1] + param[2], param[0]);
- }
-
- /**
- * Computes the value of the gradient at {@code x}.
- * The components of the gradient vector are the partial
- * derivatives of the function with respect to each of the
- * parameters (amplitude, angular frequency and phase).
- *
- * @param x Value at which the gradient must be computed.
- * @param param Values of amplitude, angular frequency and phase.
- * @return the gradient vector at {@code x}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- */
- @Override
- public double[] gradient(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
-
- final double amplitude = param[0];
- final double omega = param[1];
- final double phase = param[2];
-
- final double xTimesOmegaPlusPhase = omega * x + phase;
- final double a = HarmonicOscillator.value(xTimesOmegaPlusPhase, 1);
- final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase);
- final double w = p * x;
-
- return new double[] { a, w, p };
- }
-
- /**
- * Validates parameters to ensure they are appropriate for the evaluation of
- * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
- * methods.
- *
- * @param param Values of norm, mean and standard deviation.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 3.
- */
- private void validateParameters(double[] param)
- throws NullArgumentException,
- DimensionMismatchException {
- if (param == null) {
- throw new NullArgumentException();
- }
- if (param.length != 3) {
- throw new DimensionMismatchException(param.length, 3);
- }
- }
- }
-
- /**
- * @param xTimesOmegaPlusPhase {@code omega * x + phase}.
- * @param amplitude Amplitude.
- * @return the value of the harmonic oscillator function at {@code x}.
- */
- private static double value(double xTimesOmegaPlusPhase,
- double amplitude) {
- return amplitude * FastMath.cos(xTimesOmegaPlusPhase);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t)
- throws DimensionMismatchException {
- final double x = t.getValue();
- double[] f = new double[t.getOrder() + 1];
-
- final double alpha = omega * x + phase;
- f[0] = amplitude * FastMath.cos(alpha);
- if (f.length > 1) {
- f[1] = -amplitude * omega * FastMath.sin(alpha);
- final double mo2 = - omega * omega;
- for (int i = 2; i < f.length; ++i) {
- f[i] = mo2 * f[i - 2];
- }
- }
-
- return t.compose(f);
-
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Identity.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Identity.java
deleted file mode 100644
index 56567d464..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Identity.java
+++ /dev/null
@@ -1,43 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-
-/**
- * Identity function.
- *
- * @since 3.0
- */
-public class Identity implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return x;
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t;
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Inverse.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Inverse.java
deleted file mode 100644
index 500496265..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Inverse.java
+++ /dev/null
@@ -1,43 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-
-/**
- * Inverse function.
- *
- * @since 3.0
- */
-public class Inverse implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return 1 / x;
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.reciprocal();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log.java
deleted file mode 100644
index 5f114669a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Natural logarithm function.
- *
- * @since 3.0
- */
-public class Log implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.log(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.log();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log10.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log10.java
deleted file mode 100644
index e0ad0b421..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log10.java
+++ /dev/null
@@ -1,45 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Base 10 logarithm function.
- *
- * @since 3.0
- */
-public class Log10 implements UnivariateDifferentiableFunction {
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.log10(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.log10();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log1p.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log1p.java
deleted file mode 100644
index f95c97058..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Log1p.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * log(1 + p)
function.
- *
- * @since 3.0
- */
-public class Log1p implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.log1p(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.log1p();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logistic.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logistic.java
deleted file mode 100644
index c5ff5e0ec..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logistic.java
+++ /dev/null
@@ -1,221 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- *
- * Generalised logistic function.
- *
- * @since 3.0
- */
-public class Logistic implements UnivariateDifferentiableFunction {
- /** Lower asymptote. */
- private final double a;
- /** Upper asymptote. */
- private final double k;
- /** Growth rate. */
- private final double b;
- /** Parameter that affects near which asymptote maximum growth occurs. */
- private final double oneOverN;
- /** Parameter that affects the position of the curve along the ordinate axis. */
- private final double q;
- /** Abscissa of maximum growth. */
- private final double m;
-
- /**
- * @param k If {@code b > 0}, value of the function for x going towards +∞.
- * If {@code b < 0}, value of the function for x going towards -∞.
- * @param m Abscissa of maximum growth.
- * @param b Growth rate.
- * @param q Parameter that affects the position of the curve along the
- * ordinate axis.
- * @param a If {@code b > 0}, value of the function for x going towards -∞.
- * If {@code b < 0}, value of the function for x going towards +∞.
- * @param n Parameter that affects near which asymptote the maximum
- * growth occurs.
- * @throws NotStrictlyPositiveException if {@code n <= 0}.
- */
- public Logistic(double k,
- double m,
- double b,
- double q,
- double a,
- double n)
- throws NotStrictlyPositiveException {
- if (n <= 0) {
- throw new NotStrictlyPositiveException(n);
- }
-
- this.k = k;
- this.m = m;
- this.b = b;
- this.q = q;
- this.a = a;
- oneOverN = 1 / n;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return value(m - x, k, b, q, a, oneOverN);
- }
-
- /**
- * Parametric function where the input array contains the parameters of
- * the {@link Logistic#Logistic(double,double,double,double,double,double)
- * logistic function}, ordered as follows:
- *
- *
- */
- public static class Parametric implements ParametricUnivariateFunction {
- /**
- * Computes the value of the sigmoid at {@code x}.
- *
- * @param x Value for which the function must be computed.
- * @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
- * {@code a} and {@code n}.
- * @return the value of the function.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 6.
- * @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
- */
- @Override
- public double value(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- validateParameters(param);
- return Logistic.value(param[1] - x, param[0],
- param[2], param[3],
- param[4], 1 / param[5]);
- }
-
- /**
- * Computes the value of the gradient at {@code x}.
- * The components of the gradient vector are the partial
- * derivatives of the function with respect to each of the
- * parameters.
- *
- * @param x Value at which the gradient must be computed.
- * @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
- * {@code a} and {@code n}.
- * @return the gradient vector at {@code x}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 6.
- * @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
- */
- @Override
- public double[] gradient(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- validateParameters(param);
-
- final double b = param[2];
- final double q = param[3];
-
- final double mMinusX = param[1] - x;
- final double oneOverN = 1 / param[5];
- final double exp = FastMath.exp(b * mMinusX);
- final double qExp = q * exp;
- final double qExp1 = qExp + 1;
- final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN);
- final double factor2 = -factor1 / qExp1;
-
- // Components of the gradient.
- final double gk = Logistic.value(mMinusX, 1, b, q, 0, oneOverN);
- final double gm = factor2 * b * qExp;
- final double gb = factor2 * mMinusX * qExp;
- final double gq = factor2 * exp;
- final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN);
- final double gn = factor1 * FastMath.log(qExp1) * oneOverN;
-
- return new double[] { gk, gm, gb, gq, ga, gn };
- }
-
- /**
- * Validates parameters to ensure they are appropriate for the evaluation of
- * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
- * methods.
- *
- * @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
- * {@code a} and {@code n}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 6.
- * @throws NotStrictlyPositiveException if {@code param[5] <= 0}.
- */
- private void validateParameters(double[] param)
- throws NullArgumentException,
- DimensionMismatchException,
- NotStrictlyPositiveException {
- if (param == null) {
- throw new NullArgumentException();
- }
- if (param.length != 6) {
- throw new DimensionMismatchException(param.length, 6);
- }
- if (param[5] <= 0) {
- throw new NotStrictlyPositiveException(param[5]);
- }
- }
- }
-
- /**
- * @param mMinusX {@code m - x}.
- * @param k {@code k}.
- * @param b {@code b}.
- * @param q {@code q}.
- * @param a {@code a}.
- * @param oneOverN {@code 1 / n}.
- * @return the value of the function.
- */
- private static double value(double mMinusX,
- double k,
- double b,
- double q,
- double a,
- double oneOverN) {
- return a + (k - a) / FastMath.pow(1 + q * FastMath.exp(b * mMinusX), oneOverN);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.negate().add(m).multiply(b).exp().multiply(q).add(1).pow(oneOverN).reciprocal().multiply(k - a).add(a);
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logit.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logit.java
deleted file mode 100644
index 55b1fd9a8..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Logit.java
+++ /dev/null
@@ -1,205 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- *
- * Logit function.
- * It is the inverse of the {@link Sigmoid sigmoid} function.
- *
- * @since 3.0
- */
-public class Logit implements UnivariateDifferentiableFunction {
- /** Lower bound. */
- private final double lo;
- /** Higher bound. */
- private final double hi;
-
- /**
- * Usual logit function, where the lower bound is 0 and the higher
- * bound is 1.
- */
- public Logit() {
- this(0, 1);
- }
-
- /**
- * Logit function.
- *
- * @param lo Lower bound of the function domain.
- * @param hi Higher bound of the function domain.
- */
- public Logit(double lo,
- double hi) {
- this.lo = lo;
- this.hi = hi;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x)
- throws OutOfRangeException {
- return value(x, lo, hi);
- }
-
- /**
- * Parametric function where the input array contains the parameters of
- * the logit function, ordered as follows:
- *
- *
- */
- public static class Parametric implements ParametricUnivariateFunction {
- /**
- * Computes the value of the logit at {@code x}.
- *
- * @param x Value for which the function must be computed.
- * @param param Values of lower bound and higher bounds.
- * @return the value of the function.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- @Override
- public double value(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
- return Logit.value(x, param[0], param[1]);
- }
-
- /**
- * Computes the value of the gradient at {@code x}.
- * The components of the gradient vector are the partial
- * derivatives of the function with respect to each of the
- * parameters (lower bound and higher bound).
- *
- * @param x Value at which the gradient must be computed.
- * @param param Values for lower and higher bounds.
- * @return the gradient vector at {@code x}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- @Override
- public double[] gradient(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
-
- final double lo = param[0];
- final double hi = param[1];
-
- return new double[] { 1 / (lo - x), 1 / (hi - x) };
- }
-
- /**
- * Validates parameters to ensure they are appropriate for the evaluation of
- * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
- * methods.
- *
- * @param param Values for lower and higher bounds.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- private void validateParameters(double[] param)
- throws NullArgumentException,
- DimensionMismatchException {
- if (param == null) {
- throw new NullArgumentException();
- }
- if (param.length != 2) {
- throw new DimensionMismatchException(param.length, 2);
- }
- }
- }
-
- /**
- * @param x Value at which to compute the logit.
- * @param lo Lower bound.
- * @param hi Higher bound.
- * @return the value of the logit function at {@code x}.
- * @throws OutOfRangeException if {@code x < lo} or {@code x > hi}.
- */
- private static double value(double x,
- double lo,
- double hi)
- throws OutOfRangeException {
- if (x < lo || x > hi) {
- throw new OutOfRangeException(x, lo, hi);
- }
- return FastMath.log((x - lo) / (hi - x));
- }
-
- /** {@inheritDoc}
- * @since 3.1
- * @exception OutOfRangeException if parameter is outside of function domain
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t)
- throws OutOfRangeException {
- final double x = t.getValue();
- if (x < lo || x > hi) {
- throw new OutOfRangeException(x, lo, hi);
- }
- double[] f = new double[t.getOrder() + 1];
-
- // function value
- f[0] = FastMath.log((x - lo) / (hi - x));
-
- if (Double.isInfinite(f[0])) {
-
- if (f.length > 1) {
- f[1] = Double.POSITIVE_INFINITY;
- }
- // fill the array with infinities
- // (for x close to lo the signs will flip between -inf and +inf,
- // for x close to hi the signs will always be +inf)
- // this is probably overkill, since the call to compose at the end
- // of the method will transform most infinities into NaN ...
- for (int i = 2; i < f.length; ++i) {
- f[i] = f[i - 2];
- }
-
- } else {
-
- // function derivatives
- final double invL = 1.0 / (x - lo);
- double xL = invL;
- final double invH = 1.0 / (hi - x);
- double xH = invH;
- for (int i = 1; i < f.length; ++i) {
- f[i] = xL + xH;
- xL *= -i * invL;
- xH *= i * invH;
- }
- }
-
- return t.compose(f);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Max.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Max.java
deleted file mode 100644
index cf6a3e351..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Max.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.BivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Maximum function.
- *
- * @since 3.0
- */
-public class Max implements BivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x, double y) {
- return FastMath.max(x, y);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Min.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Min.java
deleted file mode 100644
index 0866dde53..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Min.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.BivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Minimum function.
- *
- * @since 3.0
- */
-public class Min implements BivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x, double y) {
- return FastMath.min(x, y);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Minus.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Minus.java
deleted file mode 100644
index 714de04b2..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Minus.java
+++ /dev/null
@@ -1,43 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-
-/**
- * Minus function.
- *
- * @since 3.0
- */
-public class Minus implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return -x;
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.negate();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Multiply.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Multiply.java
deleted file mode 100644
index df3bb50c9..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Multiply.java
+++ /dev/null
@@ -1,33 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.BivariateFunction;
-
-/**
- * Multiply the two operands.
- *
- * @since 3.0
- */
-public class Multiply implements BivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x, double y) {
- return x * y;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Pow.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Pow.java
deleted file mode 100644
index 52df284cc..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Pow.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.BivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Power function.
- *
- * @since 3.0
- */
-public class Pow implements BivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x, double y) {
- return FastMath.pow(x, y);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Power.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Power.java
deleted file mode 100644
index f605c9351..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Power.java
+++ /dev/null
@@ -1,54 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Power function.
- *
- * @since 3.0
- */
-public class Power implements UnivariateDifferentiableFunction {
- /** Power. */
- private final double p;
-
- /**
- * @param p Power.
- */
- public Power(double p) {
- this.p = p;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.pow(x, p);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.pow(p);
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Rint.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Rint.java
deleted file mode 100644
index 31312237e..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Rint.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * {@code rint} function.
- *
- * @since 3.0
- */
-public class Rint implements UnivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.rint(x);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sigmoid.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sigmoid.java
deleted file mode 100644
index 52d582523..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sigmoid.java
+++ /dev/null
@@ -1,211 +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.analysis.function;
-
-import java.util.Arrays;
-
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- *
- * Sigmoid function.
- * It is the inverse of the {@link Logit logit} function.
- * A more flexible version, the generalised logistic, is implemented
- * by the {@link Logistic} class.
- *
- * @since 3.0
- */
-public class Sigmoid implements UnivariateDifferentiableFunction {
- /** Lower asymptote. */
- private final double lo;
- /** Higher asymptote. */
- private final double hi;
-
- /**
- * Usual sigmoid function, where the lower asymptote is 0 and the higher
- * asymptote is 1.
- */
- public Sigmoid() {
- this(0, 1);
- }
-
- /**
- * Sigmoid function.
- *
- * @param lo Lower asymptote.
- * @param hi Higher asymptote.
- */
- public Sigmoid(double lo,
- double hi) {
- this.lo = lo;
- this.hi = hi;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return value(x, lo, hi);
- }
-
- /**
- * Parametric function where the input array contains the parameters of
- * the {@link Sigmoid#Sigmoid(double,double) sigmoid function}, ordered
- * as follows:
- *
- *
- */
- public static class Parametric implements ParametricUnivariateFunction {
- /**
- * Computes the value of the sigmoid at {@code x}.
- *
- * @param x Value for which the function must be computed.
- * @param param Values of lower asymptote and higher asymptote.
- * @return the value of the function.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- @Override
- public double value(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
- return Sigmoid.value(x, param[0], param[1]);
- }
-
- /**
- * Computes the value of the gradient at {@code x}.
- * The components of the gradient vector are the partial
- * derivatives of the function with respect to each of the
- * parameters (lower asymptote and higher asymptote).
- *
- * @param x Value at which the gradient must be computed.
- * @param param Values for lower asymptote and higher asymptote.
- * @return the gradient vector at {@code x}.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- @Override
- public double[] gradient(double x, double ... param)
- throws NullArgumentException,
- DimensionMismatchException {
- validateParameters(param);
-
- final double invExp1 = 1 / (1 + FastMath.exp(-x));
-
- return new double[] { 1 - invExp1, invExp1 };
- }
-
- /**
- * Validates parameters to ensure they are appropriate for the evaluation of
- * the {@link #value(double,double[])} and {@link #gradient(double,double[])}
- * methods.
- *
- * @param param Values for lower and higher asymptotes.
- * @throws NullArgumentException if {@code param} is {@code null}.
- * @throws DimensionMismatchException if the size of {@code param} is
- * not 2.
- */
- private void validateParameters(double[] param)
- throws NullArgumentException,
- DimensionMismatchException {
- if (param == null) {
- throw new NullArgumentException();
- }
- if (param.length != 2) {
- throw new DimensionMismatchException(param.length, 2);
- }
- }
- }
-
- /**
- * @param x Value at which to compute the sigmoid.
- * @param lo Lower asymptote.
- * @param hi Higher asymptote.
- * @return the value of the sigmoid function at {@code x}.
- */
- private static double value(double x,
- double lo,
- double hi) {
- return lo + (hi - lo) / (1 + FastMath.exp(-x));
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t)
- throws DimensionMismatchException {
-
- double[] f = new double[t.getOrder() + 1];
- final double exp = FastMath.exp(-t.getValue());
- if (Double.isInfinite(exp)) {
-
- // special handling near lower boundary, to avoid NaN
- f[0] = lo;
- Arrays.fill(f, 1, f.length, 0.0);
-
- } else {
-
- // the nth order derivative of sigmoid has the form:
- // dn(sigmoid(x)/dxn = P_n(exp(-x)) / (1+exp(-x))^(n+1)
- // where P_n(t) is a degree n polynomial with normalized higher term
- // P_0(t) = 1, P_1(t) = t, P_2(t) = t^2 - t, P_3(t) = t^3 - 4 t^2 + t...
- // the general recurrence relation for P_n is:
- // P_n(x) = n t P_(n-1)(t) - t (1 + t) P_(n-1)'(t)
- final double[] p = new double[f.length];
-
- final double inv = 1 / (1 + exp);
- double coeff = hi - lo;
- for (int n = 0; n < f.length; ++n) {
-
- // update and evaluate polynomial P_n(t)
- double v = 0;
- p[n] = 1;
- for (int k = n; k >= 0; --k) {
- v = v * exp + p[k];
- if (k > 1) {
- p[k - 1] = (n - k + 2) * p[k - 2] - (k - 1) * p[k - 1];
- } else {
- p[0] = 0;
- }
- }
-
- coeff *= inv;
- f[n] = coeff * v;
-
- }
-
- // fix function value
- f[0] += lo;
-
- }
-
- return t.compose(f);
-
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Signum.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Signum.java
deleted file mode 100644
index 45fbc47c0..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Signum.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * {@code signum} function.
- *
- * @since 3.0
- */
-public class Signum implements UnivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.signum(x);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sin.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sin.java
deleted file mode 100644
index 08e958112..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sin.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Sine function.
- *
- * @since 3.0
- */
-public class Sin implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.sin(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.sin();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinc.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinc.java
deleted file mode 100644
index b6207fcac..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinc.java
+++ /dev/null
@@ -1,196 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Sinc function,
- * defined by
- *
- *
- * @since 3.0
- */
-public class Sinc implements UnivariateDifferentiableFunction {
- /**
- * Value below which the computations are done using Taylor series.
- *
- * sinc(x) = 1 if x = 0,
- * sin(x) / x otherwise.
- *
- * d^(2n)sinc/dx^(2n) = Sum_(k>=0) (-1)^(n+k) / ((2k)!(2n+2k+1)) x^(2k)
- * = (-1)^n [ 1/(2n+1) - x^2/(4n+6) + x^4/(48n+120) - x^6/(1440n+5040) + O(x^8) ]
- *
- *
- * The Taylor series for sinc odd order derivatives are: - *
- * d^(2n+1)sinc/dx^(2n+1) = Sum_(k>=0) (-1)^(n+k+1) / ((2k+1)!(2n+2k+3)) x^(2k+1) - * = (-1)^(n+1) [ x/(2n+3) - x^3/(12n+30) + x^5/(240n+840) - x^7/(10080n+45360) + O(x^9) ] - *- * - *
- * So the ratio of the fourth term with respect to the first term - * is always smaller than x^6/720, for all derivative orders. - * This implies that neglecting this term and using only the first three terms induces - * a relative error bounded by x^6/720. The SHORTCUT value is chosen such that this - * relative error is below double precision accuracy when |x| <= SHORTCUT. - *
- */ - private static final double SHORTCUT = 6.0e-3; - /** For normalized sinc function. */ - private final boolean normalized; - - /** - * The sinc function, {@code sin(x) / x}. - */ - public Sinc() { - this(false); - } - - /** - * Instantiates the sinc function. - * - * @param normalized If {@code true}, the function is - * sin(πx) / πx
, otherwise {@code sin(x) / x}.
- */
- public Sinc(boolean normalized) {
- this.normalized = normalized;
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(final double x) {
- final double scaledX = normalized ? FastMath.PI * x : x;
- if (FastMath.abs(scaledX) <= SHORTCUT) {
- // use Taylor series
- final double scaledX2 = scaledX * scaledX;
- return ((scaledX2 - 20) * scaledX2 + 120) / 120;
- } else {
- // use definition expression
- return FastMath.sin(scaledX) / scaledX;
- }
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t)
- throws DimensionMismatchException {
-
- final double scaledX = (normalized ? FastMath.PI : 1) * t.getValue();
- final double scaledX2 = scaledX * scaledX;
-
- double[] f = new double[t.getOrder() + 1];
-
- if (FastMath.abs(scaledX) <= SHORTCUT) {
-
- for (int i = 0; i < f.length; ++i) {
- final int k = i / 2;
- if ((i & 0x1) == 0) {
- // even derivation order
- f[i] = (((k & 0x1) == 0) ? 1 : -1) *
- (1.0 / (i + 1) - scaledX2 * (1.0 / (2 * i + 6) - scaledX2 / (24 * i + 120)));
- } else {
- // odd derivation order
- f[i] = (((k & 0x1) == 0) ? -scaledX : scaledX) *
- (1.0 / (i + 2) - scaledX2 * (1.0 / (6 * i + 24) - scaledX2 / (120 * i + 720)));
- }
- }
-
- } else {
-
- final double inv = 1 / scaledX;
- final double cos = FastMath.cos(scaledX);
- final double sin = FastMath.sin(scaledX);
-
- f[0] = inv * sin;
-
- // the nth order derivative of sinc has the form:
- // dn(sinc(x)/dxn = [S_n(x) sin(x) + C_n(x) cos(x)] / x^(n+1)
- // where S_n(x) is an even polynomial with degree n-1 or n (depending on parity)
- // and C_n(x) is an odd polynomial with degree n-1 or n (depending on parity)
- // S_0(x) = 1, S_1(x) = -1, S_2(x) = -x^2 + 2, S_3(x) = 3x^2 - 6...
- // C_0(x) = 0, C_1(x) = x, C_2(x) = -2x, C_3(x) = -x^3 + 6x...
- // the general recurrence relations for S_n and C_n are:
- // S_n(x) = x S_(n-1)'(x) - n S_(n-1)(x) - x C_(n-1)(x)
- // C_n(x) = x C_(n-1)'(x) - n C_(n-1)(x) + x S_(n-1)(x)
- // as per polynomials parity, we can store both S_n and C_n in the same array
- final double[] sc = new double[f.length];
- sc[0] = 1;
-
- double coeff = inv;
- for (int n = 1; n < f.length; ++n) {
-
- double s = 0;
- double c = 0;
-
- // update and evaluate polynomials S_n(x) and C_n(x)
- final int kStart;
- if ((n & 0x1) == 0) {
- // even derivation order, S_n is degree n and C_n is degree n-1
- sc[n] = 0;
- kStart = n;
- } else {
- // odd derivation order, S_n is degree n-1 and C_n is degree n
- sc[n] = sc[n - 1];
- c = sc[n];
- kStart = n - 1;
- }
-
- // in this loop, k is always even
- for (int k = kStart; k > 1; k -= 2) {
-
- // sine part
- sc[k] = (k - n) * sc[k] - sc[k - 1];
- s = s * scaledX2 + sc[k];
-
- // cosine part
- sc[k - 1] = (k - 1 - n) * sc[k - 1] + sc[k -2];
- c = c * scaledX2 + sc[k - 1];
-
- }
- sc[0] *= -n;
- s = s * scaledX2 + sc[0];
-
- coeff *= inv;
- f[n] = coeff * (s * sin + c * scaledX * cos);
-
- }
-
- }
-
- if (normalized) {
- double scale = FastMath.PI;
- for (int i = 1; i < f.length; ++i) {
- f[i] *= scale;
- scale *= FastMath.PI;
- }
- }
-
- return t.compose(f);
-
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinh.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinh.java
deleted file mode 100644
index 617f9a46d..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sinh.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Hyperbolic sine function.
- *
- * @since 3.0
- */
-public class Sinh implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.sinh(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.sinh();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sqrt.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sqrt.java
deleted file mode 100644
index 979e67d7c..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Sqrt.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Square-root function.
- *
- * @since 3.0
- */
-public class Sqrt implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.sqrt(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.sqrt();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java
deleted file mode 100644
index 08461cb2c..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/StepFunction.java
+++ /dev/null
@@ -1,102 +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.analysis.function;
-
-import java.util.Arrays;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NoDataException;
-import org.apache.commons.math4.exception.NonMonotonicSequenceException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.util.MathArrays;
-
-/**
- *
- * Step function.
- *
- * @since 3.0
- */
-public class StepFunction implements UnivariateFunction {
- /** Abscissae. */
- private final double[] abscissa;
- /** Ordinates. */
- private final double[] ordinate;
-
- /**
- * Builds a step function from a list of arguments and the corresponding
- * values. Specifically, returns the function h(x) defined by
- * h(x) = y[0] for all x < x[1]
- * y[1] for x[1] ≤ x < x[2]
- * ...
- * y[y.length - 1] for x ≥ x[x.length - 1]
- *
- * The value of {@code x[0]} is ignored, but it must be strictly less than
- * {@code x[1]}.
- *
- * @param x Domain values where the function changes value.
- * @param y Values of the function.
- * @throws NonMonotonicSequenceException
- * if the {@code x} array is not sorted in strictly increasing order.
- * @throws NullArgumentException if {@code x} or {@code y} are {@code null}.
- * @throws NoDataException if {@code x} or {@code y} are zero-length.
- * @throws DimensionMismatchException if {@code x} and {@code y} do not
- * have the same length.
- */
- public StepFunction(double[] x,
- double[] y)
- throws NullArgumentException, NoDataException,
- DimensionMismatchException, NonMonotonicSequenceException {
- if (x == null ||
- y == null) {
- throw new NullArgumentException();
- }
- if (x.length == 0 ||
- y.length == 0) {
- throw new NoDataException();
- }
- if (y.length != x.length) {
- throw new DimensionMismatchException(y.length, x.length);
- }
- MathArrays.checkOrder(x);
-
- abscissa = MathArrays.copyOf(x);
- ordinate = MathArrays.copyOf(y);
- }
-
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- int index = Arrays.binarySearch(abscissa, x);
- double fx = 0;
-
- if (index < -1) {
- // "x" is between "abscissa[-index-2]" and "abscissa[-index-1]".
- fx = ordinate[-index-2];
- } else if (index >= 0) {
- // "x" is exactly "abscissa[index]".
- fx = ordinate[index];
- } else {
- // Otherwise, "x" is smaller than the first value in "abscissa"
- // (hence the returned value should be "ordinate[0]").
- fx = ordinate[0];
- }
-
- return fx;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Subtract.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Subtract.java
deleted file mode 100644
index 1ce5e95a4..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Subtract.java
+++ /dev/null
@@ -1,33 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.BivariateFunction;
-
-/**
- * Subtract the second operand from the first.
- *
- * @since 3.0
- */
-public class Subtract implements BivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x, double y) {
- return x - y;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tan.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tan.java
deleted file mode 100644
index dc205892e..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tan.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Tangent function.
- *
- * @since 3.0
- */
-public class Tan implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.tan(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.tan();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tanh.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tanh.java
deleted file mode 100644
index 2769ca537..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Tanh.java
+++ /dev/null
@@ -1,44 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Hyperbolic tangent function.
- *
- * @since 3.0
- */
-public class Tanh implements UnivariateDifferentiableFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.tanh(x);
- }
-
- /** {@inheritDoc}
- * @since 3.1
- */
- @Override
- public DerivativeStructure value(final DerivativeStructure t) {
- return t.tanh();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Ulp.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Ulp.java
deleted file mode 100644
index 543a7d46a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/Ulp.java
+++ /dev/null
@@ -1,34 +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.analysis.function;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * {@code ulp} function.
- *
- * @since 3.0
- */
-public class Ulp implements UnivariateFunction {
- /** {@inheritDoc} */
- @Override
- public double value(double x) {
- return FastMath.ulp(x);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/package-info.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/package-info.java
deleted file mode 100644
index 695f68985..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/function/package-info.java
+++ /dev/null
@@ -1,26 +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.
- */
-/**
- *
- * - * The {@code function} package contains function objects that wrap the - * methods contained in {@link java.lang.Math}, as well as common - * mathematical functions such as the gaussian and sinc functions. - *
- * - */ -package org.apache.commons.math4.analysis.function; diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java deleted file mode 100644 index 595f18f3d..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java +++ /dev/null @@ -1,287 +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.analysis.integration; - -import org.apache.commons.math4.analysis.UnivariateFunction; -import org.apache.commons.math4.analysis.solvers.UnivariateSolverUtils; -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; -import org.apache.commons.math4.exception.TooManyEvaluationsException; -import org.apache.commons.math4.util.Incrementor; -import org.apache.commons.math4.util.MathUtils; - -/** - * Provide a default implementation for several generic functions. - * - * @since 1.2 - */ -public abstract class BaseAbstractUnivariateIntegrator implements UnivariateIntegrator { - - /** Default absolute accuracy. */ - public static final double DEFAULT_ABSOLUTE_ACCURACY = 1.0e-15; - - /** Default relative accuracy. */ - public static final double DEFAULT_RELATIVE_ACCURACY = 1.0e-6; - - /** Default minimal iteration count. */ - public static final int DEFAULT_MIN_ITERATIONS_COUNT = 3; - - /** Default maximal iteration count. */ - public static final int DEFAULT_MAX_ITERATIONS_COUNT = Integer.MAX_VALUE; - - /** The iteration count. */ - protected final Incrementor iterations; - - /** Maximum absolute error. */ - private final double absoluteAccuracy; - - /** Maximum relative error. */ - private final double relativeAccuracy; - - /** minimum number of iterations */ - private final int minimalIterationCount; - - /** The functions evaluation count. */ - private final Incrementor evaluations; - - /** Function to integrate. */ - private UnivariateFunction function; - - /** Lower bound for the interval. */ - private double min; - - /** Upper bound for the interval. */ - private double max; - - /** - * Construct an integrator with given accuracies and iteration counts. - *- * The meanings of the various parameters are: - *
- * The function should be integrable.
- * - * @since 3.3 - */ -public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator { - - /** Maximum number of iterations for midpoint. */ - public static final int MIDPOINT_MAX_ITERATIONS_COUNT = 64; - - /** - * Build a midpoint integrator with given accuracies and iterations counts. - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT} - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT} - */ - public MidPointIntegrator(final double relativeAccuracy, - final double absoluteAccuracy, - final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - MIDPOINT_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Build a midpoint integrator with given iteration counts. - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT} - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT} - */ - public MidPointIntegrator(final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - MIDPOINT_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Construct a midpoint integrator with default settings. - * (max iteration count set to {@link #MIDPOINT_MAX_ITERATIONS_COUNT}) - */ - public MidPointIntegrator() { - super(DEFAULT_MIN_ITERATIONS_COUNT, MIDPOINT_MAX_ITERATIONS_COUNT); - } - - /** - * Compute the n-th stage integral of midpoint rule. - * This function should only be called by APIintegrate()
in the package.
- * To save time it does not verify arguments - caller does.
- * - * The interval is divided equally into 2^n sections rather than an - * arbitrary m sections because this configuration can best utilize the - * already computed values.
- * - * @param n the stage of 1/2 refinement. Must be larger than 0. - * @param previousStageResult Result from the previous call to the - * {@code stage} method. - * @param min Lower bound of the integration interval. - * @param diffMaxMin Difference between the lower bound and upper bound - * of the integration interval. - * @return the value of n-th stage integral - * @throws TooManyEvaluationsException if the maximal number of evaluations - * is exceeded. - */ - private double stage(final int n, - double previousStageResult, - double min, - double diffMaxMin) - throws TooManyEvaluationsException { - - // number of new points in this stage - final long np = 1L << (n - 1); - double sum = 0; - - // spacing between adjacent new points - final double spacing = diffMaxMin / np; - - // the first new point - double x = min + 0.5 * spacing; - for (long i = 0; i < np; i++) { - sum += computeObjectiveValue(x); - x += spacing; - } - // add the new sum to previously calculated result - return 0.5 * (previousStageResult + sum * spacing); - } - - - /** {@inheritDoc} */ - @Override - protected double doIntegrate() - throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { - - final double min = getMin(); - final double diff = getMax() - min; - final double midPoint = min + 0.5 * diff; - - double oldt = diff * computeObjectiveValue(midPoint); - - while (true) { - iterations.incrementCount(); - final int i = iterations.getCount(); - final double t = stage(i, oldt, min, diff); - if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(t - oldt); - final double rLimit = - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; - if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { - return t; - } - } - oldt = t; - } - - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/RombergIntegrator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/RombergIntegrator.java deleted file mode 100644 index 923de73f7..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/RombergIntegrator.java +++ /dev/null @@ -1,142 +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.analysis.integration; - -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -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.util.FastMath; - -/** - * Implements the - * Romberg Algorithm for integration of real univariate functions. For - * reference, see Introduction to Numerical Analysis, ISBN 038795452X, - * chapter 3. - *- * Romberg integration employs k successive refinements of the trapezoid - * rule to remove error terms less than order O(N^(-2k)). Simpson's rule - * is a special case of k = 2.
- * - * @since 1.2 - */ -public class RombergIntegrator extends BaseAbstractUnivariateIntegrator { - - /** Maximal number of iterations for Romberg. */ - public static final int ROMBERG_MAX_ITERATIONS_COUNT = 32; - - /** - * Build a Romberg integrator with given accuracies and iterations counts. - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT}) - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT} - */ - public RombergIntegrator(final double relativeAccuracy, - final double absoluteAccuracy, - final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - ROMBERG_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Build a Romberg integrator with given iteration counts. - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT}) - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT} - */ - public RombergIntegrator(final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - ROMBERG_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Construct a Romberg integrator with default settings - * (max iteration count set to {@link #ROMBERG_MAX_ITERATIONS_COUNT}) - */ - public RombergIntegrator() { - super(DEFAULT_MIN_ITERATIONS_COUNT, ROMBERG_MAX_ITERATIONS_COUNT); - } - - /** {@inheritDoc} */ - @Override - protected double doIntegrate() - throws TooManyEvaluationsException, MaxCountExceededException { - - final int m = iterations.getMaximalCount() + 1; - double previousRow[] = new double[m]; - double currentRow[] = new double[m]; - - TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); - currentRow[0] = qtrap.stage(this, 0); - iterations.incrementCount(); - double olds = currentRow[0]; - while (true) { - - final int i = iterations.getCount(); - - // switch rows - final double[] tmpRow = previousRow; - previousRow = currentRow; - currentRow = tmpRow; - - currentRow[0] = qtrap.stage(this, i); - iterations.incrementCount(); - for (int j = 1; j <= i; j++) { - // Richardson extrapolation coefficient - final double r = (1L << (2 * j)) - 1; - final double tIJm1 = currentRow[j - 1]; - currentRow[j] = tIJm1 + (tIJm1 - previousRow[j - 1]) / r; - } - final double s = currentRow[i]; - if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; - if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { - return s; - } - } - olds = s; - } - - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/SimpsonIntegrator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/SimpsonIntegrator.java deleted file mode 100644 index 0ede25e94..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/SimpsonIntegrator.java +++ /dev/null @@ -1,124 +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.analysis.integration; - -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.exception.NumberIsTooLargeException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; -import org.apache.commons.math4.util.FastMath; - -/** - * Implements - * Simpson's Rule for integration of real univariate functions. For - * reference, see Introduction to Numerical Analysis, ISBN 038795452X, - * chapter 3. - *- * This implementation employs the basic trapezoid rule to calculate Simpson's - * rule.
- * - * @since 1.2 - */ -public class SimpsonIntegrator extends BaseAbstractUnivariateIntegrator { - - /** Maximal number of iterations for Simpson. */ - public static final int SIMPSON_MAX_ITERATIONS_COUNT = 63; - - /** - * Build a Simpson integrator with given accuracies and iterations counts. - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT}) - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT} - */ - public SimpsonIntegrator(final double relativeAccuracy, - final double absoluteAccuracy, - final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - SIMPSON_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Build a Simpson integrator with given iteration counts. - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT}) - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT} - */ - public SimpsonIntegrator(final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - SIMPSON_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Construct an integrator with default settings. - * (max iteration count set to {@link #SIMPSON_MAX_ITERATIONS_COUNT}) - */ - public SimpsonIntegrator() { - super(DEFAULT_MIN_ITERATIONS_COUNT, SIMPSON_MAX_ITERATIONS_COUNT); - } - - /** {@inheritDoc} */ - @Override - protected double doIntegrate() { - // Simpson's rule requires at least two trapezoid stages. - // So we set the first sum using two trapezoid stages. - final TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); - - final double s0 = qtrap.stage(this, 0); - double oldt = qtrap.stage(this, 1); - double olds = (4 * oldt - s0) / 3.0; - while (true) { - // The first iteration is the first refinement of the sum. - iterations.incrementCount(); - final int i = getIterations(); - final double t = qtrap.stage(this, i + 1); // 1-stage ahead of the iteration - final double s = (4 * t - oldt) / 3.0; - if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(s - olds); - final double rLimit = getRelativeAccuracy() * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; - if (delta <= rLimit || - delta <= getAbsoluteAccuracy()) { - return s; - } - } - olds = s; - oldt = t; - } - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/TrapezoidIntegrator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/TrapezoidIntegrator.java deleted file mode 100644 index 893d602d0..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/TrapezoidIntegrator.java +++ /dev/null @@ -1,168 +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.analysis.integration; - -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -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.util.FastMath; - -/** - * Implements the - * Trapezoid Rule for integration of real univariate functions. For - * reference, see Introduction to Numerical Analysis, ISBN 038795452X, - * chapter 3. - *- * The function should be integrable.
- * - * @since 1.2 - */ -public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator { - - /** Maximum number of iterations for trapezoid. */ - public static final int TRAPEZOID_MAX_ITERATIONS_COUNT = 64; - - /** Intermediate result. */ - private double s; - - /** - * Build a trapezoid integrator with given accuracies and iterations counts. - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} - */ - public TrapezoidIntegrator(final double relativeAccuracy, - final double absoluteAccuracy, - final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - TRAPEZOID_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Build a trapezoid integrator with given iteration counts. - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - * @exception NumberIsTooLargeException if maximal number of iterations - * is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} - */ - public TrapezoidIntegrator(final int minimalIterationCount, - final int maximalIterationCount) - throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { - super(minimalIterationCount, maximalIterationCount); - if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) { - throw new NumberIsTooLargeException(maximalIterationCount, - TRAPEZOID_MAX_ITERATIONS_COUNT, false); - } - } - - /** - * Construct a trapezoid integrator with default settings. - * (max iteration count set to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT}) - */ - public TrapezoidIntegrator() { - super(DEFAULT_MIN_ITERATIONS_COUNT, TRAPEZOID_MAX_ITERATIONS_COUNT); - } - - /** - * Compute the n-th stage integral of trapezoid rule. This function - * should only be called by APIintegrate()
in the package.
- * To save time it does not verify arguments - caller does.
- * - * The interval is divided equally into 2^n sections rather than an - * arbitrary m sections because this configuration can best utilize the - * already computed values.
- * - * @param baseIntegrator integrator holding integration parameters - * @param n the stage of 1/2 refinement, n = 0 is no refinement - * @return the value of n-th stage integral - * @throws TooManyEvaluationsException if the maximal number of evaluations - * is exceeded. - */ - double stage(final BaseAbstractUnivariateIntegrator baseIntegrator, final int n) - throws TooManyEvaluationsException { - - if (n == 0) { - final double max = baseIntegrator.getMax(); - final double min = baseIntegrator.getMin(); - s = 0.5 * (max - min) * - (baseIntegrator.computeObjectiveValue(min) + - baseIntegrator.computeObjectiveValue(max)); - return s; - } else { - final long np = 1L << (n-1); // number of new points in this stage - double sum = 0; - final double max = baseIntegrator.getMax(); - final double min = baseIntegrator.getMin(); - // spacing between adjacent new points - final double spacing = (max - min) / np; - double x = min + 0.5 * spacing; // the first new point - for (long i = 0; i < np; i++) { - sum += baseIntegrator.computeObjectiveValue(x); - x += spacing; - } - // add the new sum to previously calculated result - s = 0.5 * (s + sum * spacing); - return s; - } - } - - /** {@inheritDoc} */ - @Override - protected double doIntegrate() - throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { - - double oldt = stage(this, 0); - iterations.incrementCount(); - while (true) { - final int i = iterations.getCount(); - final double t = stage(this, i); - if (i >= getMinimalIterationCount()) { - final double delta = FastMath.abs(t - oldt); - final double rLimit = - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; - if ((delta <= rLimit) || (delta <= getAbsoluteAccuracy())) { - return t; - } - } - oldt = t; - iterations.incrementCount(); - } - - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/UnivariateIntegrator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/UnivariateIntegrator.java deleted file mode 100644 index 60b8a444f..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/UnivariateIntegrator.java +++ /dev/null @@ -1,95 +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.analysis.integration; - -import org.apache.commons.math4.analysis.UnivariateFunction; -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.TooManyEvaluationsException; - -/** - * Interface for univariate real integration algorithms. - * - * @since 1.2 - */ -public interface UnivariateIntegrator { - - /** - * Get the relative accuracy. - * - * @return the accuracy - */ - double getRelativeAccuracy(); - - /** - * Get the absolute accuracy. - * - * @return the accuracy - */ - double getAbsoluteAccuracy(); - - /** - * Get the min limit for the number of iterations. - * - * @return the actual min limit - */ - int getMinimalIterationCount(); - - /** - * Get the upper limit for the number of iterations. - * - * @return the actual upper limit - */ - int getMaximalIterationCount(); - - /** - * Integrate the function in the given interval. - * - * @param maxEval Maximum number of evaluations. - * @param f the integrand function - * @param min the lower bound for the interval - * @param max the upper bound for the interval - * @return the value of integral - * @throws TooManyEvaluationsException if the maximum number of function - * evaluations is exceeded - * @throws MaxCountExceededException if the maximum iteration count is exceeded - * or the integrator detects convergence problems otherwise - * @throws MathIllegalArgumentException if {@code min > max} or the endpoints do not - * satisfy the requirements specified by the integrator - * @throws NullArgumentException if {@code f} is {@code null}. - */ - double integrate(int maxEval, UnivariateFunction f, double min, - double max) - throws TooManyEvaluationsException, MaxCountExceededException, - MathIllegalArgumentException, NullArgumentException; - - /** - * Get the number of function evaluations of the last run of the integrator. - * - * @return number of function evaluations - */ - int getEvaluations(); - - /** - * Get the number of iterations of the last run of the integrator. - * - * @return number of iterations - */ - int getIterations(); - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/gauss/BaseRuleFactory.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/gauss/BaseRuleFactory.java deleted file mode 100644 index bd05c5e68..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/integration/gauss/BaseRuleFactory.java +++ /dev/null @@ -1,154 +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.analysis.integration.gauss; - -import java.util.Map; -import java.util.TreeMap; - -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.Pair; - -/** - * Base class for rules that determines the integration nodes and their - * weights. - * Subclasses must implement the {@link #computeRule(int) computeRule} method. - * - * @param- * \(f(x) e^{-x^2}\) - *
- * Recurrence relation and weights computation follow - * - * Abramowitz and Stegun, 1964. - *
- * The coefficients of the standard Hermite polynomials grow very rapidly. - * In order to avoid overflows, each Hermite polynomial is normalized with - * respect to the underlying scalar product. - * The initial interval for the application of the bisection method is - * based on the roots of the previous Hermite polynomial (interlacing). - * Upper and lower bounds of these roots are provided by
- *- * I. Krasikov, - * Nonnegative quadratic forms and bounds on orthogonal polynomials, - * Journal of Approximation theory 111, 31-49 - *- * - * @since 3.3 - */ -public class HermiteRuleFactory extends BaseRuleFactory
- * This implementation is based on the Akima implementation in the CubicSpline - * class in the Math.NET Numerics library. The method referenced is - * CubicSpline.InterpolateAkimaSorted - *
- *- * The {@link #interpolate(double[], double[]) interpolate} method returns a - * {@link PolynomialSplineFunction} consisting of n cubic polynomials, defined - * over the subintervals determined by the x values, {@code x[0] < x[i] ... < x[n]}. - * The Akima algorithm requires that {@code n >= 5}. - *
- */ -public class AkimaSplineInterpolator - implements UnivariateInterpolator { - /** The minimum number of points that are needed to compute the function. */ - private static final int MINIMUM_NUMBER_POINTS = 5; - - /** - * Computes an interpolating function for the data set. - * - * @param xvals the arguments for the interpolation points - * @param yvals the values for the interpolation points - * @return a function which interpolates the data set - * @throws DimensionMismatchException if {@code xvals} and {@code yvals} have - * different sizes. - * @throws NonMonotonicSequenceException if {@code xvals} is not sorted in - * strict increasing order. - * @throws NumberIsTooSmallException if the size of {@code xvals} is smaller - * than 5. - */ - @Override - public PolynomialSplineFunction interpolate(double[] xvals, - double[] yvals) - throws DimensionMismatchException, - NumberIsTooSmallException, - NonMonotonicSequenceException { - if (xvals == null || - yvals == null) { - throw new NullArgumentException(); - } - - if (xvals.length != yvals.length) { - throw new DimensionMismatchException(xvals.length, yvals.length); - } - - if (xvals.length < MINIMUM_NUMBER_POINTS) { - throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS, - xvals.length, - MINIMUM_NUMBER_POINTS, true); - } - - MathArrays.checkOrder(xvals); - - final int numberOfDiffAndWeightElements = xvals.length - 1; - - final double[] differences = new double[numberOfDiffAndWeightElements]; - final double[] weights = new double[numberOfDiffAndWeightElements]; - - for (int i = 0; i < differences.length; i++) { - differences[i] = (yvals[i + 1] - yvals[i]) / (xvals[i + 1] - xvals[i]); - } - - for (int i = 1; i < weights.length; i++) { - weights[i] = FastMath.abs(differences[i] - differences[i - 1]); - } - - // Prepare Hermite interpolation scheme. - final double[] firstDerivatives = new double[xvals.length]; - - for (int i = 2; i < firstDerivatives.length - 2; i++) { - final double wP = weights[i + 1]; - final double wM = weights[i - 1]; - if (Precision.equals(wP, 0.0) && - Precision.equals(wM, 0.0)) { - final double xv = xvals[i]; - final double xvP = xvals[i + 1]; - final double xvM = xvals[i - 1]; - firstDerivatives[i] = (((xvP - xv) * differences[i - 1]) + ((xv - xvM) * differences[i])) / (xvP - xvM); - } else { - firstDerivatives[i] = ((wP * differences[i - 1]) + (wM * differences[i])) / (wP + wM); - } - } - - firstDerivatives[0] = differentiateThreePoint(xvals, yvals, 0, 0, 1, 2); - firstDerivatives[1] = differentiateThreePoint(xvals, yvals, 1, 0, 1, 2); - firstDerivatives[xvals.length - 2] = differentiateThreePoint(xvals, yvals, xvals.length - 2, - xvals.length - 3, xvals.length - 2, - xvals.length - 1); - firstDerivatives[xvals.length - 1] = differentiateThreePoint(xvals, yvals, xvals.length - 1, - xvals.length - 3, xvals.length - 2, - xvals.length - 1); - - return interpolateHermiteSorted(xvals, yvals, firstDerivatives); - } - - /** - * Three point differentiation helper, modeled off of the same method in the - * Math.NET CubicSpline class. This is used by both the Apache Math and the - * Math.NET Akima Cubic Spline algorithms - * - * @param xvals x values to calculate the numerical derivative with - * @param yvals y values to calculate the numerical derivative with - * @param indexOfDifferentiation index of the elemnt we are calculating the derivative around - * @param indexOfFirstSample index of the first element to sample for the three point method - * @param indexOfSecondsample index of the second element to sample for the three point method - * @param indexOfThirdSample index of the third element to sample for the three point method - * @return the derivative - */ - private double differentiateThreePoint(double[] xvals, double[] yvals, - int indexOfDifferentiation, - int indexOfFirstSample, - int indexOfSecondsample, - int indexOfThirdSample) { - final double x0 = yvals[indexOfFirstSample]; - final double x1 = yvals[indexOfSecondsample]; - final double x2 = yvals[indexOfThirdSample]; - - final double t = xvals[indexOfDifferentiation] - xvals[indexOfFirstSample]; - final double t1 = xvals[indexOfSecondsample] - xvals[indexOfFirstSample]; - final double t2 = xvals[indexOfThirdSample] - xvals[indexOfFirstSample]; - - final double a = (x2 - x0 - (t2 / t1 * (x1 - x0))) / (t2 * t2 - t1 * t2); - final double b = (x1 - x0 - a * t1 * t1) / t1; - - return (2 * a * t) + b; - } - - /** - * Creates a Hermite cubic spline interpolation from the set of (x,y) value - * pairs and their derivatives. This is modeled off of the - * InterpolateHermiteSorted method in the Math.NET CubicSpline class. - * - * @param xvals x values for interpolation - * @param yvals y values for interpolation - * @param firstDerivatives first derivative values of the function - * @return polynomial that fits the function - */ - private PolynomialSplineFunction interpolateHermiteSorted(double[] xvals, - double[] yvals, - double[] firstDerivatives) { - if (xvals.length != yvals.length) { - throw new DimensionMismatchException(xvals.length, yvals.length); - } - - if (xvals.length != firstDerivatives.length) { - throw new DimensionMismatchException(xvals.length, - firstDerivatives.length); - } - - final int minimumLength = 2; - if (xvals.length < minimumLength) { - throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS, - xvals.length, minimumLength, - true); - } - - final int size = xvals.length - 1; - final PolynomialFunction[] polynomials = new PolynomialFunction[size]; - final double[] coefficients = new double[4]; - - for (int i = 0; i < polynomials.length; i++) { - final double w = xvals[i + 1] - xvals[i]; - final double w2 = w * w; - - final double yv = yvals[i]; - final double yvP = yvals[i + 1]; - - final double fd = firstDerivatives[i]; - final double fdP = firstDerivatives[i + 1]; - - coefficients[0] = yv; - coefficients[1] = firstDerivatives[i]; - coefficients[2] = (3 * (yvP - yv) / w - 2 * fd - fdP) / w; - coefficients[3] = (2 * (yv - yvP) / w + fd + fdP) / w2; - polynomials[i] = new PolynomialFunction(coefficients); - } - - return new PolynomialSplineFunction(xvals, polynomials); - - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java deleted file mode 100644 index aa2350274..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java +++ /dev/null @@ -1,329 +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.analysis.interpolation; - -import java.util.Arrays; - -import org.apache.commons.numbers.arrays.LinearCombination; -import org.apache.commons.math4.analysis.BivariateFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.OutOfRangeException; -import org.apache.commons.math4.util.MathArrays; - -/** - * Function that implements the - * - * bicubic spline interpolation. - * - * @since 3.4 - */ -public class BicubicInterpolatingFunction - implements BivariateFunction { - /** Number of coefficients. */ - private static final int NUM_COEFF = 16; - /** - * Matrix to compute the spline coefficients from the function values - * and function derivatives values - */ - private static final double[][] AINV = { - { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 }, - { -3,3,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0 }, - { 2,-2,0,0,1,1,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 }, - { 0,0,0,0,0,0,0,0,-3,3,0,0,-2,-1,0,0 }, - { 0,0,0,0,0,0,0,0,2,-2,0,0,1,1,0,0 }, - { -3,0,3,0,0,0,0,0,-2,0,-1,0,0,0,0,0 }, - { 0,0,0,0,-3,0,3,0,0,0,0,0,-2,0,-1,0 }, - { 9,-9,-9,9,6,3,-6,-3,6,-6,3,-3,4,2,2,1 }, - { -6,6,6,-6,-3,-3,3,3,-4,4,-2,2,-2,-2,-1,-1 }, - { 2,0,-2,0,0,0,0,0,1,0,1,0,0,0,0,0 }, - { 0,0,0,0,2,0,-2,0,0,0,0,0,1,0,1,0 }, - { -6,6,6,-6,-4,-2,4,2,-3,3,-3,3,-2,-1,-2,-1 }, - { 4,-4,-4,4,2,2,-2,-2,2,-2,2,-2,1,1,1,1 } - }; - - /** Samples x-coordinates */ - private final double[] xval; - /** Samples y-coordinates */ - private final double[] yval; - /** Set of cubic splines patching the whole data grid */ - private final BicubicFunction[][] splines; - - /** - * @param x Sample values of the x-coordinate, in increasing order. - * @param y Sample values of the y-coordinate, in increasing order. - * @param f Values of the function on every grid point. - * @param dFdX Values of the partial derivative of function with respect - * to x on every grid point. - * @param dFdY Values of the partial derivative of function with respect - * to y on every grid point. - * @param d2FdXdY Values of the cross partial derivative of function on - * every grid point. - * @throws DimensionMismatchException if the various arrays do not contain - * the expected number of elements. - * @throws NonMonotonicSequenceException if {@code x} or {@code y} are - * not strictly increasing. - * @throws NoDataException if any of the arrays has zero length. - */ - public BicubicInterpolatingFunction(double[] x, - double[] y, - double[][] f, - double[][] dFdX, - double[][] dFdY, - double[][] d2FdXdY) - throws DimensionMismatchException, - NoDataException, - NonMonotonicSequenceException { - final int xLen = x.length; - final int yLen = y.length; - - if (xLen == 0 || yLen == 0 || f.length == 0 || f[0].length == 0) { - throw new NoDataException(); - } - if (xLen != f.length) { - throw new DimensionMismatchException(xLen, f.length); - } - if (xLen != dFdX.length) { - throw new DimensionMismatchException(xLen, dFdX.length); - } - if (xLen != dFdY.length) { - throw new DimensionMismatchException(xLen, dFdY.length); - } - if (xLen != d2FdXdY.length) { - throw new DimensionMismatchException(xLen, d2FdXdY.length); - } - - MathArrays.checkOrder(x); - MathArrays.checkOrder(y); - - xval = x.clone(); - yval = y.clone(); - - final int lastI = xLen - 1; - final int lastJ = yLen - 1; - splines = new BicubicFunction[lastI][lastJ]; - - for (int i = 0; i < lastI; i++) { - if (f[i].length != yLen) { - throw new DimensionMismatchException(f[i].length, yLen); - } - if (dFdX[i].length != yLen) { - throw new DimensionMismatchException(dFdX[i].length, yLen); - } - if (dFdY[i].length != yLen) { - throw new DimensionMismatchException(dFdY[i].length, yLen); - } - if (d2FdXdY[i].length != yLen) { - throw new DimensionMismatchException(d2FdXdY[i].length, yLen); - } - final int ip1 = i + 1; - final double xR = xval[ip1] - xval[i]; - for (int j = 0; j < lastJ; j++) { - final int jp1 = j + 1; - final double yR = yval[jp1] - yval[j]; - final double xRyR = xR * yR; - final double[] beta = new double[] { - f[i][j], f[ip1][j], f[i][jp1], f[ip1][jp1], - dFdX[i][j] * xR, dFdX[ip1][j] * xR, dFdX[i][jp1] * xR, dFdX[ip1][jp1] * xR, - dFdY[i][j] * yR, dFdY[ip1][j] * yR, dFdY[i][jp1] * yR, dFdY[ip1][jp1] * yR, - d2FdXdY[i][j] * xRyR, d2FdXdY[ip1][j] * xRyR, d2FdXdY[i][jp1] * xRyR, d2FdXdY[ip1][jp1] * xRyR - }; - - splines[i][j] = new BicubicFunction(computeSplineCoefficients(beta)); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public double value(double x, double y) - throws OutOfRangeException { - final int i = searchIndex(x, xval); - final int j = searchIndex(y, yval); - - final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); - final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]); - - return splines[i][j].value(xN, yN); - } - - /** - * Indicates whether a point is within the interpolation range. - * - * @param x First coordinate. - * @param y Second coordinate. - * @return {@code true} if (x, y) is a valid point. - */ - public boolean isValidPoint(double x, double y) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1]) { - return false; - } else { - return true; - } - } - - /** - * @param c Coordinate. - * @param val Coordinate samples. - * @return the index in {@code val} corresponding to the interval - * containing {@code c}. - * @throws OutOfRangeException if {@code c} is out of the - * range defined by the boundary values of {@code val}. - */ - private int searchIndex(double c, double[] val) { - final int r = Arrays.binarySearch(val, c); - - if (r == -1 || - r == -val.length - 1) { - throw new OutOfRangeException(c, val[0], val[val.length - 1]); - } - - if (r < 0) { - // "c" in within an interpolation sub-interval: Return the - // index of the sample at the lower end of the sub-interval. - return -r - 2; - } - final int last = val.length - 1; - if (r == last) { - // "c" is the last sample of the range: Return the index - // of the sample at the lower end of the last sub-interval. - return last - 1; - } - - // "c" is another sample point. - return r; - } - - /** - * Compute the spline coefficients from the list of function values and - * function partial derivatives values at the four corners of a grid - * element. They must be specified in the following order: - *- * Caveat: Because the interpolation scheme requires that derivatives be - * specified at the sample points, those are approximated with finite - * differences (using the 2-points symmetric formulae). - * Since their values are undefined at the borders of the provided - * interpolation ranges, the interpolated values will be wrong at the - * edges of the patch. - * The {@code interpolate} method will return a function that overrides - * {@link BicubicInterpolatingFunction#isValidPoint(double,double)} to - * indicate points where the interpolation will be inaccurate. - *
- * - * @since 3.4 - */ -public class BicubicInterpolator - implements BivariateGridInterpolator { - /** - * {@inheritDoc} - */ - @Override - public BicubicInterpolatingFunction interpolate(final double[] xval, - final double[] yval, - final double[][] fval) - throws NoDataException, DimensionMismatchException, - NonMonotonicSequenceException, NumberIsTooSmallException { - if (xval.length == 0 || yval.length == 0 || fval.length == 0) { - throw new NoDataException(); - } - if (xval.length != fval.length) { - throw new DimensionMismatchException(xval.length, fval.length); - } - - MathArrays.checkOrder(xval); - MathArrays.checkOrder(yval); - - final int xLen = xval.length; - final int yLen = yval.length; - - // Approximation to the partial derivatives using finite differences. - final double[][] dFdX = new double[xLen][yLen]; - final double[][] dFdY = new double[xLen][yLen]; - final double[][] d2FdXdY = new double[xLen][yLen]; - for (int i = 1; i < xLen - 1; i++) { - final int nI = i + 1; - final int pI = i - 1; - - final double nX = xval[nI]; - final double pX = xval[pI]; - - final double deltaX = nX - pX; - - for (int j = 1; j < yLen - 1; j++) { - final int nJ = j + 1; - final int pJ = j - 1; - - final double nY = yval[nJ]; - final double pY = yval[pJ]; - - final double deltaY = nY - pY; - - dFdX[i][j] = (fval[nI][j] - fval[pI][j]) / deltaX; - dFdY[i][j] = (fval[i][nJ] - fval[i][pJ]) / deltaY; - - final double deltaXY = deltaX * deltaY; - - d2FdXdY[i][j] = (fval[nI][nJ] - fval[nI][pJ] - fval[pI][nJ] + fval[pI][pJ]) / deltaXY; - } - } - - // Create the interpolating function. - return new BicubicInterpolatingFunction(xval, yval, fval, - dFdX, dFdY, d2FdXdY) { - /** {@inheritDoc} */ - @Override - public boolean isValidPoint(double x, double y) { - if (x < xval[1] || - x > xval[xval.length - 2] || - y < yval[1] || - y > yval[yval.length - 2]) { - return false; - } else { - return true; - } - } - }; - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BivariateGridInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BivariateGridInterpolator.java deleted file mode 100644 index 97ed9698d..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/BivariateGridInterpolator.java +++ /dev/null @@ -1,51 +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.analysis.interpolation; - -import org.apache.commons.math4.analysis.BivariateFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; - -/** - * Interface representing a bivariate real interpolating function where the - * sample points must be specified on a regular grid. - * - */ -public interface BivariateGridInterpolator { - /** - * Compute an interpolating function for the dataset. - * - * @param xval All the x-coordinates of the interpolation points, sorted - * in increasing order. - * @param yval All the y-coordinates of the interpolation points, sorted - * in increasing order. - * @param fval The values of the interpolation points on all the grid knots: - * {@code fval[i][j] = f(xval[i], yval[j])}. - * @return a function which interpolates the dataset. - * @throws NoDataException if any of the arrays has zero length. - * @throws DimensionMismatchException if the array lengths are inconsistent. - * @throws NonMonotonicSequenceException if the array is not sorted. - * @throws NumberIsTooSmallException if the number of points is too small for - * the order of the interpolation - */ - BivariateFunction interpolate(double[] xval, double[] yval, - double[][] fval) - throws NoDataException, DimensionMismatchException, - NonMonotonicSequenceException, NumberIsTooSmallException; -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/DividedDifferenceInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/DividedDifferenceInterpolator.java deleted file mode 100644 index e6ea96683..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/DividedDifferenceInterpolator.java +++ /dev/null @@ -1,122 +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.analysis.interpolation; - -import java.io.Serializable; - -import org.apache.commons.math4.analysis.polynomials.PolynomialFunctionLagrangeForm; -import org.apache.commons.math4.analysis.polynomials.PolynomialFunctionNewtonForm; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; - -/** - * Implements the - * Divided Difference Algorithm for interpolation of real univariate - * functions. For reference, see Introduction to Numerical Analysis, - * ISBN 038795452X, chapter 2. - *- * The actual code of Neville's evaluation is in PolynomialFunctionLagrangeForm, - * this class provides an easy-to-use interface to it.
- * - * @since 1.2 - */ -public class DividedDifferenceInterpolator - implements UnivariateInterpolator, Serializable { - /** serializable version identifier */ - private static final long serialVersionUID = 107049519551235069L; - - /** - * Compute an interpolating function for the dataset. - * - * @param x Interpolating points array. - * @param y Interpolating values array. - * @return a function which interpolates the dataset. - * @throws DimensionMismatchException if the array lengths are different. - * @throws NumberIsTooSmallException if the number of points is less than 2. - * @throws NonMonotonicSequenceException if {@code x} is not sorted in - * strictly increasing order. - */ - @Override - public PolynomialFunctionNewtonForm interpolate(double x[], double y[]) - throws DimensionMismatchException, - NumberIsTooSmallException, - NonMonotonicSequenceException { - /** - * a[] and c[] are defined in the general formula of Newton form: - * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... + - * a[n](x-c[0])(x-c[1])...(x-c[n-1]) - */ - PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true); - - /** - * When used for interpolation, the Newton form formula becomes - * p(x) = f[x0] + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ... + - * f[x0,x1,...,x[n-1]](x-x0)(x-x1)...(x-x[n-2]) - * Therefore, a[k] = f[x0,x1,...,xk], c[k] = x[k]. - *- * Note x[], y[], a[] have the same length but c[]'s size is one less.
- */ - final double[] c = new double[x.length-1]; - System.arraycopy(x, 0, c, 0, c.length); - - final double[] a = computeDividedDifference(x, y); - return new PolynomialFunctionNewtonForm(a, c); - } - - /** - * Return a copy of the divided difference array. - *- * The divided difference array is defined recursively by
- * f[x0] = f(x0) - * f[x0,x1,...,xk] = (f[x1,...,xk] - f[x0,...,x[k-1]]) / (xk - x0) - *- *
- * The computational complexity is \(O(n^2)\) where \(n\) is the common - * length of {@code x} and {@code y}.
- * - * @param x Interpolating points array. - * @param y Interpolating values array. - * @return a fresh copy of the divided difference array. - * @throws DimensionMismatchException if the array lengths are different. - * @throws NumberIsTooSmallException if the number of points is less than 2. - * @throws NonMonotonicSequenceException - * if {@code x} is not sorted in strictly increasing order. - */ - protected static double[] computeDividedDifference(final double x[], final double y[]) - throws DimensionMismatchException, - NumberIsTooSmallException, - NonMonotonicSequenceException { - PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true); - - final double[] divdiff = y.clone(); // initialization - - final int n = x.length; - final double[] a = new double [n]; - a[0] = divdiff[0]; - for (int i = 1; i < n; i++) { - for (int j = 0; j < n-i; j++) { - final double denominator = x[j+i] - x[j]; - divdiff[j] = (divdiff[j+1] - divdiff[j]) / denominator; - } - a[i] = divdiff[0]; - } - - return a; - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/FieldHermiteInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/FieldHermiteInterpolator.java deleted file mode 100644 index 3241ddf38..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/FieldHermiteInterpolator.java +++ /dev/null @@ -1,210 +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.analysis.interpolation; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.math4.FieldElement; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.MathArithmeticException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.ZeroException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.MathArrays; -import org.apache.commons.math4.util.MathUtils; - -/** Polynomial interpolator using both sample values and sample derivatives. - *- * The interpolation polynomials match all sample points, including both values - * and provided derivatives. There is one polynomial for each component of - * the values vector. All polynomials have the same degree. The degree of the - * polynomials depends on the number of points and number of derivatives at each - * point. For example the interpolation polynomials for n sample points without - * any derivatives all have degree n-1. The interpolation polynomials for n - * sample points with the two extreme points having value and first derivative - * and the remaining points having value only all have degree n+1. The - * interpolation polynomial for n sample points with value, first and second - * derivative for all points all have degree 3n-1. - *
- * - * @param- * This method must be called once for each sample point. It is allowed to - * mix some calls with values only with calls with values and first - * derivatives. - *
- *- * The point abscissae for all calls must be different. - *
- * @param x abscissa of the sample point - * @param value value and derivatives of the sample point - * (if only one row is passed, it is the value, if two rows are - * passed the first one is the value and the second the derivative - * and so on) - * @exception ZeroException if the abscissa difference between added point - * and a previous point is zero (i.e. the two points are at same abscissa) - * @exception MathArithmeticException if the number of derivatives is larger - * than 20, which prevents computation of a factorial - * @throws DimensionMismatchException if derivative structures are inconsistent - * @throws NullArgumentException if x is null - */ - @SafeVarargs - public final void addSamplePoint(final T x, final T[] ... value) - throws ZeroException, MathArithmeticException, - DimensionMismatchException, NullArgumentException { - - MathUtils.checkNotNull(x); - T factorial = x.getField().getOne(); - for (int i = 0; i < value.length; ++i) { - - final T[] y = value[i].clone(); - if (i > 1) { - factorial = factorial.multiply(i); - final T inv = factorial.reciprocal(); - for (int j = 0; j < y.length; ++j) { - y[j] = y[j].multiply(inv); - } - } - - // update the bottom diagonal of the divided differences array - final int n = abscissae.size(); - bottomDiagonal.add(n - i, y); - T[] bottom0 = y; - for (int j = i; j < n; ++j) { - final T[] bottom1 = bottomDiagonal.get(n - (j + 1)); - if (x.equals(abscissae.get(n - (j + 1)))) { - throw new ZeroException(LocalizedFormats.DUPLICATED_ABSCISSA_DIVISION_BY_ZERO, x); - } - final T inv = x.subtract(abscissae.get(n - (j + 1))).reciprocal(); - for (int k = 0; k < y.length; ++k) { - bottom1[k] = inv.multiply(bottom0[k].subtract(bottom1[k])); - } - bottom0 = bottom1; - } - - // update the top diagonal of the divided differences array - topDiagonal.add(bottom0.clone()); - - // update the abscissae array - abscissae.add(x); - - } - - } - - /** Interpolate value at a specified abscissa. - * @param x interpolation abscissa - * @return interpolated value - * @exception NoDataException if sample is empty - * @throws NullArgumentException if x is null - */ - public T[] value(T x) throws NoDataException, NullArgumentException { - - // safety check - MathUtils.checkNotNull(x); - if (abscissae.isEmpty()) { - throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); - } - - final T[] value = MathArrays.buildArray(x.getField(), topDiagonal.get(0).length); - T valueCoeff = x.getField().getOne(); - for (int i = 0; i < topDiagonal.size(); ++i) { - T[] dividedDifference = topDiagonal.get(i); - for (int k = 0; k < value.length; ++k) { - value[k] = value[k].add(dividedDifference[k].multiply(valueCoeff)); - } - final T deltaX = x.subtract(abscissae.get(i)); - valueCoeff = valueCoeff.multiply(deltaX); - } - - return value; - - } - - /** Interpolate value and first derivatives at a specified abscissa. - * @param x interpolation abscissa - * @param order maximum derivation order - * @return interpolated value and derivatives (value in row 0, - * 1st derivative in row 1, ... nth derivative in row n) - * @exception NoDataException if sample is empty - * @throws NullArgumentException if x is null - */ - public T[][] derivatives(T x, int order) throws NoDataException, NullArgumentException { - - // safety check - MathUtils.checkNotNull(x); - if (abscissae.isEmpty()) { - throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); - } - - final T zero = x.getField().getZero(); - final T one = x.getField().getOne(); - final T[] tj = MathArrays.buildArray(x.getField(), order + 1); - tj[0] = zero; - for (int i = 0; i < order; ++i) { - tj[i + 1] = tj[i].add(one); - } - - final T[][] derivatives = - MathArrays.buildArray(x.getField(), order + 1, topDiagonal.get(0).length); - final T[] valueCoeff = MathArrays.buildArray(x.getField(), order + 1); - valueCoeff[0] = x.getField().getOne(); - for (int i = 0; i < topDiagonal.size(); ++i) { - T[] dividedDifference = topDiagonal.get(i); - final T deltaX = x.subtract(abscissae.get(i)); - for (int j = order; j >= 0; --j) { - for (int k = 0; k < derivatives[j].length; ++k) { - derivatives[j][k] = - derivatives[j][k].add(dividedDifference[k].multiply(valueCoeff[j])); - } - valueCoeff[j] = valueCoeff[j].multiply(deltaX); - if (j > 0) { - valueCoeff[j] = valueCoeff[j].add(tj[j].multiply(valueCoeff[j - 1])); - } - } - } - - return derivatives; - - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/HermiteInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/HermiteInterpolator.java deleted file mode 100644 index 439eb1cc6..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/HermiteInterpolator.java +++ /dev/null @@ -1,242 +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.analysis.interpolation; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableVectorFunction; -import org.apache.commons.math4.analysis.polynomials.PolynomialFunction; -import org.apache.commons.math4.exception.MathArithmeticException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.ZeroException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.numbers.combinatorics.Factorial; - -/** Polynomial interpolator using both sample values and sample derivatives. - *- * The interpolation polynomials match all sample points, including both values - * and provided derivatives. There is one polynomial for each component of - * the values vector. All polynomials have the same degree. The degree of the - * polynomials depends on the number of points and number of derivatives at each - * point. For example the interpolation polynomials for n sample points without - * any derivatives all have degree n-1. The interpolation polynomials for n - * sample points with the two extreme points having value and first derivative - * and the remaining points having value only all have degree n+1. The - * interpolation polynomial for n sample points with value, first and second - * derivative for all points all have degree 3n-1. - *
- * - * @since 3.1 - */ -public class HermiteInterpolator implements UnivariateDifferentiableVectorFunction { - - /** Sample abscissae. */ - private final List- * This method must be called once for each sample point. It is allowed to - * mix some calls with values only with calls with values and first - * derivatives. - *
- *- * The point abscissae for all calls must be different. - *
- * @param x abscissa of the sample point - * @param value value and derivatives of the sample point - * (if only one row is passed, it is the value, if two rows are - * passed the first one is the value and the second the derivative - * and so on) - * @exception ZeroException if the abscissa difference between added point - * and a previous point is zero (i.e. the two points are at same abscissa) - * @exception MathArithmeticException if the number of derivatives is larger - * than 20, which prevents computation of a factorial - */ - public void addSamplePoint(final double x, final double[] ... value) - throws ZeroException, MathArithmeticException { - - if (value.length > 20) { - throw new MathArithmeticException(LocalizedFormats.NUMBER_TOO_LARGE, value.length, 20); - } - for (int i = 0; i < value.length; ++i) { - final double[] y = value[i].clone(); - if (i > 1) { - double inv = 1.0 / Factorial.value(i); - for (int j = 0; j < y.length; ++j) { - y[j] *= inv; - } - } - - // update the bottom diagonal of the divided differences array - final int n = abscissae.size(); - bottomDiagonal.add(n - i, y); - double[] bottom0 = y; - for (int j = i; j < n; ++j) { - final double[] bottom1 = bottomDiagonal.get(n - (j + 1)); - final double inv = 1.0 / (x - abscissae.get(n - (j + 1))); - if (Double.isInfinite(inv)) { - throw new ZeroException(LocalizedFormats.DUPLICATED_ABSCISSA_DIVISION_BY_ZERO, x); - } - for (int k = 0; k < y.length; ++k) { - bottom1[k] = inv * (bottom0[k] - bottom1[k]); - } - bottom0 = bottom1; - } - - // update the top diagonal of the divided differences array - topDiagonal.add(bottom0.clone()); - - // update the abscissae array - abscissae.add(x); - - } - - } - - /** Compute the interpolation polynomials. - * @return interpolation polynomials array - * @exception NoDataException if sample is empty - */ - public PolynomialFunction[] getPolynomials() - throws NoDataException { - - // safety check - checkInterpolation(); - - // iteration initialization - final PolynomialFunction zero = polynomial(0); - PolynomialFunction[] polynomials = new PolynomialFunction[topDiagonal.get(0).length]; - for (int i = 0; i < polynomials.length; ++i) { - polynomials[i] = zero; - } - PolynomialFunction coeff = polynomial(1); - - // build the polynomials by iterating on the top diagonal of the divided differences array - for (int i = 0; i < topDiagonal.size(); ++i) { - double[] tdi = topDiagonal.get(i); - for (int k = 0; k < polynomials.length; ++k) { - polynomials[k] = polynomials[k].add(coeff.multiply(polynomial(tdi[k]))); - } - coeff = coeff.multiply(polynomial(-abscissae.get(i), 1.0)); - } - - return polynomials; - - } - - /** Interpolate value at a specified abscissa. - *- * Calling this method is equivalent to call the {@link PolynomialFunction#value(double) - * value} methods of all polynomials returned by {@link #getPolynomials() getPolynomials}, - * except it does not build the intermediate polynomials, so this method is faster and - * numerically more stable. - *
- * @param x interpolation abscissa - * @return interpolated value - * @exception NoDataException if sample is empty - */ - @Override - public double[] value(double x) throws NoDataException { - - // safety check - checkInterpolation(); - - final double[] value = new double[topDiagonal.get(0).length]; - double valueCoeff = 1; - for (int i = 0; i < topDiagonal.size(); ++i) { - double[] dividedDifference = topDiagonal.get(i); - for (int k = 0; k < value.length; ++k) { - value[k] += dividedDifference[k] * valueCoeff; - } - final double deltaX = x - abscissae.get(i); - valueCoeff *= deltaX; - } - - return value; - - } - - /** Interpolate value at a specified abscissa. - *- * Calling this method is equivalent to call the {@link - * PolynomialFunction#value(DerivativeStructure) value} methods of all polynomials - * returned by {@link #getPolynomials() getPolynomials}, except it does not build the - * intermediate polynomials, so this method is faster and numerically more stable. - *
- * @param x interpolation abscissa - * @return interpolated value - * @exception NoDataException if sample is empty - */ - @Override - public DerivativeStructure[] value(final DerivativeStructure x) - throws NoDataException { - - // safety check - checkInterpolation(); - - final DerivativeStructure[] value = new DerivativeStructure[topDiagonal.get(0).length]; - Arrays.fill(value, x.getField().getZero()); - DerivativeStructure valueCoeff = x.getField().getOne(); - for (int i = 0; i < topDiagonal.size(); ++i) { - double[] dividedDifference = topDiagonal.get(i); - for (int k = 0; k < value.length; ++k) { - value[k] = value[k].add(valueCoeff.multiply(dividedDifference[k])); - } - final DerivativeStructure deltaX = x.subtract(abscissae.get(i)); - valueCoeff = valueCoeff.multiply(deltaX); - } - - return value; - - } - - /** Check interpolation can be performed. - * @exception NoDataException if interpolation cannot be performed - * because sample is empty - */ - private void checkInterpolation() throws NoDataException { - if (abscissae.isEmpty()) { - throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE); - } - } - - /** Create a polynomial from its coefficients. - * @param c polynomials coefficients - * @return polynomial - */ - private PolynomialFunction polynomial(double ... c) { - return new PolynomialFunction(c); - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java deleted file mode 100644 index e40d2025a..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/InterpolatingMicrosphere.java +++ /dev/null @@ -1,387 +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.analysis.interpolation; - -import java.util.List; -import java.util.ArrayList; -import org.apache.commons.numbers.arrays.CosAngle; -import org.apache.commons.numbers.arrays.SafeNorm; -import org.apache.commons.rng.sampling.UnitSphereSampler; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NotPositiveException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.OutOfRangeException; -import org.apache.commons.math4.util.FastMath; -import org.apache.commons.math4.util.MathArrays; - -/** - * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm. - * - * @since 3.6 - */ -public class InterpolatingMicrosphere { - /** Microsphere. */ - private final List- * For reference, see - * - * William S. Cleveland - Robust Locally Weighted Regression and Smoothing - * Scatterplots
- *- * This class implements both the loess method and serves as an interpolation - * adapter to it, allowing one to build a spline on the obtained loess fit.
- * - * @since 2.0 - */ -public class LoessInterpolator - implements UnivariateInterpolator, Serializable { - /** Default value of the bandwidth parameter. */ - public static final double DEFAULT_BANDWIDTH = 0.3; - /** Default value of the number of robustness iterations. */ - public static final int DEFAULT_ROBUSTNESS_ITERS = 2; - /** - * Default value for accuracy. - * @since 2.1 - */ - public static final double DEFAULT_ACCURACY = 1e-12; - /** serializable version identifier. */ - private static final long serialVersionUID = 5204927143605193821L; - /** - * The bandwidth parameter: when computing the loess fit at - * a particular point, this fraction of source points closest - * to the current point is taken into account for computing - * a least-squares regression. - *- * A sensible value is usually 0.25 to 0.5.
- */ - private final double bandwidth; - /** - * The number of robustness iterations parameter: this many - * robustness iterations are done. - *- * A sensible value is usually 0 (just the initial fit without any - * robustness iterations) to 4.
- */ - private final int robustnessIters; - /** - * If the median residual at a certain robustness iteration - * is less than this amount, no more iterations are done. - */ - private final double accuracy; - - /** - * Constructs a new {@link LoessInterpolator} - * with a bandwidth of {@link #DEFAULT_BANDWIDTH}, - * {@link #DEFAULT_ROBUSTNESS_ITERS} robustness iterations - * and an accuracy of {#link #DEFAULT_ACCURACY}. - * See {@link #LoessInterpolator(double, int, double)} for an explanation of - * the parameters. - */ - public LoessInterpolator() { - this.bandwidth = DEFAULT_BANDWIDTH; - this.robustnessIters = DEFAULT_ROBUSTNESS_ITERS; - this.accuracy = DEFAULT_ACCURACY; - } - - /** - * Construct a new {@link LoessInterpolator} - * with given bandwidth and number of robustness iterations. - *- * Calling this constructor is equivalent to calling {link {@link - * #LoessInterpolator(double, int, double) LoessInterpolator(bandwidth, - * robustnessIters, LoessInterpolator.DEFAULT_ACCURACY)} - *
- * - * @param bandwidth when computing the loess fit at - * a particular point, this fraction of source points closest - * to the current point is taken into account for computing - * a least-squares regression. - * A sensible value is usually 0.25 to 0.5, the default value is - * {@link #DEFAULT_BANDWIDTH}. - * @param robustnessIters This many robustness iterations are done. - * A sensible value is usually 0 (just the initial fit without any - * robustness iterations) to 4, the default value is - * {@link #DEFAULT_ROBUSTNESS_ITERS}. - - * @see #LoessInterpolator(double, int, double) - */ - public LoessInterpolator(double bandwidth, int robustnessIters) { - this(bandwidth, robustnessIters, DEFAULT_ACCURACY); - } - - /** - * Construct a new {@link LoessInterpolator} - * with given bandwidth, number of robustness iterations and accuracy. - * - * @param bandwidth when computing the loess fit at - * a particular point, this fraction of source points closest - * to the current point is taken into account for computing - * a least-squares regression. - * A sensible value is usually 0.25 to 0.5, the default value is - * {@link #DEFAULT_BANDWIDTH}. - * @param robustnessIters This many robustness iterations are done. - * A sensible value is usually 0 (just the initial fit without any - * robustness iterations) to 4, the default value is - * {@link #DEFAULT_ROBUSTNESS_ITERS}. - * @param accuracy If the median residual at a certain robustness iteration - * is less than this amount, no more iterations are done. - * @throws OutOfRangeException if bandwidth does not lie in the interval [0,1]. - * @throws NotPositiveException if {@code robustnessIters} is negative. - * @see #LoessInterpolator(double, int) - * @since 2.1 - */ - public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) - throws OutOfRangeException, - NotPositiveException { - if (bandwidth < 0 || - bandwidth > 1) { - throw new OutOfRangeException(LocalizedFormats.BANDWIDTH, bandwidth, 0, 1); - } - this.bandwidth = bandwidth; - if (robustnessIters < 0) { - throw new NotPositiveException(LocalizedFormats.ROBUSTNESS_ITERATIONS, robustnessIters); - } - this.robustnessIters = robustnessIters; - this.accuracy = accuracy; - } - - /** - * Compute an interpolating function by performing a loess fit - * on the data at the original abscissae and then building a cubic spline - * with a - * {@link org.apache.commons.math4.analysis.interpolation.SplineInterpolator} - * on the resulting fit. - * - * @param xval the arguments for the interpolation points - * @param yval the values for the interpolation points - * @return A cubic spline built upon a loess fit to the data at the original abscissae - * @throws NonMonotonicSequenceException if {@code xval} not sorted in - * strictly increasing order. - * @throws DimensionMismatchException if {@code xval} and {@code yval} have - * different sizes. - * @throws NoDataException if {@code xval} or {@code yval} has zero size. - * @throws NotFiniteNumberException if any of the arguments and values are - * not finite real numbers. - * @throws NumberIsTooSmallException if the bandwidth is too small to - * accomodate the size of the input data (i.e. the bandwidth must be - * larger than 2/n). - */ - @Override - public final PolynomialSplineFunction interpolate(final double[] xval, - final double[] yval) - throws NonMonotonicSequenceException, - DimensionMismatchException, - NoDataException, - NotFiniteNumberException, - NumberIsTooSmallException { - return new SplineInterpolator().interpolate(xval, smooth(xval, yval)); - } - - /** - * Compute a weighted loess fit on the data at the original abscissae. - * - * @param xval Arguments for the interpolation points. - * @param yval Values for the interpolation points. - * @param weights point weights: coefficients by which the robustness weight - * of a point is multiplied. - * @return the values of the loess fit at corresponding original abscissae. - * @throws NonMonotonicSequenceException if {@code xval} not sorted in - * strictly increasing order. - * @throws DimensionMismatchException if {@code xval} and {@code yval} have - * different sizes. - * @throws NoDataException if {@code xval} or {@code yval} has zero size. - * @throws NotFiniteNumberException if any of the arguments and values are - not finite real numbers. - * @throws NumberIsTooSmallException if the bandwidth is too small to - * accomodate the size of the input data (i.e. the bandwidth must be - * larger than 2/n). - * @since 2.1 - */ - public final double[] smooth(final double[] xval, final double[] yval, - final double[] weights) - throws NonMonotonicSequenceException, - DimensionMismatchException, - NoDataException, - NotFiniteNumberException, - NumberIsTooSmallException { - if (xval.length != yval.length) { - throw new DimensionMismatchException(xval.length, yval.length); - } - - final int n = xval.length; - - if (n == 0) { - throw new NoDataException(); - } - - checkAllFiniteReal(xval); - checkAllFiniteReal(yval); - checkAllFiniteReal(weights); - - MathArrays.checkOrder(xval); - - if (n == 1) { - return new double[]{yval[0]}; - } - - if (n == 2) { - return new double[]{yval[0], yval[1]}; - } - - int bandwidthInPoints = (int) (bandwidth * n); - - if (bandwidthInPoints < 2) { - throw new NumberIsTooSmallException(LocalizedFormats.BANDWIDTH, - bandwidthInPoints, 2, true); - } - - final double[] res = new double[n]; - - final double[] residuals = new double[n]; - final double[] sortedResiduals = new double[n]; - - final double[] robustnessWeights = new double[n]; - - // Do an initial fit and 'robustnessIters' robustness iterations. - // This is equivalent to doing 'robustnessIters+1' robustness iterations - // starting with all robustness weights set to 1. - Arrays.fill(robustnessWeights, 1); - - for (int iter = 0; iter <= robustnessIters; ++iter) { - final int[] bandwidthInterval = {0, bandwidthInPoints - 1}; - // At each x, compute a local weighted linear regression - for (int i = 0; i < n; ++i) { - final double x = xval[i]; - - // Find out the interval of source points on which - // a regression is to be made. - if (i > 0) { - updateBandwidthInterval(xval, weights, i, bandwidthInterval); - } - - final int ileft = bandwidthInterval[0]; - final int iright = bandwidthInterval[1]; - - // Compute the point of the bandwidth interval that is - // farthest from x - final int edge; - if (xval[i] - xval[ileft] > xval[iright] - xval[i]) { - edge = ileft; - } else { - edge = iright; - } - - // Compute a least-squares linear fit weighted by - // the product of robustness weights and the tricube - // weight function. - // See http://en.wikipedia.org/wiki/Linear_regression - // (section "Univariate linear case") - // and http://en.wikipedia.org/wiki/Weighted_least_squares - // (section "Weighted least squares") - double sumWeights = 0; - double sumX = 0; - double sumXSquared = 0; - double sumY = 0; - double sumXY = 0; - double denom = FastMath.abs(1.0 / (xval[edge] - x)); - for (int k = ileft; k <= iright; ++k) { - final double xk = xval[k]; - final double yk = yval[k]; - final double dist = (k < i) ? x - xk : xk - x; - final double w = tricube(dist * denom) * robustnessWeights[k] * weights[k]; - final double xkw = xk * w; - sumWeights += w; - sumX += xkw; - sumXSquared += xk * xkw; - sumY += yk * w; - sumXY += yk * xkw; - } - - final double meanX = sumX / sumWeights; - final double meanY = sumY / sumWeights; - final double meanXY = sumXY / sumWeights; - final double meanXSquared = sumXSquared / sumWeights; - - final double beta; - if (FastMath.sqrt(FastMath.abs(meanXSquared - meanX * meanX)) < accuracy) { - beta = 0; - } else { - beta = (meanXY - meanX * meanY) / (meanXSquared - meanX * meanX); - } - - final double alpha = meanY - beta * meanX; - - res[i] = beta * x + alpha; - residuals[i] = FastMath.abs(yval[i] - res[i]); - } - - // No need to recompute the robustness weights at the last - // iteration, they won't be needed anymore - if (iter == robustnessIters) { - break; - } - - // Recompute the robustness weights. - - // Find the median residual. - // An arraycopy and a sort are completely tractable here, - // because the preceding loop is a lot more expensive - System.arraycopy(residuals, 0, sortedResiduals, 0, n); - Arrays.sort(sortedResiduals); - final double medianResidual = sortedResiduals[n / 2]; - - if (FastMath.abs(medianResidual) < accuracy) { - break; - } - - for (int i = 0; i < n; ++i) { - final double arg = residuals[i] / (6 * medianResidual); - if (arg >= 1) { - robustnessWeights[i] = 0; - } else { - final double w = 1 - arg * arg; - robustnessWeights[i] = w * w; - } - } - } - - return res; - } - - /** - * Compute a loess fit on the data at the original abscissae. - * - * @param xval the arguments for the interpolation points - * @param yval the values for the interpolation points - * @return values of the loess fit at corresponding original abscissae - * @throws NonMonotonicSequenceException if {@code xval} not sorted in - * strictly increasing order. - * @throws DimensionMismatchException if {@code xval} and {@code yval} have - * different sizes. - * @throws NoDataException if {@code xval} or {@code yval} has zero size. - * @throws NotFiniteNumberException if any of the arguments and values are - * not finite real numbers. - * @throws NumberIsTooSmallException if the bandwidth is too small to - * accomodate the size of the input data (i.e. the bandwidth must be - * larger than 2/n). - */ - public final double[] smooth(final double[] xval, final double[] yval) - throws NonMonotonicSequenceException, - DimensionMismatchException, - NoDataException, - NotFiniteNumberException, - NumberIsTooSmallException { - if (xval.length != yval.length) { - throw new DimensionMismatchException(xval.length, yval.length); - } - - final double[] unitWeights = new double[xval.length]; - Arrays.fill(unitWeights, 1.0); - - return smooth(xval, yval, unitWeights); - } - - /** - * Given an index interval into xval that embraces a certain number of - * points closest to {@code xval[i-1]}, update the interval so that it - * embraces the same number of points closest to {@code xval[i]}, - * ignoring zero weights. - * - * @param xval Arguments array. - * @param weights Weights array. - * @param i Index around which the new interval should be computed. - * @param bandwidthInterval a two-element array {left, right} such that: - * {@code (left==0 or xval[i] - xval[left-1] > xval[right] - xval[i])} - * and - * {@code (right==xval.length-1 or xval[right+1] - xval[i] > xval[i] - xval[left])}. - * The array will be updated. - */ - private static void updateBandwidthInterval(final double[] xval, final double[] weights, - final int i, - final int[] bandwidthInterval) { - final int left = bandwidthInterval[0]; - final int right = bandwidthInterval[1]; - - // The right edge should be adjusted if the next point to the right - // is closer to xval[i] than the leftmost point of the current interval - int nextRight = nextNonzero(weights, right); - if (nextRight < xval.length && xval[nextRight] - xval[i] < xval[i] - xval[left]) { - int nextLeft = nextNonzero(weights, bandwidthInterval[0]); - bandwidthInterval[0] = nextLeft; - bandwidthInterval[1] = nextRight; - } - } - - /** - * Return the smallest index {@code j} such that - * {@code j > i && (j == weights.length || weights[j] != 0)}. - * - * @param weights Weights array. - * @param i Index from which to start search. - * @return the smallest compliant index. - */ - private static int nextNonzero(final double[] weights, final int i) { - int j = i + 1; - while(j < weights.length && weights[j] == 0) { - ++j; - } - return j; - } - - /** - * Compute the - * tricube - * weight function - * - * @param x Argument. - * @return(1 - |x|3)3
for |x| < 1, 0 otherwise.
- */
- private static double tricube(final double x) {
- final double absX = FastMath.abs(x);
- if (absX >= 1.0) {
- return 0.0;
- }
- final double tmp = 1 - absX * absX * absX;
- return tmp * tmp * tmp;
- }
-
- /**
- * Check that all elements of an array are finite real numbers.
- *
- * @param values Values array.
- * @throws NotFiniteNumberException
- * if one of the values is not a finite real number.
- */
- private static void checkAllFiniteReal(final double[] values) {
- for (int i = 0; i < values.length; i++) {
- MathUtils.checkFinite(values[i]);
- }
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
deleted file mode 100644
index 49cbf2e83..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MicrosphereProjectionInterpolator.java
+++ /dev/null
@@ -1,168 +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.analysis.interpolation;
-
-import org.apache.commons.rng.simple.RandomSource;
-import org.apache.commons.rng.sampling.UnitSphereSampler;
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NoDataException;
-import org.apache.commons.math4.exception.NotPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
-
-/**
- * Interpolator that implements the algorithm described in
- * William Dudziak's
- * MS thesis.
- *
- * @since 3.6
- */
-public class MicrosphereProjectionInterpolator
- implements MultivariateInterpolator {
- /** Brightness exponent. */
- private final double exponent;
- /** Microsphere. */
- private final InterpolatingMicrosphere microsphere;
- /** Whether to share the sphere. */
- private final boolean sharedSphere;
- /** Tolerance value below which no interpolation is necessary. */
- private final double noInterpolationTolerance;
-
- /**
- * Create a microsphere interpolator.
- *
- * @param dimension Space dimension.
- * @param elements Number of surface elements of the microsphere.
- * @param exponent Exponent used in the power law that computes the
- * @param maxDarkFraction Maximum fraction of the facets that can be dark.
- * If the fraction of "non-illuminated" facets is larger, no estimation
- * of the value will be performed, and the {@code background} value will
- * be returned instead.
- * @param darkThreshold Value of the illumination below which a facet is
- * considered dark.
- * @param background Value returned when the {@code maxDarkFraction}
- * threshold is exceeded.
- * @param sharedSphere Whether the sphere can be shared among the
- * interpolating function instances. If {@code true}, the instances
- * will share the same data, and thus will not be thread-safe.
- * @param noInterpolationTolerance When the distance between an
- * interpolated point and one of the sample points is less than this
- * value, no interpolation will be performed (the value of the sample
- * will be returned).
- * @throws org.apache.commons.math4.exception.NotStrictlyPositiveException
- * if {@code dimension <= 0} or {@code elements <= 0}.
- * @throws NotPositiveException if {@code exponent < 0}.
- * @throws NotPositiveException if {@code darkThreshold < 0}.
- * @throws org.apache.commons.math4.exception.OutOfRangeException if
- * {@code maxDarkFraction} does not belong to the interval {@code [0, 1]}.
- */
- public MicrosphereProjectionInterpolator(int dimension,
- int elements,
- double maxDarkFraction,
- double darkThreshold,
- double background,
- double exponent,
- boolean sharedSphere,
- double noInterpolationTolerance) {
- this(new InterpolatingMicrosphere(dimension,
- elements,
- maxDarkFraction,
- darkThreshold,
- background,
- new UnitSphereSampler(dimension,
- RandomSource.create(RandomSource.MT_64))),
- exponent,
- sharedSphere,
- noInterpolationTolerance);
- }
-
- /**
- * Create a microsphere interpolator.
- *
- * @param microsphere Microsphere.
- * @param exponent Exponent used in the power law that computes the
- * weights (distance dimming factor) of the sample data.
- * @param sharedSphere Whether the sphere can be shared among the
- * interpolating function instances. If {@code true}, the instances
- * will share the same data, and thus will not be thread-safe.
- * @param noInterpolationTolerance When the distance between an
- * interpolated point and one of the sample points is less than this
- * value, no interpolation will be performed (the value of the sample
- * will be returned).
- * @throws NotPositiveException if {@code exponent < 0}.
- */
- public MicrosphereProjectionInterpolator(InterpolatingMicrosphere microsphere,
- double exponent,
- boolean sharedSphere,
- double noInterpolationTolerance)
- throws NotPositiveException {
- if (exponent < 0) {
- throw new NotPositiveException(exponent);
- }
-
- this.microsphere = microsphere;
- this.exponent = exponent;
- this.sharedSphere = sharedSphere;
- this.noInterpolationTolerance = noInterpolationTolerance;
- }
-
- /**
- * {@inheritDoc}
- *
- * @throws DimensionMismatchException if the space dimension of the
- * given samples does not match the space dimension of the microsphere.
- */
- @Override
- public MultivariateFunction interpolate(final double[][] xval,
- final double[] yval)
- throws DimensionMismatchException,
- NoDataException,
- NullArgumentException {
- if (xval == null ||
- yval == null) {
- throw new NullArgumentException();
- }
- if (xval.length == 0) {
- throw new NoDataException();
- }
- if (xval.length != yval.length) {
- throw new DimensionMismatchException(xval.length, yval.length);
- }
- if (xval[0] == null) {
- throw new NullArgumentException();
- }
- final int dimension = microsphere.getDimension();
- if (dimension != xval[0].length) {
- throw new DimensionMismatchException(xval[0].length, dimension);
- }
-
- // Microsphere copy.
- final InterpolatingMicrosphere m = sharedSphere ? microsphere : microsphere.copy();
-
- return new MultivariateFunction() {
- /** {inheritDoc} */
- @Override
- public double value(double[] point) {
- return m.value(point,
- xval,
- yval,
- exponent,
- noInterpolationTolerance);
- }
- };
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MultivariateInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MultivariateInterpolator.java
deleted file mode 100644
index 97ae5b642..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/MultivariateInterpolator.java
+++ /dev/null
@@ -1,51 +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.analysis.interpolation;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.exception.NoDataException;
-import org.apache.commons.math4.exception.NullArgumentException;
-
-/**
- * Interface representing a univariate real interpolating function.
- *
- * @since 2.1
- */
-public interface MultivariateInterpolator {
-
- /**
- * Computes an interpolating function for the data set.
- *
- * @param xval the arguments for the interpolation points.
- * {@code xval[i][0]} is the first component of interpolation point
- * {@code i}, {@code xval[i][1]} is the second component, and so on
- * until {@code xval[i][d-1]}, the last component of that interpolation
- * point (where {@code d} is thus the dimension of the space).
- * @param yval the values for the interpolation points
- * @return a function which interpolates the data set
- * @throws MathIllegalArgumentException if the arguments violate assumptions
- * made by the interpolation algorithm.
- * @throws DimensionMismatchException when the array dimensions are not consistent.
- * @throws NoDataException if an array has zero-length.
- * @throws NullArgumentException if the arguments are {@code null}.
- */
- MultivariateFunction interpolate(double[][] xval, double[] yval)
- throws MathIllegalArgumentException, DimensionMismatchException,
- NoDataException, NullArgumentException;
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/NevilleInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/NevilleInterpolator.java
deleted file mode 100644
index d214cc87c..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/NevilleInterpolator.java
+++ /dev/null
@@ -1,61 +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.analysis.interpolation;
-
-import java.io.Serializable;
-
-import org.apache.commons.math4.analysis.polynomials.PolynomialFunctionLagrangeForm;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.NonMonotonicSequenceException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-
-/**
- * Implements the
- * Neville's Algorithm for interpolation of real univariate functions. For
- * reference, see Introduction to Numerical Analysis, ISBN 038795452X,
- * chapter 2.
- * - * The actual code of Neville's algorithm is in PolynomialFunctionLagrangeForm, - * this class provides an easy-to-use interface to it.
- * - * @since 1.2 - */ -public class NevilleInterpolator implements UnivariateInterpolator, - Serializable { - - /** serializable version identifier */ - static final long serialVersionUID = 3003707660147873733L; - - /** - * Computes an interpolating function for the data set. - * - * @param x Interpolating points. - * @param y Interpolating values. - * @return a function which interpolates the data set - * @throws DimensionMismatchException if the array lengths are different. - * @throws NumberIsTooSmallException if the number of points is less than 2. - * @throws NonMonotonicSequenceException if two abscissae have the same - * value. - */ - @Override - public PolynomialFunctionLagrangeForm interpolate(double x[], double y[]) - throws DimensionMismatchException, - NumberIsTooSmallException, - NonMonotonicSequenceException { - return new PolynomialFunctionLagrangeForm(x, y); - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java deleted file mode 100644 index f547a1f3b..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java +++ /dev/null @@ -1,212 +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.analysis.interpolation; - -import java.util.Arrays; - -import org.apache.commons.math4.analysis.BivariateFunction; -import org.apache.commons.math4.analysis.polynomials.PolynomialSplineFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.InsufficientDataException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.OutOfRangeException; -import org.apache.commons.math4.util.MathArrays; - -/** - * Function that implements the - * bicubic spline - * interpolation. - * This implementation currently uses {@link AkimaSplineInterpolator} as the - * underlying one-dimensional interpolator, which requires 5 sample points; - * insufficient data will raise an exception when the - * {@link #value(double,double) value} method is called. - * - * @since 3.4 - */ -public class PiecewiseBicubicSplineInterpolatingFunction - implements BivariateFunction { - /** The minimum number of points that are needed to compute the function. */ - private static final int MIN_NUM_POINTS = 5; - /** Samples x-coordinates */ - private final double[] xval; - /** Samples y-coordinates */ - private final double[] yval; - /** Set of cubic splines patching the whole data grid */ - private final double[][] fval; - - /** - * @param x Sample values of the x-coordinate, in increasing order. - * @param y Sample values of the y-coordinate, in increasing order. - * @param f Values of the function on every grid point. the expected number - * of elements. - * @throws NonMonotonicSequenceException if {@code x} or {@code y} are not - * strictly increasing. - * @throws NullArgumentException if any of the arguments are null - * @throws NoDataException if any of the arrays has zero length. - * @throws DimensionMismatchException if the length of x and y don't match the row, column - * height of f - */ - public PiecewiseBicubicSplineInterpolatingFunction(double[] x, - double[] y, - double[][] f) - throws DimensionMismatchException, - NullArgumentException, - NoDataException, - NonMonotonicSequenceException { - if (x == null || - y == null || - f == null || - f[0] == null) { - throw new NullArgumentException(); - } - - final int xLen = x.length; - final int yLen = y.length; - - if (xLen == 0 || - yLen == 0 || - f.length == 0 || - f[0].length == 0) { - throw new NoDataException(); - } - - if (xLen < MIN_NUM_POINTS || - yLen < MIN_NUM_POINTS || - f.length < MIN_NUM_POINTS || - f[0].length < MIN_NUM_POINTS) { - throw new InsufficientDataException(); - } - - if (xLen != f.length) { - throw new DimensionMismatchException(xLen, f.length); - } - - if (yLen != f[0].length) { - throw new DimensionMismatchException(yLen, f[0].length); - } - - MathArrays.checkOrder(x); - MathArrays.checkOrder(y); - - xval = x.clone(); - yval = y.clone(); - fval = f.clone(); - } - - /** - * {@inheritDoc} - */ - @Override - public double value(double x, - double y) - throws OutOfRangeException { - final AkimaSplineInterpolator interpolator = new AkimaSplineInterpolator(); - final int offset = 2; - final int count = offset + 3; - final int i = searchIndex(x, xval, offset, count); - final int j = searchIndex(y, yval, offset, count); - - final double xArray[] = new double[count]; - final double yArray[] = new double[count]; - final double zArray[] = new double[count]; - final double interpArray[] = new double[count]; - - for (int index = 0; index < count; index++) { - xArray[index] = xval[i + index]; - yArray[index] = yval[j + index]; - } - - for (int zIndex = 0; zIndex < count; zIndex++) { - for (int index = 0; index < count; index++) { - zArray[index] = fval[i + index][j + zIndex]; - } - final PolynomialSplineFunction spline = interpolator.interpolate(xArray, zArray); - interpArray[zIndex] = spline.value(x); - } - - final PolynomialSplineFunction spline = interpolator.interpolate(yArray, interpArray); - - double returnValue = spline.value(y); - - return returnValue; - } - - /** - * Indicates whether a point is within the interpolation range. - * - * @param x First coordinate. - * @param y Second coordinate. - * @return {@code true} if (x, y) is a valid point. - * @since 3.3 - */ - public boolean isValidPoint(double x, - double y) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1]) { - return false; - } else { - return true; - } - } - - /** - * @param c Coordinate. - * @param val Coordinate samples. - * @param offset how far back from found value to offset for querying - * @param count total number of elements forward from beginning that will be - * queried - * @return the index in {@code val} corresponding to the interval containing - * {@code c}. - * @throws OutOfRangeException if {@code c} is out of the range defined by - * the boundary values of {@code val}. - */ - private int searchIndex(double c, - double[] val, - int offset, - int count) { - int r = Arrays.binarySearch(val, c); - - if (r == -1 || r == -val.length - 1) { - throw new OutOfRangeException(c, val[0], val[val.length - 1]); - } - - if (r < 0) { - // "c" in within an interpolation sub-interval, which returns - // negative - // need to remove the negative sign for consistency - r = -r - offset - 1; - } else { - r -= offset; - } - - if (r < 0) { - r = 0; - } - - if ((r + count) >= val.length) { - // "c" is the last sample of the range: Return the index - // of the sample at the lower end of the last sub-interval. - r = val.length - count; - } - - return r; - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java deleted file mode 100644 index 7d16b2c2f..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolator.java +++ /dev/null @@ -1,62 +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.analysis.interpolation; - -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.util.MathArrays; - -/** - * Generates a piecewise-bicubic interpolating function. - * - * @since 2.2 - */ -public class PiecewiseBicubicSplineInterpolator - implements BivariateGridInterpolator { - - /** - * {@inheritDoc} - */ - @Override - public PiecewiseBicubicSplineInterpolatingFunction interpolate( final double[] xval, - final double[] yval, - final double[][] fval) - throws DimensionMismatchException, - NullArgumentException, - NoDataException, - NonMonotonicSequenceException { - if ( xval == null || - yval == null || - fval == null || - fval[0] == null ) { - throw new NullArgumentException(); - } - - if ( xval.length == 0 || - yval.length == 0 || - fval.length == 0 ) { - throw new NoDataException(); - } - - MathArrays.checkOrder(xval); - MathArrays.checkOrder(yval); - - return new PiecewiseBicubicSplineInterpolatingFunction( xval, yval, fval ); - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java deleted file mode 100644 index 9515dde87..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/SplineInterpolator.java +++ /dev/null @@ -1,128 +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.analysis.interpolation; - -import org.apache.commons.math4.analysis.polynomials.PolynomialFunction; -import org.apache.commons.math4.analysis.polynomials.PolynomialSplineFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.MathArrays; - -/** - * Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set. - *- * The {@link #interpolate(double[], double[])} method returns a {@link PolynomialSplineFunction} - * consisting of n cubic polynomials, defined over the subintervals determined by the x values, - * {@code x[0] < x[i] ... < x[n].} The x values are referred to as "knot points."
- *
- * The value of the PolynomialSplineFunction at a point x that is greater than or equal to the smallest
- * knot point and strictly less than the largest knot point is computed by finding the subinterval to which
- * x belongs and computing the value of the corresponding polynomial at x - x[i]
where
- * i
is the index of the subinterval. See {@link PolynomialSplineFunction} for more details.
- *
- * The interpolating polynomials satisfy:
- * The cubic spline interpolation algorithm implemented is as described in R.L. Burden, J.D. Faires, - * Numerical Analysis, 4th Ed., 1989, PWS-Kent, ISBN 0-53491-585-X, pp 126-131. - *
- * - */ -public class SplineInterpolator implements UnivariateInterpolator { - /** - * Computes an interpolating function for the data set. - * @param x the arguments for the interpolation points - * @param y the values for the interpolation points - * @return a function which interpolates the data set - * @throws DimensionMismatchException if {@code x} and {@code y} - * have different sizes. - * @throws NonMonotonicSequenceException if {@code x} is not sorted in - * strict increasing order. - * @throws NumberIsTooSmallException if the size of {@code x} is smaller - * than 3. - */ - @Override - public PolynomialSplineFunction interpolate(double x[], double y[]) - throws DimensionMismatchException, - NumberIsTooSmallException, - NonMonotonicSequenceException { - if (x.length != y.length) { - throw new DimensionMismatchException(x.length, y.length); - } - - if (x.length < 3) { - throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS, - x.length, 3, true); - } - - // Number of intervals. The number of data points is n + 1. - final int n = x.length - 1; - - MathArrays.checkOrder(x); - - // Differences between knot points - final double h[] = new double[n]; - for (int i = 0; i < n; i++) { - h[i] = x[i + 1] - x[i]; - } - - final double mu[] = new double[n]; - final double z[] = new double[n + 1]; - mu[0] = 0d; - z[0] = 0d; - double g = 0; - for (int i = 1; i < n; i++) { - g = 2d * (x[i+1] - x[i - 1]) - h[i - 1] * mu[i -1]; - mu[i] = h[i] / g; - z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) / - (h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g; - } - - // cubic spline coefficients -- b is linear, c quadratic, d is cubic (original y's are constants) - final double b[] = new double[n]; - final double c[] = new double[n + 1]; - final double d[] = new double[n]; - - z[n] = 0d; - c[n] = 0d; - - for (int j = n -1; j >=0; j--) { - c[j] = z[j] - mu[j] * c[j + 1]; - b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d; - d[j] = (c[j + 1] - c[j]) / (3d * h[j]); - } - - final PolynomialFunction polynomials[] = new PolynomialFunction[n]; - final double coefficients[] = new double[4]; - for (int i = 0; i < n; i++) { - coefficients[0] = y[i]; - coefficients[1] = b[i]; - coefficients[2] = c[i]; - coefficients[3] = d[i]; - polynomials[i] = new PolynomialFunction(coefficients); - } - - return new PolynomialSplineFunction(x, polynomials); - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java deleted file mode 100644 index d81b6642d..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java +++ /dev/null @@ -1,509 +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.analysis.interpolation; - -import org.apache.commons.math4.analysis.TrivariateFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.OutOfRangeException; -import org.apache.commons.math4.util.MathArrays; - -/** - * Function that implements the - * - * tricubic spline interpolation, as proposed in - *- * Tricubic interpolation in three dimensions- * - * @since 3.4. - */ -public class TricubicInterpolatingFunction - implements TrivariateFunction { - /** - * Matrix to compute the spline coefficients from the function values - * and function derivatives values - */ - private static final double[][] AINV = { - { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -3,3,0,0,0,0,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 2,-2,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,-3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 9,-9,-9,9,0,0,0,0,6,3,-6,-3,0,0,0,0,6,-6,3,-3,0,0,0,0,0,0,0,0,0,0,0,0,4,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -6,6,6,-6,0,0,0,0,-3,-3,3,3,0,0,0,0,-4,4,-2,2,0,0,0,0,0,0,0,0,0,0,0,0,-2,-2,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 2,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,2,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -6,6,6,-6,0,0,0,0,-4,-2,4,2,0,0,0,0,-3,3,-3,3,0,0,0,0,0,0,0,0,0,0,0,0,-2,-1,-2,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 4,-4,-4,4,0,0,0,0,2,2,-2,-2,0,0,0,0,2,-2,2,-2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,3,0,0,0,0,0,0,-2,-1,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,-2,0,0,0,0,0,0,1,1,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-1,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,-9,-9,9,0,0,0,0,0,0,0,0,0,0,0,0,6,3,-6,-3,0,0,0,0,6,-6,3,-3,0,0,0,0,4,2,2,1,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-6,6,6,-6,0,0,0,0,0,0,0,0,0,0,0,0,-3,-3,3,3,0,0,0,0,-4,4,-2,2,0,0,0,0,-2,-2,-1,-1,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-6,6,6,-6,0,0,0,0,0,0,0,0,0,0,0,0,-4,-2,4,2,0,0,0,0,-3,3,-3,3,0,0,0,0,-2,-1,-2,-1,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,-4,-4,4,0,0,0,0,0,0,0,0,0,0,0,0,2,2,-2,-2,0,0,0,0,2,-2,2,-2,0,0,0,0,1,1,1,1,0,0,0,0 }, - {-3,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,-3,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 9,-9,0,0,-9,9,0,0,6,3,0,0,-6,-3,0,0,0,0,0,0,0,0,0,0,6,-6,0,0,3,-3,0,0,0,0,0,0,0,0,0,0,4,2,0,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -6,6,0,0,6,-6,0,0,-3,-3,0,0,3,3,0,0,0,0,0,0,0,0,0,0,-4,4,0,0,-2,2,0,0,0,0,0,0,0,0,0,0,-2,-2,0,0,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,0,0,-1,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,-9,0,0,-9,9,0,0,0,0,0,0,0,0,0,0,6,3,0,0,-6,-3,0,0,0,0,0,0,0,0,0,0,6,-6,0,0,3,-3,0,0,4,2,0,0,2,1,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-6,6,0,0,6,-6,0,0,0,0,0,0,0,0,0,0,-3,-3,0,0,3,3,0,0,0,0,0,0,0,0,0,0,-4,4,0,0,-2,2,0,0,-2,-2,0,0,-1,-1,0,0 }, - { 9,0,-9,0,-9,0,9,0,0,0,0,0,0,0,0,0,6,0,3,0,-6,0,-3,0,6,0,-6,0,3,0,-3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,2,0,2,0,1,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,9,0,-9,0,-9,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,3,0,-6,0,-3,0,6,0,-6,0,3,0,-3,0,0,0,0,0,0,0,0,0,4,0,2,0,2,0,1,0 }, - { -27,27,27,-27,27,-27,-27,27,-18,-9,18,9,18,9,-18,-9,-18,18,-9,9,18,-18,9,-9,-18,18,18,-18,-9,9,9,-9,-12,-6,-6,-3,12,6,6,3,-12,-6,12,6,-6,-3,6,3,-12,12,-6,6,-6,6,-3,3,-8,-4,-4,-2,-4,-2,-2,-1 }, - { 18,-18,-18,18,-18,18,18,-18,9,9,-9,-9,-9,-9,9,9,12,-12,6,-6,-12,12,-6,6,12,-12,-12,12,6,-6,-6,6,6,6,3,3,-6,-6,-3,-3,6,6,-6,-6,3,3,-3,-3,8,-8,4,-4,4,-4,2,-2,4,4,2,2,2,2,1,1 }, - { -6,0,6,0,6,0,-6,0,0,0,0,0,0,0,0,0,-3,0,-3,0,3,0,3,0,-4,0,4,0,-2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-2,0,-1,0,-1,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,-6,0,6,0,6,0,-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-3,0,-3,0,3,0,3,0,-4,0,4,0,-2,0,2,0,0,0,0,0,0,0,0,0,-2,0,-2,0,-1,0,-1,0 }, - { 18,-18,-18,18,-18,18,18,-18,12,6,-12,-6,-12,-6,12,6,9,-9,9,-9,-9,9,-9,9,12,-12,-12,12,6,-6,-6,6,6,3,6,3,-6,-3,-6,-3,8,4,-8,-4,4,2,-4,-2,6,-6,6,-6,3,-3,3,-3,4,2,4,2,2,1,2,1 }, - { -12,12,12,-12,12,-12,-12,12,-6,-6,6,6,6,6,-6,-6,-6,6,-6,6,6,-6,6,-6,-8,8,8,-8,-4,4,4,-4,-3,-3,-3,-3,3,3,3,3,-4,-4,4,4,-2,-2,2,2,-4,4,-4,4,-2,2,-2,2,-2,-2,-2,-2,-1,-1,-1,-1 }, - { 2,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,2,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { -6,6,0,0,6,-6,0,0,-4,-2,0,0,4,2,0,0,0,0,0,0,0,0,0,0,-3,3,0,0,-3,3,0,0,0,0,0,0,0,0,0,0,-2,-1,0,0,-2,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 4,-4,0,0,-4,4,0,0,2,2,0,0,-2,-2,0,0,0,0,0,0,0,0,0,0,2,-2,0,0,2,-2,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-6,6,0,0,6,-6,0,0,0,0,0,0,0,0,0,0,-4,-2,0,0,4,2,0,0,0,0,0,0,0,0,0,0,-3,3,0,0,-3,3,0,0,-2,-1,0,0,-2,-1,0,0 }, - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,-4,0,0,-4,4,0,0,0,0,0,0,0,0,0,0,2,2,0,0,-2,-2,0,0,0,0,0,0,0,0,0,0,2,-2,0,0,2,-2,0,0,1,1,0,0,1,1,0,0 }, - { -6,0,6,0,6,0,-6,0,0,0,0,0,0,0,0,0,-4,0,-2,0,4,0,2,0,-3,0,3,0,-3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-2,0,-1,0,-2,0,-1,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,-6,0,6,0,6,0,-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-4,0,-2,0,4,0,2,0,-3,0,3,0,-3,0,3,0,0,0,0,0,0,0,0,0,-2,0,-1,0,-2,0,-1,0 }, - { 18,-18,-18,18,-18,18,18,-18,12,6,-12,-6,-12,-6,12,6,12,-12,6,-6,-12,12,-6,6,9,-9,-9,9,9,-9,-9,9,8,4,4,2,-8,-4,-4,-2,6,3,-6,-3,6,3,-6,-3,6,-6,3,-3,6,-6,3,-3,4,2,2,1,4,2,2,1 }, - { -12,12,12,-12,12,-12,-12,12,-6,-6,6,6,6,6,-6,-6,-8,8,-4,4,8,-8,4,-4,-6,6,6,-6,-6,6,6,-6,-4,-4,-2,-2,4,4,2,2,-3,-3,3,3,-3,-3,3,3,-4,4,-2,2,-4,4,-2,2,-2,-2,-1,-1,-2,-2,-1,-1 }, - { 4,0,-4,0,-4,0,4,0,0,0,0,0,0,0,0,0,2,0,2,0,-2,0,-2,0,2,0,-2,0,2,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0 }, - { 0,0,0,0,0,0,0,0,4,0,-4,0,-4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,-2,0,-2,0,2,0,-2,0,2,0,-2,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0 }, - { -12,12,12,-12,12,-12,-12,12,-8,-4,8,4,8,4,-8,-4,-6,6,-6,6,6,-6,6,-6,-6,6,6,-6,-6,6,6,-6,-4,-2,-4,-2,4,2,4,2,-4,-2,4,2,-4,-2,4,2,-3,3,-3,3,-3,3,-3,3,-2,-1,-2,-1,-2,-1,-2,-1 }, - { 8,-8,-8,8,-8,8,8,-8,4,4,-4,-4,-4,-4,4,4,4,-4,4,-4,-4,4,-4,4,4,-4,-4,4,4,-4,-4,4,2,2,2,2,-2,-2,-2,-2,2,2,-2,-2,2,2,-2,-2,2,-2,2,-2,2,-2,2,-2,1,1,1,1,1,1,1,1 } - }; - - /** Samples x-coordinates */ - private final double[] xval; - /** Samples y-coordinates */ - private final double[] yval; - /** Samples z-coordinates */ - private final double[] zval; - /** Set of cubic splines pacthing the whole data grid */ - private final TricubicFunction[][][] splines; - - /** - * @param x Sample values of the x-coordinate, in increasing order. - * @param y Sample values of the y-coordinate, in increasing order. - * @param z Sample values of the y-coordinate, in increasing order. - * @param f Values of the function on every grid point. - * @param dFdX Values of the partial derivative of function with respect to x on every grid point. - * @param dFdY Values of the partial derivative of function with respect to y on every grid point. - * @param dFdZ Values of the partial derivative of function with respect to z on every grid point. - * @param d2FdXdY Values of the cross partial derivative of function on every grid point. - * @param d2FdXdZ Values of the cross partial derivative of function on every grid point. - * @param d2FdYdZ Values of the cross partial derivative of function on every grid point. - * @param d3FdXdYdZ Values of the cross partial derivative of function on every grid point. - * @throws NoDataException if any of the arrays has zero length. - * @throws DimensionMismatchException if the various arrays do not contain the expected number of elements. - * @throws NonMonotonicSequenceException if {@code x}, {@code y} or {@code z} are not strictly increasing. - */ - public TricubicInterpolatingFunction(double[] x, - double[] y, - double[] z, - double[][][] f, - double[][][] dFdX, - double[][][] dFdY, - double[][][] dFdZ, - double[][][] d2FdXdY, - double[][][] d2FdXdZ, - double[][][] d2FdYdZ, - double[][][] d3FdXdYdZ) - throws NoDataException, - DimensionMismatchException, - NonMonotonicSequenceException { - final int xLen = x.length; - final int yLen = y.length; - final int zLen = z.length; - - if (xLen == 0 || yLen == 0 || z.length == 0 || f.length == 0 || f[0].length == 0) { - throw new NoDataException(); - } - if (xLen != f.length) { - throw new DimensionMismatchException(xLen, f.length); - } - if (xLen != dFdX.length) { - throw new DimensionMismatchException(xLen, dFdX.length); - } - if (xLen != dFdY.length) { - throw new DimensionMismatchException(xLen, dFdY.length); - } - if (xLen != dFdZ.length) { - throw new DimensionMismatchException(xLen, dFdZ.length); - } - if (xLen != d2FdXdY.length) { - throw new DimensionMismatchException(xLen, d2FdXdY.length); - } - if (xLen != d2FdXdZ.length) { - throw new DimensionMismatchException(xLen, d2FdXdZ.length); - } - if (xLen != d2FdYdZ.length) { - throw new DimensionMismatchException(xLen, d2FdYdZ.length); - } - if (xLen != d3FdXdYdZ.length) { - throw new DimensionMismatchException(xLen, d3FdXdYdZ.length); - } - - MathArrays.checkOrder(x); - MathArrays.checkOrder(y); - MathArrays.checkOrder(z); - - xval = x.clone(); - yval = y.clone(); - zval = z.clone(); - - final int lastI = xLen - 1; - final int lastJ = yLen - 1; - final int lastK = zLen - 1; - splines = new TricubicFunction[lastI][lastJ][lastK]; - - for (int i = 0; i < lastI; i++) { - if (f[i].length != yLen) { - throw new DimensionMismatchException(f[i].length, yLen); - } - if (dFdX[i].length != yLen) { - throw new DimensionMismatchException(dFdX[i].length, yLen); - } - if (dFdY[i].length != yLen) { - throw new DimensionMismatchException(dFdY[i].length, yLen); - } - if (dFdZ[i].length != yLen) { - throw new DimensionMismatchException(dFdZ[i].length, yLen); - } - if (d2FdXdY[i].length != yLen) { - throw new DimensionMismatchException(d2FdXdY[i].length, yLen); - } - if (d2FdXdZ[i].length != yLen) { - throw new DimensionMismatchException(d2FdXdZ[i].length, yLen); - } - if (d2FdYdZ[i].length != yLen) { - throw new DimensionMismatchException(d2FdYdZ[i].length, yLen); - } - if (d3FdXdYdZ[i].length != yLen) { - throw new DimensionMismatchException(d3FdXdYdZ[i].length, yLen); - } - - final int ip1 = i + 1; - final double xR = xval[ip1] - xval[i]; - for (int j = 0; j < lastJ; j++) { - if (f[i][j].length != zLen) { - throw new DimensionMismatchException(f[i][j].length, zLen); - } - if (dFdX[i][j].length != zLen) { - throw new DimensionMismatchException(dFdX[i][j].length, zLen); - } - if (dFdY[i][j].length != zLen) { - throw new DimensionMismatchException(dFdY[i][j].length, zLen); - } - if (dFdZ[i][j].length != zLen) { - throw new DimensionMismatchException(dFdZ[i][j].length, zLen); - } - if (d2FdXdY[i][j].length != zLen) { - throw new DimensionMismatchException(d2FdXdY[i][j].length, zLen); - } - if (d2FdXdZ[i][j].length != zLen) { - throw new DimensionMismatchException(d2FdXdZ[i][j].length, zLen); - } - if (d2FdYdZ[i][j].length != zLen) { - throw new DimensionMismatchException(d2FdYdZ[i][j].length, zLen); - } - if (d3FdXdYdZ[i][j].length != zLen) { - throw new DimensionMismatchException(d3FdXdYdZ[i][j].length, zLen); - } - - final int jp1 = j + 1; - final double yR = yval[jp1] - yval[j]; - final double xRyR = xR * yR; - for (int k = 0; k < lastK; k++) { - final int kp1 = k + 1; - final double zR = zval[kp1] - zval[k]; - final double xRzR = xR * zR; - final double yRzR = yR * zR; - final double xRyRzR = xR * yRzR; - - final double[] beta = new double[] { - f[i][j][k], f[ip1][j][k], - f[i][jp1][k], f[ip1][jp1][k], - f[i][j][kp1], f[ip1][j][kp1], - f[i][jp1][kp1], f[ip1][jp1][kp1], - - dFdX[i][j][k] * xR, dFdX[ip1][j][k] * xR, - dFdX[i][jp1][k] * xR, dFdX[ip1][jp1][k] * xR, - dFdX[i][j][kp1] * xR, dFdX[ip1][j][kp1] * xR, - dFdX[i][jp1][kp1] * xR, dFdX[ip1][jp1][kp1] * xR, - - dFdY[i][j][k] * yR, dFdY[ip1][j][k] * yR, - dFdY[i][jp1][k] * yR, dFdY[ip1][jp1][k] * yR, - dFdY[i][j][kp1] * yR, dFdY[ip1][j][kp1] * yR, - dFdY[i][jp1][kp1] * yR, dFdY[ip1][jp1][kp1] * yR, - - dFdZ[i][j][k] * zR, dFdZ[ip1][j][k] * zR, - dFdZ[i][jp1][k] * zR, dFdZ[ip1][jp1][k] * zR, - dFdZ[i][j][kp1] * zR, dFdZ[ip1][j][kp1] * zR, - dFdZ[i][jp1][kp1] * zR, dFdZ[ip1][jp1][kp1] * zR, - - d2FdXdY[i][j][k] * xRyR, d2FdXdY[ip1][j][k] * xRyR, - d2FdXdY[i][jp1][k] * xRyR, d2FdXdY[ip1][jp1][k] * xRyR, - d2FdXdY[i][j][kp1] * xRyR, d2FdXdY[ip1][j][kp1] * xRyR, - d2FdXdY[i][jp1][kp1] * xRyR, d2FdXdY[ip1][jp1][kp1] * xRyR, - - d2FdXdZ[i][j][k] * xRzR, d2FdXdZ[ip1][j][k] * xRzR, - d2FdXdZ[i][jp1][k] * xRzR, d2FdXdZ[ip1][jp1][k] * xRzR, - d2FdXdZ[i][j][kp1] * xRzR, d2FdXdZ[ip1][j][kp1] * xRzR, - d2FdXdZ[i][jp1][kp1] * xRzR, d2FdXdZ[ip1][jp1][kp1] * xRzR, - - d2FdYdZ[i][j][k] * yRzR, d2FdYdZ[ip1][j][k] * yRzR, - d2FdYdZ[i][jp1][k] * yRzR, d2FdYdZ[ip1][jp1][k] * yRzR, - d2FdYdZ[i][j][kp1] * yRzR, d2FdYdZ[ip1][j][kp1] * yRzR, - d2FdYdZ[i][jp1][kp1] * yRzR, d2FdYdZ[ip1][jp1][kp1] * yRzR, - - d3FdXdYdZ[i][j][k] * xRyRzR, d3FdXdYdZ[ip1][j][k] * xRyRzR, - d3FdXdYdZ[i][jp1][k] * xRyRzR, d3FdXdYdZ[ip1][jp1][k] * xRyRzR, - d3FdXdYdZ[i][j][kp1] * xRyRzR, d3FdXdYdZ[ip1][j][kp1] * xRyRzR, - d3FdXdYdZ[i][jp1][kp1] * xRyRzR, d3FdXdYdZ[ip1][jp1][kp1] * xRyRzR, - }; - - splines[i][j][k] = new TricubicFunction(computeCoefficients(beta)); - } - } - } - } - - /** - * {@inheritDoc} - * - * @throws OutOfRangeException if any of the variables is outside its interpolation range. - */ - @Override - public double value(double x, double y, double z) - throws OutOfRangeException { - final int i = searchIndex(x, xval); - if (i == -1) { - throw new OutOfRangeException(x, xval[0], xval[xval.length - 1]); - } - final int j = searchIndex(y, yval); - if (j == -1) { - throw new OutOfRangeException(y, yval[0], yval[yval.length - 1]); - } - final int k = searchIndex(z, zval); - if (k == -1) { - throw new OutOfRangeException(z, zval[0], zval[zval.length - 1]); - } - - final double xN = (x - xval[i]) / (xval[i + 1] - xval[i]); - final double yN = (y - yval[j]) / (yval[j + 1] - yval[j]); - final double zN = (z - zval[k]) / (zval[k + 1] - zval[k]); - - return splines[i][j][k].value(xN, yN, zN); - } - - /** - * Indicates whether a point is within the interpolation range. - * - * @param x First coordinate. - * @param y Second coordinate. - * @param z Third coordinate. - * @return {@code true} if (x, y, z) is a valid point. - */ - public boolean isValidPoint(double x, double y, double z) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1] || - z < zval[0] || - z > zval[zval.length - 1]) { - return false; - } else { - return true; - } - } - - /** - * @param c Coordinate. - * @param val Coordinate samples. - * @return the index in {@code val} corresponding to the interval containing {@code c}, or {@code -1} - * if {@code c} is out of the range defined by the end values of {@code val}. - */ - private int searchIndex(double c, double[] val) { - if (c < val[0]) { - return -1; - } - - final int max = val.length; - for (int i = 1; i < max; i++) { - if (c <= val[i]) { - return i - 1; - } - } - - return -1; - } - - /** - * Compute the spline coefficients from the list of function values and - * function partial derivatives values at the four corners of a grid - * element. They must be specified in the following order: - *
- * F. Lekien and J. Marsden
- * Int. J. Numer. Meth. Eng 2005; 63:455-471
- *
- * Parent package for common numerical analysis procedures, including root finding, - * function interpolation and integration. Note that optimization (i.e. minimization - * and maximization) is a separate top-level package. - *
- *- * Function interfaces are intended to be implemented by user code to represent - * domain problems. The algorithms provided by the library operate on these - * functions to find their roots, or integrate them, or ... Functions can be multivariate - * or univariate, real vectorial or matrix-valued, and they can be differentiable or not. - *
- * - */ -package org.apache.commons.math4.analysis; diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java deleted file mode 100644 index 9333c1eb3..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java +++ /dev/null @@ -1,406 +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.analysis.polynomials; - -import java.io.Serializable; -import java.util.Arrays; - -import org.apache.commons.math4.analysis.ParametricUnivariateFunction; -import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.FastMath; -import org.apache.commons.math4.util.MathUtils; - -/** - * Immutable representation of a real polynomial function with real coefficients. - *- * Horner's Method - * is used to evaluate the function.
- * - */ -public class PolynomialFunction implements UnivariateDifferentiableFunction, Serializable { - /** - * Serialization identifier - */ - private static final long serialVersionUID = -7726511984200295583L; - /** - * The coefficients of the polynomial, ordered by degree -- i.e., - * coefficients[0] is the constant term and coefficients[n] is the - * coefficient of x^n where n is the degree of the polynomial. - */ - private final double coefficients[]; - - /** - * Construct a polynomial with the given coefficients. The first element - * of the coefficients array is the constant term. Higher degree - * coefficients follow in sequence. The degree of the resulting polynomial - * is the index of the last non-null element of the array, or 0 if all elements - * are null. - *- * The constructor makes a copy of the input array and assigns the copy to - * the coefficients property.
- * - * @param c Polynomial coefficients. - * @throws NullArgumentException if {@code c} is {@code null}. - * @throws NoDataException if {@code c} is empty. - */ - public PolynomialFunction(double c[]) - throws NullArgumentException, NoDataException { - super(); - MathUtils.checkNotNull(c); - int n = c.length; - if (n == 0) { - throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); - } - while ((n > 1) && (c[n - 1] == 0)) { - --n; - } - this.coefficients = new double[n]; - System.arraycopy(c, 0, this.coefficients, 0, n); - } - - /** - * Compute the value of the function for the given argument. - *- * The value returned is
- * {@code coefficients[n] * x^n + ... + coefficients[1] * x + coefficients[0]} - *
- * - * @param x Argument for which the function value should be computed. - * @return the value of the polynomial at the given point. - * - * @see org.apache.commons.math4.analysis.UnivariateFunction#value(double) - */ - @Override - public double value(double x) { - return evaluate(coefficients, x); - } - - /** - * Returns the degree of the polynomial. - * - * @return the degree of the polynomial. - */ - public int degree() { - return coefficients.length - 1; - } - - /** - * Returns a copy of the coefficients array. - *- * Changes made to the returned copy will not affect the coefficients of - * the polynomial.
- * - * @return a fresh copy of the coefficients array. - */ - public double[] getCoefficients() { - return coefficients.clone(); - } - - /** - * Uses Horner's Method to evaluate the polynomial with the given coefficients at - * the argument. - * - * @param coefficients Coefficients of the polynomial to evaluate. - * @param argument Input value. - * @return the value of the polynomial. - * @throws NoDataException if {@code coefficients} is empty. - * @throws NullArgumentException if {@code coefficients} is {@code null}. - */ - protected static double evaluate(double[] coefficients, double argument) - throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); - int n = coefficients.length; - if (n == 0) { - throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); - } - double result = coefficients[n - 1]; - for (int j = n - 2; j >= 0; j--) { - result = argument * result + coefficients[j]; - } - return result; - } - - - /** {@inheritDoc} - * @since 3.1 - * @throws NoDataException if {@code coefficients} is empty. - * @throws NullArgumentException if {@code coefficients} is {@code null}. - */ - @Override - public DerivativeStructure value(final DerivativeStructure t) - throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); - int n = coefficients.length; - if (n == 0) { - throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); - } - DerivativeStructure result = - new DerivativeStructure(t.getFreeParameters(), t.getOrder(), coefficients[n - 1]); - for (int j = n - 2; j >= 0; j--) { - result = result.multiply(t).add(coefficients[j]); - } - return result; - } - - /** - * Add a polynomial to the instance. - * - * @param p Polynomial to add. - * @return a new polynomial which is the sum of the instance and {@code p}. - */ - public PolynomialFunction add(final PolynomialFunction p) { - // identify the lowest degree polynomial - final int lowLength = FastMath.min(coefficients.length, p.coefficients.length); - final int highLength = FastMath.max(coefficients.length, p.coefficients.length); - - // build the coefficients array - double[] newCoefficients = new double[highLength]; - for (int i = 0; i < lowLength; ++i) { - newCoefficients[i] = coefficients[i] + p.coefficients[i]; - } - System.arraycopy((coefficients.length < p.coefficients.length) ? - p.coefficients : coefficients, - lowLength, - newCoefficients, lowLength, - highLength - lowLength); - - return new PolynomialFunction(newCoefficients); - } - - /** - * Subtract a polynomial from the instance. - * - * @param p Polynomial to subtract. - * @return a new polynomial which is the instance minus {@code p}. - */ - public PolynomialFunction subtract(final PolynomialFunction p) { - // identify the lowest degree polynomial - int lowLength = FastMath.min(coefficients.length, p.coefficients.length); - int highLength = FastMath.max(coefficients.length, p.coefficients.length); - - // build the coefficients array - double[] newCoefficients = new double[highLength]; - for (int i = 0; i < lowLength; ++i) { - newCoefficients[i] = coefficients[i] - p.coefficients[i]; - } - if (coefficients.length < p.coefficients.length) { - for (int i = lowLength; i < highLength; ++i) { - newCoefficients[i] = -p.coefficients[i]; - } - } else { - System.arraycopy(coefficients, lowLength, newCoefficients, lowLength, - highLength - lowLength); - } - - return new PolynomialFunction(newCoefficients); - } - - /** - * Negate the instance. - * - * @return a new polynomial with all coefficients negated - */ - public PolynomialFunction negate() { - double[] newCoefficients = new double[coefficients.length]; - for (int i = 0; i < coefficients.length; ++i) { - newCoefficients[i] = -coefficients[i]; - } - return new PolynomialFunction(newCoefficients); - } - - /** - * Multiply the instance by a polynomial. - * - * @param p Polynomial to multiply by. - * @return a new polynomial equal to this times {@code p} - */ - public PolynomialFunction multiply(final PolynomialFunction p) { - double[] newCoefficients = new double[coefficients.length + p.coefficients.length - 1]; - - for (int i = 0; i < newCoefficients.length; ++i) { - newCoefficients[i] = 0.0; - for (int j = FastMath.max(0, i + 1 - p.coefficients.length); - j < FastMath.min(coefficients.length, i + 1); - ++j) { - newCoefficients[i] += coefficients[j] * p.coefficients[i-j]; - } - } - - return new PolynomialFunction(newCoefficients); - } - - /** - * Returns the coefficients of the derivative of the polynomial with the given coefficients. - * - * @param coefficients Coefficients of the polynomial to differentiate. - * @return the coefficients of the derivative or {@code null} if coefficients has length 1. - * @throws NoDataException if {@code coefficients} is empty. - * @throws NullArgumentException if {@code coefficients} is {@code null}. - */ - protected static double[] differentiate(double[] coefficients) - throws NullArgumentException, NoDataException { - MathUtils.checkNotNull(coefficients); - int n = coefficients.length; - if (n == 0) { - throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); - } - if (n == 1) { - return new double[]{0}; - } - double[] result = new double[n - 1]; - for (int i = n - 1; i > 0; i--) { - result[i - 1] = i * coefficients[i]; - } - return result; - } - - /** - * Returns the derivative as a {@link PolynomialFunction}. - * - * @return the derivative polynomial. - */ - public PolynomialFunction polynomialDerivative() { - return new PolynomialFunction(differentiate(coefficients)); - } - - /** - * Returns a string representation of the polynomial. - * - *The representation is user oriented. Terms are displayed lowest
- * degrees first. The multiplications signs, coefficients equals to
- * one and null terms are not displayed (except if the polynomial is 0,
- * in which case the 0 constant term is displayed). Addition of terms
- * with negative coefficients are replaced by subtraction of terms
- * with positive coefficients except for the first displayed term
- * (i.e. we display -3
for a constant negative polynomial,
- * but 1 - 3 x + x^2
if the negative coefficient is not
- * the first one displayed).
- * The approximated function should be smooth enough for Lagrange polynomial - * to work well. Otherwise, consider using splines instead.
- * - * @since 1.2 - */ -public class PolynomialFunctionLagrangeForm implements UnivariateFunction { - /** - * The coefficients of the polynomial, ordered by degree -- i.e. - * coefficients[0] is the constant term and coefficients[n] is the - * coefficient of x^n where n is the degree of the polynomial. - */ - private double coefficients[]; - /** - * Interpolating points (abscissas). - */ - private final double x[]; - /** - * Function values at interpolating points. - */ - private final double y[]; - /** - * Whether the polynomial coefficients are available. - */ - private boolean coefficientsComputed; - - /** - * Construct a Lagrange polynomial with the given abscissas and function - * values. The order of interpolating points are not important. - *- * The constructor makes copy of the input arrays and assigns them.
- * - * @param x interpolating points - * @param y function values at interpolating points - * @throws DimensionMismatchException if the array lengths are different. - * @throws NumberIsTooSmallException if the number of points is less than 2. - * @throws NonMonotonicSequenceException - * if two abscissae have the same value. - */ - public PolynomialFunctionLagrangeForm(double x[], double y[]) - throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { - this.x = new double[x.length]; - this.y = new double[y.length]; - System.arraycopy(x, 0, this.x, 0, x.length); - System.arraycopy(y, 0, this.y, 0, y.length); - coefficientsComputed = false; - - if (!verifyInterpolationArray(x, y, false)) { - MathArrays.sortInPlace(this.x, this.y); - // Second check in case some abscissa is duplicated. - verifyInterpolationArray(this.x, this.y, true); - } - } - - /** - * Calculate the function value at the given point. - * - * @param z Point at which the function value is to be computed. - * @return the function value. - * @throws DimensionMismatchException if {@code x} and {@code y} have - * different lengths. - * @throws NonMonotonicSequenceException - * if {@code x} is not sorted in strictly increasing order. - * @throws NumberIsTooSmallException if the size of {@code x} is less - * than 2. - */ - @Override - public double value(double z) { - return evaluateInternal(x, y, z); - } - - /** - * Returns the degree of the polynomial. - * - * @return the degree of the polynomial - */ - public int degree() { - return x.length - 1; - } - - /** - * Returns a copy of the interpolating points array. - *- * Changes made to the returned copy will not affect the polynomial.
- * - * @return a fresh copy of the interpolating points array - */ - public double[] getInterpolatingPoints() { - double[] out = new double[x.length]; - System.arraycopy(x, 0, out, 0, x.length); - return out; - } - - /** - * Returns a copy of the interpolating values array. - *- * Changes made to the returned copy will not affect the polynomial.
- * - * @return a fresh copy of the interpolating values array - */ - public double[] getInterpolatingValues() { - double[] out = new double[y.length]; - System.arraycopy(y, 0, out, 0, y.length); - return out; - } - - /** - * Returns a copy of the coefficients array. - *- * Changes made to the returned copy will not affect the polynomial.
- *- * Note that coefficients computation can be ill-conditioned. Use with caution - * and only when it is necessary.
- * - * @return a fresh copy of the coefficients array - */ - public double[] getCoefficients() { - if (!coefficientsComputed) { - computeCoefficients(); - } - double[] out = new double[coefficients.length]; - System.arraycopy(coefficients, 0, out, 0, coefficients.length); - return out; - } - - /** - * Evaluate the Lagrange polynomial using - * - * Neville's Algorithm. It takes O(n^2) time. - * - * @param x Interpolating points array. - * @param y Interpolating values array. - * @param z Point at which the function value is to be computed. - * @return the function value. - * @throws DimensionMismatchException if {@code x} and {@code y} have - * different lengths. - * @throws NonMonotonicSequenceException - * if {@code x} is not sorted in strictly increasing order. - * @throws NumberIsTooSmallException if the size of {@code x} is less - * than 2. - */ - public static double evaluate(double x[], double y[], double z) - throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { - if (verifyInterpolationArray(x, y, false)) { - return evaluateInternal(x, y, z); - } - - // Array is not sorted. - final double[] xNew = new double[x.length]; - final double[] yNew = new double[y.length]; - System.arraycopy(x, 0, xNew, 0, x.length); - System.arraycopy(y, 0, yNew, 0, y.length); - - MathArrays.sortInPlace(xNew, yNew); - // Second check in case some abscissa is duplicated. - verifyInterpolationArray(xNew, yNew, true); - return evaluateInternal(xNew, yNew, z); - } - - /** - * Evaluate the Lagrange polynomial using - * - * Neville's Algorithm. It takes O(n^2) time. - * - * @param x Interpolating points array. - * @param y Interpolating values array. - * @param z Point at which the function value is to be computed. - * @return the function value. - * @throws DimensionMismatchException if {@code x} and {@code y} have - * different lengths. - * @throws NonMonotonicSequenceException - * if {@code x} is not sorted in strictly increasing order. - * @throws NumberIsTooSmallException if the size of {@code x} is less - * than 2. - */ - private static double evaluateInternal(double x[], double y[], double z) { - int nearest = 0; - final int n = x.length; - final double[] c = new double[n]; - final double[] d = new double[n]; - double min_dist = Double.POSITIVE_INFINITY; - for (int i = 0; i < n; i++) { - // initialize the difference arrays - c[i] = y[i]; - d[i] = y[i]; - // find out the abscissa closest to z - final double dist = FastMath.abs(z - x[i]); - if (dist < min_dist) { - nearest = i; - min_dist = dist; - } - } - - // initial approximation to the function value at z - double value = y[nearest]; - - for (int i = 1; i < n; i++) { - for (int j = 0; j < n-i; j++) { - final double tc = x[j] - z; - final double td = x[i+j] - z; - final double divider = x[j] - x[i+j]; - // update the difference arrays - final double w = (c[j+1] - d[j]) / divider; - c[j] = tc * w; - d[j] = td * w; - } - // sum up the difference terms to get the final value - if (nearest < 0.5*(n-i+1)) { - value += c[nearest]; // fork down - } else { - nearest--; - value += d[nearest]; // fork up - } - } - - return value; - } - - /** - * Calculate the coefficients of Lagrange polynomial from the - * interpolation data. It takes O(n^2) time. - * Note that this computation can be ill-conditioned: Use with caution - * and only when it is necessary. - */ - protected void computeCoefficients() { - final int n = degree() + 1; - coefficients = new double[n]; - for (int i = 0; i < n; i++) { - coefficients[i] = 0.0; - } - - // c[] are the coefficients of P(x) = (x-x[0])(x-x[1])...(x-x[n-1]) - final double[] c = new double[n+1]; - c[0] = 1.0; - for (int i = 0; i < n; i++) { - for (int j = i; j > 0; j--) { - c[j] = c[j-1] - c[j] * x[i]; - } - c[0] *= -x[i]; - c[i+1] = 1; - } - - final double[] tc = new double[n]; - for (int i = 0; i < n; i++) { - // d = (x[i]-x[0])...(x[i]-x[i-1])(x[i]-x[i+1])...(x[i]-x[n-1]) - double d = 1; - for (int j = 0; j < n; j++) { - if (i != j) { - d *= x[i] - x[j]; - } - } - final double t = y[i] / d; - // Lagrange polynomial is the sum of n terms, each of which is a - // polynomial of degree n-1. tc[] are the coefficients of the i-th - // numerator Pi(x) = (x-x[0])...(x-x[i-1])(x-x[i+1])...(x-x[n-1]). - tc[n-1] = c[n]; // actually c[n] = 1 - coefficients[n-1] += t * tc[n-1]; - for (int j = n-2; j >= 0; j--) { - tc[j] = c[j+1] + tc[j+1] * x[i]; - coefficients[j] += t * tc[j]; - } - } - - coefficientsComputed = true; - } - - /** - * Check that the interpolation arrays are valid. - * The arrays features checked by this method are that both arrays have the - * same length and this length is at least 2. - * - * @param x Interpolating points array. - * @param y Interpolating values array. - * @param abort Whether to throw an exception if {@code x} is not sorted. - * @throws DimensionMismatchException if the array lengths are different. - * @throws NumberIsTooSmallException if the number of points is less than 2. - * @throws NonMonotonicSequenceException - * if {@code x} is not sorted in strictly increasing order and {@code abort} - * is {@code true}. - * @return {@code false} if the {@code x} is not sorted in increasing order, - * {@code true} otherwise. - * @see #evaluate(double[], double[], double) - * @see #computeCoefficients() - */ - public static boolean verifyInterpolationArray(double x[], double y[], boolean abort) - throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { - if (x.length != y.length) { - throw new DimensionMismatchException(x.length, y.length); - } - if (x.length < 2) { - throw new NumberIsTooSmallException(LocalizedFormats.WRONG_NUMBER_OF_POINTS, 2, x.length, true); - } - - return MathArrays.checkOrder(x, MathArrays.OrderDirection.INCREASING, true, abort); - } -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunctionNewtonForm.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunctionNewtonForm.java deleted file mode 100644 index 09fa2b009..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunctionNewtonForm.java +++ /dev/null @@ -1,247 +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.analysis.polynomials; - -import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NoDataException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.MathUtils; - -/** - * Implements the representation of a real polynomial function in - * Newton Form. For reference, see Elementary Numerical Analysis, - * ISBN 0070124477, chapter 2. - *- * The formula of polynomial in Newton form is - * p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... + - * a[n](x-c[0])(x-c[1])...(x-c[n-1]) - * Note that the length of a[] is one more than the length of c[]
- * - * @since 1.2 - */ -public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFunction { - - /** - * The coefficients of the polynomial, ordered by degree -- i.e. - * coefficients[0] is the constant term and coefficients[n] is the - * coefficient of x^n where n is the degree of the polynomial. - */ - private double coefficients[]; - - /** - * Centers of the Newton polynomial. - */ - private final double c[]; - - /** - * When all c[i] = 0, a[] becomes normal polynomial coefficients, - * i.e. a[i] = coefficients[i]. - */ - private final double a[]; - - /** - * Whether the polynomial coefficients are available. - */ - private boolean coefficientsComputed; - - /** - * Construct a Newton polynomial with the given a[] and c[]. The order of - * centers are important in that if c[] shuffle, then values of a[] would - * completely change, not just a permutation of old a[]. - *- * The constructor makes copy of the input arrays and assigns them.
- * - * @param a Coefficients in Newton form formula. - * @param c Centers. - * @throws NullArgumentException if any argument is {@code null}. - * @throws NoDataException if any array has zero length. - * @throws DimensionMismatchException if the size difference between - * {@code a} and {@code c} is not equal to 1. - */ - public PolynomialFunctionNewtonForm(double a[], double c[]) - throws NullArgumentException, NoDataException, DimensionMismatchException { - - verifyInputArray(a, c); - this.a = new double[a.length]; - this.c = new double[c.length]; - System.arraycopy(a, 0, this.a, 0, a.length); - System.arraycopy(c, 0, this.c, 0, c.length); - coefficientsComputed = false; - } - - /** - * Calculate the function value at the given point. - * - * @param z Point at which the function value is to be computed. - * @return the function value. - */ - @Override - public double value(double z) { - return evaluate(a, c, z); - } - - /** - * {@inheritDoc} - * @since 3.1 - */ - @Override - public DerivativeStructure value(final DerivativeStructure t) { - verifyInputArray(a, c); - - final int n = c.length; - DerivativeStructure value = new DerivativeStructure(t.getFreeParameters(), t.getOrder(), a[n]); - for (int i = n - 1; i >= 0; i--) { - value = t.subtract(c[i]).multiply(value).add(a[i]); - } - - return value; - - } - - /** - * Returns the degree of the polynomial. - * - * @return the degree of the polynomial - */ - public int degree() { - return c.length; - } - - /** - * Returns a copy of coefficients in Newton form formula. - *- * Changes made to the returned copy will not affect the polynomial.
- * - * @return a fresh copy of coefficients in Newton form formula - */ - public double[] getNewtonCoefficients() { - double[] out = new double[a.length]; - System.arraycopy(a, 0, out, 0, a.length); - return out; - } - - /** - * Returns a copy of the centers array. - *- * Changes made to the returned copy will not affect the polynomial.
- * - * @return a fresh copy of the centers array. - */ - public double[] getCenters() { - double[] out = new double[c.length]; - System.arraycopy(c, 0, out, 0, c.length); - return out; - } - - /** - * Returns a copy of the coefficients array. - *- * Changes made to the returned copy will not affect the polynomial.
- * - * @return a fresh copy of the coefficients array. - */ - public double[] getCoefficients() { - if (!coefficientsComputed) { - computeCoefficients(); - } - double[] out = new double[coefficients.length]; - System.arraycopy(coefficients, 0, out, 0, coefficients.length); - return out; - } - - /** - * Evaluate the Newton polynomial using nested multiplication. It is - * also called - * Horner's Rule and takes O(N) time. - * - * @param a Coefficients in Newton form formula. - * @param c Centers. - * @param z Point at which the function value is to be computed. - * @return the function value. - * @throws NullArgumentException if any argument is {@code null}. - * @throws NoDataException if any array has zero length. - * @throws DimensionMismatchException if the size difference between - * {@code a} and {@code c} is not equal to 1. - */ - public static double evaluate(double a[], double c[], double z) - throws NullArgumentException, DimensionMismatchException, NoDataException { - verifyInputArray(a, c); - - final int n = c.length; - double value = a[n]; - for (int i = n - 1; i >= 0; i--) { - value = a[i] + (z - c[i]) * value; - } - - return value; - } - - /** - * Calculate the normal polynomial coefficients given the Newton form. - * It also uses nested multiplication but takes O(N^2) time. - */ - protected void computeCoefficients() { - final int n = degree(); - - coefficients = new double[n+1]; - for (int i = 0; i <= n; i++) { - coefficients[i] = 0.0; - } - - coefficients[0] = a[n]; - for (int i = n-1; i >= 0; i--) { - for (int j = n-i; j > 0; j--) { - coefficients[j] = coefficients[j-1] - c[i] * coefficients[j]; - } - coefficients[0] = a[i] - c[i] * coefficients[0]; - } - - coefficientsComputed = true; - } - - /** - * Verifies that the input arrays are valid. - *- * The centers must be distinct for interpolation purposes, but not - * for general use. Thus it is not verified here.
- * - * @param a the coefficients in Newton form formula - * @param c the centers - * @throws NullArgumentException if any argument is {@code null}. - * @throws NoDataException if any array has zero length. - * @throws DimensionMismatchException if the size difference between - * {@code a} and {@code c} is not equal to 1. - * @see org.apache.commons.math4.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[], - * double[]) - */ - protected static void verifyInputArray(double a[], double c[]) - throws NullArgumentException, NoDataException, DimensionMismatchException { - MathUtils.checkNotNull(a); - MathUtils.checkNotNull(c); - if (a.length == 0 || c.length == 0) { - throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); - } - if (a.length != c.length + 1) { - throw new DimensionMismatchException(LocalizedFormats.ARRAY_SIZES_SHOULD_HAVE_DIFFERENCE_1, - a.length, c.length); - } - } - -} diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java deleted file mode 100644 index d7263c2fd..000000000 --- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java +++ /dev/null @@ -1,237 +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.analysis.polynomials; - -import java.util.Arrays; - -import org.apache.commons.math4.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math4.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math4.exception.DimensionMismatchException; -import org.apache.commons.math4.exception.NonMonotonicSequenceException; -import org.apache.commons.math4.exception.NullArgumentException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; -import org.apache.commons.math4.exception.OutOfRangeException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.MathArrays; - -/** - * Represents a polynomial spline function. - *
- * A polynomial spline function consists of a set of
- * interpolating polynomials and an ascending array of domain
- * knot points, determining the intervals over which the spline function
- * is defined by the constituent polynomials. The polynomials are assumed to
- * have been computed to match the values of another function at the knot
- * points. The value consistency constraints are not currently enforced by
- * PolynomialSplineFunction
itself, but are assumed to hold among
- * the polynomials and knot points passed to the constructor.
- * N.B.: The polynomials in the polynomials
property must be
- * centered on the knot points to compute the spline function values.
- * See below.
- * The domain of the polynomial spline function is
- * [smallest knot, largest knot]
. Attempts to evaluate the
- * function at values outside of this range generate IllegalArgumentExceptions.
- *
- * The value of the polynomial spline function for an argument x
- * is computed as follows:
- *
x
- * belongs. If x
is less than the smallest knot point or greater
- * than the largest one, an IllegalArgumentException
- * is thrown.j
be the index of the largest knot point that is less
- * than or equal to x
. The value returned is
- * {@code polynomials[j](x - knot[j])}Chebyshev - * polynomials of the first kind are orthogonal polynomials. - * They can be defined by the following recurrence relations:
- * \( - * T_0(x) = 1 \\ - * T_1(x) = x \\ - * T_{k+1}(x) = 2x T_k(x) - T_{k-1}(x) - * \) - *
- * @param degree degree of the polynomial - * @return Chebyshev polynomial of specified degree - */ - public static PolynomialFunction createChebyshevPolynomial(final int degree) { - return buildPolynomial(degree, CHEBYSHEV_COEFFICIENTS, - new RecurrenceCoefficientsGenerator() { - /** Fixed recurrence coefficients. */ - private final BigFraction[] coeffs = { BigFraction.ZERO, BigFraction.TWO, BigFraction.ONE }; - /** {@inheritDoc} */ - @Override - public BigFraction[] generate(int k) { - return coeffs; - } - }); - } - - /** - * Create a Hermite polynomial. - *Hermite - * polynomials are orthogonal polynomials. - * They can be defined by the following recurrence relations:
- * \( - * H_0(x) = 1 \\ - * H_1(x) = 2x \\ - * H_{k+1}(x) = 2x H_k(X) - 2k H_{k-1}(x) - * \) - *
- - * @param degree degree of the polynomial - * @return Hermite polynomial of specified degree - */ - public static PolynomialFunction createHermitePolynomial(final int degree) { - return buildPolynomial(degree, HERMITE_COEFFICIENTS, - new RecurrenceCoefficientsGenerator() { - /** {@inheritDoc} */ - @Override - public BigFraction[] generate(int k) { - return new BigFraction[] { - BigFraction.ZERO, - BigFraction.TWO, - new BigFraction(2 * k)}; - } - }); - } - - /** - * Create a Laguerre polynomial. - *Laguerre - * polynomials are orthogonal polynomials. - * They can be defined by the following recurrence relations:
- * \( - * L_0(x) = 1 \\ - * L_1(x) = 1 - x \\ - * (k+1) L_{k+1}(x) = (2k + 1 - x) L_k(x) - k L_{k-1}(x) - * \) - *
- * @param degree degree of the polynomial - * @return Laguerre polynomial of specified degree - */ - public static PolynomialFunction createLaguerrePolynomial(final int degree) { - return buildPolynomial(degree, LAGUERRE_COEFFICIENTS, - new RecurrenceCoefficientsGenerator() { - /** {@inheritDoc} */ - @Override - public BigFraction[] generate(int k) { - final int kP1 = k + 1; - return new BigFraction[] { - new BigFraction(2 * k + 1, kP1), - new BigFraction(-1, kP1), - new BigFraction(k, kP1)}; - } - }); - } - - /** - * Create a Legendre polynomial. - *Legendre - * polynomials are orthogonal polynomials. - * They can be defined by the following recurrence relations:
- * \( - * P_0(x) = 1 \\ - * P_1(x) = x \\ - * (k+1) P_{k+1}(x) = (2k+1) x P_k(x) - k P_{k-1}(x) - * \) - *
- * @param degree degree of the polynomial - * @return Legendre polynomial of specified degree - */ - public static PolynomialFunction createLegendrePolynomial(final int degree) { - return buildPolynomial(degree, LEGENDRE_COEFFICIENTS, - new RecurrenceCoefficientsGenerator() { - /** {@inheritDoc} */ - @Override - public BigFraction[] generate(int k) { - final int kP1 = k + 1; - return new BigFraction[] { - BigFraction.ZERO, - new BigFraction(k + kP1, kP1), - new BigFraction(k, kP1)}; - } - }); - } - - /** - * Create a Jacobi polynomial. - *Jacobi - * polynomials are orthogonal polynomials. - * They can be defined by the following recurrence relations:
- * \( - * P_0^{vw}(x) = 1 \\ - * P_{-1}^{vw}(x) = 0 \\ - * 2k(k + v + w)(2k + v + w - 2) P_k^{vw}(x) = \\ - * (2k + v + w - 1)[(2k + v + w)(2k + v + w - 2) x + v^2 - w^2] P_{k-1}^{vw}(x) \\ - * - 2(k + v - 1)(k + w - 1)(2k + v + w) P_{k-2}^{vw}(x) - * \) - *
- * @param degree degree of the polynomial - * @param v first exponent - * @param w second exponent - * @return Jacobi polynomial of specified degree - */ - public static PolynomialFunction createJacobiPolynomial(final int degree, final int v, final int w) { - - // select the appropriate list - final JacobiKey key = new JacobiKey(v, w); - - if (!JACOBI_COEFFICIENTS.containsKey(key)) { - - // allocate a new list for v, w - final List
- * More precisely, let \(\Delta = \) {@code shift} and let
- * \(P_s(x) = P(x + \Delta)\). The returned array
- * consists of the coefficients of \(P_s\). So if \(a_0, ..., a_{n-1}\)
- * are the coefficients of \(P\), then the returned array
- * \(b_0, ..., b_{n-1}\) satisfies the identity
- * \(\sum_{i=0}^{n-1} b_i x^i = \sum_{i=0}^{n-1} a_i (x + \Delta)^i\) for all \(x\).
- *
- * @param coefficients Coefficients of the original polynomial.
- * @param shift Shift value.
- * @return the coefficients \(b_i\) of the shifted
- * polynomial.
- */
- public static double[] shift(final double[] coefficients,
- final double shift) {
- final int dp1 = coefficients.length;
- final double[] newCoefficients = new double[dp1];
-
- // Pascal triangle.
- final int[][] coeff = new int[dp1][dp1];
- for (int i = 0; i < dp1; i++){
- for(int j = 0; j <= i; j++){
- coeff[i][j] = (int) BinomialCoefficient.value(i, j);
- }
- }
-
- // First polynomial coefficient.
- for (int i = 0; i < dp1; i++){
- newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i);
- }
-
- // Superior order.
- final int d = dp1 - 1;
- for (int i = 0; i < d; i++) {
- for (int j = i; j < d; j++){
- newCoefficients[i + 1] += coeff[j + 1][j - i] *
- coefficients[j + 1] * FastMath.pow(shift, j - i);
- }
- }
-
- return newCoefficients;
- }
-
-
- /** Get the coefficients array for a given degree.
- * @param degree degree of the polynomial
- * @param coefficients list where the computed coefficients are stored
- * @param generator recurrence coefficients generator
- * @return coefficients array
- */
- private static PolynomialFunction buildPolynomial(final int degree,
- final List If all solutions are accepted ({@link #ANY_SIDE}), then the solution
- * that the root-finding algorithm returns for a given root may be equal to the
- * actual root, but it may also be an approximation that is slightly smaller
- * or slightly larger than the actual root. Root-finding algorithms generally
- * only guarantee that the returned solution is within the requested
- * tolerances. In certain cases however, in particular for
- * org.apache.commons.math4.ode.events.EventHandler state events of
- * org.apache.commons.math4.ode.ODEIntegrator ODE solvers, it
- * may be necessary to guarantee that a solution is returned that lies on a
- * specific side the solution. Implementation of the {@link RegulaFalsiSolver Regula Falsi} and
- * {@link IllinoisSolver Illinois} methods is based on the
- * following article: M. Dowell and P. Jarratt,
- * A modified regula falsi method for computing the root of an
- * equation, BIT Numerical Mathematics, volume 11, number 2,
- * pages 168-174, Springer, 1971. Implementation of the {@link PegasusSolver Pegasus} method is
- * based on the following article: M. Dowell and P. Jarratt,
- * The "Pegasus" method for computing the root of an equation,
- * BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer,
- * 1972. The {@link SecantSolver Secant} method is not a
- * bracketing method, so it is not implemented here. It has a separate
- * implementation.
- * The function should be continuous but not necessarily smooth. For backwards compatibility, all root-finding algorithms must have
- * {@link AllowedSolution#ANY_SIDE ANY_SIDE} as default for the allowed
- * solutions. For backwards compatibility, all root-finding algorithms must have
- * {@link AllowedSolution#ANY_SIDE ANY_SIDE} as default for the allowed
- * solutions.
- * The changes with respect to the original Brent algorithm are:
- *
- * The given interval must bracket the root.
- * The x value is guessed by evaluating polynomial Q(y) at y = targetY, where Q
- * is built such that for all considered points (xi, yi),
- * Q(yi) = xi.
- * The given interval must bracket the root.
- * The reference implementation is given in chapter 4 of
- *
- * The changes with respect to the original Brent algorithm are:
- *
- * The given interval must bracket the root.
- * The x value is guessed by evaluating polynomial Q(y) at y = targetY, where Q
- * is built such that for all considered points (xi, yi),
- * Q(yi) = xi.
- * Like the Regula Falsi method, convergence is guaranteed by
- * maintaining a bracketed solution. The Illinois method however,
- * should converge much faster than the original Regula Falsi
- * method. Furthermore, this implementation of the Illinois method
- * should not suffer from the same implementation issues as the Regula
- * Falsi method, which may fail to convergence in certain cases. The Illinois method assumes that the function is continuous,
- * but not necessarily smooth. Implementation based on the following article: M. Dowell and P. Jarratt,
- * A modified regula falsi method for computing the root of an
- * equation, BIT Numerical Mathematics, volume 11, number 2,
- * pages 168-174, Springer, 1971.
- * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
- * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
- * Muller's method applies to both real and complex functions, but here we
- * restrict ourselves to real functions.
- * This class differs from {@link MullerSolver} in the way it avoids complex
- * operations.
- * Muller's original method would have function evaluation at complex point.
- * Since our f(x) is real, we have to find ways to avoid that. Bracketing
- * condition is one way to go: by requiring bracketing in every iteration,
- * the newly computed approximation is guaranteed to be real.
- * Normally Muller's method converges quadratically in the vicinity of a
- * zero, however it may be very slow in regions far away from zeros. For
- * example, f(x) = exp(x) - 1, min = -50, max = 100. In such case we use
- * bisection as a safety backup if it performs very poorly.
- * The formulas here use divided differences directly.
- * Muller's method applies to both real and complex functions, but here we
- * restrict ourselves to real functions.
- * This class differs from {@link MullerSolver} in the way it avoids complex
- * operations.
- * Except for the initial [min, max], it does not require bracketing
- * condition, e.g. f(x0), f(x1), f(x2) can have the same sign. If a complex
- * number arises in the computation, we simply use its modulus as a real
- * approximation.
- * Because the interval may not be bracketing, the bisection alternative is
- * not applicable here. However in practice our treatment usually works
- * well, especially near real zeroes where the imaginary part of the complex
- * approximation is often negligible.
- * The formulas here do not use divided differences directly. Like the Regula Falsi method, convergence is guaranteed by
- * maintaining a bracketed solution. The Pegasus method however,
- * should converge much faster than the original Regula Falsi
- * method. Furthermore, this implementation of the Pegasus method
- * should not suffer from the same implementation issues as the Regula
- * Falsi method, which may fail to convergence in certain cases. Also,
- * the Pegasus method should converge faster than the
- * {@link IllinoisSolver Illinois} method, another Regula
- * Falsi-based method. The Pegasus method assumes that the function is continuous,
- * but not necessarily smooth. Implementation based on the following article: M. Dowell and P. Jarratt,
- * The "Pegasus" method for computing the root of an equation,
- * BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer,
- * 1972. The Regula Falsi method is included for completeness, for
- * testing purposes, for educational purposes, for comparison to other
- * algorithms, etc. It is however not intended to be used
- * for actual problems, as one of the bounds often remains fixed, resulting
- * in very slow convergence. Instead, one of the well-known modified
- * Regula Falsi algorithms can be used ({@link IllinoisSolver
- * Illinois} or {@link PegasusSolver Pegasus}). These two
- * algorithms solve the fundamental issues of the original Regula
- * Falsi algorithm, and greatly out-performs it for most, if not all,
- * (practical) functions.
- *
- * Unlike the Secant method, the Regula Falsi guarantees
- * convergence, by maintaining a bracketed solution. Note however, that due to
- * the finite/limited precision of Java's {@link Double double} type, which is
- * used in this implementation, the algorithm may get stuck in a situation
- * where it no longer makes any progress. Such cases are detected and result
- * in a {@code ConvergenceException} exception being thrown. In other words,
- * the algorithm theoretically guarantees convergence, but the implementation
- * does not. The Regula Falsi method assumes that the function is continuous,
- * but not necessarily smooth. Implementation based on the following article: M. Dowell and P. Jarratt,
- * A modified regula falsi method for computing the root of an
- * equation, BIT Numerical Mathematics, volume 11, number 2,
- * pages 168-174, Springer, 1971.
- * The function should be continuous but not necessarily smooth. Implementation based on the following article: M. Dowell and P. Jarratt,
- * A modified regula falsi method for computing the root of an
- * equation, BIT Numerical Mathematics, volume 11, number 2,
- * pages 168-174, Springer, 1971. Note that since release 3.0 this class implements the actual
- * Secant algorithm, and not a modified one. As such, the 3.0 version
- * is not backwards compatible with previous versions. To use an algorithm
- * similar to the pre-3.0 releases, use the
- * {@link IllinoisSolver Illinois} algorithm or the
- * {@link PegasusSolver Pegasus} algorithm.
- * Note: this method can take {@code Integer.MAX_VALUE}
- * iterations to throw a {@code ConvergenceException.} Unless you are
- * confident that there is a root between {@code lowerBound} and
- * {@code upperBound} near {@code initial}, it is better to use
- * {@link #bracket(UnivariateFunction, double, double, double, double,double, int)
- * bracket(function, initial, lowerBound, upperBound, q, r, maximumIterations)},
- * explicitly specifying the maximum number of iterations.
- * The algorithm checks the sign of \( f(l_k) \) and \( f(u_k) \) for increasing
- * values of k, where \( l_k = max(lower, initial - \delta_k) \),
- * \( u_k = min(upper, initial + \delta_k) \), using recurrence
- * \( \delta_{k+1} = r \delta_k + q, \delta_0 = 0\) and starting search with \( k=1 \).
- * The algorithm stops when one of the following happens:
- * If different signs are found at first iteration ({@code k=1}), then the returned
- * interval will be \( [a, b] = [l_1, u_1] \). If different signs are found at a later
- * iteration {@code k>1}, then the returned interval will be either
- * \( [a, b] = [l_{k+1}, l_{k}] \) or \( [a, b] = [u_{k}, u_{k+1}] \). A root solver called
- * with these parameters will therefore start with the smallest bracketing interval known
- * at this step.
- *
- * Interval expansion rate is tuned by changing the recurrence parameters {@code r} and
- * {@code q}. When the multiplicative factor {@code r} is set to 1, the sequence is a
- * simple arithmetic sequence with linear increase. When the multiplicative factor {@code r}
- * is larger than 1, the sequence has an asymptotically exponential rate. Note than the
- * additive parameter {@code q} should never be set to zero, otherwise the interval would
- * degenerate to the single initial point for all values of {@code k}.
- *
- * As a rule of thumb, when the location of the root is expected to be approximately known
- * within some error margin, {@code r} should be set to 1 and {@code q} should be set to the
- * order of magnitude of the error margin. When the location of the root is really a wild guess,
- * then {@code r} should be set to a value larger than 1 (typically 2 to double the interval
- * length at each iteration) and {@code q} should be set according to half the initial
- * search interval length.
- *
- * As an example, if we consider the trivial function {@code f(x) = 1 - x} and use
- * {@code initial = 4}, {@code r = 1}, {@code q = 2}, the algorithm will compute
- * {@code f(4-2) = f(2) = -1} and {@code f(4+2) = f(6) = -5} for {@code k = 1}, then
- * {@code f(4-4) = f(0) = +1} and {@code f(4+4) = f(8) = -7} for {@code k = 2}. Then it will
- * return the interval {@code [0, 2]} as the smallest one known to be bracketing the root.
- * As shown by this example, the initial value (here {@code 4}) may lie outside of the returned
- * bracketing interval.
- * {@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}
- * The default implementation simply computes the logarithm of {@code probability(x)}.
- */
- @Override
- public double logProbability(int x) {
- return FastMath.log(probability(x));
- }
-
- /**
- * Utility function for allocating an array and filling it with {@code n}
- * samples generated by the given {@code sampler}.
- *
- * @param n Number of samples.
- * @param sampler Sampler.
- * @return an array of size {@code n}.
- */
- public static int[] sample(int n,
- Sampler sampler) {
- final int[] samples = new int[n];
- for (int i = 0; i < n; i++) {
- samples[i] = sampler.sample();
- }
- return samples;
- }
-
- /**{@inheritDoc} */
- @Override
- public Sampler createSampler(final UniformRandomProvider rng) {
- return new Sampler() {
- /**
- * Inversion method distribution sampler.
- */
- private final DiscreteSampler sampler =
- new InverseTransformDiscreteSampler(rng, createICPF());
-
- /** {@inheritDoc} */
- @Override
- public int sample() {
- return sampler.sample();
- }
- };
- }
-
- /**
- * @return an instance for use by {@link #createSampler(UniformRandomProvider)}
- */
- private DiscreteInverseCumulativeProbabilityFunction createICPF() {
- return new DiscreteInverseCumulativeProbabilityFunction() {
- /** {@inheritDoc} */
- @Override
- public int inverseCumulativeProbability(double p) {
- return AbstractIntegerDistribution.this.inverseCumulativeProbability(p);
- }
- };
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractMultivariateRealDistribution.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractMultivariateRealDistribution.java
deleted file mode 100644
index f48d188b4..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractMultivariateRealDistribution.java
+++ /dev/null
@@ -1,72 +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.distribution;
-
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
-
-/**
- * Base class for multivariate probability distributions.
- *
- * @since 3.1
- */
-public abstract class AbstractMultivariateRealDistribution
- implements MultivariateRealDistribution {
- /** The number of dimensions or columns in the multivariate distribution. */
- private final int dimension;
-
- /**
- * @param n Number of dimensions.
- */
- protected AbstractMultivariateRealDistribution(int n) {
- dimension = n;
- }
-
- /** {@inheritDoc} */
- @Override
- public int getDimension() {
- return dimension;
- }
-
- /** {@inheritDoc} */
- @Override
- public abstract Sampler createSampler(UniformRandomProvider rng);
-
- /**
- * Utility function for creating {@code n} vectors generated by the
- * given {@code sampler}.
- *
- * @param n Number of samples.
- * @param sampler Sampler.
- * @return an array of size {@code n} whose elements are random vectors
- * sampled from this distribution.
- */
- public static double[][] sample(int n,
- MultivariateRealDistribution.Sampler sampler) {
- if (n <= 0) {
- throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
- n);
- }
-
- final double[][] samples = new double[n][];
- for (int i = 0; i < n; i++) {
- samples[i] = sampler.sample();
- }
- return samples;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
deleted file mode 100644
index 20f02ab63..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
+++ /dev/null
@@ -1,277 +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.distribution;
-
-import java.io.Serializable;
-
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.analysis.solvers.UnivariateSolverUtils;
-import org.apache.commons.math4.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSampler;
-import org.apache.commons.rng.sampling.distribution.ContinuousInverseCumulativeProbabilityFunction;
-import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Base class for probability distributions on the reals.
- * Default implementations are provided for some of the methods
- * that do not vary from distribution to distribution.
- *
- *
- * This base class provides a default factory method for creating
- * a {@link Sampler
- * sampler instance} that uses the
- *
- * inversion method for generating random samples that follow the
- * distribution.
- *
- * The default implementation simply computes the logarithm of {@code density(x)}.
- */
- @Override
- public double logDensity(double x) {
- return FastMath.log(density(x));
- }
-
- /**
- * Utility function for allocating an array and filling it with {@code n}
- * samples generated by the given {@code sampler}.
- *
- * @param n Number of samples.
- * @param sampler Sampler.
- * @return an array of size {@code n}.
- */
- public static double[] sample(int n,
- Sampler sampler) {
- final double[] samples = new double[n];
- for (int i = 0; i < n; i++) {
- samples[i] = sampler.sample();
- }
- return samples;
- }
-
- /**{@inheritDoc} */
- @Override
- public Sampler createSampler(final UniformRandomProvider rng) {
- return new Sampler() {
- /**
- * Inversion method distribution sampler.
- */
- private final ContinuousSampler sampler =
- new InverseTransformContinuousSampler(rng, createICPF());
-
- /** {@inheritDoc} */
- @Override
- public double sample() {
- return sampler.sample();
- }
- };
- }
-
- /**
- * @return an instance for use by {@link #createSampler(UniformRandomProvider)}
- */
- private ContinuousInverseCumulativeProbabilityFunction createICPF() {
- return new ContinuousInverseCumulativeProbabilityFunction() {
- /** {@inheritDoc} */
- @Override
- public double inverseCumulativeProbability(double p) {
- return AbstractRealDistribution.this.inverseCumulativeProbability(p);
- }
- };
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EmpiricalDistribution.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EmpiricalDistribution.java
deleted file mode 100644
index 65ee260d1..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EmpiricalDistribution.java
+++ /dev/null
@@ -1,747 +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.distribution;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.statistics.distribution.NormalDistribution;
-import org.apache.commons.statistics.distribution.ContinuousDistribution;
-import org.apache.commons.statistics.distribution.ConstantContinuousDistribution;
-import org.apache.commons.math4.exception.MathIllegalStateException;
-import org.apache.commons.math4.exception.MathInternalError;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.exception.ZeroException;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.stat.descriptive.StatisticalSummary;
-import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathUtils;
-
-/**
- * Represents an
- * empirical probability distribution -- a probability distribution derived
- * from observed data without making any assumptions about the functional form
- * of the population distribution that the data come from. An The implementation uses what amounts to the
- *
- * Variable Kernel Method with Gaussian smoothing:
- * Digesting the input file
- * EmpiricalDistribution implements the {@link RealDistribution} interface
- * as follows. Given x within the range of values in the dataset, let B
- * be the bin containing x and let K be the within-bin kernel for B. Let P(B-)
- * be the sum of the probabilities of the bins below B and let K(B) be the
- * mass of B under K (i.e., the integral of the kernel density over B). Then
- * set {@code P(X < x) = P(B-) + P(B) * K(x) / K(B)} where {@code K(x)} is the
- * kernel distribution evaluated at x. This results in a cdf that matches the
- * grouped frequency distribution at the bin endpoints and interpolates within
- * bins using within-bin kernels. The input file must be an ASCII text file containing one
- * valid numeric entry per line. The input file must be an ASCII text file containing one
- * valid numeric entry per line. Returns a fresh copy of the array of upper bounds for the bins.
- * Bins are: Note: In versions 1.0-2.0 of commons-math, this method
- * incorrectly returned the array of probability generator upper
- * bounds now returned by {@link #getGeneratorUpperBounds()}. Returns a fresh copy of the array of upper bounds of the subintervals
- * of [0,1] used in generating data from the empirical distribution.
- * Subintervals correspond to bins with lengths proportional to bin counts. In versions 1.0-2.0 of commons-math, this array was (incorrectly) returned
- * by {@link #getUpperBounds()}. Returns the kernel density normalized so that its integral over each bin
- * equals the bin mass. Algorithm description: Algorithm description: Algorithm description: A generic implementation of a
- *
- * discrete probability distribution (Wikipedia) over a finite sample space,
- * based on an enumerated list of <value, probability> pairs. Input probabilities must all be non-negative,
- * but zero values are allowed and their sum does not have to equal one. Constructors will normalize input
- * probabilities to make them sum to one. The list of <value, probability> pairs does not, strictly speaking, have to be a function and it can
- * contain null values. The pmf created by the constructor will combine probabilities of equal values and
- * will treat null values as equal. For example, if the list of pairs <"dog", 0.2>, <null, 0.1>,
- * <"pig", 0.2>, <"dog", 0.1>, <null, 0.4> is provided to the constructor, the resulting
- * pmf will assign mass of 0.5 to null, 0.3 to "dog" and 0.2 to null. For a random variable {@code X} whose values are distributed according to
- * this distribution, this method returns {@code P(X = x)}. In other words,
- * this method represents the probability mass function (PMF) for the
- * distribution. Note that if {@code x1} and {@code x2} satisfy {@code x1.equals(x2)},
- * or both are null, then {@code probability(x1) = probability(x2)}. Return the probability mass function as a list of <value, probability> pairs. Note that if duplicate and / or null values were provided to the constructor
- * when creating this EnumeratedDistribution, the returned list will contain these
- * values. If duplicates values exist, what is returned will not represent
- * a pmf (i.e., it is up to the caller to consolidate duplicate mass points).
- * If the requested samples fit in the specified array, it is returned
- * therein. Otherwise, a new array is allocated with the runtime type of
- * the specified array and the size of this collection.
- *
- * @param sampleSize the number of random values to generate.
- * @param array the array to populate.
- * @return an array representing the random sample.
- * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive.
- * @throws NullArgumentException if {@code array} is null
- */
- public T[] sample(int sampleSize, final T[] array) throws NotStrictlyPositiveException {
- if (sampleSize <= 0) {
- throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize);
- }
-
- if (array == null) {
- throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
- }
-
- T[] out;
- if (array.length < sampleSize) {
- @SuppressWarnings("unchecked") // safe as both are of type T
- final T[] unchecked = (T[]) Array.newInstance(array.getClass().getComponentType(), sampleSize);
- out = unchecked;
- } else {
- out = array;
- }
-
- for (int i = 0; i < sampleSize; i++) {
- out[i] = sample();
- }
-
- return out;
- }
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistribution.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistribution.java
deleted file mode 100644
index c12227141..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedIntegerDistribution.java
+++ /dev/null
@@ -1,246 +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.distribution;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.NotANumberException;
-import org.apache.commons.math4.exception.NotFiniteNumberException;
-import org.apache.commons.math4.exception.NotPositiveException;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.math4.util.Pair;
-
-/**
- * Implementation of an integer-valued {@link EnumeratedDistribution}. Values with zero-probability are allowed but they do not extend the
- * support. Implementation of a real-valued {@link EnumeratedDistribution}.
- *
- * Values with zero-probability are allowed but they do not extend the
- * support.
- * The number of dimensions is equal to the length of the mean vector
- * and to the number of rows and columns of the covariance matrix.
- * It is frequently written as "p" in formulae.
- *
- * Note: from 4.0 onwards, this class extends {@link NullPointerException} instead
- * of {@link MathIllegalArgumentException}.
- *
- * @since 2.2
- */
-public class NullArgumentException extends NullPointerException
- implements ExceptionContextProvider {
-
- /** Serializable version Id. */
- private static final long serialVersionUID = 20150225L;
-
- /** Context. */
- private final ExceptionContext context;
-
- /**
- * Default constructor.
- */
- public NullArgumentException() {
- this(LocalizedFormats.NULL_NOT_ALLOWED);
- }
- /**
- * @param pattern Message pattern providing the specific context of
- * the error.
- * @param arguments Values for replacing the placeholders in {@code pattern}.
- */
- public NullArgumentException(Localizable pattern,
- Object ... arguments) {
- context = new ExceptionContext(this);
- context.addMessage(pattern, arguments);
- }
-
- /**
- * {@inheritDoc}
- * @since 4.0
- */
- @Override
- public ExceptionContext getContext() {
- return context;
- }
-
- /** {@inheritDoc} */
- @Override
- public String getMessage() {
- return context.getMessage();
- }
-
- /** {@inheritDoc} */
- @Override
- public String getLocalizedMessage() {
- return context.getLocalizedMessage();
- }
-
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooLargeException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooLargeException.java
deleted file mode 100644
index 9498320a2..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooLargeException.java
+++ /dev/null
@@ -1,85 +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.exception;
-
-import org.apache.commons.math4.exception.util.Localizable;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when a number is too large.
- *
- * @since 2.2
- */
-public class NumberIsTooLargeException extends MathIllegalNumberException {
- /** Serializable version Id. */
- private static final long serialVersionUID = 4330003017885151975L;
- /**
- * Higher bound.
- */
- private final Number max;
- /**
- * Whether the maximum is included in the allowed range.
- */
- private final boolean boundIsAllowed;
-
- /**
- * Construct the exception.
- *
- * @param wrong Value that is larger than the maximum.
- * @param max Maximum.
- * @param boundIsAllowed if true the maximum is included in the allowed range.
- */
- public NumberIsTooLargeException(Number wrong,
- Number max,
- boolean boundIsAllowed) {
- this(boundIsAllowed ?
- LocalizedFormats.NUMBER_TOO_LARGE :
- LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
- wrong, max, boundIsAllowed);
- }
- /**
- * Construct the exception with a specific context.
- *
- * @param specific Specific context pattern.
- * @param wrong Value that is larger than the maximum.
- * @param max Maximum.
- * @param boundIsAllowed if true the maximum is included in the allowed range.
- */
- public NumberIsTooLargeException(Localizable specific,
- Number wrong,
- Number max,
- boolean boundIsAllowed) {
- super(specific, wrong, max);
-
- this.max = max;
- this.boundIsAllowed = boundIsAllowed;
- }
-
- /**
- * @return {@code true} if the maximum is included in the allowed range.
- */
- public boolean getBoundIsAllowed() {
- return boundIsAllowed;
- }
-
- /**
- * @return the maximum.
- */
- public Number getMax() {
- return max;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooSmallException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooSmallException.java
deleted file mode 100644
index 5a6cf700a..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/NumberIsTooSmallException.java
+++ /dev/null
@@ -1,86 +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.exception;
-
-import org.apache.commons.math4.exception.util.Localizable;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when a number is too small.
- *
- * @since 2.2
- */
-public class NumberIsTooSmallException extends MathIllegalNumberException {
- /** Serializable version Id. */
- private static final long serialVersionUID = -6100997100383932834L;
- /**
- * Higher bound.
- */
- private final Number min;
- /**
- * Whether the maximum is included in the allowed range.
- */
- private final boolean boundIsAllowed;
-
- /**
- * Construct the exception.
- *
- * @param wrong Value that is smaller than the minimum.
- * @param min Minimum.
- * @param boundIsAllowed Whether {@code min} is included in the allowed range.
- */
- public NumberIsTooSmallException(Number wrong,
- Number min,
- boolean boundIsAllowed) {
- this(boundIsAllowed ?
- LocalizedFormats.NUMBER_TOO_SMALL :
- LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
- wrong, min, boundIsAllowed);
- }
-
- /**
- * Construct the exception with a specific context.
- *
- * @param specific Specific context pattern.
- * @param wrong Value that is smaller than the minimum.
- * @param min Minimum.
- * @param boundIsAllowed Whether {@code min} is included in the allowed range.
- */
- public NumberIsTooSmallException(Localizable specific,
- Number wrong,
- Number min,
- boolean boundIsAllowed) {
- super(specific, wrong, min);
-
- this.min = min;
- this.boundIsAllowed = boundIsAllowed;
- }
-
- /**
- * @return {@code true} if the minimum is included in the allowed range.
- */
- public boolean getBoundIsAllowed() {
- return boundIsAllowed;
- }
-
- /**
- * @return the minimum.
- */
- public Number getMin() {
- return min;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/OutOfRangeException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/OutOfRangeException.java
deleted file mode 100644
index 4e8dd6212..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/OutOfRangeException.java
+++ /dev/null
@@ -1,78 +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.exception;
-
-import org.apache.commons.math4.exception.util.Localizable;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when some argument is out of range.
- *
- * @since 2.2
- */
-public class OutOfRangeException extends MathIllegalNumberException {
- /** Serializable version Id. */
- private static final long serialVersionUID = 111601815794403609L;
- /** Lower bound. */
- private final Number lo;
- /** Higher bound. */
- private final Number hi;
-
- /**
- * Construct an exception from the mismatched dimensions.
- *
- * @param wrong Requested value.
- * @param lo Lower bound.
- * @param hi Higher bound.
- */
- public OutOfRangeException(Number wrong,
- Number lo,
- Number hi) {
- this(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
- }
-
- /**
- * Construct an exception from the mismatched dimensions with a
- * specific context information.
- *
- * @param specific Context information.
- * @param wrong Requested value.
- * @param lo Lower bound.
- * @param hi Higher bound.
- */
- public OutOfRangeException(Localizable specific,
- Number wrong,
- Number lo,
- Number hi) {
- super(specific, wrong, lo, hi);
- this.lo = lo;
- this.hi = hi;
- }
-
- /**
- * @return the lower bound.
- */
- public Number getLo() {
- return lo;
- }
- /**
- * @return the higher bound.
- */
- public Number getHi() {
- return hi;
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyEvaluationsException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyEvaluationsException.java
deleted file mode 100644
index 45d3c3aec..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyEvaluationsException.java
+++ /dev/null
@@ -1,39 +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.exception;
-
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when the maximal number of evaluations is exceeded.
- *
- * @since 3.0
- */
-public class TooManyEvaluationsException extends MaxCountExceededException {
- /** Serializable version Id. */
- private static final long serialVersionUID = 4330003017885151975L;
-
- /**
- * Construct the exception.
- *
- * @param max Maximum number of evaluations.
- */
- public TooManyEvaluationsException(Number max) {
- super(max);
- getContext().addMessage(LocalizedFormats.EVALUATIONS);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyIterationsException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyIterationsException.java
deleted file mode 100644
index bd68f6ee2..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/TooManyIterationsException.java
+++ /dev/null
@@ -1,39 +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.exception;
-
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when the maximal number of iterations is exceeded.
- *
- * @since 3.1
- */
-public class TooManyIterationsException extends MaxCountExceededException {
- /** Serializable version Id. */
- private static final long serialVersionUID = 20121211L;
-
- /**
- * Construct the exception.
- *
- * @param max Maximum number of evaluations.
- */
- public TooManyIterationsException(Number max) {
- super(max);
- getContext().addMessage(LocalizedFormats.ITERATIONS);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/ZeroException.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/ZeroException.java
deleted file mode 100644
index 617193a4f..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/ZeroException.java
+++ /dev/null
@@ -1,48 +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.exception;
-
-import org.apache.commons.math4.exception.util.Localizable;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-
-/**
- * Exception to be thrown when zero is provided where it is not allowed.
- *
- * @since 2.2
- */
-public class ZeroException extends MathIllegalNumberException {
-
- /** Serializable version identifier */
- private static final long serialVersionUID = -1960874856936000015L;
-
- /**
- * Construct the exception.
- */
- public ZeroException() {
- this(LocalizedFormats.ZERO_NOT_ALLOWED);
- }
-
- /**
- * Construct the exception with a specific context.
- *
- * @param specific Specific context pattern.
- * @param arguments Arguments.
- */
- public ZeroException(Localizable specific, Object ... arguments) {
- super(specific, INTEGER_ZERO, arguments);
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/package-info.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/package-info.java
deleted file mode 100644
index 884f4c3fd..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-/**
- *
- * Specialized exceptions for algorithms errors. The exceptions can be localized
- * using simple java properties.
- *
- */
-package org.apache.commons.math4.exception;
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/util/ArgUtils.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/util/ArgUtils.java
deleted file mode 100644
index 6e447a019..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/exception/util/ArgUtils.java
+++ /dev/null
@@ -1,55 +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.exception.util;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * Utility class for transforming the list of arguments passed to
- * constructors of exceptions.
- *
- */
-public class ArgUtils {
- /**
- * Class contains only static methods.
- */
- private ArgUtils() {}
-
- /**
- * Transform a multidimensional array into a one-dimensional list.
- *
- * @param array Array (possibly multidimensional).
- * @return a list of all the {@code Object} instances contained in
- * {@code array}.
- */
- public static Object[] flatten(Object[] array) {
- final List
- *
- *
- *
- *
- *
- *
- *
- * Algorithms for Minimization Without Derivatives,
- * Richard P. Brent,
- * Dover, 2002
- *
- *
- * @see BaseAbstractUnivariateSolver
- */
-public class BrentSolver extends AbstractUnivariateSolver {
-
- /** Default absolute accuracy. */
- private static final double DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
-
- /**
- * Construct a solver with default absolute accuracy (1e-6).
- */
- public BrentSolver() {
- this(DEFAULT_ABSOLUTE_ACCURACY);
- }
- /**
- * Construct a solver.
- *
- * @param absoluteAccuracy Absolute accuracy.
- */
- public BrentSolver(double absoluteAccuracy) {
- super(absoluteAccuracy);
- }
- /**
- * Construct a solver.
- *
- * @param relativeAccuracy Relative accuracy.
- * @param absoluteAccuracy Absolute accuracy.
- */
- public BrentSolver(double relativeAccuracy,
- double absoluteAccuracy) {
- super(relativeAccuracy, absoluteAccuracy);
- }
- /**
- * Construct a solver.
- *
- * @param relativeAccuracy Relative accuracy.
- * @param absoluteAccuracy Absolute accuracy.
- * @param functionValueAccuracy Function value accuracy.
- *
- * @see BaseAbstractUnivariateSolver#BaseAbstractUnivariateSolver(double,double,double)
- */
- public BrentSolver(double relativeAccuracy,
- double absoluteAccuracy,
- double functionValueAccuracy) {
- super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected double doSolve()
- throws NoBracketingException,
- TooManyEvaluationsException,
- NumberIsTooLargeException {
- double min = getMin();
- double max = getMax();
- final double initial = getStartValue();
- final double functionValueAccuracy = getFunctionValueAccuracy();
-
- verifySequence(min, initial, max);
-
- // Return the initial guess if it is good enough.
- double yInitial = computeObjectiveValue(initial);
- if (FastMath.abs(yInitial) <= functionValueAccuracy) {
- return initial;
- }
-
- // Return the first endpoint if it is good enough.
- double yMin = computeObjectiveValue(min);
- if (FastMath.abs(yMin) <= functionValueAccuracy) {
- return min;
- }
-
- // Reduce interval if min and initial bracket the root.
- if (yInitial * yMin < 0) {
- return brent(min, initial, yMin, yInitial);
- }
-
- // Return the second endpoint if it is good enough.
- double yMax = computeObjectiveValue(max);
- if (FastMath.abs(yMax) <= functionValueAccuracy) {
- return max;
- }
-
- // Reduce interval if initial and max bracket the root.
- if (yInitial * yMax < 0) {
- return brent(initial, max, yInitial, yMax);
- }
-
- throw new NoBracketingException(min, max, yMin, yMax);
- }
-
- /**
- * Search for a zero inside the provided interval.
- * This implementation is based on the algorithm described at page 58 of
- * the book
- *
- * Algorithms for Minimization Without Derivatives,
- *
- *
- * @param lo Lower bound of the search interval.
- * @param hi Higher bound of the search interval.
- * @param fLo Function value at the lower bound of the search interval.
- * @param fHi Function value at the higher bound of the search interval.
- * @return the value where the function is zero.
- */
- private double brent(double lo, double hi,
- double fLo, double fHi) {
- double a = lo;
- double fa = fLo;
- double b = hi;
- double fb = fHi;
- double c = a;
- double fc = fa;
- double d = b - a;
- double e = d;
-
- final double t = getAbsoluteAccuracy();
- final double eps = getRelativeAccuracy();
-
- while (true) {
- if (FastMath.abs(fc) < FastMath.abs(fb)) {
- a = b;
- b = c;
- c = a;
- fa = fb;
- fb = fc;
- fc = fa;
- }
-
- final double tol = 2 * eps * FastMath.abs(b) + t;
- final double m = 0.5 * (c - b);
-
- if (FastMath.abs(m) <= tol ||
- Precision.equals(fb, 0)) {
- return b;
- }
- if (FastMath.abs(e) < tol ||
- FastMath.abs(fa) <= FastMath.abs(fb)) {
- // Force bisection.
- d = m;
- e = d;
- } else {
- double s = fb / fa;
- double p;
- double q;
- // The equality test (a == c) is intentional,
- // it is part of the original Brent's method and
- // it should NOT be replaced by proximity test.
- if (a == c) {
- // Linear interpolation.
- p = 2 * m * s;
- q = 1 - s;
- } else {
- // Inverse quadratic interpolation.
- q = fa / fc;
- final double r = fb / fc;
- p = s * (2 * m * q * (q - r) - (b - a) * (r - 1));
- q = (q - 1) * (r - 1) * (s - 1);
- }
- if (p > 0) {
- q = -q;
- } else {
- p = -p;
- }
- s = e;
- e = d;
- if (p >= 1.5 * m * q - FastMath.abs(tol * q) ||
- p >= FastMath.abs(0.5 * s * q)) {
- // Inverse quadratic interpolation gives a value
- // in the wrong direction, or progress is slow.
- // Fall back to bisection.
- d = m;
- e = d;
- } else {
- d = p / q;
- }
- }
- a = b;
- fa = fb;
-
- if (FastMath.abs(d) > tol) {
- b += d;
- } else if (m > 0) {
- b += tol;
- } else {
- b -= tol;
- }
- fb = computeObjectiveValue(b);
- if ((fb > 0 && fc > 0) ||
- (fb <= 0 && fc <= 0)) {
- c = a;
- fc = fa;
- d = b - a;
- e = d;
- }
- }
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/solvers/FieldBracketingNthOrderBrentSolver.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
deleted file mode 100644
index 9b902fdc7..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/analysis/solvers/FieldBracketingNthOrderBrentSolver.java
+++ /dev/null
@@ -1,453 +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.analysis.solvers;
-
-
-import org.apache.commons.math4.Field;
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.analysis.RealFieldUnivariateFunction;
-import org.apache.commons.math4.exception.MathInternalError;
-import org.apache.commons.math4.exception.NoBracketingException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.util.IntegerSequence;
-import org.apache.commons.math4.util.MathArrays;
-import org.apache.commons.math4.util.MathUtils;
-import org.apache.commons.numbers.core.Precision;
-
-/**
- * This class implements a modification of the Brent algorithm.
- *
- *
- * A First Course in Numerical Analysis,
- * ISBN 048641454X, chapter 8.
- *
- * Laguerre's method is global in the sense that it can start with any initial
- * approximation and be able to solve all roots from that point.
- * The algorithm requires a bracketing condition.
- *
- * @since 1.2
- */
-public class LaguerreSolver extends AbstractPolynomialSolver {
- /** Default absolute accuracy. */
- private static final double DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
- /** Complex solver. */
- private final ComplexSolver complexSolver = new ComplexSolver();
-
- /**
- * Construct a solver with default accuracy (1e-6).
- */
- public LaguerreSolver() {
- this(DEFAULT_ABSOLUTE_ACCURACY);
- }
- /**
- * Construct a solver.
- *
- * @param absoluteAccuracy Absolute accuracy.
- */
- public LaguerreSolver(double absoluteAccuracy) {
- super(absoluteAccuracy);
- }
- /**
- * Construct a solver.
- *
- * @param relativeAccuracy Relative accuracy.
- * @param absoluteAccuracy Absolute accuracy.
- */
- public LaguerreSolver(double relativeAccuracy,
- double absoluteAccuracy) {
- super(relativeAccuracy, absoluteAccuracy);
- }
- /**
- * Construct a solver.
- *
- * @param relativeAccuracy Relative accuracy.
- * @param absoluteAccuracy Absolute accuracy.
- * @param functionValueAccuracy Function value accuracy.
- */
- public LaguerreSolver(double relativeAccuracy,
- double absoluteAccuracy,
- double functionValueAccuracy) {
- super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double doSolve()
- throws TooManyEvaluationsException,
- NumberIsTooLargeException,
- NoBracketingException {
- final double min = getMin();
- final double max = getMax();
- final double initial = getStartValue();
- final double functionValueAccuracy = getFunctionValueAccuracy();
-
- verifySequence(min, initial, max);
-
- // Return the initial guess if it is good enough.
- final double yInitial = computeObjectiveValue(initial);
- if (FastMath.abs(yInitial) <= functionValueAccuracy) {
- return initial;
- }
-
- // Return the first endpoint if it is good enough.
- final double yMin = computeObjectiveValue(min);
- if (FastMath.abs(yMin) <= functionValueAccuracy) {
- return min;
- }
-
- // Reduce interval if min and initial bracket the root.
- if (yInitial * yMin < 0) {
- return laguerre(min, initial);
- }
-
- // Return the second endpoint if it is good enough.
- final double yMax = computeObjectiveValue(max);
- if (FastMath.abs(yMax) <= functionValueAccuracy) {
- return max;
- }
-
- // Reduce interval if initial and max bracket the root.
- if (yInitial * yMax < 0) {
- return laguerre(initial, max);
- }
-
- throw new NoBracketingException(min, max, yMin, yMax);
- }
-
- /**
- * Find a real root in the given interval.
- *
- * Despite the bracketing condition, the root returned by
- * {@link ComplexSolver#solve(Complex[],Complex)} may
- * not be a real zero inside {@code [min, max]}.
- * For example, p(x) = x3 + 1,
- * with {@code min = -2}, {@code max = 2}, {@code initial = 0}.
- * When it occurs, this code calls
- * {@link ComplexSolver#solveAll(Complex[],Complex)}
- * in order to obtain all roots and picks up one real root.
- *
- * @param lo Lower bound of the search interval.
- * @param hi Higher bound of the search interval.
- * @return the point at which the function value is zero.
- */
- private double laguerre(double lo, double hi) {
- final Complex c[] = ComplexUtils.real2Complex(getCoefficients());
-
- final Complex initial = Complex.ofCartesian(0.5 * (lo + hi), 0);
- final Complex z = complexSolver.solve(c, initial);
- if (complexSolver.isRoot(lo, hi, z)) {
- return z.getReal();
- } else {
- double r = Double.NaN;
- // Solve all roots and select the one we are seeking.
- Complex[] root = complexSolver.solveAll(c, initial);
- for (int i = 0; i < root.length; i++) {
- if (complexSolver.isRoot(lo, hi, root[i])) {
- r = root[i].getReal();
- break;
- }
- }
- return r;
- }
- }
-
- /**
- * Find all complex roots for the polynomial with the given
- * coefficients, starting from the given initial value.
- *
- *
- * If {@code f} is continuous on {@code [a,b]}, this means that {@code a}
- * and {@code b} bracket a root of {@code f}.
- *
- *
- *
- *
- */
- @Override
- public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
- if (p < 0.0 || p > 1.0) {
- throw new OutOfRangeException(p, 0, 1);
- }
-
- int lower = getSupportLowerBound();
- if (p == 0.0) {
- return lower;
- }
- if (lower == Integer.MIN_VALUE) {
- if (checkedCumulativeProbability(lower) >= p) {
- return lower;
- }
- } else {
- lower -= 1; // this ensures cumulativeProbability(lower) < p, which
- // is important for the solving step
- }
-
- int upper = getSupportUpperBound();
- if (p == 1.0) {
- return upper;
- }
-
- // use the one-sided Chebyshev inequality to narrow the bracket
- // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
- final double mu = getMean();
- final double sigma = FastMath.sqrt(getVariance());
- final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
- Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
- if (chebyshevApplies) {
- double k = FastMath.sqrt((1.0 - p) / p);
- double tmp = mu - k * sigma;
- if (tmp > lower) {
- lower = ((int) FastMath.ceil(tmp)) - 1;
- }
- k = 1.0 / k;
- tmp = mu + k * sigma;
- if (tmp < upper) {
- upper = ((int) FastMath.ceil(tmp)) - 1;
- }
- }
-
- return solveInverseCumulativeProbability(p, lower, upper);
- }
-
- /**
- * This is a utility function used by {@link
- * #inverseCumulativeProbability(double)}. It assumes {@code 0 < p < 1} and
- * that the inverse cumulative probability lies in the bracket {@code
- * (lower, upper]}. The implementation does simple bisection to find the
- * smallest {@code p}-quantile {@code inf{x in Z | P(X<=x) >= p}}.
- *
- * @param p the cumulative probability
- * @param lower a value satisfying {@code cumulativeProbability(lower) < p}
- * @param upper a value satisfying {@code p <= cumulativeProbability(upper)}
- * @return the smallest {@code p}-quantile of this distribution
- */
- protected int solveInverseCumulativeProbability(final double p, int lower, int upper) {
- while (lower + 1 < upper) {
- int xm = (lower + upper) / 2;
- if (xm < lower || xm > upper) {
- /*
- * Overflow.
- * There will never be an overflow in both calculation methods
- * for xm at the same time
- */
- xm = lower + (upper - lower) / 2;
- }
-
- double pm = checkedCumulativeProbability(xm);
- if (pm >= p) {
- upper = xm;
- } else {
- lower = xm;
- }
- }
- return upper;
- }
-
- /**
- * Computes the cumulative probability function and checks for {@code NaN}
- * values returned. Throws {@code MathInternalError} if the value is
- * {@code NaN}. Rethrows any exception encountered evaluating the cumulative
- * probability function. Throws {@code MathInternalError} if the cumulative
- * probability function returns {@code NaN}.
- *
- * @param argument input value
- * @return the cumulative probability
- * @throws MathInternalError if the cumulative probability is {@code NaN}
- */
- private double checkedCumulativeProbability(int argument)
- throws MathInternalError {
- final double result = cumulativeProbability(argument);
- if (Double.isNaN(result)) {
- throw new MathInternalError(LocalizedFormats
- .DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN, argument);
- }
- return result;
- }
-
- /**
- * {@inheritDoc}
- *
- *
- */
- @Override
- public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
- /*
- * IMPLEMENTATION NOTES
- * --------------------
- * Where applicable, use is made of the one-sided Chebyshev inequality
- * to bracket the root. This inequality states that
- * P(X - mu >= k * sig) <= 1 / (1 + k^2),
- * mu: mean, sig: standard deviation. Equivalently
- * 1 - P(X < mu + k * sig) <= 1 / (1 + k^2),
- * F(mu + k * sig) >= k^2 / (1 + k^2).
- *
- * For k = sqrt(p / (1 - p)), we find
- * F(mu + k * sig) >= p,
- * and (mu + k * sig) is an upper-bound for the root.
- *
- * Then, introducing Y = -X, mean(Y) = -mu, sd(Y) = sig, and
- * P(Y >= -mu + k * sig) <= 1 / (1 + k^2),
- * P(-X >= -mu + k * sig) <= 1 / (1 + k^2),
- * P(X <= mu - k * sig) <= 1 / (1 + k^2),
- * F(mu - k * sig) <= 1 / (1 + k^2).
- *
- * For k = sqrt((1 - p) / p), we find
- * F(mu - k * sig) <= p,
- * and (mu - k * sig) is a lower-bound for the root.
- *
- * In cases where the Chebyshev inequality does not apply, geometric
- * progressions 1, 2, 4, ... and -1, -2, -4, ... are used to bracket
- * the root.
- */
- if (p < 0.0 || p > 1.0) {
- throw new OutOfRangeException(p, 0, 1);
- }
-
- double lowerBound = getSupportLowerBound();
- if (p == 0.0) {
- return lowerBound;
- }
-
- double upperBound = getSupportUpperBound();
- if (p == 1.0) {
- return upperBound;
- }
-
- final double mu = getMean();
- final double sig = FastMath.sqrt(getVariance());
- final boolean chebyshevApplies;
- chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
- Double.isInfinite(sig) || Double.isNaN(sig));
-
- if (lowerBound == Double.NEGATIVE_INFINITY) {
- if (chebyshevApplies) {
- lowerBound = mu - sig * FastMath.sqrt((1. - p) / p);
- } else {
- lowerBound = -1.0;
- while (cumulativeProbability(lowerBound) >= p) {
- lowerBound *= 2.0;
- }
- }
- }
-
- if (upperBound == Double.POSITIVE_INFINITY) {
- if (chebyshevApplies) {
- upperBound = mu + sig * FastMath.sqrt(p / (1. - p));
- } else {
- upperBound = 1.0;
- while (cumulativeProbability(upperBound) < p) {
- upperBound *= 2.0;
- }
- }
- }
-
- final UnivariateFunction toSolve = new UnivariateFunction() {
- /** {@inheritDoc} */
- @Override
- public double value(final double x) {
- return cumulativeProbability(x) - p;
- }
- };
-
- double x = UnivariateSolverUtils.solve(toSolve,
- lowerBound,
- upperBound,
- getSolverAbsoluteAccuracy());
-
- if (!isSupportConnected()) {
- /* Test for plateau. */
- final double dx = getSolverAbsoluteAccuracy();
- if (x - dx >= getSupportLowerBound()) {
- double px = cumulativeProbability(x);
- if (cumulativeProbability(x - dx) == px) {
- upperBound = x;
- while (upperBound - lowerBound > dx) {
- final double midPoint = 0.5 * (lowerBound + upperBound);
- if (cumulativeProbability(midPoint) < px) {
- lowerBound = midPoint;
- } else {
- upperBound = midPoint;
- }
- }
- return upperBound;
- }
- }
- }
- return x;
- }
-
- /**
- * Returns the solver absolute accuracy for inverse cumulative computation.
- * You can override this method in order to use a Brent solver with an
- * absolute accuracy different from the default.
- *
- * @return the maximum absolute error in inverse cumulative probability estimates
- */
- protected double getSolverAbsoluteAccuracy() {
- return SOLVER_DEFAULT_ABSOLUTE_ACCURACY;
- }
-
- /**
- * {@inheritDoc}
- *
- * @return zero.
- * @since 3.1
- */
- @Override
- public double probability(double x) {
- return 0d;
- }
-
- /**
- * {@inheritDoc}
- * EmpiricalDistribution
maintains data structures, called
- * distribution digests, that describe empirical distributions and
- * support the following operations:
- *
- * Applications can use EmpiricalDistribution
to build grouped
- * frequency histograms representing the input data or to generate random values
- * "like" those in the input file -- i.e., the values generated will follow the
- * distribution of the values in the file.
- *
- *
- * Generating random values from the distributionbinCount
"bins."
- *
- *
- *
- *
- *
- */
-public class EmpiricalDistribution extends AbstractRealDistribution
- implements ContinuousDistribution {
-
- /** Default bin count */
- public static final int DEFAULT_BIN_COUNT = 1000;
-
- /** Character set for file input */
- private static final String FILE_CHARSET = "US-ASCII";
-
- /** Serializable version identifier */
- private static final long serialVersionUID = 5729073523949762654L;
-
- /** List of SummaryStatistics objects characterizing the bins */
- private final ListbinCount
is set by default to 1000. A good rule of thumb
- * is to set the bin count to approximately the length of the input file divided
- * by 10. sampleStats
and
- * beanStats
abstracting the source of data.
- */
- private abstract class DataAdapter{
-
- /**
- * Compute bin stats.
- *
- * @throws IOException if an error occurs computing bin stats
- */
- public abstract void computeBinStats() throws IOException;
-
- /**
- * Compute sample statistics.
- *
- * @throws IOException if an error occurs computing sample stats
- */
- public abstract void computeStats() throws IOException;
-
- }
-
- /**
- * DataAdapter
for data provided through some input stream
- */
- private class StreamDataAdapter extends DataAdapter{
-
- /** Input stream providing access to the data */
- private BufferedReader inputStream;
-
- /**
- * Create a StreamDataAdapter from a BufferedReader
- *
- * @param in BufferedReader input stream
- */
- StreamDataAdapter(BufferedReader in){
- super();
- inputStream = in;
- }
-
- /** {@inheritDoc} */
- @Override
- public void computeBinStats() throws IOException {
- String str = null;
- double val = 0.0d;
- while ((str = inputStream.readLine()) != null) {
- val = Double.parseDouble(str);
- SummaryStatistics stats = binStats.get(findBin(val));
- stats.addValue(val);
- }
-
- inputStream.close();
- inputStream = null;
- }
-
- /** {@inheritDoc} */
- @Override
- public void computeStats() throws IOException {
- String str = null;
- double val = 0.0;
- sampleStats = new SummaryStatistics();
- while ((str = inputStream.readLine()) != null) {
- val = Double.parseDouble(str);
- sampleStats.addValue(val);
- }
- inputStream.close();
- inputStream = null;
- }
- }
-
- /**
- * DataAdapter
for data provided as array of doubles.
- */
- private class ArrayDataAdapter extends DataAdapter {
-
- /** Array of input data values */
- private final double[] inputArray;
-
- /**
- * Construct an ArrayDataAdapter from a double[] array
- *
- * @param in double[] array holding the data
- * @throws NullArgumentException if in is null
- */
- ArrayDataAdapter(double[] in) throws NullArgumentException {
- super();
- MathUtils.checkNotNull(in);
- inputArray = in;
- }
-
- /** {@inheritDoc} */
- @Override
- public void computeStats() throws IOException {
- sampleStats = new SummaryStatistics();
- for (int i = 0; i < inputArray.length; i++) {
- sampleStats.addValue(inputArray[i]);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void computeBinStats() throws IOException {
- for (int i = 0; i < inputArray.length; i++) {
- SummaryStatistics stats =
- binStats.get(findBin(inputArray[i]));
- stats.addValue(inputArray[i]);
- }
- }
- }
-
- /**
- * Fills binStats array (second pass through data file).
- *
- * @param da object providing access to the data
- * @throws IOException if an IO error occurs
- */
- private void fillBinStats(final DataAdapter da)
- throws IOException {
- // Set up grid
- min = sampleStats.getMin();
- max = sampleStats.getMax();
- delta = (max - min)/binCount;
-
- // Initialize binStats ArrayList
- if (!binStats.isEmpty()) {
- binStats.clear();
- }
- for (int i = 0; i < binCount; i++) {
- SummaryStatistics stats = new SummaryStatistics();
- binStats.add(i,stats);
- }
-
- // Filling data in binStats Array
- da.computeBinStats();
-
- // Assign upperBounds based on bin counts
- upperBounds = new double[binCount];
- upperBounds[0] =
- ((double) binStats.get(0).getN()) / (double) sampleStats.getN();
- for (int i = 1; i < binCount-1; i++) {
- upperBounds[i] = upperBounds[i-1] +
- ((double) binStats.get(i).getN()) / (double) sampleStats.getN();
- }
- upperBounds[binCount-1] = 1.0d;
- }
-
- /**
- * Returns the index of the bin to which the given value belongs
- *
- * @param value the value whose bin we are trying to find
- * @return the index of the bin containing the value
- */
- private int findBin(double value) {
- return FastMath.min(
- FastMath.max((int) FastMath.ceil((value - min) / delta) - 1, 0),
- binCount - 1);
- }
-
- /**
- * Returns a {@link StatisticalSummary} describing this distribution.
- * Preconditions:
- *
- *
- * @return the sample statistics
- * @throws IllegalStateException if the distribution has not been loaded
- */
- public StatisticalSummary getSampleStats() {
- return sampleStats;
- }
-
- /**
- * Returns the number of bins.
- *
- * @return the number of bins.
- */
- public int getBinCount() {
- return binCount;
- }
-
- /**
- * Returns a List of {@link SummaryStatistics} instances containing
- * statistics describing the values in each of the bins. The list is
- * indexed on the bin number.
- *
- * @return List of bin statistics.
- */
- public List
- * [min,upperBounds[0]],(upperBounds[0],upperBounds[1]],...,
- * (upperBounds[binCount-2], upperBounds[binCount-1] = max].
- *
- *
- *
- *
- * @since 3.1
- */
- @Override
- public double density(double x) {
- if (x < min || x > max) {
- return 0d;
- }
- final int binIndex = findBin(x);
- final ContinuousDistribution kernel = getKernel(binStats.get(binIndex));
- return kernel.density(x) * pB(binIndex) / kB(binIndex);
- }
-
- /**
- * {@inheritDoc}
- *
- *
- *
- * If K is a constant distribution, we return P(B-) + P(B) (counting the full
- * mass of B).
- *
- * @since 3.1
- */
- @Override
- public double cumulativeProbability(double x) {
- if (x < min) {
- return 0d;
- } else if (x >= max) {
- return 1d;
- }
- final int binIndex = findBin(x);
- final double pBminus = pBminus(binIndex);
- final double pB = pB(binIndex);
- final ContinuousDistribution kernel = k(x);
- if (kernel instanceof ConstantContinuousDistribution) {
- if (x < kernel.getMean()) {
- return pBminus;
- } else {
- return pBminus + pB;
- }
- }
- final double[] binBounds = getUpperBounds();
- final double kB = kB(binIndex);
- final double lower = binIndex == 0 ? min : binBounds[binIndex - 1];
- final double withinBinCum =
- (kernel.cumulativeProbability(x) - kernel.cumulativeProbability(lower)) / kB;
- return pBminus + pB * withinBinCum;
- }
-
- /**
- * {@inheritDoc}
- *
- *
- *
- *
- * @since 3.1
- */
- @Override
- public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
- if (p < 0.0 || p > 1.0) {
- throw new OutOfRangeException(p, 0, 1);
- }
-
- if (p == 0.0) {
- return getSupportLowerBound();
- }
-
- if (p == 1.0) {
- return getSupportUpperBound();
- }
-
- int i = 0;
- while (cumBinP(i) < p) {
- i++;
- }
-
- final ContinuousDistribution kernel = getKernel(binStats.get(i));
- final double kB = kB(i);
- final double[] binBounds = getUpperBounds();
- final double lower = i == 0 ? min : binBounds[i - 1];
- final double kBminus = kernel.cumulativeProbability(lower);
- final double pB = pB(i);
- final double pBminus = pBminus(i);
- final double pCrit = p - pBminus;
- if (pCrit <= 0) {
- return lower;
- }
- return kernel.inverseCumulativeProbability(kBminus + pCrit * kB / pB);
- }
-
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- public double getMean() {
- return sampleStats.getMean();
- }
-
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- public double getVariance() {
- return sampleStats.getVariance();
- }
-
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- public double getSupportLowerBound() {
- return min;
- }
-
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- public double getSupportUpperBound() {
- return max;
- }
-
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- public boolean isSupportConnected() {
- return true;
- }
-
- /**{@inheritDoc} */
- @Override
- public Sampler createSampler(final UniformRandomProvider rng) {
- if (!loaded) {
- throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED);
- }
- return super.createSampler(rng);
- }
-
- /**
- * The probability of bin i.
- *
- * @param i the index of the bin
- * @return the probability that selection begins in bin i
- */
- private double pB(int i) {
- return i == 0 ? upperBounds[0] :
- upperBounds[i] - upperBounds[i - 1];
- }
-
- /**
- * The combined probability of the bins up to but not including bin i.
- *
- * @param i the index of the bin
- * @return the probability that selection begins in a bin below bin i.
- */
- private double pBminus(int i) {
- return i == 0 ? 0 : upperBounds[i - 1];
- }
-
- /**
- * Mass of bin i under the within-bin kernel of the bin.
- *
- * @param i index of the bin
- * @return the difference in the within-bin kernel cdf between the
- * upper and lower endpoints of bin i
- */
- private double kB(int i) {
- final double[] binBounds = getUpperBounds();
- final ContinuousDistribution kernel = getKernel(binStats.get(i));
- return i == 0 ? kernel.probability(min, binBounds[0]) :
- kernel.probability(binBounds[i - 1], binBounds[i]);
- }
-
- /**
- * The within-bin kernel of the bin that x belongs to.
- *
- * @param x the value to locate within a bin
- * @return the within-bin kernel of the bin containing x
- */
- private ContinuousDistribution k(double x) {
- final int binIndex = findBin(x);
- return getKernel(binStats.get(binIndex));
- }
-
- /**
- * The combined probability of the bins up to and including binIndex.
- *
- * @param binIndex maximum bin index
- * @return sum of the probabilities of bins through binIndex
- */
- private double cumBinP(int binIndex) {
- return upperBounds[binIndex];
- }
-
- /**
- * The within-bin smoothing kernel. Returns a Gaussian distribution
- * parameterized by {@code bStats}, unless the bin contains only one
- * observation, in which case a constant distribution is returned.
- *
- * @param bStats summary statistics for the bin
- * @return within-bin kernel parameterized by bStats
- */
- protected ContinuousDistribution getKernel(SummaryStatistics bStats) {
- if (bStats.getN() == 1 || bStats.getVariance() == 0) {
- return new ConstantContinuousDistribution(bStats.getMean());
- } else {
- return new NormalDistribution(bStats.getMean(), bStats.getStandardDeviation());
- }
- }
-}
diff --git a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java b/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java
deleted file mode 100644
index 5b1cd302d..000000000
--- a/virtdata-lib-curves4/src/main/java/org/apache/commons/math4/distribution/EnumeratedDistribution.java
+++ /dev/null
@@ -1,255 +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.distribution;
-
-import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.exception.NotANumberException;
-import org.apache.commons.math4.exception.NotFiniteNumberException;
-import org.apache.commons.math4.exception.NotPositiveException;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.sampling.DiscreteProbabilityCollectionSampler;
-import org.apache.commons.math4.util.MathArrays;
-import org.apache.commons.math4.util.Pair;
-
-/**
- *
- * Let K(B) be the mass of B under K.
- * Let K(B-) be K evaluated at the lower endpoint of B (the combined
- * mass of the bins below B under K).
- * Let P(B) be the probability of bin i.
- * Let P(B-) be the sum of the bin masses below bin i.
- * Let pCrit = p - P(B-)
- *
- * K(B-) + pCrit * K(B) / P(B)
- * Duplicate values are allowed. Probabilities of duplicate values are combined
- * when computing cumulative probabilities and statistics.
- * Duplicate values are allowed. Probabilities of duplicate values are combined
- * when computing cumulative probabilities and statistics.