|
OpenMS
2.5.0
|
Go to the documentation of this file.
39 #include <unsupported/Eigen/NonLinearOptimization>
78 double log_eval_no_normalize(
double x)
const;
92 template<
typename _Scalar,
int NX = Eigen::Dynamic,
int NY = Eigen::Dynamic>
97 InputsAtCompileTime = NX,
98 ValuesAtCompileTime = NY
100 typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1>
InputType;
101 typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,1>
ValueType;
102 typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime>
JacobianType;
106 Functor() : m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {}
107 Functor(
int inputs,
int values) : m_inputs(inputs), m_values(values) {}
119 m_data(data), m_weights(weights)
123 int operator()(
const Eigen::VectorXd &x, Eigen::VectorXd &fvec)
const
126 double sigma = fabs(x(1));
127 double logsigma = log(sigma);
128 auto wit = m_weights.cbegin();
129 for (
auto it = m_data.cbegin(); it != m_data.cend(); ++it, ++wit)
131 double diff = (*it - x(0)) / sigma;
132 fvec(0) += *wit * (-logsigma - diff - exp(-diff));
134 double foo = -fvec(0);
155 Eigen::VectorXd x_init (2);
156 x_init(0) = init_param_.a;
157 x_init(1) = init_param_.b;
159 Eigen::NumericalDiff<GumbelDistributionFunctor> numDiff(functor);
160 Eigen::LevenbergMarquardt<Eigen::NumericalDiff<GumbelDistributionFunctor>,
double> lm(numDiff);
161 Eigen::LevenbergMarquardtSpace::Status status = lm.minimize(x_init);
166 if (status <= Eigen::LevenbergMarquardtSpace::Status::ImproperInputParameters)
168 throw Exception::UnableToFit(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"UnableToFit-GumbelMaxLikelihoodFitter",
"Could not fit the gumbel distribution to the data");
171 #ifdef GUMBEL_DISTRIBUTION_FITTER_VERBOSE
173 stringstream formula;
174 formula <<
"f(x)=" <<
"(1/" << x_init(1) <<
") * " <<
"exp(( " << x_init(0) <<
"- x)/" << x_init(1) <<
") * exp(-exp((" << x_init(0) <<
" - x)/" << x_init(1) <<
"))";
175 cout << formula.str() << endl;
177 init_param_.a = x_init(0);
178 init_param_.b = fabs(x_init(1));
180 return {x_init(0), fabs(x_init(1))};
Implements a fitter for the Gumbel distribution.
Definition: GumbelMaxLikelihoodFitter.h:59
int m_values
Definition: GumbelMaxLikelihoodFitter.h:104
struct to represent the parameters of a gumbel distribution
Definition: GumbelMaxLikelihoodFitter.h:65
Definition: GumbelMaxLikelihoodFitter.h:93
GumbelDistributionFunctor(const std::vector< double > &data, const std::vector< double > &weights)
Definition: GumbelMaxLikelihoodFitter.h:117
Eigen::Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Definition: GumbelMaxLikelihoodFitter.h:100
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
Definition: GumbelMaxLikelihoodFitter.h:123
Eigen::Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
Definition: GumbelMaxLikelihoodFitter.h:102
const std::vector< double > & m_weights
Definition: GumbelMaxLikelihoodFitter.h:140
int inputs() const
Definition: GumbelMaxLikelihoodFitter.h:109
Functor(int inputs, int values)
Definition: GumbelMaxLikelihoodFitter.h:107
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
GumbelDistributionFitResult fitWeighted(const std::vector< double > &x, const std::vector< double > &w)
Fits a gumbel distribution to the given data x values. Fills a weighted histogram first and generates...
Definition: GumbelMaxLikelihoodFitter.h:152
Eigen::Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
Definition: GumbelMaxLikelihoodFitter.h:101
double b
scale parameter b
Definition: GumbelMaxLikelihoodFitter.h:76
const std::vector< double > & m_data
Definition: GumbelMaxLikelihoodFitter.h:139
GumbelDistributionFitResult(double local_a, double local_b)
Definition: GumbelMaxLikelihoodFitter.h:67
Definition: GumbelMaxLikelihoodFitter.h:114
int values() const
Definition: GumbelMaxLikelihoodFitter.h:110
double a
location parameter a
Definition: GumbelMaxLikelihoodFitter.h:74
Functor()
Definition: GumbelMaxLikelihoodFitter.h:106
GumbelDistributionFitResult init_param_
Definition: GumbelMaxLikelihoodFitter.h:185
_Scalar Scalar
Definition: GumbelMaxLikelihoodFitter.h:95
Exception used if an error occurred while fitting a model to a given dataset.
Definition: Exception.h:676