static double[] doLSQ(List<Tuple<float, float, float>> data, Action<double[], double[], object> fitalgo,
double[] x)
{
double epsg = 0.001;
double epsf = 0;
double epsx = 0;
int maxits = 100;
alglib.minlmstate state;
alglib.minlmreport rep;
alglib.minlmcreatev(data.Count, x, 1, out state);
alglib.minlmsetcond(state, epsg, epsf, epsx, maxits);
var t1 = new alglib.ndimensional_fvec(fitalgo);
alglib.minlmoptimize(state, t1, null, data);
alglib.minlmresults(state, out x, out rep);
log.InfoFormat("passes {0}", rep.iterationscount);
log.InfoFormat("term type {0}", rep.terminationtype);
log.InfoFormat("njac {0}", rep.njac);
log.InfoFormat("ncholesky {0}", rep.ncholesky);
log.InfoFormat("nfunc{0}", rep.nfunc);
log.InfoFormat("ngrad {0}", rep.ngrad);
log.InfoFormat("ans {0}", alglib.ap.format(x, 4));
if (data == datacompass1)
{
error = 0;
foreach (var item in state.fi)
{
error += item;
}
error = Math.Round(Math.Sqrt(Math.Abs(error)), 2);
}
if (data == datacompass2)
{
error2 = 0;
foreach (var item in state.fi)
{
error2 += item;
}
error2 = Math.Round(Math.Sqrt(Math.Abs(error2)), 2);
}
if (data == datacompass3)
{
error3 = 0;
foreach (var item in state.fi)
{
error3 += item;
}
error3 = Math.Round(Math.Sqrt(Math.Abs(error3)), 2);
}
return x;
}