Skip to content

Commit

Permalink
Fix multi-peak model to avoid bimodalities
Browse files Browse the repository at this point in the history
Co-authored-by: Jochen Nießer <j.niesser@fz-juelich.de>
  • Loading branch information
michaelosthege and Y0dler committed May 10, 2024
1 parent a5c7d44 commit 4c73517
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions peak_performance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,23 @@ def double_model_mean_prior(time):
"""
pmodel = pm.modelcontext(None)
meanmean = pm.Normal("meanmean", mu=np.min(time) + np.ptp(time) / 2, sigma=np.ptp(time) / 6)
diff = pm.ZeroSumNormal(
"diff",
sigma=1,
diff_unsorted = pm.ZeroSumNormal(
"diff_unsorted",
sigma=2,
# Support arbitrary number of subpeaks
shape=len(pmodel.coords["subpeak"]),
# NOTE: As of PyMC v5.13, the OrderedTransform and ZeroSumTransform are incompatible.
# NOTE: As of PyMC v5.14, the OrderedTransform and ZeroSumTransform are incompatible.
# See https://github.com/pymc-devs/pymc/issues/6975.
# As a workaround we'll call pt.sort a few lines below.
)
mean = pm.Deterministic(
diff = pm.Deterministic("diff", pt.sort(diff_unsorted), dims="subpeak")
mean = pm.Normal(
"mean",
meanmean + pt.sort(diff),
meanmean + diff,
# Introduce a small jitter to the subpeak means to decouple them
# from the strictly asymmetric ZeroSumNormal entries.
# This reduces the chances of unwanted bimodality.
sigma=0.01,
dims=("subpeak",),
)
return mean, diff, meanmean
Expand Down

0 comments on commit 4c73517

Please sign in to comment.