1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#ifndef NLPL_FITTER_H
#define NLPL_FITTER_H
#include <cmath>
#include <memory>
#include <aocommon/uvector.h>
/**
* This class fits a power law to a set of points. Note that there is a
* linear solution for this problem, but the linear solution requires
* all values to be positive, which is not the case for e.g. spectral
* energy distributions, because these have noise.
* This fitter does not have this requirement.
*/
class NonLinearPowerLawFitter
{
public:
NonLinearPowerLawFitter();
~NonLinearPowerLawFitter();
void AddDataPoint(double x, double y);
void Fit(double& exponent, double& factor);
void Fit(double& a, double& b, double& c);
void Fit(aocommon::UVector<double>& terms, size_t nTerms);
void FitStable(aocommon::UVector<double>& terms, size_t nTerms);
void FastFit(double& exponent, double& factor);
static double Evaluate(double x, const aocommon::UVector<double>& terms, double referenceFrequencyHz=1.0);
static long double Evaluate(long double factor, long double exponent, long double frequencyHz)
{
return factor * powl(frequencyHz, exponent);
}
/*static double Term0ToFactor(double term0, double term1)
{
return exp10(term0); // + term1*log(NLPLFact));
}
static double FactorToTerm0(double factor, double term1)
{
return log10(factor); // - (term1*log(NLPLFact));
}*/
private:
void fit_implementation(aocommon::UVector<double>& terms, size_t nTerms);
std::unique_ptr<class NLPLFitterData> _data;
};
#endif
|