Comments (5)
I think overall option 4 provides the best balance between precision, performance, ease of implementation and platform compatibility.
Unfortunately, this is not safe either:
=============================== warnings summary ===============================
.pybuild/cpython3_3.11_iminuit/build/tests/test_cost.py::test_multinominal_chi2
.pybuild/cpython3_3.11_iminuit/build/tests/test_without_numba.py::test_no_numba[_safe_log-args0]
.pybuild/cpython3_3.11_iminuit/build/tests/test_without_numba.py::test_no_numba[_safe_log-args0]
.pybuild/cpython3_3.11_iminuit/build/tests/test_without_numba.py::test_no_numba[_unbinned_nll-args2]
.pybuild/cpython3_3.11_iminuit/build/tests/test_without_numba.py::test_no_numba[multinominal_chi2-args3]
.pybuild/cpython3_3.11_iminuit/build/tests/test_without_numba.py::test_no_numba[poisson_chi2-args5]
/home/stephan/Projects/debian/iminuit/iminuit/.pybuild/cpython3_3.11_iminuit/build/iminuit/cost.py:119: RuntimeWarning: divide by zero encountered in log
return np.clip(np.log(x), -1e3, None)
from iminuit.
Okay, I can up with another option:
np.log(np.maximum(np.finfo(np.float64).smallest_subnormal, x))
It takes the smallest subnormal of the 64-bit float representation and has with no loss in precision. Drawback is that this returns at least float64 type, no matter if x is float32. I have to check whether this actually works though.
from iminuit.
@stephanlachnit Thank you for this great and deep analysis, this all makes sense to me.
Why do you think that np.log(np.finfo(np.float64).smallest_subnormal + x)
would not work?
Adding is a bit faster, but if your version is better for compatibility, then we should use that.
In [7]: x = np.linspace(0, 20, 1000)
In [8]: %timeit np.log(np.finfo(np.float64).smallest_subnormal + x)
6.51 µs ± 69.2 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [9]: %timeit np.log(np.maximum(np.finfo(np.float64).smallest_subnormal, x))
6.64 µs ± 54.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
from iminuit.
Why do you think that
np.log(np.finfo(np.float64).smallest_subnormal + x)
would not work?Adding is a bit faster, but if your version is better for compatibility, then we should use that.
If x is negative for some reason, the operation is not safe.
from iminuit.
Good point.
from iminuit.
Related Issues (20)
- 2 tests fail HOT 3
- Problems with iminuit on ubuntu version 22.04.2 ? HOT 1
- FitResult may raise ImportError if matplotlib is not installed in Jupyter notebooks
- Fails to build from source on Fedora 38 x86_64 HOT 9
- Support Minuit.fixed[...] = number
- Proof-read iminuit basic manual HOT 1
- Improve Minuit.fmin._repr_html_ and repr
- Cannot redirect output to text file HOT 1
- Suppression of Migrad output HOT 1
- 1 test fails: AssertionError: assert True == ('no convergence' in 'jacobi: iter=0 d=[3.194528] ... HOT 1
- `test_Template_with_model_2D ` fails on aarch64 HOT 10
- Error in iminuit.util.describe HOT 2
- 7 tests fail HOT 1
- Tests fail without ipywidgets HOT 3
- iminuit hangs when trying to visualize step function HOT 1
- Better documentation for errordef HOT 1
- arm64 test failure in test_without_numba HOT 2
- test_minimize.py fails two tests HOT 2
- CostSum support for cost functions accepting a parameter array HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iminuit.