ComPWA
Common Partial-Wave-Analysis Framework
SumMinLogLH.cpp
Go to the documentation of this file.
1 // Copyright (c) 2013, 2015, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
6 #include "Core/Event.hpp"
7 #include "Core/FitResult.hpp"
10 #include "Core/Kinematics.hpp"
11 #include "Core/FourMomentum.hpp"
13 
14 namespace ComPWA {
15 namespace Estimator {
16 
17 using namespace ComPWA::FunctionTree;
18 
19 SumMinLogLH::SumMinLogLH(std::vector<std::shared_ptr<Estimator>> Estimators)
20  : LogLikelihoods(Estimators) {}
21 
22 double SumMinLogLH::evaluate() noexcept {
23  double lh(0.0);
24  for (auto x : LogLikelihoods)
25  lh += x->evaluate();
26  return lh;
27 }
28 
29 void SumMinLogLH::updateParametersFrom(const std::vector<double> &params) {
30  auto CurrentSubRangeBegin = params.begin();
31  for (auto LLH : LogLikelihoods) {
32  size_t SubRangeSize = LLH->getParameters().size();
33  std::vector<double> SubParameterRange;
34  SubParameterRange.reserve(SubRangeSize);
35  std::copy(CurrentSubRangeBegin, CurrentSubRangeBegin + SubRangeSize,
36  std::back_inserter(SubParameterRange));
37  CurrentSubRangeBegin += SubRangeSize;
38  LLH->updateParametersFrom(SubParameterRange);
39  }
40 }
41 
42 std::vector<ComPWA::Parameter> SumMinLogLH::getParameters() const {
43  std::vector<ComPWA::Parameter> Parameters;
44  for (auto x : LogLikelihoods) {
45  auto pars = x->getParameters();
46  Parameters.insert(Parameters.end(), pars.begin(), pars.end());
47  }
48  return Parameters;
49 }
50 
51 // This function is one part, which suggest a bad design
52 std::tuple<FunctionTreeEstimator, FitParameterList>
54  std::vector<std::pair<ComPWA::FunctionTree::FunctionTreeEstimator,
56  Estimators) {
57 
58  unsigned int counter(1);
59  FitParameterList TempParameters;
60  FitParameterList Pars;
61  ParameterList ParList;
62 
63  auto EvaluationTree = std::make_shared<ComPWA::FunctionTree::TreeNode>(
64  std::make_shared<Value<double>>(),
65  std::make_shared<AddAll>(ParType::DOUBLE));
66 
67  for (auto &x : Estimators) {
68  try {
69  EvaluationTree->addNode(x.first.getFunctionTree());
70  } catch (std::exception &ex) {
71  LOG(ERROR) << "createSumMinLogLHEstimatorFunctionTree(): Construction of "
72  "one or more sub trees has failed! Error: "
73  << ex.what();
74  }
75  ++counter;
76  TempParameters.insert(TempParameters.begin(), x.second.begin(),
77  x.second.end());
78  }
79  EvaluationTree->fillParameters(ParList);
80 
81  for (auto x : ParList.doubleParameters()) {
82  auto result = std::find_if(TempParameters.begin(), TempParameters.end(),
83  [x](const ComPWA::FitParameter<double> &fp) {
84  return fp.Name == x->name();
85  });
86  if (TempParameters.end() != result) {
87  Pars.push_back(*result);
88  }
89  }
90 
91  EvaluationTree->parameter();
92 
93  return std::make_tuple(FunctionTreeEstimator(EvaluationTree, ParList), Pars);
94 } // namespace Estimator
95 
96 } // namespace Estimator
97 } // namespace ComPWA
double evaluate() noexcept final
Value of minimum log likelihood function.
Definition: SumMinLogLH.cpp:22
std::vector< FitParameter< double > > FitParameterList
ParameterList class.
void updateParametersFrom(const std::vector< double > &params) final
It is important to input the vector in the same length and order as defined in the getParameters() me...
Definition: SumMinLogLH.cpp:29
std::vector< ComPWA::Parameter > getParameters() const final
Definition: SumMinLogLH.cpp:42
std::vector< std::shared_ptr< Estimator > > LogLikelihoods
Definition: SumMinLogLH.hpp:36
SumMinLogLH(std::vector< std::shared_ptr< Estimator >> Estimators)
Definition: SumMinLogLH.cpp:19
virtual std::vector< std::shared_ptr< FitParameter > > & doubleParameters()
TreeNode class.
This class provides a list of parameters and values of different types.
std::tuple< FunctionTreeEstimator, FitParameterList > createSumMinLogLHFunctionTreeEstimator(std::vector< std::pair< ComPWA::FunctionTree::FunctionTreeEstimator, FitParameterList >> Estimators)
Definition: SumMinLogLH.cpp:53