http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Gaussian.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Gaussian.java b/src/main/java/org/apache/commons/math3/analysis/function/Gaussian.java deleted file mode 100644 index 8c64c8b..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Gaussian.java +++ /dev/null @@ -1,259 +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.math3.analysis.function; - -import java.util.Arrays; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.ParametricUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.NotStrictlyPositiveException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.util.FastMath; -import org.apache.commons.math3.util.Precision; - -/** - * <a href="http://en.wikipedia.org/wiki/Gaussian_function"> - * Gaussian</a> function. - * - * @since 3.0 - */ -public class Gaussian implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** 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} */ - public double value(double x) { - return value(x - mean, norm, i2s2); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** - * Parametric function where the input array contains the parameters of - * the Gaussian, ordered as follows: - * <ul> - * <li>Norm</li> - * <li>Mean</li> - * <li>Standard deviation</li> - * </ul> - */ - 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. - */ - 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 - * <em>parameters</em> (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. - */ - 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 - */ - 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); - - } - -}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/HarmonicOscillator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/HarmonicOscillator.java b/src/main/java/org/apache/commons/math3/analysis/function/HarmonicOscillator.java deleted file mode 100644 index 0fbad9c..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/HarmonicOscillator.java +++ /dev/null @@ -1,183 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.ParametricUnivariateFunction; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.util.FastMath; - -/** - * <a href="http://en.wikipedia.org/wiki/Harmonic_oscillator"> - * simple harmonic oscillator</a> function. - * - * @since 3.0 - */ -public class HarmonicOscillator implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** 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} */ - public double value(double x) { - return value(omega * x + phase, amplitude); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** - * Parametric function where the input array contains the parameters of - * the harmonic oscillator function, ordered as follows: - * <ul> - * <li>Amplitude</li> - * <li>Angular frequency</li> - * <li>Phase</li> - * </ul> - */ - 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. - */ - 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 - * <em>parameters</em> (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. - */ - 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 - */ - 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); - - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Identity.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Identity.java b/src/main/java/org/apache/commons/math3/analysis/function/Identity.java deleted file mode 100644 index d21f7e0..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Identity.java +++ /dev/null @@ -1,50 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; - -/** - * Identity function. - * - * @since 3.0 - */ -public class Identity implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return x; - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public DifferentiableUnivariateFunction derivative() { - return new Constant(1); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t; - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Inverse.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Inverse.java b/src/main/java/org/apache/commons/math3/analysis/function/Inverse.java deleted file mode 100644 index e38f689..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Inverse.java +++ /dev/null @@ -1,52 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; - -/** - * Inverse function. - * - * @since 3.0 - */ -public class Inverse implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return 1 / x; - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.reciprocal(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Log.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Log.java b/src/main/java/org/apache/commons/math3/analysis/function/Log.java deleted file mode 100644 index a1e12dc..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Log.java +++ /dev/null @@ -1,53 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Natural logarithm function. - * - * @since 3.0 - */ -public class Log implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.log(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.log(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Log10.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Log10.java b/src/main/java/org/apache/commons/math3/analysis/function/Log10.java deleted file mode 100644 index 66c03e1..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Log10.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Base 10 logarithm function. - * - * @since 3.0 - */ -public class Log10 implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.log10(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.log10(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Log1p.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Log1p.java b/src/main/java/org/apache/commons/math3/analysis/function/Log1p.java deleted file mode 100644 index 4966318..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Log1p.java +++ /dev/null @@ -1,53 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * <code>log(1 + p)</code> function. - * - * @since 3.0 - */ -public class Log1p implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.log1p(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.log1p(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Logistic.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Logistic.java b/src/main/java/org/apache/commons/math3/analysis/function/Logistic.java deleted file mode 100644 index c90203c..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Logistic.java +++ /dev/null @@ -1,228 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.ParametricUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.NotStrictlyPositiveException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.util.FastMath; - -/** - * <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function"> - * Generalised logistic</a> function. - * - * @since 3.0 - */ -public class Logistic implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** 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} */ - public double value(double x) { - return value(m - x, k, b, q, a, oneOverN); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** - * 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: - * <ul> - * <li>k</li> - * <li>m</li> - * <li>b</li> - * <li>q</li> - * <li>a</li> - * <li>n</li> - * </ul> - */ - 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}. - */ - 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 - * <em>parameters</em>. - * - * @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}. - */ - 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 - */ - 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); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Logit.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Logit.java b/src/main/java/org/apache/commons/math3/analysis/function/Logit.java deleted file mode 100644 index 39abe4d..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Logit.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.ParametricUnivariateFunction; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.OutOfRangeException; -import org.apache.commons.math3.util.FastMath; - -/** - * <a href="http://en.wikipedia.org/wiki/Logit"> - * Logit</a> function. - * It is the inverse of the {@link Sigmoid sigmoid} function. - * - * @since 3.0 - */ -public class Logit implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** 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} */ - public double value(double x) - throws OutOfRangeException { - return value(x, lo, hi); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** - * Parametric function where the input array contains the parameters of - * the logit function, ordered as follows: - * <ul> - * <li>Lower bound</li> - * <li>Higher bound</li> - * </ul> - */ - 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. - */ - 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 - * <em>parameters</em> (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. - */ - 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 - */ - 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); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Max.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Max.java b/src/main/java/org/apache/commons/math3/analysis/function/Max.java deleted file mode 100644 index 591ac55..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Max.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.BivariateFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Maximum function. - * - * @since 3.0 - */ -public class Max implements BivariateFunction { - /** {@inheritDoc} */ - public double value(double x, double y) { - return FastMath.max(x, y); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Min.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Min.java b/src/main/java/org/apache/commons/math3/analysis/function/Min.java deleted file mode 100644 index a776b79..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Min.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.BivariateFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Minimum function. - * - * @since 3.0 - */ -public class Min implements BivariateFunction { - /** {@inheritDoc} */ - public double value(double x, double y) { - return FastMath.min(x, y); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Minus.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Minus.java b/src/main/java/org/apache/commons/math3/analysis/function/Minus.java deleted file mode 100644 index e532779..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Minus.java +++ /dev/null @@ -1,50 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; - -/** - * Minus function. - * - * @since 3.0 - */ -public class Minus implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return -x; - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public DifferentiableUnivariateFunction derivative() { - return new Constant(-1); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.negate(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Multiply.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Multiply.java b/src/main/java/org/apache/commons/math3/analysis/function/Multiply.java deleted file mode 100644 index b7e771b..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Multiply.java +++ /dev/null @@ -1,32 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.BivariateFunction; - -/** - * Multiply the two operands. - * - * @since 3.0 - */ -public class Multiply implements BivariateFunction { - /** {@inheritDoc} */ - public double value(double x, double y) { - return x * y; - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Pow.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Pow.java b/src/main/java/org/apache/commons/math3/analysis/function/Pow.java deleted file mode 100644 index 756dc42..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Pow.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.BivariateFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Power function. - * - * @since 3.0 - */ -public class Pow implements BivariateFunction { - /** {@inheritDoc} */ - public double value(double x, double y) { - return FastMath.pow(x, y); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Power.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Power.java b/src/main/java/org/apache/commons/math3/analysis/function/Power.java deleted file mode 100644 index 953bcab..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Power.java +++ /dev/null @@ -1,63 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Power function. - * - * @since 3.0 - */ -public class Power implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** Power. */ - private final double p; - - /** - * @param p Power. - */ - public Power(double p) { - this.p = p; - } - - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.pow(x, p); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.pow(p); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Rint.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Rint.java b/src/main/java/org/apache/commons/math3/analysis/function/Rint.java deleted file mode 100644 index 4edde58..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Rint.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * {@code rint} function. - * - * @since 3.0 - */ -public class Rint implements UnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.rint(x); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Sigmoid.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Sigmoid.java b/src/main/java/org/apache/commons/math3/analysis/function/Sigmoid.java deleted file mode 100644 index 54639f9..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Sigmoid.java +++ /dev/null @@ -1,218 +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.math3.analysis.function; - -import java.util.Arrays; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.ParametricUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.NullArgumentException; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.util.FastMath; - -/** - * <a href="http://en.wikipedia.org/wiki/Sigmoid_function"> - * Sigmoid</a> 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, DifferentiableUnivariateFunction { - /** 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} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} */ - 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: - * <ul> - * <li>Lower asymptote</li> - * <li>Higher asymptote</li> - * </ul> - */ - 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. - */ - 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 - * <em>parameters</em> (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. - */ - 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 - */ - 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); - - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Signum.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Signum.java b/src/main/java/org/apache/commons/math3/analysis/function/Signum.java deleted file mode 100644 index ddde66e..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Signum.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * {@code signum} function. - * - * @since 3.0 - */ -public class Signum implements UnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.signum(x); - } -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Sin.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Sin.java b/src/main/java/org/apache/commons/math3/analysis/function/Sin.java deleted file mode 100644 index 71c91e7..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Sin.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Sine function. - * - * @since 3.0 - */ -public class Sin implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.sin(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public DifferentiableUnivariateFunction derivative() { - return new Cos(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.sin(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Sinc.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Sinc.java b/src/main/java/org/apache/commons/math3/analysis/function/Sinc.java deleted file mode 100644 index 553cfff..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Sinc.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.exception.DimensionMismatchException; -import org.apache.commons.math3.util.FastMath; - -/** - * <a href="http://en.wikipedia.org/wiki/Sinc_function">Sinc</a> function, - * defined by - * <pre><code> - * sinc(x) = 1 if x = 0, - * sin(x) / x otherwise. - * </code></pre> - * - * @since 3.0 - */ -public class Sinc implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** - * Value below which the computations are done using Taylor series. - * <p> - * The Taylor series for sinc even order derivatives are: - * <pre> - * 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) ] - * </pre> - * </p> - * <p> - * The Taylor series for sinc odd order derivatives are: - * <pre> - * 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) ] - * </pre> - * </p> - * <p> - * 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. - * </p> - */ - 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 - * <code> sin(πx) / πx</code>, otherwise {@code sin(x) / x}. - */ - public Sinc(boolean normalized) { - this.normalized = normalized; - } - - /** {@inheritDoc} */ - 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} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - 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); - - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Sinh.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Sinh.java b/src/main/java/org/apache/commons/math3/analysis/function/Sinh.java deleted file mode 100644 index 1eac044..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Sinh.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.math3.analysis.function; - -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Hyperbolic sine function. - * - * @since 3.0 - */ -public class Sinh implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.sinh(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public DifferentiableUnivariateFunction derivative() { - return new Cosh(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.sinh(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/a7b4803f/src/main/java/org/apache/commons/math3/analysis/function/Sqrt.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/function/Sqrt.java b/src/main/java/org/apache/commons/math3/analysis/function/Sqrt.java deleted file mode 100644 index 720d44d..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/function/Sqrt.java +++ /dev/null @@ -1,53 +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.math3.analysis.function; - -import org.apache.commons.math3.analysis.FunctionUtils; -import org.apache.commons.math3.analysis.UnivariateFunction; -import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction; -import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; -import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction; -import org.apache.commons.math3.util.FastMath; - -/** - * Square-root function. - * - * @since 3.0 - */ -public class Sqrt implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { - /** {@inheritDoc} */ - public double value(double x) { - return FastMath.sqrt(x); - } - - /** {@inheritDoc} - * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} - */ - @Deprecated - public UnivariateFunction derivative() { - return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); - } - - /** {@inheritDoc} - * @since 3.1 - */ - public DerivativeStructure value(final DerivativeStructure t) { - return t.sqrt(); - } - -}