public void RunGaussian() { int npts = 100; //produce test data - a is a vecor with exact solution double[] x = new double[npts]; for (int i = 0; i < npts; i++) { x[i] = 0.1 * (i + 1); // NR always counts from 1 } double[] a = { 5, 2, 3, 2, 5, 3 }; LMAFunction f = new GaussianFunction(); double[][] dataPoints = f.GenerateData(a, x); LMA algorithm = new LMA(f, new double[] { 4, 2, 2, 2, 5, 2 }, dataPoints, null, new GeneralMatrix(6, 6), 1d - 30, 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()); }
public void RunGaussian() { int npts=100; //produce test data - a is a vecor with exact solution double[] x = new double[npts]; for (int i = 0; i < npts; i++) { x[i] = 0.1 * (i + 1); // NR always counts from 1 } double[] a = {5, 2, 3, 2, 5, 3}; LMAFunction f = new GaussianFunction(); double[][] dataPoints = f.GenerateData(a,x); LMA algorithm = new LMA(f,new double[] {4, 2, 2, 2, 5, 2}, dataPoints, null, new GeneralMatrix(6,6),1d-30,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()); }