ComPWA
Common Partial-Wave-Analysis Framework
MinLogLH.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 
5 #include "MinLogLH.hpp"
8 #include "Core/Kinematics.hpp"
9 #include "Core/FourMomentum.hpp"
10 #include "Data/DataSet.hpp"
11 
12 namespace ComPWA {
13 namespace Estimator {
14 
15 using namespace ComPWA::FunctionTree;
16 
18  const Data::DataSet &datasample,
19  const Data::DataSet &phspdatasample)
20  : Intensity(intensity), DataSample(datasample),
21  PhspDataSample(phspdatasample) {
22 
23  LOG(INFO) << "MinLogLH::MinLogLH() | Size of data sample = "
24  << DataSample.Weights.size();
25 }
26 
27 double MinLogLH::evaluate() noexcept {
28  double lh(0.0);
29 
30  double Norm(0.0);
31  if (0 < PhspDataSample.Weights.size()) {
32  double PhspIntegral(0.0);
33  double WeightSum(0.0);
34  auto Intensities = Intensity.evaluate(PhspDataSample.Data);
35  auto IntensIter = Intensities.begin();
36  for (auto x = PhspDataSample.Weights.begin();
37  x != PhspDataSample.Weights.end(); ++x) {
38  PhspIntegral += *x * *IntensIter;
39  WeightSum += *x;
40  ++IntensIter;
41  }
42  Norm = (std::log(PhspIntegral / WeightSum) * DataSample.Weights.size());
43  }
44  // calculate data log sum
45  double LogSum(0.0);
46  auto Intensities = Intensity.evaluate(DataSample.Data);
47  for (size_t i = 0; i < DataSample.Weights.size(); ++i) {
48  LogSum += std::log(Intensities[i]) * DataSample.Weights[i];
49  }
50  lh = Norm - LogSum;
51 
52  return lh;
53 }
54 
55 void MinLogLH::updateParametersFrom(const std::vector<double> &params) {
57 }
58 
59 std::vector<ComPWA::Parameter> MinLogLH::getParameters() const {
60  return Intensity.getParameters();
61 }
62 
63 std::pair<ComPWA::FunctionTree::FunctionTreeEstimator, FitParameterList>
67  using namespace ComPWA::FunctionTree;
68  LOG(DEBUG)
69  << "createMinLogLHEstimatorFunctionTree(): constructing FunctionTree!";
70 
71  if (0 == DataSample.Weights.size()) {
72  LOG(ERROR) << "createMinLogLHEstimatorFunctionTree(): Data sample is "
73  "empty! Please supply some data.";
74  return std::make_pair(FunctionTreeEstimator(nullptr, ParameterList()),
76  }
77 
78  std::shared_ptr<ComPWA::FunctionTree::TreeNode> DataIntensityFunctionTree;
80  std::tie(DataIntensityFunctionTree, Parameters) =
81  Intensity.bind(DataSample.Data);
82 
83  FitParameterList FitParList =
85 
86  auto weights = std::make_shared<Value<std::vector<double>>>(
87  "Weights", DataSample.Weights);
88 
89  std::shared_ptr<ComPWA::FunctionTree::TreeNode> EvaluationTree =
90  std::make_shared<ComPWA::FunctionTree::TreeNode>(
91  std::make_shared<Value<double>>(),
92  std::make_shared<AddAll>(ParType::DOUBLE));
93 
94  auto dataTree = std::make_shared<ComPWA::FunctionTree::TreeNode>(
95  std::make_shared<Value<double>>(),
96  std::make_shared<MultAll>(ParType::DOUBLE));
97  dataTree->addNode(createLeaf(-1));
98  auto Sum = std::make_shared<TreeNode>(
99  std::shared_ptr<Strategy>(new AddAll(ParType::DOUBLE)));
100  dataTree->addNode(Sum);
101  auto WeightedLogIntensities = std::make_shared<TreeNode>(
102  std::shared_ptr<Strategy>(new MultAll(ParType::MDOUBLE)));
103  Sum->addNode(WeightedLogIntensities);
104  if (weights)
105  WeightedLogIntensities->addNode(createLeaf(weights));
106  auto Log = std::make_shared<TreeNode>(
107  std::shared_ptr<Strategy>(new LogOf(ParType::MDOUBLE)));
108  WeightedLogIntensities->addNode(Log);
109  Log->addNode(DataIntensityFunctionTree);
110 
111  EvaluationTree->addNode(dataTree);
112 
113  LOG(DEBUG) << "createMinLogLHEstimatorFunctionTree(): construction of LH "
114  "tree finished! Performing checks ...";
115 
116  EvaluationTree->parameter();
117  LOG(DEBUG) << "createMinLogLHEstimatorFunctionTree(): finished!";
118 
119  return std::make_pair(FunctionTreeEstimator(EvaluationTree, Parameters),
120  FitParList);
121 }
122 
123 } // namespace Estimator
124 } // namespace ComPWA
virtual void updateParametersFrom(const std::vector< double > &)=0
It is important to input the vector in the same length and order as defined in the getParameters() me...
ComPWA::DataMap Data
Definition: DataSet.hpp:18
double evaluate() noexcept final
Value of log likelihood function.
Definition: MinLogLH.cpp:27
std::vector< FitParameter< double > > FitParameterList
std::vector< double > Weights
Definition: DataSet.hpp:19
ParameterList class.
const Data::DataSet & PhspDataSample
Definition: MinLogLH.hpp:67
std::tuple< std::shared_ptr< ComPWA::FunctionTree::TreeNode >, ComPWA::FunctionTree::ParameterList > bind(const ComPWA::DataMap &data)
std::vector< ComPWA::Parameter > getParameters() const final
Definition: MinLogLH.cpp:59
virtual OutputType evaluate(const InputTypes &... args) noexcept=0
FitParameterList createFitParameterList(ComPWA::FunctionTree::ParameterList Parameters)
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: MinLogLH.cpp:55
const Data::DataSet & DataSample
Definition: MinLogLH.hpp:66
std::pair< ComPWA::FunctionTree::FunctionTreeEstimator, FitParameterList > createMinLogLHFunctionTreeEstimator(ComPWA::FunctionTree::FunctionTreeIntensity &Intensity, const ComPWA::Data::DataSet &DataSample)
Definition: MinLogLH.cpp:64
std::shared_ptr< TreeNode > createLeaf(std::shared_ptr< Parameter > parameter)
Definition: TreeNode.cpp:156
TreeNode class.
virtual std::vector< Parameter > getParameters() const =0
This class provides a list of parameters and values of different types.
Interface template for a general Function of the form OutputType Function(InputTypes) The concept clo...
Definition: Function.hpp:24
Calculates the square root of input double values and double parameters.
Definition: Functions.hpp:91
MinLogLH(ComPWA::Intensity &intensity, const Data::DataSet &datasample, const Data::DataSet &phspdatasample)
Definition: MinLogLH.cpp:17