Open schmitse opened 1 year ago
Hey @schmitse , coming back to this: instead of using the (overcomplicated) MultiSpace in zfit, the newest developments rather try to get rid of it, but instead, a "TruncatedPDF" can be used. I think the above case could be best solved.
import zfit
import numpy as np
obs1 = zfit.Space('obs', limits=(0., 0.25))
obs2 = zfit.Space('obs', limits=(0.75, 1.))
obs = obs1 + obs2
obsall= zfit.Space('obs', 0, 1)
gen = np.random.default_rng(seed=1337)
data = gen.exponential(1, size=(1000,))
data_zfit = zfit.Data.from_numpy(obs=obsall, array=data)
kde = zfit.pdf.KDE1DimExact(data=data_zfit, obs=obsall, name='test')
kdetrunc = kde.to_truncated([obs1, obs2])
# plot
import matplotlib.pyplot as plt
x = np.linspace(0, 1, num=273)
plt.plot(x, kdetrunc.pdf(x), label='trunc')
plt.plot(x, kde.pdf(x), "--", label='kde',)
plt.legend()
plt.show()
what do you think?
(yes, the normalization changes, but this should not matter for pdf
, as we don't care about the absolute norm, for extended, this will by default be adjusted accordingly)
Creating a kernel density estimation from a dataset using a
MultiSpace
is currently not working.Current Behaviour
When creating a KDE from over a
MultiSpace
the constructor throws an error due toMultiSpace
s not having thelimits
attribute, which is required for the padding of the data:. I attached a minimal (not) working example of the issue:
When running this you get the following error:
Context (Environment)
Possible Solution/Implementation
KDEs over
MultiSpaces
should either raise aNotImplementedError
or the padding of the input dataset should be reflected around the edges of the subspaces of theMultiSpace
.A quick fix to make the KDEs work again would be to pass the observable space limits only if the
Space
has thelimits
attribute: