mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-20 08:16:55 +01:00
lot of fixes, XYSampleData fit now seems to work (more checks are probably needed)
This commit is contained in:
@ -1,11 +1,3 @@
|
||||
if CC_GNU
|
||||
COM_CFLAGS = -Wall -W -pedantic
|
||||
else
|
||||
if CC_INTEL
|
||||
COM_CFLAGS = -Wall
|
||||
endif
|
||||
endif
|
||||
|
||||
if CXX_GNU
|
||||
COM_CXXFLAGS = -Wall -W -pedantic
|
||||
else
|
||||
@ -26,55 +18,59 @@ noinst_PROGRAMS = \
|
||||
exRootFinder
|
||||
|
||||
if HAVE_MINUIT
|
||||
noinst_PROGRAMS += exFit exMin
|
||||
noinst_PROGRAMS += exFit exFitSample exMin
|
||||
endif
|
||||
|
||||
exCompiledDoubleFunction_SOURCES = exCompiledDoubleFunction.cpp
|
||||
exCompiledDoubleFunction_CFLAGS = -g -O2
|
||||
exCompiledDoubleFunction_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exCompiledDoubleFunction_SOURCES = exCompiledDoubleFunction.cpp
|
||||
exCompiledDoubleFunction_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exCompiledDoubleFunction_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exDerivative_SOURCES = exDerivative.cpp
|
||||
exDerivative_CFLAGS = -g -O2
|
||||
exDerivative_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exDerivative_SOURCES = exDerivative.cpp
|
||||
exDerivative_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exDerivative_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
if HAVE_MINUIT
|
||||
exFit_SOURCES = exFit.cpp
|
||||
exFit_CFLAGS = -g -O2
|
||||
exFit_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exFit_SOURCES = exFit.cpp
|
||||
exFit_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exFit_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exFitSample_SOURCES = exFitSample.cpp
|
||||
exFitSample_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exFitSample_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
endif
|
||||
|
||||
exInterp_SOURCES = exInterp.cpp
|
||||
exInterp_CFLAGS = -g -O2
|
||||
exInterp_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exInterp_SOURCES = exInterp.cpp
|
||||
exInterp_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exInterp_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exIntegrator_SOURCES = exIntegrator.cpp
|
||||
exIntegrator_CFLAGS = -g -O2
|
||||
exIntegrator_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exIntegrator_SOURCES = exIntegrator.cpp
|
||||
exIntegrator_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exIntegrator_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exMat_SOURCES = exMat.cpp
|
||||
exMat_CFLAGS = -g -O2
|
||||
exMat_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exMat_SOURCES = exMat.cpp
|
||||
exMat_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exMat_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
if HAVE_MINUIT
|
||||
exMin_SOURCES = exMin.cpp
|
||||
exMin_CFLAGS = -g -O2
|
||||
exMin_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exMin_SOURCES = exMin.cpp
|
||||
exMin_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exMin_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
endif
|
||||
|
||||
exMathInterpreter_SOURCES = exMathInterpreter.cpp
|
||||
exMathInterpreter_CFLAGS = -g -O2
|
||||
exMathInterpreter_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exMathInterpreter_SOURCES = exMathInterpreter.cpp
|
||||
exMathInterpreter_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exMathInterpreter_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exPlot_SOURCES = exPlot.cpp
|
||||
exPlot_CFLAGS = -g -O2
|
||||
exPlot_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exPlot_SOURCES = exPlot.cpp
|
||||
exPlot_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exPlot_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exRand_SOURCES = exRand.cpp
|
||||
exRand_CFLAGS = -g -O2
|
||||
exRand_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exRand_SOURCES = exRand.cpp
|
||||
exRand_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exRand_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
exRootFinder_SOURCES = exRootFinder.cpp
|
||||
exRootFinder_CFLAGS = -g -O2
|
||||
exRootFinder_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
exRootFinder_SOURCES = exRootFinder.cpp
|
||||
exRootFinder_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
exRootFinder_LDFLAGS = -L../lib/.libs -lLatAnalyze
|
||||
|
||||
ACLOCAL_AMFLAGS = -I .buildutils/m4
|
||||
|
@ -9,7 +9,7 @@ using namespace std;
|
||||
using namespace Latan;
|
||||
|
||||
const Index nPoint = 30;
|
||||
const double xErr = .01, yErr = .1;
|
||||
const double xErr = .2, yErr = .1;
|
||||
const double exactPar[2] = {0.5,5.0}, dx = 10.0/static_cast<double>(nPoint);
|
||||
|
||||
int main(void)
|
||||
@ -17,7 +17,7 @@ int main(void)
|
||||
// generate fake data
|
||||
XYStatData data;
|
||||
RandGen rg;
|
||||
double x_k, y_k;
|
||||
double x1_k, x2_k;
|
||||
DoubleModel f([](const double *x, const double *p)
|
||||
{return p[1]*exp(-x[0]*p[0]);}, 1, 2);
|
||||
|
||||
@ -25,11 +25,11 @@ int main(void)
|
||||
data.addYDim("y");
|
||||
for (Index k = 0; k < nPoint; ++k)
|
||||
{
|
||||
x_k = k*dx + rg.gaussian(0.0, xErr);
|
||||
y_k = f(&x_k, exactPar) + rg.gaussian(0.0, yErr);
|
||||
printf("% 8e % 8e % 8e % 8e\n", x_k, xErr, y_k, yErr);
|
||||
data.x(k) = x_k;
|
||||
data.y(k) = y_k;
|
||||
x1_k = rg.gaussian(k*dx, xErr);
|
||||
x2_k = rg.gaussian(k*dx, xErr);
|
||||
data.x(k) = x1_k;
|
||||
data.y(k) = rg.gaussian(f(&x2_k, exactPar), yErr);
|
||||
printf("% 8e % 8e % 8e % 8e\n", data.x(k), data.y(k), xErr, yErr);
|
||||
}
|
||||
cout << endl;
|
||||
data.setXError(0, DVec::Constant(nPoint, xErr));
|
||||
@ -42,9 +42,9 @@ int main(void)
|
||||
MinuitMinimizer minimizer;
|
||||
|
||||
p = data.fit(minimizer, init, f);
|
||||
cout << "a= " << p(0) << " b= " << p(1);
|
||||
cout << " chi^2/ndof= " << p.getChi2PerDof();
|
||||
cout << " p-value= " << p.getPValue() <<endl;
|
||||
cout << "a= " << p(0) << " b= " << p(1) << endl;
|
||||
cout << "chi^2/ndof= " << p.getChi2PerDof() << endl;
|
||||
cout << "p-value= " << p.getPValue() <<endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
54
examples/exFitSample.cpp
Normal file
54
examples/exFitSample.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <LatAnalyze/CompiledModel.hpp>
|
||||
#include <LatAnalyze/MinuitMinimizer.hpp>
|
||||
#include <LatAnalyze/RandGen.hpp>
|
||||
#include <LatAnalyze/XYSampleData.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Latan;
|
||||
|
||||
const Index nPoint = 30;
|
||||
const Index nSample = 1000;
|
||||
const double xErr = .2, yErr = .1;
|
||||
const double exactPar[2] = {0.5,5.0}, dx = 10.0/static_cast<double>(nPoint);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// generate fake data
|
||||
DMatSample x(nSample, nPoint, 1), y(nSample, nPoint, 1);
|
||||
XYSampleData data(nSample);
|
||||
RandGen rg;
|
||||
double x1_k, x2_k;
|
||||
DoubleModel f([](const double *t, const double *p)
|
||||
{return p[1]*exp(-t[0]*p[0]);}, 1, 2);
|
||||
|
||||
data.addXDim("x", nPoint);
|
||||
data.addYDim("y");
|
||||
FOR_STAT_ARRAY(x, s)
|
||||
{
|
||||
for (Index k = 0; k < nPoint; ++k)
|
||||
{
|
||||
x1_k = rg.gaussian(k*dx, xErr);
|
||||
x2_k = rg.gaussian(k*dx, xErr);
|
||||
data.x(k)[s] = x1_k;
|
||||
data.y(k)[s] = rg.gaussian(f(&x2_k, exactPar), yErr);
|
||||
}
|
||||
}
|
||||
cout << data << endl;
|
||||
|
||||
// fit
|
||||
DVec init = DVec::Constant(2, 0.5);
|
||||
DMat err;
|
||||
SampleFitResult p;
|
||||
MinuitMinimizer minimizer;
|
||||
|
||||
p = data.fit(minimizer, init, f);
|
||||
err = p.variance().cwiseSqrt();
|
||||
cout << "a= " << p[central](0) << " +/- " << err(0) << endl;
|
||||
cout << "b= " << p[central](1) << " +/- " << err(1) << endl;
|
||||
cout << "chi^2/ndof= " << p.getChi2PerDof() << endl;
|
||||
cout << "p-value= " << p.getPValue() << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user