Commit Graph

5244 Commits

Author SHA1 Message Date
Luc Maisonobe eb66fe4a1f Improved test coverage.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571737 13f79535-47bb-0310-9956-ffa450edef68
2014-02-25 16:42:07 +00:00
Gilles Sadowski d3470c37ab Typo.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571640 13f79535-47bb-0310-9956-ffa450edef68
2014-02-25 10:27:21 +00:00
Gilles Sadowski 1358d274db Fixed small inconsistency.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571639 13f79535-47bb-0310-9956-ffa450edef68
2014-02-25 10:26:55 +00:00
Luc Maisonobe 856e3cf007 Javadoc.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571627 13f79535-47bb-0310-9956-ffa450edef68
2014-02-25 09:21:32 +00:00
Luc Maisonobe b122db9eda Make AbstractEvaluation public
Allow custom implementations of LeastSquaresProblem to use the default
methods for computing the covariance, rms, etc.

JIRA: MATH-1102

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571307 13f79535-47bb-0310-9956-ffa450edef68
2014-02-24 14:58:07 +00:00
Luc Maisonobe 9ac2b15e4a In LeastSquaresProblem.Evaluation removed the getValue() method.
- The residuals are the really the values of the objective function
  that is being minimized.
- Forcing the value to be a real vector and the residual computed
  through subtraction is an unnecessary constraint. For example
  Rotation.distance() will compute a better residual than
  subtracting the quaternion elements of two rotations.
- Method was not used by any optimizer.

JIRA: MATH-1102

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571306 13f79535-47bb-0310-9956-ffa450edef68
2014-02-24 14:57:44 +00:00
Luc Maisonobe a573059d05 Moved OptimizationProblem interface to optim package.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571015 13f79535-47bb-0310-9956-ffa450edef68
2014-02-23 14:00:48 +00:00
Luc Maisonobe dcdfd7ed9e Change private least square problem implementation to internal class.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1571014 13f79535-47bb-0310-9956-ffa450edef68
2014-02-23 14:00:20 +00:00
Luc Maisonobe f299ecf330 Improved documentation of QR decomposition handling of singular matrix.
JIRA: MATH-1101

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570994 13f79535-47bb-0310-9956-ffa450edef68
2014-02-23 11:10:41 +00:00
Luc Maisonobe 927361d787 QR decomposition can compute pseudo-inverses for tall matrices.
Thanks to Sean Owen for the patch.

JIRA: MATH-1053

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570566 13f79535-47bb-0310-9956-ffa450edef68
2014-02-21 13:18:35 +00:00
Luc Maisonobe ed7ac7cf74 Field vectors now implement the visitor pattern just like real vectors.
JIRA: MATH-820

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570536 13f79535-47bb-0310-9956-ffa450edef68
2014-02-21 11:26:09 +00:00
Luc Maisonobe 5ea537df99 Un-deprecated RealVector.sparseIterator.
The documentation now explicitly states that entries not iterated above
are the zero ones.

This is part of Apache Commons Math reconsidering support for sparse
linear algebra.

JIRA: MATH-875

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570510 13f79535-47bb-0310-9956-ffa450edef68
2014-02-21 10:16:52 +00:00
Luc Maisonobe a9d0cc42fe Relaxed specification for function mapping on vectors.
JIRA: MATH-821

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570254 13f79535-47bb-0310-9956-ffa450edef68
2014-02-20 16:16:19 +00:00
Luc Maisonobe 1cd5a3229c Continue un-deprecation of sparse methods.
JIRA: MATH-870
JIRA: MATH-803

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570246 13f79535-47bb-0310-9956-ffa450edef68
2014-02-20 15:56:37 +00:00
Luc Maisonobe 4332119866 Added a test showing the limitation of sparse matrices implementation.
JIRA:MATH-870.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570209 13f79535-47bb-0310-9956-ffa450edef68
2014-02-20 14:52:13 +00:00
Luc Maisonobe fe0f518f50 computeXxx renamed getXxx in the Evaluation interface (leastsquares).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1570206 13f79535-47bb-0310-9956-ffa450edef68
2014-02-20 14:35:14 +00:00
Luc Maisonobe d19b226c54 Make QR the default in GaussNewtonOptimizer
Theoretically QR offers the best blend of speed and numerical stability.
Empirically the QR implementation is slightly faster than the Cholesky
implementation.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569907 13f79535-47bb-0310-9956-ffa450edef68
2014-02-19 20:32:43 +00:00
Luc Maisonobe 3c1bf79202 Add Cholesky option to GaussNewtonOptimizer
Since the normal matrix is symmetric positive (semi-)definite, the
Cholesky decomposition is theoretically faster.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569906 13f79535-47bb-0310-9956-ffa450edef68
2014-02-19 20:32:20 +00:00
Luc Maisonobe 1a6879a002 Make QR in GaussNewton faster and more accurate
Re-factored the code in GaussNewtonOptimizer so that the decomposition
algorithm sees the Jacobian and residuals instead of the normal
equation. This lets the QR algorithm operate directly on the Jacobian
matrix, which is faster and less sensitive to numerical errors. As a
result, one test case that threw a singular matrix exception now passes
with the QR decomposition.

The refactoring also include a speed improvement when computing the
normal matrix for the LU decomposition. Since the normal matrix is
symmetric only half of is computed, which results in a factor of 2 speed
up in computing the normal matrix for problems with many more
measurements than states.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569905 13f79535-47bb-0310-9956-ffa450edef68
2014-02-19 20:31:47 +00:00
Luc Maisonobe 499101c88c The sparse vector and matrix classes have been un-deprecated.
This is a reversal of a former decision, as we now think we should adopt
a generally accepted behavior which is ... to ignore the problems of
NaNs and infinities in sparse linear algebra entities.

JIRA: MATH-870 (which is therefore NOT fixed)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569825 13f79535-47bb-0310-9956-ffa450edef68
2014-02-19 17:19:59 +00:00
Luc Maisonobe 785ea269eb Javadoc.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569380 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 15:11:46 +00:00
Luc Maisonobe b0521ef7e0 Removed interfaces in the fluent API that do not add any value.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569363 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:57 +00:00
Luc Maisonobe 613a83c56a Fixed checkstyle and compiler warnings.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569362 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:49 +00:00
Luc Maisonobe b01933b17f Expand Evaluation tests, use weighted values.
Added more test cases to EvaluationTest to test the other methods of
DenseWeightedEvaluation/UnweightedEvaluation.
    
Fixed a bug in DenseWeightedEvaluation.computeValue() where the the
weights were not applied to the return value.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569361 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:41 +00:00
Luc Maisonobe 9a012f530e Qualify Evaluation in interfaces.
Use LeastSquaresProblem.Evaluation in the public interfaces for
readability.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569360 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:33 +00:00
Luc Maisonobe 57096ad696 JUnit directly executes least squares tests
Previously JUnit would make the call to test a specific optimizer, and
then that method would call all of the individual test cases relevant to
that optimizer.,Now JUnit will directly call each individual test case.
    
The same test coverage is preserved. The GaussNewtonOptimizerTest is
split into two classes, one for each decomposition algorithm it can use.
There is a significant amount of duplicated code between
GaussNewtonOptimizerWithLUTest and GaussNewtonOptimizerWithQRTest.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569359 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:28 +00:00
Luc Maisonobe c12ae52424 Fixed errors introduced by few previous API changes.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569358 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:20 +00:00
Luc Maisonobe 46b2ce2ee0 Fix Javadoc and checkstyle errors.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569357 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:14 +00:00
Luc Maisonobe 8916830e8a Clean up LeastSquaresBuilder
Provide methods for using old and new interfaces. Data is stored internally
using the new interfaces now.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569356 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:08 +00:00
Luc Maisonobe 4dcae270e6 Clean up LeastSquaresFactory
* There are now 3 factory methods: one using the previous interfaces, one using
  the new interfaces with weights, and one using the new interfaces without
  weights.

* Make model(...) method public.

* Fix javadoc typo

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569355 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:33:00 +00:00
Luc Maisonobe 0079828734 Use Real{Vector,Matrix} in LeastSquares interfaces
Covered all of the interfaces in the leastsquares package to use RealVector and
RealMatrix instead of double[] and double[][]. This reduced some duplicated code.
For example Evaluation.computeResiduals() was a complete duplication of
RealVector.subtract(). It also presents a consistent interface and allows data
encapsulation.

Lastly, this change enables [math] to "eat our own dog food." It enables the
linear package to be used in the implementation of the optimization algorithms.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569354 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:54 +00:00
Luc Maisonobe a7a380f934 Use Evaluation instead of PointVectorValuePair
Use Evaluation instead of PointVectorValuePair in the ConvergenceChecker. This
gives the checkers access to more information, such as the rms and covariances.
The change also simplified the optimizer implementations since they no longer
have to keep track of the current function value.

A method was added to LeastSquaresFactory to convert between the two types of
checkers and a method added to LeastSquaresBuilder so that it can accept either
type. I would have prefered to do this through method overloading, but
overloading doesn't play well with generics.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569353 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:44 +00:00
Luc Maisonobe 3e18e999c7 Use enum for LU or QR in GaussNewtonOptimizer
Changed the boolean useLu prarameter to an enum. This is benificial because:
1. user code is easier to read: new GNO(Decomposition.QR) instead of new GNO(false)
2. Allows other algorithms to be added in the future
3. developer code is easier to read. One less if statement in optimize()

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569352 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:36 +00:00
Luc Maisonobe 49685c8bb4 Make infinite loop in GaussNewton explicit.
The main loop in GN could only be ended by convergence or exception. I made that
explicit with while(true) and removed an unreachable MathInternalError.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569350 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:28 +00:00
Luc Maisonobe 8b697afded LevenbergMarquardtOptimizer is thread safe.
Converted the mutable fields to locals.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569349 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:23 +00:00
Luc Maisonobe 4cdfc143ea Add Javadoc to LeastSquaresBuilder.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569348 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:17 +00:00
Luc Maisonobe 9444e28967 Fixup javadoc in LeastSquaresProblem
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569347 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:11 +00:00
Luc Maisonobe fc9cb0ce16 Value and Jacobian evaluated in a single method.
A new interface MultivariateJacobianFunction lets the function value and
Jacobian be evaluated at the same time. This saves the user from having to cache
the result between calls to get the value and the jacobian.

A factory method was added to create LeastSquaresProblems from the new interface.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569346 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:32:06 +00:00
Luc Maisonobe 4158f97463 Clean up LeastSquaresProblemImpl
Reorder constructor parameters to match LeastSquaresFactory and remove an unused
method.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569345 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:31:59 +00:00
Luc Maisonobe 06d490a4bd Implicit Weights
The weights are no longer implicit in LeastSquaresProblem.Evaluation. They are
already included in the computed residuals and Jacobian.

GN and LM multiplied the residuals by the weights immediately, so that was easy
to remove.

Created an AbstractEvaluation class which handles the derived quantitied (cost,
rms, covariance,...) and two implementations. UnweightedEvaluation uses the
straight forward formulas. DenseWeightedEvaluation delegates to an Evaluation
and multiples the residuals and Jacobian by the square root of the weight matrix
before returning them. Allowed me to remove the reference to the full weight
matrix.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569344 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:31:53 +00:00
Luc Maisonobe 567127c109 Immutable Optimizer configuration.
The GN and LM optimizers now use an immutable fields for their configuration
parameters and a fluent api. LM still has some mutable fields it uses a scratch
space.

This commit is a backport of Evan Ward github commit
    https://github.com/wardev/commons-math/commit/157cdde
into the current development version.

Conflicts:
	src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java
	src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569343 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:31:43 +00:00
Luc Maisonobe 7460c082a3 Separate least squares algorithm from problem.
The least squares package now has two main interfaces LeastSquaresOptimizer and
LeastSquaresProblem, where the optimizer can be applied to the problem.

In this commit all of the test cases pass with one change (annotated) to
LevenbergMarquardt.testControlParameters(). The tests for Gauss Newton were
expanded to cover using the QR decomposition, which revealed a QR default
tolerance discrepancy.

A factory and a mutable builder were create for LeastSquaresProblem.

This commit is a backport of Evan Ward github commit
 7e9a15efb5
into the current development version.

Conflicts:
	src/main/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizer.java
	src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java
	src/main/java/org/apache/commons/math3/optim/AbstractOptimizer.java
	src/test/java/org/apache/commons/math3/fitting/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java
	src/test/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizerTest.java
	src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1569342 13f79535-47bb-0310-9956-ffa450edef68
2014-02-18 14:31:34 +00:00
Thomas Neidhart 675d4c8fc8 Update test after adding new error message.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1568754 13f79535-47bb-0310-9956-ffa450edef68
2014-02-16 12:32:52 +00:00
Thomas Neidhart e8d0d4c1dd [MATH-749] Remove GrahamScan, GiftWrap, make MonotoneChain more robust wrt collinear points, add ConvergenceException in case the specified tolerance results in a non-convex hull.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1568752 13f79535-47bb-0310-9956-ffa450edef68
2014-02-16 12:19:51 +00:00
Luc Maisonobe 39430886ba Rewrote completely the enclosing spherical cap computation on 2-sphere.
The previous version was based on Welzl algorithm, but it appeared this
algorithm really need some properties that hold in Euclidean spaces and
not on the sphere.

The current version is not perfect in the sense that some times the
enclosing spherical cap returned is not the smallest possible. It is
documented in the Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1567599 13f79535-47bb-0310-9956-ffa450edef68
2014-02-12 11:12:45 +00:00
Thomas Neidhart b9b73fbef5 Further improvements.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1567427 13f79535-47bb-0310-9956-ffa450edef68
2014-02-11 22:33:39 +00:00
Thomas Neidhart 7e6304ce63 Add zooming, center of enclosing ball.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566774 13f79535-47bb-0310-9956-ffa450edef68
2014-02-10 22:35:10 +00:00
Thomas Neidhart 12ddf37f23 Simplify geometry examples by using piccolo2d.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566450 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 22:10:04 +00:00
Luc Maisonobe 06e1ff5008 Configured rules for Clirr, as per discussion on the mailing list.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566417 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 20:57:24 +00:00
Luc Maisonobe d41b96e58d Added a warning about interfaces not implementable by users.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566416 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 20:56:55 +00:00