ComPWA
Common Partial-Wave-Analysis Framework
FunctionTreeEstimator.cpp
Go to the documentation of this file.
2 
3 #include "TreeNode.hpp"
4 #include "Value.hpp"
5 
6 namespace ComPWA {
7 namespace FunctionTree {
8 
9 FunctionTreeEstimator::FunctionTreeEstimator(std::shared_ptr<TreeNode> tree,
10  ParameterList parameters)
11  : Tree(tree), Parameters(parameters) {
12 
13  if (!Tree) {
14  throw std::runtime_error("FunctionTreeEstimator::FunctionTreeEstimator(): "
15  "FunctionTree is empty!");
16  }
17  Tree->parameter();
18 
19  for (auto x : Parameters.doubleParameters()) {
20  x->fixParameter(false);
21  // IMPORTANT: we have to unfix all parameters
22  // since the optimizer will take care of this
23  // and we can't maintain which parameters will
24  // be fixed later on. So internally we treat them
25  // all as free. But of course only the parameters
26  // that are not fixed will change...
27  // So the function tree caching and recalculation
28  // still works fine
29  // When improving the FunctionTree later on
30  // The Parameters should be more "dumb" and not have
31  // information about a fixed or not fixed status.
32  }
33 }
34 
36  auto val = std::dynamic_pointer_cast<Value<double>>(Tree->parameter());
37  return val->value();
38 }
39 
41  const std::vector<double> &params) {
42  size_t pos = 0;
43  for (auto p : Parameters.doubleParameters()) {
44  p->setValue(params[pos]);
45  ++pos;
46  }
47 }
48 
49 std::vector<ComPWA::Parameter> FunctionTreeEstimator::getParameters() const {
50  std::vector<ComPWA::Parameter> params;
51  for (auto p : Parameters.doubleParameters()) {
52  params.push_back(ComPWA::Parameter{p->name(), p->value()});
53  }
54  return params;
55 }
56 
57 std::string FunctionTreeEstimator::print(int level) const {
58  return Tree->print(level);
59 }
60 
61 std::shared_ptr<TreeNode> FunctionTreeEstimator::getFunctionTree() const {
62  return Tree;
63 }
65  return Parameters;
66 }
67 
70  FitParameterList Pars;
71  for (auto x : Parameters.doubleParameters()) {
73  p.Value = x->value();
74  p.Name = x->name();
75  p.HasBounds = x->hasBounds();
76  if (p.HasBounds) {
77  p.Bounds = x->bounds();
78  }
79  if (x->hasError()) {
80  p.Error = x->error();
81  }
82  p.IsFixed = x->isFixed();
83  Pars.push_back(p);
84  }
85  return Pars;
86 }
87 
88 } // namespace FunctionTree
89 } // namespace ComPWA
std::pair< T, T > Error
Template implementation of Parameter for simple values.
void updateParametersFrom(const std::vector< double > &params)
It is important to input the vector in the same length and order as defined in the getParameters() me...
std::vector< FitParameter< double > > FitParameterList
std::vector< ComPWA::Parameter > getParameters() const
FitParameterList createFitParameterList(ComPWA::FunctionTree::ParameterList Parameters)
FunctionTreeEstimator(std::shared_ptr< TreeNode > tree, ParameterList parameters)
virtual T value() const
Definition: Value.hpp:45
std::shared_ptr< TreeNode > getFunctionTree() const
std::pair< T, T > Bounds
virtual std::vector< std::shared_ptr< FitParameter > > & doubleParameters()
TreeNode class.
This class provides a list of parameters and values of different types.