27 #ifndef fitGammaDistribution_hpp
28 #define fitGammaDistribution_hpp
31 #include "../func/gammaDistribution.hpp"
40 template<
typename realT>
41 struct array2FitGammaDistribution;
65 template<
typename fitterT>
71 typedef typename fitterT::realT realT;
73 static const int nparams = fitterT::nparams;
99 static_assert( nparams==4 ,
"fitGammaDistribution: Wrong setGuess called for no location parameter.");
113 static_assert( nparams==3 ,
"fitGammaDistribution: Wrong setGuess called for no location parameter.");
125 static_assert( nparams==2 ,
"fitGammaDistribution: Wrong setGuess called for location parameter.");
131 void setArray(realT *data,
int n)
155 void theta( realT na )
161 void denom( realT nd)
205 return func::gammaDistributionDenom<realT>(this->
p[0], this->
p[1]);
216 template<
typename realT>
234 template<
typename _realT>
237 typedef _realT realT;
239 static const int nparams = 4;
241 static void func(realT *p, realT *hx,
int m,
int n,
void *adata)
245 for(
int i=0;i<arr->
n; i++)
247 hx[i] = func::gammaDistribution<realT>(i, p[2], p[0], p[1], p[3]) - arr->
data[i];
258 template<
typename _realT>
261 typedef _realT realT;
263 static const int nparams = 3;
265 static void func(realT *p, realT *hx,
int m,
int n,
void *adata)
269 realT denom = func::gammaDistributionDenom<realT>(p[0], p[1]);
271 for(
int i=0;i<arr->
n; i++)
273 hx[i] = func::gammaDistribution<realT>(i, p[2], p[0], p[1], denom) - arr->
data[i];
284 template<
typename _realT>
287 typedef _realT realT;
289 static const int nparams = 2;
291 static void func(realT *p, realT *hx,
int m,
int n,
void *adata)
295 realT denom = func::gammaDistributionDenom<realT>(p[0], p[1]);
297 for(
int i=0;i<arr->
n; i++)
299 hx[i] = func::gammaDistribution<realT>(i, 0.0, p[0], p[1], denom) - arr->
data[i];
Class to manage fitting the GammaDistribution Distribution to data via the levmarInterface.
void setGuess(realT x0, realT k, realT theta, realT denom)
Set the initial guess.
void setGuess(realT x0, realT k, realT theta)
Set the initial guess.
void setGuess(realT k, realT theta)
Set the initial guess when no location parameter is used.
A templatized interface to the levmar package.
int fit()
Perform the fit.
void allocate_params()
Allocate parameters array based on previous call to nParams.
realT * p
Parameter array. On input is the initial estimates. On output has the estimated solution.
int n
I: measurement vector dimension.
void * adata
Pointer to possibly additional data, passed uninterpreted to func & jacf.
A c++ interface to the templatized levmar minimization routines..
Wrapper for a native array to pass to levmarInterface, with GammaDistribution details.
realT k
the shape parameter
realT * data
Pointer to the array.
realT denom
the denominator or 1/peak-scale
realT theta
the scale parameter
size_t n
dimension of the array
realT x0
the location parameter.
levmarInterface fitter structure for the Gamma Distribution
levmarInterface fitter structure for the shifted Gamma Distribution
levmarInterface fitter structure for the shifted Gamma Distribution with arbitrary peak scaling