commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <gil...@harfang.homelinux.org>
Subject Re: [Math] Fluent API, inheritance and immutability
Date Mon, 26 Aug 2013 19:43:33 GMT
On Mon, 26 Aug 2013 15:11:22 -0400, Konstantin Berlin wrote:
> I looked only at the GuassNewton class as a general guide to how
> things work. I like it a lot! I only wish all of the optimizations
> were rewritten in this way.
>
> Several comments
>
> 1) I believe this code can now be simplified
>
> // build the linear problem
>             final double[] b = new double[nC];
>             final double[][] a = new double[nC][nC];
>             for (int i = 0; i < nR; ++i) {
>
>                 final double[] grad = weightedJacobian.getRow(i);
>                 final double residual = currentResiduals.getEntry(i);
>
>                 // compute the normal equation
>                 //residual is already weighted
>                 for (int j = 0; j < nC; ++j) {
>                     b[j] += residual * grad[j];
>                 }
>
>                 // build the contribution matrix for measurement i
>                 for (int k = 0; k < nC; ++k) {
>                     double[] ak = a[k];
>                     //Jacobian/gradient is already weighted
>                     for (int l = 0; l < nC; ++l) {
>                         ak[l] += grad[k] * grad[l];
>                     }
>                 }
>             }
>
> Should be just this (I haven't checked the math)
>
> jt = weightedJacobian.transpose();
> a = jt* weightedJacobian;
> b= jt*currentResiduals;

I've adviced against too many changes at once.
[A good idea will not become stale if its application is delayed
a little.]

>
> 2) Based on the reasons I previously describe, would it be possible 
> to
> separate the newton step into a separate function (which you would
> also add to the interface)?
> The idea here is that solving for the newton step can be
> computationally intensive depending on the size of the problem. So
> there is no one universal approach. There are several somewhat
> different ways that his can be solved, with
> some methods requiring information from previous steps in order to
> work. This would also allow to plug in line search or trust region
> control of step size. In order to allow all of these approaches, I
> would suggest this function:
>
> //this function would solve for dX
> public NewtonStepResult solveStep(LeastSquaresProblem lsp, RealVector
> currentPoint, Object prevStepInfo)
> {
>   NewtonStepResult result  = new NewtonStepResult();
>
>   //code to solve for the next step dx followed by
>   result.newtonStep = dx;
>
>   //code to update the step information
>   //leave blank for now
>   result.stepInfo = null;
> }
>
> where
>
> public class NewtonStepResult
> {
>   public class RealVector newtonStep;
>   public class Object stepInfo;
> }

I can't comment on the math principle but on from a programming
viewpoint, an "Object" is a no-no. :-)


Gilles

>
>
> Please tell me if what I wrote is not clear.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message