-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RooFit::MultiProcess & TestStatistics part 1: mathcore & Minuit2 chan…
…ges (#8369) * add virtuals to IFunction to calculate second derivative and stepsize Used in Minuit2 ExternalInternalGradientCalculator (introduced in a later commit) and in RooFit (also later commits) to enable calculation of all derivative and related numbers outside of Minuit2. Specifically, having second derivative and step size calculated outside of Minuit2 allows exact replication of the gradients as calculated in Minuit2 itself, which in turn enables external optimization and parallelization of this process without having to modify Minuit2. * add second derivative and step size calculation to Minuit2 function adaptors Like the changes to IFunction in the previous commit, this is also necessary for Minuit2-external gradient calculation. * add second derivative and step size to Minuit2 parameter transformers and increase their precision This commit changes two (functionally speaking strictly separate, but unified in their ultimate purpose) things. First, to further accomodate the added ability of external gradient calculators to pass in second derivative and step sizes, the internal to external parameter transformers in Minuit2 need to have added D2Int2Ext and GStepInt2Ext functions that perform these transformations for those added parts. Second, we increase the precision of the transformers to long double. This is necessary to make sure that trigonometric transformations don't lose a few bits of precision on back-and-forth parameter transformations, which they do when using the double versions. Both changes are necessary for the external gradient calculation in Minuit2 which will be introduced in a next commit in ExternalInternalGradientCalculator. * implement optional second derivative and step size calculation in AnalyticalGradientCalculator * remove unnecessary temporary objects * add ExternalInternalGradientCalculator to minuit2 Derived class from AnalyticalGradientCalculator. Allows Minuit2 using codes to calculate gradients themselves, but in Minuit2 "internal" parameter space, in order to preserve exact value correspondence with the Minuit2 implementation. * Update math/mathcore/inc/Math/IFunction.h Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch> * revert unnecessary math/minuit2 changes As highlighted by @lmoneta in PR review comments (#8369 (review)), the second derivative and step size information is not necessary at this point. The floating point exact minuit-external (roofit-internal) derivative duplication is currently done using ExternalInternalGradientCalculator and further made possible by the long double parameter transformation functions. This is all we need for now. * fix previous revert commit + revert one additional thing Fixes: some merge mistakes + some remaining layout diffs. The additional reverted thing is the block from line 119 in MnSeedGenerator.cxx. * fix additional layout Just trying to keep the PR diff minimal. * remove copyright line [skip ci] * add ExternalInternalGradientCalculator doxygen Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
- Loading branch information
1 parent
00a1681
commit 0396d49
Showing
15 changed files
with
185 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
math/minuit2/inc/Minuit2/ExternalInternalGradientCalculator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// @(#)root/minuit2:$Id$ | ||
// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei, E.G.P. Bos 2003-2017 | ||
|
||
/********************************************************************** | ||
* * | ||
* Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * | ||
* * | ||
**********************************************************************/ | ||
|
||
#ifndef ROOT_Minuit2_ExternalInternalGradientCalculator | ||
#define ROOT_Minuit2_ExternalInternalGradientCalculator | ||
|
||
#include "Minuit2/AnalyticalGradientCalculator.h" | ||
|
||
namespace ROOT { | ||
|
||
namespace Minuit2 { | ||
|
||
class FCNGradientBase; | ||
class MnUserTransformation; | ||
|
||
/// Similar to the AnalyticalGradientCalculator, the ExternalInternalGradientCalculator | ||
/// supplies Minuit with an externally calculated gradient. The main difference is that | ||
/// ExternalInternalGradientCalculator expects that the external gradient calculator does | ||
/// things in Minuit2-internal parameter space, which means many int2ext and ext2int | ||
/// transformation steps are not necessary. This avoids loss of precision in some cases, | ||
/// where trigonometrically transforming parameters back and forth can lose a few bits of | ||
/// floating point precision on every pass. | ||
|
||
class ExternalInternalGradientCalculator : public AnalyticalGradientCalculator { | ||
|
||
public: | ||
ExternalInternalGradientCalculator(const FCNGradientBase &fcn, const MnUserTransformation &state) | ||
: AnalyticalGradientCalculator(fcn, state) | ||
{ | ||
} | ||
|
||
~ExternalInternalGradientCalculator() {} | ||
|
||
virtual FunctionGradient operator()(const MinimumParameters &) const; | ||
|
||
virtual FunctionGradient operator()(const MinimumParameters &, const FunctionGradient &) const; | ||
}; | ||
|
||
} // namespace Minuit2 | ||
|
||
} // namespace ROOT | ||
|
||
#endif // ROOT_Minuit2_ExternalInternalGradientCalculator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @(#)root/minuit2:$Id$ | ||
// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei, E.G.P. Bos 2003-2017 | ||
|
||
/********************************************************************** | ||
* * | ||
* Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * | ||
* * | ||
**********************************************************************/ | ||
|
||
#include <vector> | ||
#include "Minuit2/ExternalInternalGradientCalculator.h" | ||
#include "Minuit2/FCNGradientBase.h" | ||
#include "Minuit2/MnUserTransformation.h" | ||
#include "Minuit2/FunctionGradient.h" | ||
#include "Minuit2/MinimumParameters.h" | ||
|
||
namespace ROOT { | ||
namespace Minuit2 { | ||
|
||
FunctionGradient ExternalInternalGradientCalculator::operator()(const MinimumParameters &par) const | ||
{ | ||
// evaluate analytical gradient. take care of parameter transformations | ||
std::vector<double> par_vec; | ||
par_vec.resize(par.Vec().size()); | ||
for (std::size_t ix = 0; ix < par.Vec().size(); ++ix) { | ||
par_vec[ix] = par.Vec()(ix); | ||
} | ||
|
||
std::vector<double> grad = fGradCalc.Gradient(par_vec); | ||
assert(grad.size() == fTransformation.Parameters().size()); | ||
|
||
MnAlgebraicVector v(par.Vec().size()); | ||
for (unsigned int i = 0; i < par.Vec().size(); i++) { | ||
unsigned int ext = fTransformation.ExtOfInt(i); | ||
v(i) = grad[ext]; | ||
} | ||
|
||
#ifdef DEBUG | ||
std::cout << "User given gradient in Minuit2" << v << std::endl; | ||
#endif | ||
|
||
return FunctionGradient(v); | ||
} | ||
|
||
FunctionGradient | ||
ExternalInternalGradientCalculator::operator()(const MinimumParameters &par, const FunctionGradient &) const | ||
{ | ||
// needed from base class | ||
return (*this)(par); | ||
} | ||
|
||
} // namespace Minuit2 | ||
} // namespace ROOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.