You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/06/24 02:12:18 UTC
svn commit: r1139126 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/solvers/ site/xdoc/
test/java/org/apache/commons/math/analysis/
test/java/org/apache/commons/math/analysis/solvers/
Author: erans
Date: Fri Jun 24 00:12:17 2011
New Revision: 1139126
URL: http://svn.apache.org/viewvc?rev=1139126&view=rev
Log:
MATH-599
"SecantSolver" modified to correspond to the original algorithm. Added several
secant-based solvers. Patch provided by Dennis Hendriks.
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java (with props)
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java (with props)
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java (with props)
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java (with props)
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java (with props)
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java (with props)
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java (with props)
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java (with props)
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java (with props)
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java (with props)
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java (with props)
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.math.analysis.solvers;
+
+
+/** The kinds of solutions that a {@link UnivariateRealSolver (univariate real)
+ * root-finding algorithm} may accept as solutions. This basically controls
+ * whether or not under-approximations and over-approximations are allowed.
+ *
+ * <p>If all solutions are accepted ({@link #EITHER_SIDE}), then the solution
+ * that the root-finding algorithm returns for a given root may be equal to the
+ * actual root, but it may also be an approximation that is slightly smaller
+ * or slightly larger than the actual root. Root-finding algorithms generally
+ * only guarantee that the returned solution is within the requested
+ * tolerances. In certain cases however, in particular for
+ * {@link EventHandler state events} of {@link ODEIntegrator ODE solvers}, it
+ * may be necessary to guarantee that a solution is returned that does not
+ * under-approximate the solution.</p>
+ *
+ * @see BracketedSolution
+ * @since 3.0
+ * @version $Id$
+ */
+public enum AllowedSolutions {
+ /** There are no additional side restriction on the solutions for
+ * root-finding. That is, both under-approximations and over-approximations
+ * are allowed. So, if a function f(x) has a root at x = y, then the
+ * root-finding result s may be smaller than y, equal to y, or greater
+ * than y.
+ */
+ EITHER_SIDE,
+
+ /** Only solutions that are less than or equal to the actual root are
+ * acceptable as solutions for root-finding. In other words,
+ * over-approximations are not allowed. So, if a function f(x) has a root
+ * at x = y, then the root-finding result s must satisfy s <= y.
+ */
+ LEFT_SIDE,
+
+ /** Only solutions that are greater than or equal to the actual root are
+ * acceptable as solutions for root-finding. In other words,
+ * under-approximations are not allowed. So, if a function f(x) has a root
+ * at x = y, then the root-finding result s must satisfy s >= y.
+ */
+ RIGHT_SIDE;
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/AllowedSolutions.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java?rev=1139126&r1=1139125&r2=1139126&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BaseUnivariateRealSolver.java Fri Jun 24 00:12:17 2011
@@ -65,10 +65,10 @@ public interface BaseUnivariateRealSolve
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.
*
+ * @param maxEval Maximum number of evaluations.
* @param f Function to solve.
* @param min Lower bound for the interval.
* @param max Upper bound for the interval.
- * @param maxEval Maximum number of evaluations.
* @return a value where the function is zero.
* @throws org.apache.commons.math.exception.MathIllegalArgumentException
* if the arguments do not satisfy the requirements specified by the solver.
@@ -83,11 +83,11 @@ public interface BaseUnivariateRealSolve
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.
*
+ * @param maxEval Maximum number of evaluations.
* @param f Function to solve.
* @param min Lower bound for the interval.
* @param max Upper bound for the interval.
* @param startValue Start value to use.
- * @param maxEval Maximum number of evaluations.
* @return a value where the function is zero.
* @throws org.apache.commons.math.exception.MathIllegalArgumentException
* if the arguments do not satisfy the requirements specified by the solver.
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.math.analysis.solvers;
+
+/** Interface for {@link UnivariateRealSolver (univariate real) root-finding
+ * algorithms} that maintain a bracketed solution. There are several advantages
+ * to having such root-finding algorithms:
+ * <ul>
+ * <li>The bracketed solution guarantees that the root is kept within the
+ * interval. As such, these algorithms generally also guarantee
+ * convergence.</li>
+ * <li>The bracketed solution means that we have the opportunity to only
+ * return roots that are greater than or equal to the actual root, or
+ * are less than or equal to the actual root. That is, we can control
+ * whether under-approximations and over-approximations are
+ * {@link AllowedSolutions allowed solutions}. Other root-finding
+ * algorithms can usually only guarantee that the solution (the root that
+ * was found) is around the actual root.</li>
+ * </ul>
+ *
+ * <p>For backwards compatibility, all root-finding algorithms must have
+ * {@link AllowedSolutions#EITHER_SIDE EITHER_SIDE} as default for the allowed
+ * solutions.</p>
+ *
+ * @see AllowedSolutions
+ * @since 3.0
+ * @version $Id$
+ */
+public interface BracketedSolution {
+ /** Returns the kind of solutions that the root-finding algorithm may
+ * accept as solutions.
+ *
+ * @return the kind of solutions that the root-finding algorithm may
+ * accept as solutions
+ */
+ AllowedSolutions getAllowedSolutions();
+
+ /** Sets the kind of solutions that the root-finding algorithm may accept
+ * as solutions.
+ *
+ * @param allowedSolutions the kind of solutions that the root-finding
+ * algorithm may accept as solutions
+ */
+ void setAllowedSolutions(AllowedSolutions allowedSolutions);
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/BracketedSolution.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Implements the <em>Illinois</em> method for root-finding (approximating
+ * a zero of a univariate real function). It is a modified
+ * {@link RegulaFalsiSolver <em>Regula Falsi</em>} method.
+ *
+ * <p>Like the <em>Regula Falsi</em> method, convergence is guaranteed by
+ * maintaining a bracketed solution. The <em>Illinois</em> method however,
+ * should converge much faster than the original <em>Regula Falsi</em>
+ * method.</p>
+ *
+ * <p>The <em>Illinois</em> method assumes that the function is continuous,
+ * but not necessarily smooth.</p>
+ *
+ * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
+ * <em>A modified regula falsi method for computing the root of an
+ * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
+ * pages 168-174, Springer, 1971.</p>
+ *
+ * @since 3.0
+ * @version $Id$
+ */
+public class IllinoisSolver extends SecantBase implements BracketedSolution {
+ /** Construct a solver with default accuracy (1e-6). */
+ public IllinoisSolver() {
+ super(DEFAULT_ABSOLUTE_ACCURACY, Method.ILLINOIS);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public IllinoisSolver(final double absoluteAccuracy) {
+ super(absoluteAccuracy, Method.ILLINOIS);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param relativeAccuracy relative accuracy
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public IllinoisSolver(final double relativeAccuracy,
+ final double absoluteAccuracy) {
+ super(relativeAccuracy, absoluteAccuracy, Method.ILLINOIS);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public AllowedSolutions getAllowedSolutions() {
+ return allowedSolutions;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setAllowedSolutions(final AllowedSolutions allowedSolutions) {
+ this.allowedSolutions = allowedSolutions;
+ }
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/IllinoisSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Implements the <em>Pegasus</em> method for root-finding (approximating
+ * a zero of a univariate real function). It is a modified
+ * {@link RegulaFalsiSolver <em>Regula Falsi</em>} method.
+ *
+ * <p>Like the <em>Regula Falsi</em> method, convergence is guaranteed by
+ * maintaining a bracketed solution. The <em>Pegasus</em> method however,
+ * should converge much faster than the original <em>Regula Falsi</em> method.
+ * Furthermore, it should converge faster than the
+ * {@link IllinoisSolver <em>Illinois</em>} method, another
+ * <em>Regula Falsi</em>-based method.</p>
+ *
+ * <p>The <em>Pegasus</em> method assumes that the function is continuous,
+ * but not necessarily smooth.</p>
+ *
+ * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
+ * <em>The "Pegasus" method for computing the root of an equation</em>,
+ * BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer,
+ * 1972.</p>
+ *
+ * @since 3.0
+ * @version $Id$
+ */
+public class PegasusSolver extends SecantBase implements BracketedSolution {
+ /** Construct a solver with default accuracy (1e-6). */
+ public PegasusSolver() {
+ super(DEFAULT_ABSOLUTE_ACCURACY, Method.PEGASUS);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public PegasusSolver(final double absoluteAccuracy) {
+ super(absoluteAccuracy, Method.PEGASUS);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param relativeAccuracy relative accuracy
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public PegasusSolver(final double relativeAccuracy,
+ final double absoluteAccuracy) {
+ super(relativeAccuracy, absoluteAccuracy, Method.PEGASUS);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public AllowedSolutions getAllowedSolutions() {
+ return allowedSolutions;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setAllowedSolutions(final AllowedSolutions allowedSolutions) {
+ this.allowedSolutions = allowedSolutions;
+ }
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/PegasusSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Implements the <em>Regula Falsi</em> or <em>False position</em> method for
+ * root-finding (approximating a zero of a univariate real function). It is a
+ * modified {@link SecantSolver <em>Secant</em>} method. Unlike the
+ * <em>Secant</em> method, convergence is guaranteed by maintaining a
+ * {@link BracketedSolution bracketed solution}.
+ *
+ * <p>The <em>Regula Falsi</em> method assumes that the function is continuous,
+ * but not necessarily smooth.</p>
+ *
+ * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
+ * <em>A modified regula falsi method for computing the root of an
+ * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
+ * pages 168-174, Springer, 1971.</p>
+ *
+ * @since 3.0
+ * @version $Id$
+ */
+public class RegulaFalsiSolver extends SecantBase implements BracketedSolution {
+ /** Construct a solver with default accuracy (1e-6). */
+ public RegulaFalsiSolver() {
+ super(DEFAULT_ABSOLUTE_ACCURACY, Method.REGULA_FALSI);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public RegulaFalsiSolver(final double absoluteAccuracy) {
+ super(absoluteAccuracy, Method.REGULA_FALSI);
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param relativeAccuracy relative accuracy
+ * @param absoluteAccuracy absolute accuracy
+ */
+ public RegulaFalsiSolver(final double relativeAccuracy,
+ final double absoluteAccuracy) {
+ super(relativeAccuracy, absoluteAccuracy, Method.REGULA_FALSI);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public AllowedSolutions getAllowedSolutions() {
+ return allowedSolutions;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setAllowedSolutions(final AllowedSolutions allowedSolutions) {
+ this.allowedSolutions = allowedSolutions;
+ }
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,200 @@
+/*
+ * 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.math.analysis.solvers;
+
+import org.apache.commons.math.util.FastMath;
+import org.apache.commons.math.exception.MathInternalError;
+
+/**
+ * Base class for all <em>Secant</em>-based methods for root-finding
+ * (approximating a zero of a univariate real function).
+ *
+ * <p>Implementation of the {@link SecantSolver <em>Secant</em>},
+ * {@link RegulaFalsiSolver <em>Regula Falsi</em>}, and
+ * {@link IllinoisSolver <em>Illinois</em>} methods is based on the
+ * following article: M. Dowell and P. Jarratt,
+ * <em>A modified regula falsi method for computing the root of an
+ * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
+ * pages 168-174, Springer, 1971.</p>
+ *
+ * <p>Implementation of the {@link PegasusSolver <em>Pegasus</em>} method is
+ * based on the following article: M. Dowell and P. Jarratt,
+ * <em>The "Pegasus" method for computing the root of an equation</em>,
+ * BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer,
+ * 1972.</p>
+ *
+ * @since 3.0
+ * @version $Id$
+ */
+public abstract class SecantBase extends AbstractUnivariateRealSolver {
+ /** Default absolute accuracy. */
+ protected static final double DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
+ /** The kinds of solutions that the algorithm may accept. */
+ protected AllowedSolutions allowedSolutions = AllowedSolutions.EITHER_SIDE;
+ /** The <em>Secant</em>-based root-finding method to use. */
+ private final Method method;
+
+ /**
+ * Construct a solver.
+ *
+ * @param absoluteAccuracy absolute accuracy
+ * @param method <em>Secant</em>-based root-finding method to use
+ */
+ protected SecantBase(final double absoluteAccuracy, final Method method) {
+ super(absoluteAccuracy);
+ this.method = method;
+ }
+
+ /**
+ * Construct a solver.
+ *
+ * @param relativeAccuracy relative accuracy
+ * @param absoluteAccuracy absolute accuracy
+ * @param method <em>Secant</em>-based root-finding method to use
+ */
+ protected SecantBase(final double relativeAccuracy,
+ final double absoluteAccuracy,
+ final Method method) {
+ super(relativeAccuracy, absoluteAccuracy);
+ this.method = method;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected final double doSolve() {
+ // Get initial solution
+ double x0 = getMin();
+ double x1 = getMax();
+ double f0 = computeObjectiveValue(x0);
+ double f1 = computeObjectiveValue(x1);
+
+ // If one of the bounds is the exact root, return it. Since these are
+ // not under-approximations or over-approximations, we can return them
+ // regardless of the allowed solutions.
+ if (f0 == 0.0) return x0;
+ if (f1 == 0.0) return x1;
+
+ // Verify bracketing of initial solution.
+ verifyBracketing(x0, x1);
+
+ // Get accuracies.
+ final double ftol = getFunctionValueAccuracy();
+ final double atol = getAbsoluteAccuracy();
+ final double rtol = getRelativeAccuracy();
+
+ // Variables to hold new bounds.
+ double x;
+ double fx;
+
+ // Keep track of inverted intervals, meaning that the left bound is
+ // larger than the right bound. Not used for the original Secant
+ // method.
+ boolean inverted = false;
+
+ // Keep finding better approximations.
+ while (true) {
+ // Calculate the next approximation.
+ x = x1 - ((f1 * (x1 - x0)) / (f1 - f0));
+ fx = computeObjectiveValue(x);
+
+ // If the new approximation is the exact root, return it. Since
+ // this is not an under-approximation or an over-approximation,
+ // we can return it regardless of the allowed solutions.
+ if (fx == 0.0) return x;
+
+ // Update the bounds with the new approximation.
+ if (method == Method.SECANT) {
+ x0 = x1;
+ f0 = f1;
+ x1 = x;
+ f1 = fx;
+ } else if (f1 * fx < 0) {
+ // We had [x0..x1]. We update it to [x1, x]. Note that the
+ // value of x1 has switched to the other bound, thus inverting
+ // the interval.
+ x0 = x1;
+ f0 = f1;
+ x1 = x;
+ f1 = fx;
+ inverted = !inverted;
+ } else {
+ // We had [x0..x1]. We update it to [x0, x].
+ if (method == Method.ILLINOIS) f0 *= 0.5;
+ if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
+ x1 = x;
+ f1 = fx;
+ }
+
+ // If the function value of the last approximation is too small,
+ // given the function value accuracy, then we can't get close to
+ // the root than we already are.
+ if (FastMath.abs(f1) <= ftol) {
+ switch (allowedSolutions) {
+ case EITHER_SIDE:
+ return x1;
+ case LEFT_SIDE:
+ if (inverted) {
+ return x1;
+ }
+ break;
+ case RIGHT_SIDE:
+ if (!inverted) {
+ return x1;
+ }
+ break;
+ default:
+ throw new MathInternalError();
+ }
+ }
+
+ // If the current interval is within the given accuracies, we
+ // are satisfied with the current approximation.
+ if (FastMath.abs(x1 - x0) < FastMath.max(rtol * FastMath.abs(x1),
+ atol)) {
+ switch (allowedSolutions) {
+ case EITHER_SIDE:
+ return x1;
+ case LEFT_SIDE:
+ return inverted ? x1 : x0;
+ case RIGHT_SIDE:
+ return inverted ? x0 : x1;
+ default:
+ throw new MathInternalError();
+ }
+ }
+ }
+ }
+
+ /** <em>Secant</em>-based root-finding methods. */
+ protected enum Method {
+ /** The original {@link SecantSolver <em>Secant</em>} method. */
+ SECANT,
+
+ /**
+ * The {@link RegulaFalsiSolver <em>Regula Falsi</em>} or
+ * <em>False Position</em> method.
+ */
+ REGULA_FALSI,
+
+ /** The {@link IllinoisSolver <em>Illinois</em>} method. */
+ ILLINOIS,
+
+ /** The {@link PegasusSolver <em>Pegasus</em>} method. */
+ PEGASUS,
+ }
+}
Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java?rev=1139126&r1=1139125&r2=1139126&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/SecantSolver.java Fri Jun 24 00:12:17 2011
@@ -14,137 +14,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis.solvers;
-
-import org.apache.commons.math.exception.NoBracketingException;
-import org.apache.commons.math.util.FastMath;
+package org.apache.commons.math.analysis.solvers;
/**
- * Implements a modified version of the
- * <a href="http://mathworld.wolfram.com/SecantMethod.html">secant method</a>
- * for approximating a zero of a real univariate function.
- * <p>
- * The algorithm is modified to maintain bracketing of a root by successive
- * approximations. Because of forced bracketing, convergence may be slower than
- * the unrestricted secant algorithm. However, this implementation should in
- * general outperform the
- * <a href="http://mathworld.wolfram.com/MethodofFalsePosition.html">
- * regula falsi method.</a></p>
- * <p>
- * The function is assumed to be continuous but not necessarily smooth.</p>
+ * Implements the <em>Secant</em> method for root-finding (approximating a
+ * zero of a univariate real function). The solution that is maintained is
+ * not bracketed, and as such convergence is not guaranteed.
+ *
+ * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
+ * <em>A modified regula falsi method for computing the root of an
+ * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
+ * pages 168-174, Springer, 1971.</p>
+ *
+ * <p>Note that since release 3.0 this class implements the actual
+ * <em>Secant</em> algorithm, and not a modified one. As such, the 3.0 version
+ * is not backwards compatible with previous versions. To use an algorithm
+ * similar to the pre-3.0 releases, use the
+ * {@link IllinoisSolver <em>Illinois</em>} algorithm or the
+ * {@link PegasusSolver <em>Pegasus</em>} algorithm.</p>
*
* @version $Id$
*/
-public class SecantSolver extends AbstractUnivariateRealSolver {
- /** Default absolute accuracy. */
- private static final double DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
-
- /**
- * Construct a solver with default accuracy (1e-6).
- */
+public class SecantSolver extends SecantBase {
+ /** Construct a solver with default accuracy (1e-6). */
public SecantSolver() {
- this(DEFAULT_ABSOLUTE_ACCURACY);
+ super(DEFAULT_ABSOLUTE_ACCURACY, Method.SECANT);
}
+
/**
* Construct a solver.
*
- * @param absoluteAccuracy Absolute accuracy.
+ * @param absoluteAccuracy absolute accuracy
*/
- public SecantSolver(double absoluteAccuracy) {
- super(absoluteAccuracy);
+ public SecantSolver(final double absoluteAccuracy) {
+ super(absoluteAccuracy, Method.SECANT);
}
+
/**
* Construct a solver.
*
- * @param relativeAccuracy Relative accuracy.
- * @param absoluteAccuracy Absolute accuracy.
+ * @param relativeAccuracy relative accuracy
+ * @param absoluteAccuracy absolute accuracy
*/
- public SecantSolver(double relativeAccuracy,
- double absoluteAccuracy) {
- super(relativeAccuracy, absoluteAccuracy);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected double doSolve() {
- double min = getMin();
- double max = getMax();
- verifyInterval(min, max);
-
- final double functionValueAccuracy = getFunctionValueAccuracy();
-
- // Index 0 is the old approximation for the root.
- // Index 1 is the last calculated approximation for the root.
- // Index 2 is a bracket for the root with respect to x0.
- // OldDelta is the length of the bracketing interval of the last
- // iteration.
- double x0 = min;
- double x1 = max;
-
- double y0 = computeObjectiveValue(x0);
- // return the first endpoint if it is good enough
- if (FastMath.abs(y0) <= functionValueAccuracy) {
- return x0;
- }
-
- // return the second endpoint if it is good enough
- double y1 = computeObjectiveValue(x1);
- if (FastMath.abs(y1) <= functionValueAccuracy) {
- return x1;
- }
-
- // Verify bracketing
- if (y0 * y1 >= 0) {
- throw new NoBracketingException(min, max, y0, y1);
- }
-
- final double absoluteAccuracy = getAbsoluteAccuracy();
- final double relativeAccuracy = getRelativeAccuracy();
-
- double x2 = x0;
- double y2 = y0;
- double oldDelta = x2 - x1;
- while (true) {
- if (FastMath.abs(y2) < FastMath.abs(y1)) {
- x0 = x1;
- x1 = x2;
- x2 = x0;
- y0 = y1;
- y1 = y2;
- y2 = y0;
- }
- if (FastMath.abs(y1) <= functionValueAccuracy) {
- return x1;
- }
- if (FastMath.abs(oldDelta) < FastMath.max(relativeAccuracy * FastMath.abs(x1),
- absoluteAccuracy)) {
- return x1;
- }
- double delta;
- if (FastMath.abs(y1) > FastMath.abs(y0)) {
- // Function value increased in last iteration. Force bisection.
- delta = 0.5 * oldDelta;
- } else {
- delta = (x0 - x1) / (1 - y0 / y1);
- if (delta / oldDelta > 1) {
- // New approximation falls outside bracket.
- // Fall back to bisection.
- delta = 0.5 * oldDelta;
- }
- }
- x0 = x1;
- y0 = y1;
- x1 = x1 + delta;
- y1 = computeObjectiveValue(x1);
- if ((y1 > 0) == (y2 > 0)) {
- // New bracket is (x0,x1).
- x2 = x0;
- y2 = y0;
- }
- oldDelta = x2 - x1;
- }
+ public SecantSolver(final double relativeAccuracy,
+ final double absoluteAccuracy) {
+ super(relativeAccuracy, absoluteAccuracy, Method.SECANT);
}
}
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1139126&r1=1139125&r2=1139126&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Jun 24 00:12:17 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
+ <action dev="eran" type="add" issue="MATH-599" due-to="Dennis Hendriks">
+ Modified "SecantSolver" to comply with the original algorithm. Added several
+ secant-based solvers.
+ </action>
<action dev="luc" type="fix" issue="MATH-600">
Fixed javadoc for ODEIntegrator interface
</action>
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.math.analysis;
+
+/**
+ * Auxiliary class for testing solvers.
+ *
+ * @version $Id$
+ */
+public class XMinus5Function implements DifferentiableUnivariateRealFunction {
+
+ /* Evaluate x - 5 fuction.
+ * @see org.apache.commons.math.UnivariateRealFunction#value(double)
+ */
+ public double value(double x) {
+ return x - 5;
+ }
+
+ /* First derivative of x - 5 function
+ */
+ public UnivariateRealFunction derivative() {
+ return new UnivariateRealFunction() {
+ public double value(double x) {
+ return 1.0;
+ }
+ };
+ }
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/XMinus5Function.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Test case for {@link IllinoisSolver Illinois} solver.
+ *
+ * @version $Id$
+ */
+public final class IllinoisSolverTest extends SecantBaseTest {
+ /** {@inheritDoc} */
+ protected UnivariateRealSolver getSolver() {
+ return new IllinoisSolver();
+ }
+
+ /** {@inheritDoc} */
+ protected int[] getQuinticEvalCounts() {
+ return new int[] {3, 7, 9, 10, 10, 10, 12, 12, 14, 15, 20};
+ }
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/IllinoisSolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Test case for {@link PegasusSolver Pegasus} solver.
+ *
+ * @version $Id$
+ */
+public final class PegasusSolverTest extends SecantBaseTest {
+ /** {@inheritDoc} */
+ protected UnivariateRealSolver getSolver() {
+ return new PegasusSolver();
+ }
+
+ /** {@inheritDoc} */
+ protected int[] getQuinticEvalCounts() {
+ return new int[] {3, 7, 9, 8, 9, 8, 10, 10, 12, 16, 18};
+ }
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/PegasusSolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.math.analysis.solvers;
+
+/**
+ * Test case for {@link RegulaFalsiSolver Regula Falsi} solver.
+ *
+ * @version $Id$
+ */
+public final class RegulaFalsiSolverTest extends SecantBaseTest {
+ /** {@inheritDoc} */
+ protected UnivariateRealSolver getSolver() {
+ return new RegulaFalsiSolver();
+ }
+
+ /** {@inheritDoc} */
+ protected int[] getQuinticEvalCounts() {
+ // While the Regula Falsi method guarantees convergence, convergence
+ // may be extremely slow. The last test case does not converge within
+ // even a million iterations. As such, it was disabled.
+ return new int[] {3, 7, 8, 19, 18, 11, 67, 55, 288, 151, -1};
+ }
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/RegulaFalsiSolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java?rev=1139126&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java Fri Jun 24 00:12:17 2011
@@ -0,0 +1,199 @@
+/*
+ * 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.math.analysis.solvers;
+
+import org.apache.commons.math.analysis.QuinticFunction;
+import org.apache.commons.math.analysis.SinFunction;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.analysis.XMinus5Function;
+import org.apache.commons.math.exception.NumberIsTooLargeException;
+import org.apache.commons.math.exception.NoBracketingException;
+import org.apache.commons.math.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Base class for {@link SecantBase} derived root-finding algorithms tests.
+ *
+ * @version $Id$
+ */
+public abstract class SecantBaseTest {
+ /** Returns the solver to use to perform the tests.
+ * @return the solver to use to perform the tests
+ */
+ protected abstract UnivariateRealSolver getSolver();
+
+ /** Returns the expected number of evaluations for the
+ * {@link #testQuinticZero} unit test. A value of {@code -1} indicates that
+ * the test should be skipped for that solver.
+ * @return the expected number of evaluations for the
+ * {@link #testQuinticZero} unit test
+ */
+ protected abstract int[] getQuinticEvalCounts();
+
+ @Test
+ public void testSinZero() {
+ // The sinus function is behaved well around the root at pi. The second
+ // order derivative is zero, which means linear approximating methods
+ // still converge quadratically.
+ UnivariateRealFunction f = new SinFunction();
+ double result;
+ UnivariateRealSolver solver = getSolver();
+
+ result = solver.solve(100, f, 3, 4);
+ //System.out.println(
+ // "Root: " + result + " Evaluations: " + solver.getEvaluations());
+ Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+ Assert.assertTrue(solver.getEvaluations() <= 6);
+ result = solver.solve(100, f, 1, 4);
+ //System.out.println(
+ // "Root: " + result + " Evaluations: " + solver.getEvaluations());
+ Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
+ Assert.assertTrue(solver.getEvaluations() <= 7);
+ }
+
+ @Test
+ public void testQuinticZero() {
+ // The quintic function has zeros at 0, +-0.5 and +-1.
+ // Around the root of 0 the function is well behaved, with a second
+ // derivative of zero a 0.
+ // The other roots are less well to find, in particular the root at 1,
+ // because the function grows fast for x>1.
+ // The function has extrema (first derivative is zero) at 0.27195613
+ // and 0.82221643, intervals containing these values are harder for
+ // the solvers.
+ UnivariateRealFunction f = new QuinticFunction();
+ double result;
+ UnivariateRealSolver solver = getSolver();
+ double atol = solver.getAbsoluteAccuracy();
+ int[] counts = getQuinticEvalCounts();
+
+ // Tests data: initial bounds, and expected solution, per test case.
+ double[][] testsData = {{-0.2, 0.2, 0.0},
+ {-0.1, 0.3, 0.0},
+ {-0.3, 0.45, 0.0},
+ { 0.3, 0.7, 0.5},
+ { 0.2, 0.6, 0.5},
+ { 0.05, 0.95, 0.5},
+ { 0.85, 1.25, 1.0},
+ { 0.8, 1.2, 1.0},
+ { 0.85, 1.75, 1.0},
+ { 0.55, 1.45, 1.0},
+ { 0.85, 5.0, 1.0},
+ };
+ int maxIter = 500;
+
+ for(int i = 0; i < testsData.length; i++) {
+ // Skip test, if needed.
+ if (counts[i] == -1) continue;
+
+ // Compute solution.
+ double[] testData = testsData[i];
+ result = solver.solve(maxIter, f, testData[0], testData[1]);
+ //System.out.println(
+ // "Root: " + result + " Evaluations: " + solver.getEvaluations());
+
+ // Check solution.
+ Assert.assertEquals(result, testData[2], atol);
+ Assert.assertTrue(solver.getEvaluations() <= counts[i] + 1);
+ }
+ }
+
+ @Test
+ public void testRootEndpoints() {
+ UnivariateRealFunction f = new XMinus5Function();
+ UnivariateRealSolver solver = getSolver();
+
+ // End-point is root. This should be a special case in the solver, and
+ // the initial end-point should be returned exactly.
+ double result = solver.solve(100, f, 5.0, 6.0);
+ Assert.assertEquals(5.0, result, 0.0);
+
+ result = solver.solve(100, f, 4.0, 5.0);
+ Assert.assertEquals(5.0, result, 0.0);
+
+ result = solver.solve(100, f, 5.0, 6.0, 5.5);
+ Assert.assertEquals(5.0, result, 0.0);
+
+ result = solver.solve(100, f, 4.0, 5.0, 4.5);
+ Assert.assertEquals(5.0, result, 0.0);
+ }
+
+ @Test
+ public void testBadEndpoints() {
+ UnivariateRealFunction f = new SinFunction();
+ UnivariateRealSolver solver = getSolver();
+ try { // bad interval
+ solver.solve(100, f, 1, -1);
+ Assert.fail("Expecting NumberIsTooLargeException - bad interval");
+ } catch (NumberIsTooLargeException ex) {
+ // expected
+ }
+ try { // no bracket
+ solver.solve(100, f, 1, 1.5);
+ Assert.fail("Expecting NoBracketingException - non-bracketing");
+ } catch (NoBracketingException ex) {
+ // expected
+ }
+ try { // no bracket
+ solver.solve(100, f, 1, 1.5, 1.2);
+ Assert.fail("Expecting NoBracketingException - non-bracketing");
+ } catch (NoBracketingException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testSolutionLeftSide() {
+ UnivariateRealFunction f = new SinFunction();
+ UnivariateRealSolver solver = getSolver();
+ if (!(solver instanceof BracketedSolution)) return;
+ ((BracketedSolution)solver).setAllowedSolutions(
+ AllowedSolutions.LEFT_SIDE);
+ double left = -1.5;
+ double right = 0.05;
+ for(int i = 0; i < 10; i++) {
+ // Test whether the allowed solutions are taken into account.
+ double solution = solver.solve(100, f, left, right);
+ Assert.assertTrue(solution <= 0.0);
+
+ // Prepare for next test.
+ left -= 0.1;
+ right += 0.3;
+ }
+ }
+
+ @Test
+ public void testSolutionRightSide() {
+ UnivariateRealFunction f = new SinFunction();
+ UnivariateRealSolver solver = getSolver();
+ if (!(solver instanceof BracketedSolution)) return;
+ ((BracketedSolution)solver).setAllowedSolutions(
+ AllowedSolutions.RIGHT_SIDE);
+ double left = -1.5;
+ double right = 0.05;
+ for(int i = 0; i < 10; i++) {
+ // Test whether the allowed solutions are taken into account.
+ double solution = solver.solve(100, f, left, right);
+ Assert.assertTrue(solution >= 0.0);
+
+ // Prepare for next test.
+ left -= 0.1;
+ right += 0.3;
+ }
+ }
+}
Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantBaseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java?rev=1139126&r1=1139125&r2=1139126&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/solvers/SecantSolverTest.java Fri Jun 24 00:12:17 2011
@@ -14,157 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis.solvers;
-import org.apache.commons.math.analysis.QuinticFunction;
-import org.apache.commons.math.analysis.SinFunction;
-import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.commons.math.exception.NumberIsTooLargeException;
-import org.apache.commons.math.exception.NoBracketingException;
-import org.apache.commons.math.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
+package org.apache.commons.math.analysis.solvers;
/**
- * Test case for {@link SecantSolver}.
+ * Test case for {@link SecantSolver Secant} solver.
*
* @version $Id$
*/
-public final class SecantSolverTest {
- @Test
- public void testSinZero() {
- // The sinus function is behaved well around the root at pi. The second
- // order derivative is zero, which means linar approximating methods will
- // still converge quadratically.
- UnivariateRealFunction f = new SinFunction();
- double result;
- UnivariateRealSolver solver = new SecantSolver();
-
- result = solver.solve(100, f, 3, 4);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 6);
- result = solver.solve(100, f, 1, 4);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 7);
- }
-
- @Test
- public void testQuinticZero() {
- // The quintic function has zeros at 0, +-0.5 and +-1.
- // Around the root of 0 the function is well behaved, with a second derivative
- // of zero a 0.
- // The other roots are less well to find, in particular the root at 1, because
- // the function grows fast for x>1.
- // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
- // intervals containing these values are harder for the solvers.
- UnivariateRealFunction f = new QuinticFunction();
- double result;
- // Brent-Dekker solver.
- UnivariateRealSolver solver = new SecantSolver();
- result = solver.solve(100, f, -0.2, 0.2);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 3);
- result = solver.solve(100, f, -0.1, 0.3);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 7);
- result = solver.solve(100, f, -0.3, 0.45);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 8);
- result = solver.solve(100, f, 0.3, 0.7);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 9);
- result = solver.solve(100, f, 0.2, 0.6);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 8);
- result = solver.solve(100, f, 0.05, 0.95);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 10);
- result = solver.solve(100, f, 0.85, 1.25);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 12);
- result = solver.solve(100, f, 0.8, 1.2);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 10);
- result = solver.solve(100, f, 0.85, 1.75);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 16);
- // The followig is especially slow because the solver first has to reduce
- // the bracket to exclude the extremum. After that, convergence is rapide.
- result = solver.solve(100, f, 0.55, 1.45);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 9);
- result = solver.solve(100, f, 0.85, 5);
- //System.out.println(
- // "Root: " + result + " Evaluations: " + solver.getEvaluations());
- Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
- Assert.assertTrue(solver.getEvaluations() <= 16);
- }
-
- @Test
- public void testRootEndpoints() {
- UnivariateRealFunction f = new SinFunction();
- SecantSolver solver = new SecantSolver();
-
- // endpoint is root
- double result = solver.solve(100, f, FastMath.PI, 4);
- Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
-
- result = solver.solve(100, f, 3, FastMath.PI);
- Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
-
- result = solver.solve(100, f, FastMath.PI, 4, 3.5);
- Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
-
- result = solver.solve(100, f, 3, FastMath.PI, 3.07);
- Assert.assertEquals(FastMath.PI, result, solver.getAbsoluteAccuracy());
-
+public final class SecantSolverTest extends SecantBaseTest {
+ /** {@inheritDoc} */
+ protected UnivariateRealSolver getSolver() {
+ return new SecantSolver();
}
- @Test
- public void testBadEndpoints() {
- UnivariateRealFunction f = new SinFunction();
- SecantSolver solver = new SecantSolver();
- try { // bad interval
- solver.solve(100, f, 1, -1);
- Assert.fail("Expecting NumberIsTooLargeException - bad interval");
- } catch (NumberIsTooLargeException ex) {
- // expected
- }
- try { // no bracket
- solver.solve(100, f, 1, 1.5);
- Assert.fail("Expecting NoBracketingException - non-bracketing");
- } catch (NoBracketingException ex) {
- // expected
- }
- try { // no bracket
- solver.solve(100, f, 1, 1.5, 1.2);
- Assert.fail("Expecting NoBracketingException - non-bracketing");
- } catch (NoBracketingException ex) {
- // expected
- }
+ /** {@inheritDoc} */
+ protected int[] getQuinticEvalCounts() {
+ // As the Secant method does not maintain a bracketed solution,
+ // convergence is not guaranteed. Two test cases are disabled (-1) due
+ // to bad solutions.
+ return new int[] {3, 7, -1, 8, 9, 8, 11, 12, 14, -1, 16};
}
}
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/solvers/ site/xdoc/
test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Sébastien Brisard <se...@m4x.org>.
+1
2011/6/24 Luc Maisonobe <Lu...@free.fr>:
> Hi all,
>
> The provided patch for MATH-599 includes a number of no-brace if statements
> like the following ones:
>
>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>
> I'm not sure if we have an unwritten rule for this, but personally I dislike
> this style a lot. Checkstyle provides a NeedBraces rule to avoid this.
>
> What about activating this rule ?
>
> Luc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/solvers/ site/xdoc/
test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by James Carman <ja...@carmanconsulting.com>.
Unless we've specifically set up our pom.xml file to handle it, the
release plugin doesn't work too well with Maven3. Do you have a copy
of Maven2 lying around?
On Mon, Jun 27, 2011 at 4:13 AM, Dennis Hendriks <D....@tue.nl> wrote:
> $ mvn -v
> Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
> Maven home: /mnt/run/dhendriks/apps/apache-maven
> Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
> Java home: /usr/java/jdk1.6.0_25/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "linux", version: "2.6.18-128.1.6.el5pae", arch: "i386", family:
> "unix"
>
> Dennis
>
> luc.maisonobe@free.fr wrote:
>>
>> ----- "Dennis Hendriks" <D....@tue.nl> a écrit :
>>
>>> I tried 'mvn clean site', and got this:
>>>
>>> (...)
>>> main:
>>> [INFO] Executed tasks
>>> [INFO]
>>> [INFO] --- maven-remote-resources-plugin:1.0:process (default) @
>>> commons-math ---
>>> [INFO]
>>> [INFO] --- maven-resources-plugin:2.4.1:resources (default-resources)
>>> @ commons-math ---
>>> [INFO] Using 'UTF-8' encoding to copy filtered resources.
>>> [INFO] Copying 2 resources to META-INF
>>> [INFO] Copying 1 resource to META-INF/localization
>>> [INFO]
>>> [INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @
>>> commons-math ---
>>> [INFO] Nothing to compile - all classes are up to date
>>> [INFO]
>>> [INFO] <<< jdepend-maven-plugin:2.0-beta-2:generate (report:generate)
>>> @ commons-math <<<
>>> [INFO] configuring report plugin
>>> org.codehaus.mojo:rat-maven-plugin:1.0-alpha-3
>>> [INFO] configuring report plugin
>>> org.codehaus.mojo:findbugs-maven-plugin:2.1
>>> [INFO]
>>> ------------------------------------------------------------------------
>>> [INFO] BUILD FAILURE
>>> [INFO]
>>> ------------------------------------------------------------------------
>>> [INFO] Total time: 1:05.413s
>>> [INFO] Finished at: Mon Jun 27 08:54:24 CEST 2011
>>> [INFO] Final Memory: 32M/280M
>>> [INFO]
>>> ------------------------------------------------------------------------
>>> [ERROR] Failed to execute goal
>>> org.apache.maven.plugins:maven-site-plugin:3.0-beta-3:site
>>> (default-site) on project commons-math: failed to get Reports: Unable to
>>> parse configuration of mojo
>>> org.codehaus.mojo:findbugs-maven-plugin:2.1:findbugs for parameter
>>> localRepository: Abstract class or interface
>>> 'org.apache.maven.artifact.repository.DefaultArtifactRepository'
>>> cannot be instantiated -> [Help 1]
>>> [ERROR]
>>> [ERROR] To see the full stack trace of the errors, re-run Maven with
>>> the -e switch.
>>> [ERROR] Re-run Maven using the -X switch to enable full debug
>>> logging.
>>> [ERROR]
>>> [ERROR] For more information about the errors and possible solutions,
>>>
>>> please read the following articles:
>>> [ERROR] [Help 1]
>>> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
>>>
>>> any ideas?
>>
>> No ideas at all :-(
>> Which version of maven do you use ?
>>
>> Luc
>>
>>> Dennis
>>>
>>>
>>> Luc Maisonobe wrote:
>>>>
>>>> Le 24/06/2011 11:33, Dennis Hendriks a écrit :
>>>>>
>>>>> > I have 137 errors only adding the check for braces, and only a
>>>
>>> handful
>>>>>
>>>>> > without this check!
>>>>>
>>>>> I used a trunk checkout and then:
>>>>>
>>>>> mvn -Prc clean package
>>>>> mvn checkstyle:checkstyle
>>>>>
>>>>> and I got 22792 checkstyle errors... See attachments.
>>>>
>>>> The checkstyle file used is not the one from Apache Commons Math.
>>>
>>> I'm
>>>>
>>>> not sure using the "rc" profile in the -Prc flag really cleaned
>>>> everything on the first command, so the second command "mvn
>>>> checkstyle:checkstyle" did use a cached value.
>>>>
>>>> Try something along these lines, without any -P flag:
>>>>
>>>> mvn clean site
>>>>
>>>> Luc
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>>>
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
$ mvn -v
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /mnt/run/dhendriks/apps/apache-maven
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_25/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.18-128.1.6.el5pae", arch: "i386", family:
"unix"
Dennis
luc.maisonobe@free.fr wrote:
> ----- "Dennis Hendriks" <D....@tue.nl> a écrit :
>
>> I tried 'mvn clean site', and got this:
>>
>> (...)
>> main:
>> [INFO] Executed tasks
>> [INFO]
>> [INFO] --- maven-remote-resources-plugin:1.0:process (default) @
>> commons-math ---
>> [INFO]
>> [INFO] --- maven-resources-plugin:2.4.1:resources (default-resources)
>> @
>> commons-math ---
>> [INFO] Using 'UTF-8' encoding to copy filtered resources.
>> [INFO] Copying 2 resources to META-INF
>> [INFO] Copying 1 resource to META-INF/localization
>> [INFO]
>> [INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @
>> commons-math ---
>> [INFO] Nothing to compile - all classes are up to date
>> [INFO]
>> [INFO] <<< jdepend-maven-plugin:2.0-beta-2:generate (report:generate)
>> @
>> commons-math <<<
>> [INFO] configuring report plugin
>> org.codehaus.mojo:rat-maven-plugin:1.0-alpha-3
>> [INFO] configuring report plugin
>> org.codehaus.mojo:findbugs-maven-plugin:2.1
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] BUILD FAILURE
>> [INFO]
>> ------------------------------------------------------------------------
>> [INFO] Total time: 1:05.413s
>> [INFO] Finished at: Mon Jun 27 08:54:24 CEST 2011
>> [INFO] Final Memory: 32M/280M
>> [INFO]
>> ------------------------------------------------------------------------
>> [ERROR] Failed to execute goal
>> org.apache.maven.plugins:maven-site-plugin:3.0-beta-3:site
>> (default-site)
>> on project commons-math: failed to get Reports: Unable to parse
>> configuration of mojo
>> org.codehaus.mojo:findbugs-maven-plugin:2.1:findbugs
>> for parameter localRepository: Abstract class or interface
>> 'org.apache.maven.artifact.repository.DefaultArtifactRepository'
>> cannot be
>> instantiated -> [Help 1]
>> [ERROR]
>> [ERROR] To see the full stack trace of the errors, re-run Maven with
>> the -e
>> switch.
>> [ERROR] Re-run Maven using the -X switch to enable full debug
>> logging.
>> [ERROR]
>> [ERROR] For more information about the errors and possible solutions,
>>
>> please read the following articles:
>> [ERROR] [Help 1]
>> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
>>
>> any ideas?
>
> No ideas at all :-(
> Which version of maven do you use ?
>
> Luc
>
>> Dennis
>>
>>
>> Luc Maisonobe wrote:
>>> Le 24/06/2011 11:33, Dennis Hendriks a écrit :
>>>> > I have 137 errors only adding the check for braces, and only a
>> handful
>>>> > without this check!
>>>>
>>>> I used a trunk checkout and then:
>>>>
>>>> mvn -Prc clean package
>>>> mvn checkstyle:checkstyle
>>>>
>>>> and I got 22792 checkstyle errors... See attachments.
>>> The checkstyle file used is not the one from Apache Commons Math.
>> I'm
>>> not sure using the "rc" profile in the -Prc flag really cleaned
>>> everything on the first command, so the second command "mvn
>>> checkstyle:checkstyle" did use a cached value.
>>>
>>> Try something along these lines, without any -P flag:
>>>
>>> mvn clean site
>>>
>>> Luc
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/solvers/ site/xdoc/
test/java/org/apache/commons/math/analysis/
test/java/org/apache/commons/math/analysis/solvers/
Posted by lu...@free.fr.
----- "Dennis Hendriks" <D....@tue.nl> a écrit :
> I tried 'mvn clean site', and got this:
>
> (...)
> main:
> [INFO] Executed tasks
> [INFO]
> [INFO] --- maven-remote-resources-plugin:1.0:process (default) @
> commons-math ---
> [INFO]
> [INFO] --- maven-resources-plugin:2.4.1:resources (default-resources)
> @
> commons-math ---
> [INFO] Using 'UTF-8' encoding to copy filtered resources.
> [INFO] Copying 2 resources to META-INF
> [INFO] Copying 1 resource to META-INF/localization
> [INFO]
> [INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @
> commons-math ---
> [INFO] Nothing to compile - all classes are up to date
> [INFO]
> [INFO] <<< jdepend-maven-plugin:2.0-beta-2:generate (report:generate)
> @
> commons-math <<<
> [INFO] configuring report plugin
> org.codehaus.mojo:rat-maven-plugin:1.0-alpha-3
> [INFO] configuring report plugin
> org.codehaus.mojo:findbugs-maven-plugin:2.1
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 1:05.413s
> [INFO] Finished at: Mon Jun 27 08:54:24 CEST 2011
> [INFO] Final Memory: 32M/280M
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-site-plugin:3.0-beta-3:site
> (default-site)
> on project commons-math: failed to get Reports: Unable to parse
> configuration of mojo
> org.codehaus.mojo:findbugs-maven-plugin:2.1:findbugs
> for parameter localRepository: Abstract class or interface
> 'org.apache.maven.artifact.repository.DefaultArtifactRepository'
> cannot be
> instantiated -> [Help 1]
> [ERROR]
> [ERROR] To see the full stack trace of the errors, re-run Maven with
> the -e
> switch.
> [ERROR] Re-run Maven using the -X switch to enable full debug
> logging.
> [ERROR]
> [ERROR] For more information about the errors and possible solutions,
>
> please read the following articles:
> [ERROR] [Help 1]
> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
>
> any ideas?
No ideas at all :-(
Which version of maven do you use ?
Luc
>
> Dennis
>
>
> Luc Maisonobe wrote:
> > Le 24/06/2011 11:33, Dennis Hendriks a écrit :
> >> > I have 137 errors only adding the check for braces, and only a
> handful
> >> > without this check!
> >>
> >> I used a trunk checkout and then:
> >>
> >> mvn -Prc clean package
> >> mvn checkstyle:checkstyle
> >>
> >> and I got 22792 checkstyle errors... See attachments.
> >
> > The checkstyle file used is not the one from Apache Commons Math.
> I'm
> > not sure using the "rc" profile in the -Prc flag really cleaned
> > everything on the first command, so the second command "mvn
> > checkstyle:checkstyle" did use a cached value.
> >
> > Try something along these lines, without any -P flag:
> >
> > mvn clean site
> >
> > Luc
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
I tried 'mvn clean site', and got this:
(...)
main:
[INFO] Executed tasks
[INFO]
[INFO] --- maven-remote-resources-plugin:1.0:process (default) @
commons-math ---
[INFO]
[INFO] --- maven-resources-plugin:2.4.1:resources (default-resources) @
commons-math ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources to META-INF
[INFO] Copying 1 resource to META-INF/localization
[INFO]
[INFO] --- maven-compiler-plugin:2.1:compile (default-compile) @
commons-math ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< jdepend-maven-plugin:2.0-beta-2:generate (report:generate) @
commons-math <<<
[INFO] configuring report plugin org.codehaus.mojo:rat-maven-plugin:1.0-alpha-3
[INFO] configuring report plugin org.codehaus.mojo:findbugs-maven-plugin:2.1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:05.413s
[INFO] Finished at: Mon Jun 27 08:54:24 CEST 2011
[INFO] Final Memory: 32M/280M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-site-plugin:3.0-beta-3:site (default-site)
on project commons-math: failed to get Reports: Unable to parse
configuration of mojo org.codehaus.mojo:findbugs-maven-plugin:2.1:findbugs
for parameter localRepository: Abstract class or interface
'org.apache.maven.artifact.repository.DefaultArtifactRepository' cannot be
instantiated -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,
please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
any ideas?
Dennis
Luc Maisonobe wrote:
> Le 24/06/2011 11:33, Dennis Hendriks a écrit :
>> > I have 137 errors only adding the check for braces, and only a handful
>> > without this check!
>>
>> I used a trunk checkout and then:
>>
>> mvn -Prc clean package
>> mvn checkstyle:checkstyle
>>
>> and I got 22792 checkstyle errors... See attachments.
>
> The checkstyle file used is not the one from Apache Commons Math. I'm
> not sure using the "rc" profile in the -Prc flag really cleaned
> everything on the first command, so the second command "mvn
> checkstyle:checkstyle" did use a cached value.
>
> Try something along these lines, without any -P flag:
>
> mvn clean site
>
> Luc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 24/06/2011 11:33, Dennis Hendriks a écrit :
> > I have 137 errors only adding the check for braces, and only a handful
> > without this check!
>
> I used a trunk checkout and then:
>
> mvn -Prc clean package
> mvn checkstyle:checkstyle
>
> and I got 22792 checkstyle errors... See attachments.
The checkstyle file used is not the one from Apache Commons Math. I'm
not sure using the "rc" profile in the -Prc flag really cleaned
everything on the first command, so the second command "mvn
checkstyle:checkstyle" did use a cached value.
Try something along these lines, without any -P flag:
mvn clean site
Luc
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
> I have 137 errors only adding the check for braces, and only a handful
> without this check!
I used a trunk checkout and then:
mvn -Prc clean package
mvn checkstyle:checkstyle
and I got 22792 checkstyle errors... See attachments.
Dennis
Luc Maisonobe wrote:
> Le 24/06/2011 10:57, Dennis Hendriks a écrit :
>> > No, we tend to fix really everything, at least at release time.
>>
>> I got this output this morning for trunk:
>>
>> [INFO] There are 22792 checkstyle errors.
>
> I have 137 errors only adding the check for braces, and only a handful
> without this check!
>
> Do you use our checkstyle.xml file ?
>
> Luc
>
>> So there is a lot of work to do for the next release...
>>
>> > If we
>> > let warnings, it becomes difficult to sort real problems from false
>> > positive. People have to take time to check every warning manually each
>> > time, so allowing warnings really wastes more time in the long term that
>> > it saves in the short term.
>>
>> I agree.
>>
>> Dennis
>>
>>
>> Luc Maisonobe wrote:
>>> Le 24/06/2011 09:09, Dennis Hendriks a écrit :
>>>> I agree with you that braces should always be used. Personally, I do
>>>> have one exception though, and that is if the statement following it is
>>>> on the same line. That way, it is one line, instead of 3 lines, which
>>>> makes it more readable. If the 'if' statement spans multiple lines, I
>>>> always include braces, even if there is only one single statement
>>>> involved. But that is just me...
>>> So we have at least two different opinions here, which is good. Let's
>>> see what other people think.
>>>
>>>> I think the rule is already active in Checkstyle. I think I just chose
>>>> to ignore it here.
>>> No, the rule is not active in our checkstyle configuration. I have
>>> tested it, there are about 130 violations of this rule in our code
>>> base, so it is really simple to fix all of them.
>>>
>>>> In general (not just this Checkstyle rule), is it allowed to ignore
>>>> checkstyle errors, if one believes that the code would be better if the
>>>> rule is ignored for a specific instance; that is, in case of false
>>>> positives?
>>> No, we tend to fix really everything, at least at release time. If we
>>> let warnings, it becomes difficult to sort real problems from false
>>> positive. People have to take time to check every warning manually
>>> each time, so allowing warnings really wastes more time in the long
>>> term that it saves in the short term.
>>>
>>> If a piece of code really needs to not comply to a rule, then we use
>>> the warning suppression mechanism around that piece of code. See at
>>> the end of our checkstyle configuration, there are already 5
>>> SuppressionCommentFilter set up.
>>>
>>> This also applies to findbugs, and we use findbugs-exclude-filter for
>>> false positives.
>>>
>>> Luc
>>>
>>>> Dennis
>>>>
>>>>
>>>> Luc Maisonobe wrote:
>>>>> Hi all,
>>>>>
>>>>> The provided patch for MATH-599 includes a number of no-brace if
>>>>> statements like the following ones:
>>>>>
>>>>>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>>>>>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>>>>> I'm not sure if we have an unwritten rule for this, but personally I
>>>>> dislike this style a lot. Checkstyle provides a NeedBraces rule to
>>>>> avoid this.
>>>>>
>>>>> What about activating this rule ?
>>>>>
>>>>> Luc
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 24/06/2011 10:57, Dennis Hendriks a écrit :
> > No, we tend to fix really everything, at least at release time.
>
> I got this output this morning for trunk:
>
> [INFO] There are 22792 checkstyle errors.
I have 137 errors only adding the check for braces, and only a handful
without this check!
Do you use our checkstyle.xml file ?
Luc
>
> So there is a lot of work to do for the next release...
>
> > If we
> > let warnings, it becomes difficult to sort real problems from false
> > positive. People have to take time to check every warning manually each
> > time, so allowing warnings really wastes more time in the long term that
> > it saves in the short term.
>
> I agree.
>
> Dennis
>
>
> Luc Maisonobe wrote:
>> Le 24/06/2011 09:09, Dennis Hendriks a écrit :
>>> I agree with you that braces should always be used. Personally, I do
>>> have one exception though, and that is if the statement following it is
>>> on the same line. That way, it is one line, instead of 3 lines, which
>>> makes it more readable. If the 'if' statement spans multiple lines, I
>>> always include braces, even if there is only one single statement
>>> involved. But that is just me...
>>
>> So we have at least two different opinions here, which is good. Let's
>> see what other people think.
>>
>>> I think the rule is already active in Checkstyle. I think I just chose
>>> to ignore it here.
>>
>> No, the rule is not active in our checkstyle configuration. I have
>> tested it, there are about 130 violations of this rule in our code
>> base, so it is really simple to fix all of them.
>>
>>> In general (not just this Checkstyle rule), is it allowed to ignore
>>> checkstyle errors, if one believes that the code would be better if the
>>> rule is ignored for a specific instance; that is, in case of false
>>> positives?
>>
>> No, we tend to fix really everything, at least at release time. If we
>> let warnings, it becomes difficult to sort real problems from false
>> positive. People have to take time to check every warning manually
>> each time, so allowing warnings really wastes more time in the long
>> term that it saves in the short term.
>>
>> If a piece of code really needs to not comply to a rule, then we use
>> the warning suppression mechanism around that piece of code. See at
>> the end of our checkstyle configuration, there are already 5
>> SuppressionCommentFilter set up.
>>
>> This also applies to findbugs, and we use findbugs-exclude-filter for
>> false positives.
>>
>> Luc
>>
>>> Dennis
>>>
>>>
>>> Luc Maisonobe wrote:
>>>> Hi all,
>>>>
>>>> The provided patch for MATH-599 includes a number of no-brace if
>>>> statements like the following ones:
>>>>
>>>>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>>>>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>>>> I'm not sure if we have an unwritten rule for this, but personally I
>>>> dislike this style a lot. Checkstyle provides a NeedBraces rule to
>>>> avoid this.
>>>>
>>>> What about activating this rule ?
>>>>
>>>> Luc
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
> No, we tend to fix really everything, at least at release time.
I got this output this morning for trunk:
[INFO] There are 22792 checkstyle errors.
So there is a lot of work to do for the next release...
> If we
> let warnings, it becomes difficult to sort real problems from false
> positive. People have to take time to check every warning manually each
> time, so allowing warnings really wastes more time in the long term that
> it saves in the short term.
I agree.
Dennis
Luc Maisonobe wrote:
> Le 24/06/2011 09:09, Dennis Hendriks a écrit :
>> I agree with you that braces should always be used. Personally, I do
>> have one exception though, and that is if the statement following it is
>> on the same line. That way, it is one line, instead of 3 lines, which
>> makes it more readable. If the 'if' statement spans multiple lines, I
>> always include braces, even if there is only one single statement
>> involved. But that is just me...
>
> So we have at least two different opinions here, which is good. Let's
> see what other people think.
>
>> I think the rule is already active in Checkstyle. I think I just chose
>> to ignore it here.
>
> No, the rule is not active in our checkstyle configuration. I have
> tested it, there are about 130 violations of this rule in our code base,
> so it is really simple to fix all of them.
>
>> In general (not just this Checkstyle rule), is it allowed to ignore
>> checkstyle errors, if one believes that the code would be better if the
>> rule is ignored for a specific instance; that is, in case of false
>> positives?
>
> No, we tend to fix really everything, at least at release time. If we
> let warnings, it becomes difficult to sort real problems from false
> positive. People have to take time to check every warning manually each
> time, so allowing warnings really wastes more time in the long term that
> it saves in the short term.
>
> If a piece of code really needs to not comply to a rule, then we use the
> warning suppression mechanism around that piece of code. See at the end
> of our checkstyle configuration, there are already 5
> SuppressionCommentFilter set up.
>
> This also applies to findbugs, and we use findbugs-exclude-filter for
> false positives.
>
> Luc
>
>> Dennis
>>
>>
>> Luc Maisonobe wrote:
>>> Hi all,
>>>
>>> The provided patch for MATH-599 includes a number of no-brace if
>>> statements like the following ones:
>>>
>>>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>>>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>>> I'm not sure if we have an unwritten rule for this, but personally I
>>> dislike this style a lot. Checkstyle provides a NeedBraces rule to
>>> avoid this.
>>>
>>> What about activating this rule ?
>>>
>>> Luc
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
> I prefer to have _one_ rule for code formatting.
> [Also, you nvere know when you might need an additional statement wihtin
> the conditional branch (e.g. when debugging).]
I would indeed consider that a reasonable reason to indeed force the braces.
Dennis
Gilles Sadowski wrote:
> Hi.
>
>>> I agree with you that braces should always be used. Personally, I do
>>> have one exception though, and that is if the statement following it is
>>> on the same line. That way, it is one line, instead of 3 lines, which
>>> makes it more readable. If the 'if' statement spans multiple lines, I
>>> always include braces, even if there is only one single statement
>>> involved. But that is just me...
>> So we have at least two different opinions here, which is good.
>> Let's see what other people think.
>
> I prefer to have _one_ rule for code formatting.
> [Also, you nvere know when you might need an additional statement wihtin the
> conditional branch (e.g. when debugging).]
>
>>> I think the rule is already active in Checkstyle. I think I just chose
>>> to ignore it here.
>> No, the rule is not active in our checkstyle configuration. I have
>> tested it, there are about 130 violations of this rule in our code
>> base, so it is really simple to fix all of them.
>
> +1 for enabling the rule.
>
>> [...]
>
> Best regards,
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Phil Steitz <ph...@gmail.com>.
On 6/24/11 2:13 AM, Gilles Sadowski wrote:
> Hi.
>
>>> I agree with you that braces should always be used. Personally, I do
>>> have one exception though, and that is if the statement following it is
>>> on the same line. That way, it is one line, instead of 3 lines, which
>>> makes it more readable. If the 'if' statement spans multiple lines, I
>>> always include braces, even if there is only one single statement
>>> involved. But that is just me...
>> So we have at least two different opinions here, which is good.
>> Let's see what other people think.
> I prefer to have _one_ rule for code formatting.
> [Also, you nvere know when you might need an additional statement wihtin the
> conditional branch (e.g. when debugging).]
+1
Phil
>>> I think the rule is already active in Checkstyle. I think I just chose
>>> to ignore it here.
>> No, the rule is not active in our checkstyle configuration. I have
>> tested it, there are about 130 violations of this rule in our code
>> base, so it is really simple to fix all of them.
> +1 for enabling the rule.
>
>> [...]
> Best regards,
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/analysis/solvers/ site/xdoc/
test/java/org/apache/commons/math/analysis/
test/java/org/apache/commons/math/analysis/solvers/
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi.
> >I agree with you that braces should always be used. Personally, I do
> >have one exception though, and that is if the statement following it is
> >on the same line. That way, it is one line, instead of 3 lines, which
> >makes it more readable. If the 'if' statement spans multiple lines, I
> >always include braces, even if there is only one single statement
> >involved. But that is just me...
>
> So we have at least two different opinions here, which is good.
> Let's see what other people think.
I prefer to have _one_ rule for code formatting.
[Also, you nvere know when you might need an additional statement wihtin the
conditional branch (e.g. when debugging).]
> >
> >I think the rule is already active in Checkstyle. I think I just chose
> >to ignore it here.
>
> No, the rule is not active in our checkstyle configuration. I have
> tested it, there are about 130 violations of this rule in our code
> base, so it is really simple to fix all of them.
+1 for enabling the rule.
> [...]
Best regards,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 24/06/2011 09:09, Dennis Hendriks a écrit :
> I agree with you that braces should always be used. Personally, I do
> have one exception though, and that is if the statement following it is
> on the same line. That way, it is one line, instead of 3 lines, which
> makes it more readable. If the 'if' statement spans multiple lines, I
> always include braces, even if there is only one single statement
> involved. But that is just me...
So we have at least two different opinions here, which is good. Let's
see what other people think.
>
> I think the rule is already active in Checkstyle. I think I just chose
> to ignore it here.
No, the rule is not active in our checkstyle configuration. I have
tested it, there are about 130 violations of this rule in our code base,
so it is really simple to fix all of them.
>
> In general (not just this Checkstyle rule), is it allowed to ignore
> checkstyle errors, if one believes that the code would be better if the
> rule is ignored for a specific instance; that is, in case of false
> positives?
No, we tend to fix really everything, at least at release time. If we
let warnings, it becomes difficult to sort real problems from false
positive. People have to take time to check every warning manually each
time, so allowing warnings really wastes more time in the long term that
it saves in the short term.
If a piece of code really needs to not comply to a rule, then we use the
warning suppression mechanism around that piece of code. See at the end
of our checkstyle configuration, there are already 5
SuppressionCommentFilter set up.
This also applies to findbugs, and we use findbugs-exclude-filter for
false positives.
Luc
>
> Dennis
>
>
> Luc Maisonobe wrote:
>> Hi all,
>>
>> The provided patch for MATH-599 includes a number of no-brace if
>> statements like the following ones:
>>
>>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>>
>> I'm not sure if we have an unwritten rule for this, but personally I
>> dislike this style a lot. Checkstyle provides a NeedBraces rule to
>> avoid this.
>>
>> What about activating this rule ?
>>
>> Luc
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Dennis Hendriks <D....@tue.nl>.
I agree with you that braces should always be used. Personally, I do have
one exception though, and that is if the statement following it is on the
same line. That way, it is one line, instead of 3 lines, which makes it
more readable. If the 'if' statement spans multiple lines, I always include
braces, even if there is only one single statement involved. But that is
just me...
I think the rule is already active in Checkstyle. I think I just chose to
ignore it here.
In general (not just this Checkstyle rule), is it allowed to ignore
checkstyle errors, if one believes that the code would be better if the
rule is ignored for a specific instance; that is, in case of false positives?
Dennis
Luc Maisonobe wrote:
> Hi all,
>
> The provided patch for MATH-599 includes a number of no-brace if
> statements like the following ones:
>
>> + if (method == Method.ILLINOIS) f0 *= 0.5;
>> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
>
> I'm not sure if we have an unwritten rule for this, but personally I
> dislike this style a lot. Checkstyle provides a NeedBraces rule to avoid
> this.
>
> What about activating this rule ?
>
> Luc
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1139126 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/
site/xdoc/ test/java/org/apache/commons/math/analysis/ test/java/org/apache/commons/math/analysis/solvers/
Posted by Luc Maisonobe <Lu...@free.fr>.
Hi all,
The provided patch for MATH-599 includes a number of no-brace if
statements like the following ones:
> + if (method == Method.ILLINOIS) f0 *= 0.5;
> + if (method == Method.PEGASUS) f0 *= f1 / (f1 + fx);
I'm not sure if we have an unwritten rule for this, but personally I
dislike this style a lot. Checkstyle provides a NeedBraces rule to avoid
this.
What about activating this rule ?
Luc
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org