ComPWA
Common Partial-Wave-Analysis Framework
GFMinIndividual.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 /*
6  * Copyright (C) Gemfony scientific UG (haftungsbeschraenkt)
7  *
8  * See the AUTHORS file in the top-level directory for a list of authors.
9  *
10  * Contact: contact [at] gemfony (dot) eu
11  *
12  * This file is part of the Geneva library collection.
13  *
14  * Geneva was developed with kind support from Karlsruhe Institute of
15  * Technology (KIT) and Steinbuch Centre for Computing (SCC). Further
16  * information about KIT and SCC can be found at http://www.kit.edu/english
17  * and http://scc.kit.edu .
18  *
19  * Geneva is free software: you can redistribute and/or modify it under
20  * the terms of version 3 of the GNU Affero General Public License
21  * as published by the Free Software Foundation.
22  *
23  * Geneva is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with the Geneva library. If not, see <http://www.gnu.org/licenses/>.
30  *
31  * For further information on Gemfony scientific and Geneva, visit
32  * http://www.gemfony.eu .
33  */
34 
35 #include "GFMinIndividual.hpp"
36 
37 #include "Core/Logging.hpp"
38 
39 #include "geneva/GConstrainedDoubleObject.hpp"
40 #include "geneva/GDoubleGaussAdaptor.hpp"
41 
42 BOOST_CLASS_EXPORT_IMPLEMENT(Gem::Geneva::GFMinIndividual)
43 
44 namespace Gem {
45 namespace Geneva {
46 
47 GFMinIndividual::GFMinIndividual(
50  : Estimator(&estimator) {
51  auto ActualParameters = estimator.getParameters();
52 
53  size_t varcounter(0);
54  // it is assumed that the Estimator Parameters and FitParameterList are
55  // synchronized (this was validated previously)
56  for (auto const &p : parlist) {
57  if (!p.IsFixed) {
58  FreeParameterIndices.push_back(varcounter);
59  double val = p.Value;
60  double min = GConstrainedValueLimitT<double>::lowest();
61  double max = GConstrainedValueLimitT<double>::highest();
62 
63  if (p.HasBounds) {
64  min = p.Bounds.first;
65  max = p.Bounds.second;
66  }
67  std::shared_ptr<GConstrainedDoubleObject> gbd_ptr(
68  new GConstrainedDoubleObject(val, min, max));
69 
70  std::shared_ptr<GDoubleGaussAdaptor> gdga_ptr(
71  new GDoubleGaussAdaptor(GFI_DEF_SIGMA, GFI_DEF_SIGMASIGMA,
72  GFI_DEF_MINSIGMA, GFI_DEF_MAXSIGMA));
73  gdga_ptr->setAdaptionThreshold(
74  1); // Adaption parameters are modified after each adaption
75  gdga_ptr->setAdaptionProbability(
76  GFI_DEF_ADPROB); // The likelihood for a parameter to be adapted
77 
78  // Register the adaptor with GConstrainedDoubleObject objects
79  gbd_ptr->addAdaptor(gdga_ptr);
80  this->push_back(gbd_ptr);
81  }
82  AllParameters.push_back(p.Value);
83  ++varcounter;
84  }
85  LOG(INFO) << "GStartIndividual::GStartIndividual() | "
86  << FreeParameterIndices.size()
87  << " Parameters were added for minimization!";
88 }
89 
90 GFMinIndividual::GFMinIndividual(const GFMinIndividual &cp)
91  : GParameterSet(cp), Estimator(cp.Estimator),
92  AllParameters(cp.AllParameters),
93  FreeParameterIndices(cp.FreeParameterIndices) {}
94 
95 const GFMinIndividual &GFMinIndividual::operator=(const GFMinIndividual &cp) {
96  GFMinIndividual::load_(&cp);
97  return *this;
98 }
99 
100 void GFMinIndividual::load_(const GObject *cp) {
101  // Check that we are dealing with a GFMinIndividual reference independent of
102  // this object and convert the pointer
103  const GFMinIndividual *p_load =
104  Gem::Common::g_convert_and_compare<GObject, GFMinIndividual>(cp, this);
105 
106  // Load our parent class'es data ...
107  GParameterSet::load_(cp);
108 
109  // ... and then our local data
110  Estimator = p_load->Estimator;
111  AllParameters = p_load->AllParameters;
112  FreeParameterIndices = p_load->FreeParameterIndices;
113 }
114 
115 GObject *GFMinIndividual::clone_() const { return new GFMinIndividual(*this); }
116 
117 double GFMinIndividual::fitnessCalculation() {
118  // Retrieve the parameters
119  std::vector<double> NewFreeParameters;
120  this->streamline(NewFreeParameters);
121 
122  auto NewParameters = AllParameters;
123  for (unsigned int i = 0; i < NewFreeParameters.size(); ++i) {
124  NewParameters[FreeParameterIndices[i]] = NewFreeParameters[i];
125  }
126 
127  Estimator->updateParametersFrom(NewParameters);
128  return Estimator->evaluate();
129 }
130 
131 } // namespace Geneva
132 } // namespace Gem
Definition: GenevaIF.hpp:23
std::vector< FitParameter< double > > FitParameterList
virtual std::vector< Parameter > getParameters() const =0