public double RunTestProblem(CalcfcDelegate calcfc, int n, int m, double rhoend, double[] xopt) { var timer = new Stopwatch(); timer.Restart(); var optimizer = new Cobyla(n, m, calcfc) { MaximumFunctionCalls = maxfun, TrustRegionRadiusStart = rhobeg, TrustRegionRadiusEnd = rhoend }; var result = optimizer.FindMinimum(Enumerable.Repeat(1.0, n).ToArray()); timer.Stop(); Assert.That(result.Status, Is.EqualTo(OptimizationStatus.Normal).Or.EqualTo(OptimizationStatus.MAXFUN_Reached)); var error = xopt.Select((xo, i) => Math.Pow(xo - result.X[i], 2.0)).Sum(); Console.WriteLine("{0}Least squares error in variables = {1,16:E6}", Environment.NewLine, error); Console.WriteLine("Elapsed time for optimization = {0} ms", timer.ElapsedMilliseconds); return(error); }
public double RunTestProblem(CalcfcDelegate calcfc, int n, int m, double rhoend, double[] xopt) { var x = Enumerable.Repeat(1.0, n).ToArray(); var timer = new Stopwatch(); timer.Restart(); Assert.That(Cobyla.FindMinimum(calcfc, n, m, x, rhobeg, rhoend, iprint, maxfun), Is.EqualTo(CobylaExitStatus.Normal).Or.EqualTo(CobylaExitStatus.MaxIterationsReached)); timer.Stop(); var error = xopt.Select((xo, i) => Math.Pow(xo - x[i], 2.0)).Sum(); Console.WriteLine("{0}Least squares error in variables = {1,16:E6}", Environment.NewLine, error); Console.WriteLine("Elapsed time for optimization = {0} ms", timer.ElapsedMilliseconds); return(error); }
public double RunTestProblem(CalcfcDelegate calcfc, int n, int m, double rhoend, double[] xopt) { var x = Enumerable.Repeat(1.0, n).ToArray(); var timer = new Stopwatch(); timer.Restart(); Assert.That(Cobyla.FindMinimum(calcfc, n, m, x, rhobeg, rhoend, iprint, maxfun), Is.EqualTo(CobylaExitStatus.Normal).Or.EqualTo(CobylaExitStatus.MaxIterationsReached)); timer.Stop(); var error = xopt.Select((xo, i) => Math.Pow(xo - x[i], 2.0)).Sum(); Console.WriteLine("{0}Least squares error in variables = {1,16:E6}", Environment.NewLine, error); Console.WriteLine("Elapsed time for optimization = {0} ms", timer.ElapsedMilliseconds); return error; }