-
Notifications
You must be signed in to change notification settings - Fork 1.5k
RooFit::MultiProcess & TestStatistics part 6: add RooFit::TestStatistics #8700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guitargeek
merged 6 commits into
root-project:master
from
roofit-dev:RooFit_MultiProcess_PR_6_TestStatistics
Sep 14, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7d1bb9
add RooFit::TestStatistics
egpbos b2025cb
modernize and clean up RooFit::TestStatistics
egpbos ecfd0c0
add doxygen documentation to RooFit::TestStatistics
egpbos 245a5ae
finish RooFit::TestStatistics::buildLikelihood
egpbos d112e81
use Math::KahanSum in RooFit::TestStatistics
egpbos b57509d
unify unbinned likelihood calculation in RooNLLVar and RooUnbinnedL
egpbos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
roofit/roofitcore/inc/TestStatistics/ConstantTermsOptimizer.h
This file contains hidden or 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,40 @@ | ||
| // Author: Patrick Bos, Netherlands eScience Center / NIKHEF 2021 | ||
|
|
||
| /***************************************************************************** | ||
| * RooFit | ||
| * Authors: * | ||
| * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * | ||
| * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * | ||
| * * | ||
| * Copyright (c) 2000-2021, Regents of the University of California * | ||
| * and Stanford University. All rights reserved. * | ||
|
Comment on lines
+9
to
+10
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do this, about to open a PR with some follow-ups to the multiprocessing |
||
| * * | ||
| * Redistribution and use in source and binary forms, * | ||
| * with or without modification, are permitted according to the terms * | ||
| * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * | ||
| *****************************************************************************/ | ||
|
|
||
| #ifndef ROOT_ROOFIT_TESTSTATISTICS_ConstantTermsOptimizer | ||
| #define ROOT_ROOFIT_TESTSTATISTICS_ConstantTermsOptimizer | ||
|
|
||
| // forward declarations | ||
| class RooAbsReal; | ||
| class RooArgSet; | ||
| class RooAbsData; | ||
|
|
||
| namespace RooFit { | ||
| namespace TestStatistics { | ||
|
|
||
| // this is a class only for convenience: it saves multiple friend definitions in RooAbsData for otherwise free functions | ||
| struct ConstantTermsOptimizer { | ||
| static void enableConstantTermsOptimization(RooAbsReal *function, RooArgSet *norm_set, RooAbsData *dataset, | ||
| bool applyTrackingOpt); | ||
| static void optimizeCaching(RooAbsReal *function, RooArgSet *norm_set, RooArgSet* observables, RooAbsData *dataset); | ||
| static void disableConstantTermsOptimization(RooAbsReal *function, RooArgSet *norm_set, RooArgSet* observables, RooAbsData *dataset); | ||
| static RooArgSet requiredExtraObservables(); | ||
| }; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| #endif // ROOT_ROOFIT_TESTSTATISTICS_ConstantTermsOptimizer | ||
73 changes: 73 additions & 0 deletions
73
roofit/roofitcore/inc/TestStatistics/LikelihoodGradientWrapper.h
This file contains hidden or 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,73 @@ | ||
| // Author: Patrick Bos, Netherlands eScience Center / NIKHEF 2021 | ||
|
|
||
| /***************************************************************************** | ||
| * RooFit | ||
| * Authors: * | ||
| * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * | ||
| * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * | ||
| * * | ||
| * Copyright (c) 2000-2021, Regents of the University of California * | ||
| * and Stanford University. All rights reserved. * | ||
| * * | ||
| * Redistribution and use in source and binary forms, * | ||
| * with or without modification, are permitted according to the terms * | ||
| * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * | ||
| *****************************************************************************/ | ||
|
|
||
| #ifndef ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper | ||
| #define ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper | ||
|
|
||
| #include <Fit/ParameterSettings.h> | ||
| #include <Math/IFunctionfwd.h> | ||
| #include "Math/MinimizerOptions.h" | ||
|
|
||
| #include <vector> | ||
| #include <memory> // shared_ptr | ||
|
|
||
| // forward declaration | ||
| class RooMinimizer; | ||
|
|
||
| namespace RooFit { | ||
| namespace TestStatistics { | ||
|
|
||
| // forward declaration | ||
| class RooAbsL; | ||
| struct WrapperCalculationCleanFlags; | ||
|
|
||
| class LikelihoodGradientWrapper { | ||
| public: | ||
| LikelihoodGradientWrapper(std::shared_ptr<RooAbsL> likelihood, std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, std::size_t N_dim, RooMinimizer* minimizer); | ||
| virtual ~LikelihoodGradientWrapper() = default; | ||
| virtual LikelihoodGradientWrapper* clone() const = 0; | ||
|
|
||
| virtual void fillGradient(double *grad) = 0; | ||
|
|
||
| /// Synchronize minimizer settings with calculators in child classes. | ||
| virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options); | ||
| virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> ¶meter_settings); | ||
| virtual void synchronizeParameterSettings(ROOT::Math::IMultiGenFunction* function, const std::vector<ROOT::Fit::ParameterSettings> ¶meter_settings) = 0; | ||
| /// Minuit passes in parameter values that may not conform to RooFit internal standards (like applying range clipping), | ||
| /// but that the specific calculator does need. This function can be implemented to receive these Minuit-internal values. | ||
| virtual void updateMinuitInternalParameterValues(const std::vector<double>& minuit_internal_x); | ||
| virtual void updateMinuitExternalParameterValues(const std::vector<double>& minuit_external_x); | ||
|
|
||
| /// \brief Implement usesMinuitInternalValues to return true when you want Minuit to send this class Minuit-internal values, or return false when you want "regular" Minuit-external values. | ||
| /// | ||
| /// Minuit internally uses a transformed parameter space to graciously handle externally mandated parameter range | ||
| /// boundaries. Transformation from Minuit-internal to external (i.e. "regular") parameters is done using | ||
| /// trigonometric functions that in some cases can cause a few bits of precision loss with respect to the original | ||
| /// parameter values. To circumvent this, Minuit also allows external gradient providers (like LikelihoodGradientWrapper) | ||
| /// to take the Minuit-internal parameter values directly, without transformation. This way, the gradient provider | ||
| /// (e.g. the implementation of this class) can handle transformation manually, possibly with higher precision. | ||
| virtual bool usesMinuitInternalValues() = 0; | ||
|
|
||
| protected: | ||
| std::shared_ptr<RooAbsL> likelihood_; | ||
| RooMinimizer * minimizer_; | ||
| std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_; | ||
| }; | ||
|
|
||
| } // namespace TestStatistics | ||
| } // namespace RooFit | ||
|
|
||
| #endif // ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper |
This file contains hidden or 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,52 @@ | ||
| // Author: Patrick Bos, Netherlands eScience Center / NIKHEF 2021 | ||
|
|
||
| /***************************************************************************** | ||
| * RooFit | ||
| * Authors: * | ||
| * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * | ||
| * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * | ||
| * * | ||
| * Copyright (c) 2000-2021, Regents of the University of California * | ||
| * and Stanford University. All rights reserved. * | ||
| * * | ||
| * Redistribution and use in source and binary forms, * | ||
| * with or without modification, are permitted according to the terms * | ||
| * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * | ||
| *****************************************************************************/ | ||
|
|
||
| #ifndef ROOT_ROOFIT_LikelihoodSerial | ||
| #define ROOT_ROOFIT_LikelihoodSerial | ||
|
|
||
| #include <TestStatistics/LikelihoodWrapper.h> | ||
| #include "RooArgList.h" | ||
|
|
||
| #include "Math/MinimizerOptions.h" | ||
|
|
||
| #include <map> | ||
|
|
||
| namespace RooFit { | ||
| namespace TestStatistics { | ||
|
|
||
| class LikelihoodSerial : public LikelihoodWrapper { | ||
|
egpbos marked this conversation as resolved.
|
||
| public: | ||
| LikelihoodSerial(std::shared_ptr<RooAbsL> likelihood, std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean); | ||
| inline LikelihoodSerial *clone() const override { return new LikelihoodSerial(*this); } | ||
|
|
||
| void initVars(); | ||
|
|
||
| void evaluate() override; | ||
| inline ROOT::Math::KahanSum<double> getResult() const override { return result; } | ||
|
|
||
| private: | ||
| ROOT::Math::KahanSum<double> result; | ||
|
|
||
| RooArgList _vars; // Variables | ||
| RooArgList _saveVars; // Copy of variables | ||
|
|
||
| LikelihoodType likelihood_type; | ||
| }; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| #endif // ROOT_ROOFIT_LikelihoodSerial | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file are not necessary,
RooAbsLis not using any non-public functions in RooDataHist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, weird. I thought this was necessary for RooAbsL::initClones, but maybe I've edited the dependency out.