2014-03-03 12:41:48 +00:00
|
|
|
#include <iostream>
|
2016-03-16 13:05:56 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <LatAnalyze/CompiledModel.hpp>
|
2016-03-23 17:08:25 +00:00
|
|
|
#include <LatAnalyze/Io.hpp>
|
2016-03-16 13:05:56 +00:00
|
|
|
#include <LatAnalyze/MinuitMinimizer.hpp>
|
|
|
|
#include <LatAnalyze/RandGen.hpp>
|
2016-03-15 16:38:57 +00:00
|
|
|
#include <LatAnalyze/XYStatData.hpp>
|
2014-03-03 12:41:48 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Latan;
|
|
|
|
|
2016-03-30 15:19:11 +01:00
|
|
|
const Index nPoint1 = 10, nPoint2 = 10;
|
2016-03-23 17:08:25 +00:00
|
|
|
const double xErr = .1, yErr = .1;
|
|
|
|
const double exactPar[2] = {0.5,5.};
|
|
|
|
const double dx1 = 10.0/static_cast<double>(nPoint1);
|
|
|
|
const double dx2 = 5.0/static_cast<double>(nPoint2);
|
2016-03-16 13:05:56 +00:00
|
|
|
|
2014-03-03 12:41:48 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2016-03-16 13:05:56 +00:00
|
|
|
// generate fake data
|
|
|
|
XYStatData data;
|
|
|
|
RandGen rg;
|
2016-03-23 17:08:25 +00:00
|
|
|
double xBuf[2];
|
2016-03-16 13:05:56 +00:00
|
|
|
DoubleModel f([](const double *x, const double *p)
|
2016-03-23 17:08:25 +00:00
|
|
|
{return p[1]*exp(-x[0]*p[0])+x[1];}, 2, 2);
|
2016-03-16 13:05:56 +00:00
|
|
|
|
2016-03-31 12:12:30 +01:00
|
|
|
data.addXDim(nPoint1);
|
|
|
|
data.addXDim(nPoint2);
|
|
|
|
data.addYDim();
|
2016-03-23 17:08:25 +00:00
|
|
|
for (Index i1 = 0; i1 < nPoint1; ++i1)
|
2016-03-16 13:05:56 +00:00
|
|
|
{
|
2016-03-23 17:08:25 +00:00
|
|
|
xBuf[0] = i1*dx1;
|
|
|
|
data.x(i1, 0) = rg.gaussian(xBuf[0], xErr);
|
|
|
|
for (Index i2 = 0; i2 < nPoint2; ++i2)
|
|
|
|
{
|
|
|
|
xBuf[1] = i2*dx2;
|
|
|
|
data.x(i2, 1) = xBuf[1];
|
|
|
|
data.y(data.dataIndex(i1, i2)) = rg.gaussian(f(xBuf, exactPar),
|
|
|
|
yErr);
|
|
|
|
printf("% 8e % 8e % 8e % 8e % 8e\n", data.x(i1, 0), xErr,
|
|
|
|
data.x(i2, 1), data.y(i1), yErr);
|
|
|
|
}
|
2016-03-16 13:05:56 +00:00
|
|
|
}
|
|
|
|
cout << endl;
|
2016-03-23 17:08:25 +00:00
|
|
|
data.setXError(0, DVec::Constant(data.getXSize(0), xErr));
|
|
|
|
data.assumeXExact(true, 1);
|
|
|
|
data.setYError(0, DVec::Constant(data.getYSize(), yErr));
|
2016-03-16 13:05:56 +00:00
|
|
|
cout << data << endl;
|
|
|
|
|
|
|
|
// fit
|
2016-03-23 17:08:25 +00:00
|
|
|
DVec init = DVec::Constant(2, 0.1);
|
2016-03-16 13:05:56 +00:00
|
|
|
FitResult p;
|
|
|
|
MinuitMinimizer minimizer;
|
2014-03-03 12:41:48 +00:00
|
|
|
|
2016-03-31 12:12:30 +01:00
|
|
|
f.parName().setName(0, "m");
|
|
|
|
f.parName().setName(1, "A");
|
2016-03-23 17:08:25 +00:00
|
|
|
minimizer.setVerbosity(Minimizer::Verbosity::Normal);
|
2016-03-16 13:05:56 +00:00
|
|
|
p = data.fit(minimizer, init, f);
|
2016-03-31 12:12:30 +01:00
|
|
|
p.print();
|
2014-03-03 12:41:48 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|