boykely
boykely

Reputation: 381

LM algorithm using EJML

I try to use the example from EJML wiki where we use Levenberg Marquardt optimization source code here

I compare it with this one .Net version in which we have the possibility to give the function model parameters.

For example: a*x^2+b*x+c and we can give as inputs all parameters for the model.

However, for the EJML LM code, I cannot see where can I give those model parameters.

I paste below how I use the LM EJML class:

public class Main {
    public static void main(String[] args) {
        LevenbergMarquardt lm = new LevenbergMarquardt(new LevenbergMarquardt.Function() {

            @Override
            public void compute(DenseMatrix64F param, DenseMatrix64F x, DenseMatrix64F y) {
                // TODO Auto-generated method stub
                System.out.println("param:");
                param.print();
                System.out.println("X:");
                x.print();
                //y=a*x^2+b*x+c
                for (int i = 0; i < x.numRows; i++) {
                    double xx = x.get(i, 0);
                    y.set(i, 0, param.get(0, 0) * xx * xx + 
                        param.get(1, 0) * xx + param.get(2, 0));
                }
                System.out.println("Y:");
                y.print();
            }
        });
        //Seed inital parameters
        lm.optimize(new DenseMatrix64F(new double[][]{{1}, {1}, {1}}),
                new DenseMatrix64F(new double[][]{{0.1975}, {0.5084}, {0.7353}, {0.9706},
                        {1.1891}}), new DenseMatrix64F(new double[][]{{-0.0126}, {0.2311}, 
                        {0.4412}, {1.0210}, {1.1891}}));    
    }
}

So How can I give those model parameters?

Upvotes: 0

Views: 210

Answers (1)

lessthanoptimal
lessthanoptimal

Reputation: 2812

You might want to checkout DDogleg . It contains a more robust LM solver and uses EJML under the hood. The LM solver you found on EJML's website is intended as an example for how to use EJML and skips a few details.

Upvotes: 0

Related Questions