question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with extended CrystalBall + other PDF, with `result.hesse()`

See original GitHub issue

Hello,

Bugs

Current Behaviour

I’ve built a PDF in the following fashion

  1. Create a CrystalBall PDF (so-called signal)
  2. Extend it (create_extended)
  3. Create another PDF (so-called background), extend it
  4. Sum up the extended signal and background PDFs

Then, I’ve performed a fit using the Minuit minimizer and the Unbinned nll (nll).

EDIT: the sample that is fitted is weighted. If it isn’t weighted, there is no problem whatsoever!

From the minimisation, I’ve got the variable result = minimizer.minimize(nll). In order to get the errors with Hesse, I’ve run : result.hesse()

and by doing so, I’ve got errors, that I’ve uploaded in this message: assertionerror.txt

Reproduce the error in a notebook

I’ve tried to reproduce the errors in a colab notebook. By doing so, I noticed that:

  • the errors only show up with the Crystal Ball
  • the errors only show up when we add up two extended PDFs, one of the PDFs being a Crystal Ball

The minimalist example with a notebook is available here: https://colab.research.google.com/drive/18UWMr7keOBDt4PjW1uk6r88X62oMvlqT?usp=sharing

EDIT: I’ve used weights of 1 in this notebook

Context (Environment)

  • zfit version: 0.7.0 but I’ve also tried previous versions, 0.6.6 and 0.5.6 (and their associated Tensorflow versions)
  • Python version: 3.7
  • Operating System: Linux
  • Tensorflow version: for zfit=0.7.0, tensorflow=2.5.0

Have a nice day, Anthony

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jonas-eschlecommented, Jun 14, 2021

Good to know, another solution is to use:

with zfit.run.set_autograd_mode(False):
    param_hesse = result.hesse()

This uses the graph mode but does the derivatives numerically. The difference between using weights and not is that with weights, an additional correction factor comes into play. And for that, the gradients are calculated differently (Forward Mode instead of Backward Mode). Seemingly, this fails in compiled mode…

Thanks again for the report!

1reaction
jonas-eschlecommented, Jun 14, 2021

Hi Anthony, many thanks for this clean report and the reproducible example!

This seems to be something nasty, if TensorFlow throws an assertion error, something is somewhere deeply wrong, clearly! I’ll investigate that further.

Meanwhile, what works is to run the relevant piece of code in eager (=Python-like) mode. This can be done with

with zfit.run.set_graph_mode(False):
    param_hesse = result.hesse()

The fact that this runs clearly shows that it is something about the graph in TF and not about derivatives or similar.

Does this work? Btw, if it works, let’s keep it open to track the upstream TF bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug in conditional product pdf with a crystal ball - ROOT Forum
I believed to have unveiled a bug in the generation of pseudo-data when you use a product of a conditional PDF and a...
Read more >
zfit/zfit - Gitter
Hi, I am having the following problem with zfit (using the develop version), hope someone can help. I want to perform an extended...
Read more >
Crystal Ball - Oracle
Learn why Oracle Crystal Ball is the leading spreadsheet-based application for predictive modeling, forecasting, simulation, and optimization.
Read more >
zfit Documentation - Scalable pythonic fitting
We can now combine these two PDFs to create a double Crystal Ball with a single mean and ... An extended PDF can...
Read more >
RooFit Tutorial – Topical Lectures June 2007
Fitting : Binned/Unbinned (extended) MLL fits, Chi2 fits ... RooFit provides a collection of compiled standard PDF classes ... ARGUS,Crystal Ball,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found