Repository: commons-math Updated Branches: refs/heads/MATH_3_X 3d055c620 -> d3911464f
Renamed FieldUnivariateFunction to RealFieldUnivariateFunction. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/d3911464 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/d3911464 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/d3911464 Branch: refs/heads/MATH_3_X Commit: d3911464f59982f3a93a2d44f627d968dca9bd04 Parents: 3d055c6 Author: Phil Steitz <phil.ste...@gmail.com> Authored: Sun Nov 15 15:30:49 2015 -0700 Committer: Phil Steitz <phil.ste...@gmail.com> Committed: Sun Nov 15 15:30:49 2015 -0700 ---------------------------------------------------------------------- .../math3/analysis/FieldUnivariateFunction.java | 86 -------------------- .../analysis/RealFieldUnivariateFunction.java | 86 ++++++++++++++++++++ .../FieldBracketingNthOrderBrentSolver.java | 6 +- .../dfp/BracketingNthOrderBrentSolverDFP.java | 4 +- .../math3/dfp/UnivariateDfpFunction.java | 2 +- .../FieldBracketingNthOrderBrentSolverTest.java | 18 ++-- 6 files changed, 101 insertions(+), 101 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/main/java/org/apache/commons/math3/analysis/FieldUnivariateFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/FieldUnivariateFunction.java b/src/main/java/org/apache/commons/math3/analysis/FieldUnivariateFunction.java deleted file mode 100644 index 51ab51d..0000000 --- a/src/main/java/org/apache/commons/math3/analysis/FieldUnivariateFunction.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.math3.analysis; - -import org.apache.commons.math3.RealFieldElement; - -/** - * An interface representing a univariate real function. - * <br/> - * When a <em>user-defined</em> function encounters an error during - * evaluation, the {@link #value(FieldElement) value} method should throw a - * <em>user-defined</em> unchecked exception. - * <br/> - * The following code excerpt shows the recommended way to do that using - * a root solver as an example, but the same construct is applicable to - * ODE integrators or optimizers. - * - * <pre> - * private static class LocalException extends RuntimeException { - * // The x value that caused the problem. - * private final SomeFieldType x; - * - * public LocalException(SomeFieldType x) { - * this.x = x; - * } - * - * public double getX() { - * return x; - * } - * } - * - * private static class MyFunction implements FieldUnivariateFunction<SomeFieldType> { - * public SomeFieldType value(SomeFieldType x) { - * SomeFieldType y = hugeFormula(x); - * if (somethingBadHappens) { - * throw new LocalException(x); - * } - * return y; - * } - * } - * - * public void compute() { - * try { - * solver.solve(maxEval, new MyFunction(a, b, c), min, max); - * } catch (LocalException le) { - * // Retrieve the x value. - * } - * } - * </pre> - * - * As shown, the exception is local to the user's code and it is guaranteed - * that Apache Commons Math will not catch it. - * - * @param <T> the type of the field elements - * @since 3.6 - * @see UnivariateFunction - */ -public interface FieldUnivariateFunction<T extends RealFieldElement<T>> { - /** - * Compute the value of the function. - * - * @param x Point at which the function value should be computed. - * @return the value of the function. - * @throws IllegalArgumentException when the activated method itself can - * ascertain that a precondition, specified in the API expressed at the - * level of the activated method, has been violated. - * When Commons Math throws an {@code IllegalArgumentException}, it is - * usually the consequence of checking the actual parameters passed to - * the method. - */ - T value(T x); -} http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/main/java/org/apache/commons/math3/analysis/RealFieldUnivariateFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/RealFieldUnivariateFunction.java b/src/main/java/org/apache/commons/math3/analysis/RealFieldUnivariateFunction.java new file mode 100644 index 0000000..21d7fa0 --- /dev/null +++ b/src/main/java/org/apache/commons/math3/analysis/RealFieldUnivariateFunction.java @@ -0,0 +1,86 @@ +/* + * 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; + +import org.apache.commons.math3.RealFieldElement; + +/** + * An interface representing a univariate real function. + * <br/> + * When a <em>user-defined</em> function encounters an error during + * evaluation, the {@link #value(FieldElement) value} method should throw a + * <em>user-defined</em> unchecked exception. + * <br/> + * The following code excerpt shows the recommended way to do that using + * a root solver as an example, but the same construct is applicable to + * ODE integrators or optimizers. + * + * <pre> + * private static class LocalException extends RuntimeException { + * // The x value that caused the problem. + * private final SomeFieldType x; + * + * public LocalException(SomeFieldType x) { + * this.x = x; + * } + * + * public double getX() { + * return x; + * } + * } + * + * private static class MyFunction implements FieldUnivariateFunction<SomeFieldType> { + * public SomeFieldType value(SomeFieldType x) { + * SomeFieldType y = hugeFormula(x); + * if (somethingBadHappens) { + * throw new LocalException(x); + * } + * return y; + * } + * } + * + * public void compute() { + * try { + * solver.solve(maxEval, new MyFunction(a, b, c), min, max); + * } catch (LocalException le) { + * // Retrieve the x value. + * } + * } + * </pre> + * + * As shown, the exception is local to the user's code and it is guaranteed + * that Apache Commons Math will not catch it. + * + * @param <T> the type of the field elements + * @since 3.6 + * @see UnivariateFunction + */ +public interface RealFieldUnivariateFunction<T extends RealFieldElement<T>> { + /** + * Compute the value of the function. + * + * @param x Point at which the function value should be computed. + * @return the value of the function. + * @throws IllegalArgumentException when the activated method itself can + * ascertain that a precondition, specified in the API expressed at the + * level of the activated method, has been violated. + * When Commons Math throws an {@code IllegalArgumentException}, it is + * usually the consequence of checking the actual parameters passed to + * the method. + */ + T value(T x); +} http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/main/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolver.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolver.java b/src/main/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolver.java index 9c9c0f0..01bb784 100644 --- a/src/main/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolver.java +++ b/src/main/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolver.java @@ -19,7 +19,7 @@ package org.apache.commons.math3.analysis.solvers; import org.apache.commons.math3.Field; import org.apache.commons.math3.RealFieldElement; -import org.apache.commons.math3.analysis.FieldUnivariateFunction; +import org.apache.commons.math3.analysis.RealFieldUnivariateFunction; import org.apache.commons.math3.exception.MathInternalError; import org.apache.commons.math3.exception.NoBracketingException; import org.apache.commons.math3.exception.NullArgumentException; @@ -162,7 +162,7 @@ public class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>> { * @exception NullArgumentException if f is null. * @exception NoBracketingException if root cannot be bracketed */ - public T solve(final int maxEval, final FieldUnivariateFunction<T> f, + public T solve(final int maxEval, final RealFieldUnivariateFunction<T> f, final T min, final T max, final AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException { return solve(maxEval, f, min, max, min.add(max).divide(2), allowedSolution); @@ -185,7 +185,7 @@ public class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>> { * @exception NullArgumentException if f is null. * @exception NoBracketingException if root cannot be bracketed */ - public T solve(final int maxEval, final FieldUnivariateFunction<T> f, + public T solve(final int maxEval, final RealFieldUnivariateFunction<T> f, final T min, final T max, final T startValue, final AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException { http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/main/java/org/apache/commons/math3/dfp/BracketingNthOrderBrentSolverDFP.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/dfp/BracketingNthOrderBrentSolverDFP.java b/src/main/java/org/apache/commons/math3/dfp/BracketingNthOrderBrentSolverDFP.java index fb6428b..0c5fa31 100644 --- a/src/main/java/org/apache/commons/math3/dfp/BracketingNthOrderBrentSolverDFP.java +++ b/src/main/java/org/apache/commons/math3/dfp/BracketingNthOrderBrentSolverDFP.java @@ -17,7 +17,7 @@ package org.apache.commons.math3.dfp; -import org.apache.commons.math3.analysis.FieldUnivariateFunction; +import org.apache.commons.math3.analysis.RealFieldUnivariateFunction; import org.apache.commons.math3.analysis.solvers.AllowedSolution; import org.apache.commons.math3.analysis.solvers.FieldBracketingNthOrderBrentSolver; import org.apache.commons.math3.exception.NoBracketingException; @@ -135,7 +135,7 @@ public class BracketingNthOrderBrentSolverDFP extends FieldBracketingNthOrderBre MathUtils.checkNotNull(f); // wrap the function - FieldUnivariateFunction<Dfp> fieldF = new FieldUnivariateFunction<Dfp>() { + RealFieldUnivariateFunction<Dfp> fieldF = new RealFieldUnivariateFunction<Dfp>() { /** {@inheritDoc} */ @Override http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/main/java/org/apache/commons/math3/dfp/UnivariateDfpFunction.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/dfp/UnivariateDfpFunction.java b/src/main/java/org/apache/commons/math3/dfp/UnivariateDfpFunction.java index 5978476..5969065 100644 --- a/src/main/java/org/apache/commons/math3/dfp/UnivariateDfpFunction.java +++ b/src/main/java/org/apache/commons/math3/dfp/UnivariateDfpFunction.java @@ -18,7 +18,7 @@ package org.apache.commons.math3.dfp; /** * An interface representing a univariate {@link Dfp} function. - * @deprecated as of 3.6, replaced with {@link org.apache.commons.math3.analysis.FieldUnivariateFunction} + * @deprecated as of 3.6, replaced with {@link org.apache.commons.math3.analysis.RealFieldUnivariateFunction} */ @Deprecated public interface UnivariateDfpFunction { http://git-wip-us.apache.org/repos/asf/commons-math/blob/d3911464/src/test/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java b/src/test/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java index 327655f..c3be9f4 100644 --- a/src/test/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java +++ b/src/test/java/org/apache/commons/math3/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java @@ -17,7 +17,7 @@ package org.apache.commons.math3.analysis.solvers; -import org.apache.commons.math3.analysis.FieldUnivariateFunction; +import org.apache.commons.math3.analysis.RealFieldUnivariateFunction; import org.apache.commons.math3.analysis.solvers.AllowedSolution; import org.apache.commons.math3.dfp.Dfp; import org.apache.commons.math3.dfp.DfpField; @@ -53,7 +53,7 @@ public final class FieldBracketingNthOrderBrentSolverTest { FieldBracketingNthOrderBrentSolver<Dfp> solver = new FieldBracketingNthOrderBrentSolver<Dfp>(relativeAccuracy, absoluteAccuracy, field.newDfp(1.0e-20), 20); - FieldUnivariateFunction<Dfp> f = new FieldUnivariateFunction<Dfp>() { + RealFieldUnivariateFunction<Dfp> f = new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { Dfp one = field.getOne(); Dfp oneHalf = one.divide(2); @@ -85,37 +85,37 @@ public final class FieldBracketingNthOrderBrentSolverTest { // intern J. Computer Math Vol 23 pp 265-282 // available here: http://www.math.nps.navy.mil/~bneta/SeveralNewMethods.PDF for (AllowedSolution allowed : AllowedSolution.values()) { - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return DfpMath.sin(x).subtract(x.divide(2)); } }, 200, -2.0, 2.0, allowed); - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return DfpMath.pow(x, 5).add(x).subtract(field.newDfp(10000)); } }, 200, -5.0, 10.0, allowed); - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return x.sqrt().subtract(field.getOne().divide(x)).subtract(field.newDfp(3)); } }, 200, 0.001, 10.0, allowed); - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return DfpMath.exp(x).add(x).subtract(field.newDfp(20)); } }, 200, -5.0, 5.0, allowed); - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return DfpMath.log(x).add(x.sqrt()).subtract(field.newDfp(5)); } }, 200, 0.001, 10.0, allowed); - check(new FieldUnivariateFunction<Dfp>() { + check(new RealFieldUnivariateFunction<Dfp>() { public Dfp value(Dfp x) { return x.subtract(field.getOne()).multiply(x).multiply(x).subtract(field.getOne()); } @@ -124,7 +124,7 @@ public final class FieldBracketingNthOrderBrentSolverTest { } - private void check(FieldUnivariateFunction<Dfp> f, int maxEval, double min, double max, + private void check(RealFieldUnivariateFunction<Dfp> f, int maxEval, double min, double max, AllowedSolution allowedSolution) { FieldBracketingNthOrderBrentSolver<Dfp> solver = new FieldBracketingNthOrderBrentSolver<Dfp>(relativeAccuracy, absoluteAccuracy,