Java Code Examples for org.apache.commons.math3.analysis.differentiation.DerivativeStructure#getFreeParameters()

The following examples show how to use org.apache.commons.math3.analysis.differentiation.DerivativeStructure#getFreeParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 2
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 3
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
Example 4
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 5
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
Example 6
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 7
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
Example 8
Source File: Nopol2017_0064_t.java    From coming with MIT License 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiable}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} with
 * <em>only</em> one parameter and up to order one. If the function is called with
 * more parameters or higher order, a {@link DimensionMismatchException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiable toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiable() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception DimensionMismatchException if number of parameters or derivation
         * order are higher than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws DimensionMismatchException {
            if (t.getFreeParameters() != 1) {
                throw new DimensionMismatchException(t.getFreeParameters(), 1);
            }
            if (t.getOrder() > 1) {
                throw new DimensionMismatchException(t.getOrder(), 1);
            }
            return t.compose(new double[] {
                f.value(t.getValue()),
                f.derivative().value(t.getValue())
            });
        }

    };
}
 
Example 9
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
Example 10
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 11
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} with
 * <em>only</em> one parameter and up to order one. If the function is called with
 * more parameters or higher order, a {@link DimensionMismatchException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception DimensionMismatchException if number of parameters or derivation
         * order are higher than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws DimensionMismatchException {
            if (t.getFreeParameters() != 1) {
                throw new DimensionMismatchException(t.getFreeParameters(), 1);
            }
            if (t.getOrder() > 1) {
                throw new DimensionMismatchException(t.getOrder(), 1);
            }
            return t.compose(new double[] {
                f.value(t.getValue()),
                f.derivative().value(t.getValue())
            });
        }

    };
}
 
Example 12
Source File: PolynomialFunction.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 * @throws NoDataException if {@code coefficients} is empty.
 * @throws NullArgumentException if {@code coefficients} is {@code null}.
 */
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;
}
 
Example 13
Source File: FunctionUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiableFunction}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} up to order one.
 * If the function is called with higher order, a {@link NumberIsTooLargeException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiableFunction toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiableFunction() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception NumberIsTooLargeException if derivation order is greater than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws NumberIsTooLargeException {
            switch (t.getOrder()) {
                case 0 :
                    return new DerivativeStructure(t.getFreeParameters(), 0, f.value(t.getValue()));
                case 1 : {
                    final int parameters = t.getFreeParameters();
                    final double[] derivatives = new double[parameters + 1];
                    derivatives[0] = f.value(t.getValue());
                    final double fPrime = f.derivative().value(t.getValue());
                    int[] orders = new int[parameters];
                    for (int i = 0; i < parameters; ++i) {
                        orders[i] = 1;
                        derivatives[i + 1] = fPrime * t.getPartialDerivative(orders);
                        orders[i] = 0;
                    }
                    return new DerivativeStructure(parameters, 1, derivatives);
                }
                default :
                    throw new NumberIsTooLargeException(t.getOrder(), 1, true);
            }
        }

    };
}
 
Example 14
Source File: Nopol2017_0064_s.java    From coming with MIT License 5 votes vote down vote up
/** Convert a {@link DifferentiableUnivariateFunction} into a {@link UnivariateDifferentiable}.
 * <p>
 * Note that the converted function is able to handle {@link DerivativeStructure} with
 * <em>only</em> one parameter and up to order one. If the function is called with
 * more parameters or higher order, a {@link DimensionMismatchException} will be thrown.
 * </p>
 * @param f function to convert
 * @return converted function
 * @deprecated this conversion method is temporary in version 3.1, as the {@link
 * DifferentiableUnivariateFunction} interface itself is deprecated
 */
@Deprecated
public static UnivariateDifferentiable toUnivariateDifferential(final DifferentiableUnivariateFunction f) {
    return new UnivariateDifferentiable() {

        /** {@inheritDoc} */
        public double value(final double x) {
            return f.value(x);
        }

        /** {@inheritDoc}
         * @exception DimensionMismatchException if number of parameters or derivation
         * order are higher than 1
         */
        public DerivativeStructure value(final DerivativeStructure t)
            throws DimensionMismatchException {
            if (t.getFreeParameters() != 1) {
                throw new DimensionMismatchException(t.getFreeParameters(), 1);
            }
            if (t.getOrder() > 1) {
                throw new DimensionMismatchException(t.getOrder(), 1);
            }
            return t.compose(new double[] {
                f.value(t.getValue()),
                f.derivative().value(t.getValue())
            });
        }

    };
}
 
Example 15
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}
 
Example 16
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}
 
Example 17
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}
 
Example 18
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}
 
Example 19
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}
 
Example 20
Source File: Constant.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc}
 * @since 3.1
 */
public DerivativeStructure value(final DerivativeStructure t) {
    return new DerivativeStructure(t.getFreeParameters(), t.getOrder(), c);
}