Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5DADB7DDB for ; Thu, 8 Sep 2011 04:27:16 +0000 (UTC) Received: (qmail 44200 invoked by uid 500); 8 Sep 2011 04:27:05 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 43703 invoked by uid 500); 8 Sep 2011 04:26:38 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 43532 invoked by uid 99); 8 Sep 2011 04:26:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2011 04:26:32 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gsterijevski@gmail.com designates 209.85.215.43 as permitted sender) Received: from [209.85.215.43] (HELO mail-ew0-f43.google.com) (209.85.215.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Sep 2011 04:26:27 +0000 Received: by ewy20 with SMTP id 20so161497ewy.30 for ; Wed, 07 Sep 2011 21:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=EOSqpjsrbZHzJ/+BXm/7lG6AVDyQ75+2qcKkZc8ER84=; b=Hq86rR8IDuK5FSLAxE19YP7d0V/dcgqMJrt6DcK4pfPk2M6CZf7N6WlP/JEINkK+hJ 5oQ4JROTxlG1y2/kStnZeMPoRVaY+UMCOtZ9MPYV+M92wV4nZpTgD5DQxvKT764vKv4S cHX1OxMSHqmvEcUh5JZyVhJEBVWYE6uT+WBGQ= MIME-Version: 1.0 Received: by 10.213.108.79 with SMTP id e15mr118379ebp.104.1315455966316; Wed, 07 Sep 2011 21:26:06 -0700 (PDT) Received: by 10.213.14.130 with HTTP; Wed, 7 Sep 2011 21:26:06 -0700 (PDT) In-Reply-To: References: <20110907104543.GR2590@dusk.harfang.homelinux.org> <4E6767C3.1060103@free.fr> <20110907130559.GV2590@dusk.harfang.homelinux.org> <4E676DB3.7080905@free.fr> <20110907133412.GW2590@dusk.harfang.homelinux.org> Date: Wed, 7 Sep 2011 23:26:06 -0500 Message-ID: Subject: Re: [Math] "LUDecomposition" in "AbstractLeastSquaresOptimizer" From: Greg Sterijevski To: Commons Developers List Content-Type: multipart/alternative; boundary=0015174c3f9a970a4204ac6675aa --0015174c3f9a970a4204ac6675aa Content-Type: text/plain; charset=ISO-8859-1 I thought that QR is of O(n^3) complexity, while LU is probably in the vicinity of O(n^2.5). While this is not a barn burning improvement, it is an improvement. Consider that if you are using the covariance of the parameters in deciding how to make the next step (some kind of inverse hessian rule), the repeated calls to inverse add up? Would it be a terrific eyesore to include a constructor with a boolean argument that says bUseQR? The call to LU is localized, so there is minimal refactoring. One could also pass the boolean into the getCovariances method. On Wed, Sep 7, 2011 at 4:48 PM, Ted Dunning wrote: > It shouldn't be all that different from QR (at most about 2x different). > > On Wed, Sep 7, 2011 at 1:16 PM, Greg Sterijevski >wrote: > > > It is also my recollection that LU is very quick to calculate. Would it > be > > possible to allow users to choose? > > > > On Wed, Sep 7, 2011 at 3:07 PM, Ted Dunning > wrote: > > > > > Does the LUDecomposition not use pivots? LU should always do so since > it > > > is > > > numerically unstable otherwise. I would be surprised if it doesn't > given > > > the normal level of quality in commons math. > > > > > > QR is, of course, almost always preferable to LU as you note. But I > > would > > > be surprised at radically different answers. > > > > > > Perhaps the only real difference between the two methods in this one > case > > > is > > > a difference in threshold. > > > > > > What is the condition number of your matrix? > > > > > > On Wed, Sep 7, 2011 at 6:34 AM, Gilles Sadowski < > > > gilles@harfang.homelinux.org> wrote: > > > > > > > Hi. > > > > > > > > > >>> > > > > > >>>In class "AbstractLeastSquaresOptimizer" (in > > > > "o.a.c.m.optimization.general"), > > > > > >>>the method "getCovariances()" uses "LUDecompositionImpl" to > > compute > > > > the > > > > > >>>inverse of a matrix. > > > > > >>>In my application, this leads to a "SingularMatrixException". If > I > > > > change > > > > > >>>"LUDecompositionImpl" to "QRDecompositionImpl", no exception is > > > > raised. > > > > > >>>Also, keeping "LUDecompositionImpl" but passing a much lower > > > > singularity > > > > > >>>threshold, does not raise the exception either. > > > > > >>> > > > > > >>>Thus, I wonder whether there was a reason for using "LU", and if > > > not, > > > > > >>>whether I could change the decomposition solver to "QR" (as this > > is > > > a > > > > > >>>cleaner solution than guessing a good value for the threshold). > > > > > >> > > > > > >>There are no reason for LU decomposition, and QR decomposition is > > > > > >>known to be more stable. So I would also consider switching to > this > > > > > >>algorithm is a cleaner solution. > > > > > > > > > > > >Fine. I'll open a JIRA issue. > > > > > > > > > > > >A unit test "testNonInvertible" in > "LevenbergMarquardtOptimizerTest" > > > > fails > > > > > >with the change to "QRDecomposition" because no > > > > "SingularMatrixException" > > > > > >is raised anymore. > > > > > >What was the purpose of that test? > > > > > > > > > > The purpose was to check that impossible problems were detected > > > properly. > > > > > > > > My question should have been clearer: Was the previous behaviour > > correct > > > > (i.e. an exception *must* be raised somehow)? > > > > The switch to "QR" seems to imply that a previously impossible > problem > > is > > > > now quite possible. So, is the problem really impossible or was the > > test > > > > actually testing a fragile implementation of "getCovariances()"? > > > > > > > > > > > > Regards, > > > > Gilles > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > > > > For additional commands, e-mail: dev-help@commons.apache.org > > > > > > > > > > > > > > --0015174c3f9a970a4204ac6675aa--