Commit Graph

5226 Commits

Author SHA1 Message Date
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
Thomas Neidhart 517ff8cbe3 Revert unneeded serializationUID field.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566396 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 20:36:24 +00:00
Luc Maisonobe 5ae01f1f99 Added a getEnclosingCap method for spherical polygons.
In simple cases (small polygon, one piece only, no holes), the enclosing
cap will be the smallest one, but this is not guaranteed in the general
case.

The enclosing cap can be used to speed up inside/outside points when the
region is small with respect to the sphere as with only one check of an
angular separation, most points of the sphere can be safely identified
as outside. The more time-consuming checks involving the full boundary
are therefore done only for a small portion of the sphere.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566358 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 19:17:55 +00:00
Thomas Neidhart 2535320878 [MATH-749] Add changelog entry.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566342 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 18:24:27 +00:00
Thomas Neidhart 996c0c164a [MATH-1065] Fix EnumeratedRealDistribution.inverseCumulativeProbability. Thanks to matteodg and Phil.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566274 13f79535-47bb-0310-9956-ffa450edef68
2014-02-09 11:21:28 +00:00
Thomas Neidhart 3f59a81a15 Add missing since tags.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566092 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 18:48:29 +00:00
Thomas Neidhart b957ee1646 Add missing serialVersionUIDs.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566088 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 18:36:30 +00:00
Thomas Neidhart 42dffede43 [MATH-1050] Added changelog entry.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566074 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 18:14:37 +00:00
Thomas Neidhart 3c644cf87e [MATH-749] Change the way the line segments are computed as they can not be serialized. Use the array only as cache and create them as needed.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566064 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 17:44:37 +00:00
Thomas Neidhart c92f7d0c8f [MATH-976] Add changelog entry.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566047 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 16:54:45 +00:00
Thomas Neidhart 683a898d55 [MATH-976] Use placeholders and fix manifest for tools jar.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566046 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 16:50:32 +00:00
Thomas Neidhart 8dae299004 [MATH-990] Added changelog entry.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566021 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 14:33:03 +00:00
Thomas Neidhart 51a7ec0633 Fix typo.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566020 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 14:28:20 +00:00
Thomas Neidhart d434c5d0cc [MATH-1044] Clarify javadoc of DecompositionSolver#getInverse and corresponding implementations. Thanks to Sean Owen.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1566017 13f79535-47bb-0310-9956-ffa450edef68
2014-02-08 14:13:34 +00:00
Thomas Neidhart b268dfbb82 Add missing AL header.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1565447 13f79535-47bb-0310-9956-ffa450edef68
2014-02-06 21:31:52 +00:00
Thomas Neidhart de21905859 [MATH-749] Rename method, add/improve javadoc, better handle degenerate cases, improve unit tests.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1565444 13f79535-47bb-0310-9956-ffa450edef68
2014-02-06 21:27:20 +00:00
Thomas Neidhart 6b43922648 [MATH-749] Handle case that all points are identical.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1564954 13f79535-47bb-0310-9956-ffa450edef68
2014-02-05 22:10:22 +00:00
Thomas Neidhart b353d07bcc [MATH-749] Add GiftWrap algorithm as precursor for Chan's algorithm.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1564951 13f79535-47bb-0310-9956-ffa450edef68
2014-02-05 21:54:10 +00:00
Thomas Neidhart e5dc3ad337 [MATH-749] Improve robustness for convex hull algorithms in case of identical / collinear points, added flag whether to include only extreme points or all points on the hull, improve unit tests.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1564934 13f79535-47bb-0310-9956-ffa450edef68
2014-02-05 21:21:31 +00:00