Exemple #1
0
        public void RunSin()
        {
            //produce test data - a is a vecor with exact solution
            double[] x = {0.0, 0.1, 0.2, 0.3, 0.5, 0.7};
            double[] a = {2.2, 0.4};
            LMAFunction f = new SinFunction();

            double[][] dataPoints = f.GenerateData(a,x);

            LMA algorithm = new LMA(f,new double[] {0.1, 10},
                dataPoints, null, new GeneralMatrix(2,2),1d-20,100);

            algorithm.Fit();

            for (int i=0; i<a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }
Exemple #2
0
        public void RunSin()
        {
            //produce test data - a is a vecor with exact solution
            double[]    x = { 0.0, 0.1, 0.2, 0.3, 0.5, 0.7 };
            double[]    a = { 2.2, 0.4 };
            LMAFunction f = new SinFunction();

            double[][] dataPoints = f.GenerateData(a, x);

            LMA algorithm = new LMA(f, new double[] { 0.1, 10 },
                                    dataPoints, null, new GeneralMatrix(2, 2), 1d - 20, 100);

            algorithm.Fit();

            for (int i = 0; i < a.Length; i++)
            {
                Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i] - a[i]) < 0.0001);
                Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString());
            }

            Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString());
        }