-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[RF] Add tutorial for simulation based inference #16044
Conversation
robsyr
commented
Jul 17, 2024
- created new tutorial for simulation based inference (SBI)
Test Results 13 files 13 suites 3d 2h 50m 52s ⏱️ For more details on these failures, see this check. Results for commit d9e398f. ♻️ This comment has been updated with latest results. |
bindings/pyroot/pythonizations/python/ROOT/_pythonization/_roofit/_rooglobalfunc.py
Outdated
Show resolved
Hide resolved
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.
Thank you very much for this contribution. I have made a few change requests, but overall this is going in a very good direction!
Thanks to @bellenot, scikit-learn
is now also installed on Windows 64 bit, but on Windows 32 bit it's not supported. Could you please add the tutorial to the list of tutorials that are vetoed on Windows 32 bit?
https://github.com/root-project/root/blob/master/tutorials/CMakeLists.txt#L131
Thanks a lot!
tutorials/CMakeLists.txt
Outdated
@@ -138,7 +138,7 @@ else() | |||
# The following tutorials are failing with this error: | |||
# IncrementalExecutor::executeFunction: symbol '__std_find_trivial_4@12' unresolved while linking [cling interface function]! | |||
# on Windows 32 bit and Visual Studio v17.8 | |||
list(APPEND roofit_veto roofit/rf509_wsinteractive.C roofit/rf614_binned_fit_problems.C) | |||
list(APPEND roofit_veto roofit/rf509_wsinteractive.C roofit/rf614_binned_fit_problems.C roofit/rf615_simulation_based_inference.py) |
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.
list(APPEND roofit_veto roofit/rf509_wsinteractive.C roofit/rf614_binned_fit_problems.C roofit/rf615_simulation_based_inference.py) | |
list(APPEND roofit_veto roofit/rf509_wsinteractive.C roofit/rf614_binned_fit_problems.C) | |
# The next tutorial uses scikit-learn, which is not available on Windows 32 bit | |
list(APPEND roofit_veto roofit/rf509_wsinteractive.C roofit/rf615_simulation_based_inference.py) |
Now it looks like the comment above with the The following tutorials are failing with this...
is also referring to you new tutorial, which is not the case. I would organize this differently.
m_varlist("!varlist", this, right.m_varlist) { | ||
} | ||
|
||
RooPyBindFunction::~RooPyBindFunction() {} |
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.
RooPyBindFunction::~RooPyBindFunction() {} |
You already deleted the destructor declaration, but you also need to remove the corresponding implementation.
|
||
#include "RooPyBindFunction.h" | ||
|
||
// ClassImp(RooPyBindFunction); |
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.
// ClassImp(RooPyBindFunction); |
We should not push commented-out code if there is not strong reason for it
## \macro_code | ||
## \macro_output |
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.
## \macro_code | |
## \macro_output | |
## \macro_image | |
## \macro_code | |
## \macro_output |
We also want to see the output plots
This clsss provides the functionality to wrap arbitrary python functions in | ||
RooFit. | ||
*/ | ||
|
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.
namespace RooFit { | |
namespace Detail { | |
The implementation needs to be in the same namespace (also think about the closing brackets at the end of the file).
@@ -0,0 +1,231 @@ | |||
## \file |
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.
Can you go over the tutorial one with the code formatter?
black --line-length=120 tutorials/roofit/rf615_simulation_based_inference.py
@@ -46,6 +46,7 @@ | |||
LineStyle, | |||
FillStyle, | |||
MarkerStyle, | |||
bindFunction |
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.
Please process this file with the code formatter.
@@ -319,3 +319,37 @@ def DataError(etype): | |||
raise exception | |||
|
|||
return RooFit._DataError(etype) | |||
|
|||
|
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.
Please process this file with the code formatter.
# frame1= x_var.frame() | ||
# c0= ROOT.TCanvas() | ||
# frame1.Draw() | ||
# input("") |
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.
# frame1= x_var.frame() | |
# c0= ROOT.TCanvas() | |
# frame1.Draw() | |
# input("") | |
# frame1 = x_var.frame() | |
# c0 = ROOT.TCanvas() | |
# frame1.Draw() | |
# input() # wait for user input to proceed |
Also the commented-out code should be formatted :)
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.
Oh, actually the part where you need to draw on the frame needs to be in the commented-out block too:
# Uncomment to see input plots
# frame1 = x_var.frame()
# for i in parampoints:
# workspace[f"histpdf{i}"].plotOn(frame1)
# c0 = ROOT.TCanvas()
# frame1.Draw()
# input() # wait for user input to proceed
workspace.Import(morph) | ||
|
||
|
||
# class used in this case to demonstate the use of SBI in Root |
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.
# class used in this case to demonstate the use of SBI in Root | |
# class used in this case to demonstrate the use of SBI in Root |
self.classifier.fit(self.X_train, self.y_train) | ||
|
||
|
||
# Setting the training and toy data samples; the factor 5 to enable a fair comparisson to morphing |
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.
# Setting the training and toy data samples; the factor 5 to enable a fair comparisson to morphing | |
# Setting the training and toy data samples; the factor 5 to enable a fair comparison to morphing |
## \file | ||
## \ingroup tutorial_roofit | ||
## \notebook | ||
## Use Simulation Based Inference (SBI) in RooFit |
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.
## Use Simulation Based Inference (SBI) in RooFit | |
## Use Simulation Based Inference (SBI) in RooFit. |
The short description is doxygen needs to end with a period
bin_mu_x = ROOT.RooBinning(4, 0., 4.) | ||
grid = ROOT.RooMomentMorphFuncND.Grid2(bin_mu_x) |
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.
bin_mu_x = ROOT.RooBinning(4, 0., 4.) | |
grid = ROOT.RooMomentMorphFuncND.Grid2(bin_mu_x) | |
grid = ROOT.RooMomentMorphFuncND.Grid(ROOT.RooBinning(4, 0., 4.)) |
Can we do this in one line? And maybe use Grid
instead of Grid2
. I think Grid2 only exists for backwards compatibility, but it is identical.
n_samples_train = n_samples * 5 | ||
|
||
|
||
# define the "observed" data in a workspade |
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.
# define the "observed" data in a workspade | |
# define the "observed" data in a workspace |
# compute the "learned" negative log likelihood ratio | ||
nllr_learned = ROOT.RooFit.bindFunction("MyBinFunc", compute_log_likelihood_sum, mu_var) | ||
|
||
# compute the morphed nll |
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.
# compute the morphed nll | |
# Create the NLL based on the template morphing pdf |
Sorry to be picky here, but to be consistent with the other RooFit tutorials, all the comments need to start with upper case. Also, we should try to be as precise as possible in the comments.
# number of 'sampled' gaussians, if you change it, adjust the binning properly | ||
parampoints = np.arange(5) | ||
|
||
for i in parampoints: |
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.
# number of 'sampled' gaussians, if you change it, adjust the binning properly | |
parampoints = np.arange(5) | |
for i in parampoints: | |
# number of 'sampled' gaussians, if you change it, adjust the binning properly | |
n_grid = 5 | |
for i in range(n_grid): |
No need to use numpy arrays here, especially not of type double
# pdf = workspace[f'histpdf{i}'] | ||
|
||
# add the pdf to the grid | ||
grid.addPdf(workspace[f'histpdf{i}'], int(i)) |
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.
grid.addPdf(workspace[f'histpdf{i}'], int(i)) | |
grid.addPdf(workspace[f'histpdf{i}'], i) |
If you use a simple integer index instead of the NumPy array element (which is a double
), I think you also won't need the conversion.
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.
Thanks for the updates, I think we're very close! Can you please also format the .h
and .cxx
files with the clang-format
style of ROOT? Thanks!
https://github.com/root-project/root/blob/master/.clang-format
- added new tutorial for simulation based inference with roofit - added RooPyBindFunction to bind python function with arbitrary number of parameters - added Realease notes about previous changes
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.
Thanks a lot for this new tutorial and following up on all the change requests.
Congrats to your first contribution!