Add ExtendedMixtureModel for yield-weighted fits - #51
Conversation
bd287a0 to
7134257
Compare
|
can component be template (i.e. histograms)? |
sure thing |
|
@Moelf could you please install I'd ask gemini to review before asking you |
|
Here are some issues:
EDIT: resolved |
Move marginalize and multivariate support helpers out of this branch so they can land in a follow-up PR after ExtendedMixtureModel merges. Co-authored-by: Cursor <cursoragent@cursor.com>
This comment was marked as outdated.
This comment was marked as outdated.
Provide component-wise bounds for nested product and mixture models, with tests matching the support/min/max consistency used elsewhere in the package. Co-authored-by: Cursor <cursoragent@cursor.com>
The inner constructor already enforces length and non-emptiness invariants. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep minimum, maximum, and support only for ExtendedMixtureModel, which this package owns. Drop tests that asserted pirated behavior on foreign types. Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the redundant _union_support helper. Co-authored-by: Cursor <cursoragent@cursor.com>
Use a single elementwise reduce over component bounds instead of separate univariate and multivariate helper functions. Co-authored-by: Cursor <cursoragent@cursor.com>
Deduplicate support checks and drop redundant pipe and gaussian cases. Co-authored-by: Cursor <cursoragent@cursor.com>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
where The model I want to bring in in this PR is not a distribution, but a measure. Still it uses the same dispatch pattern as Is there a better place for this? |
MeasureBase.jl supports things like out of the box. I'm currently in the middle of finally getting the MeasureBase Distributions extension done, to make this work with any |
Summary
This PR adds
ExtendedMixtureModel, a small distribution helper for extended likelihood fits where component weights are expected event yields rather than normalized mixture fractions.The motivating use case came from the 2D fit work in BuildConstructors.jl. There, the fitted parameters are
y_phiphi,y_mixed, andy_kkkk, and the model density iswith extended negative log-likelihood
Distributions.MixtureModelis not a direct fit for this because its weights are probabilities and are normalized to fractions. Extended fits need to preserve the absolute yield scale during density evaluation.Closes #50.
Calling the model
ExtendedMixtureModelfollows much of theDistributions.jlvocabulary (components,ncomponents,support,minimum,maximum,length, …), but it is not a drop-in replacement for a normalizedMixtureModelat the density API.There is no
pdf(model, x)orlogpdf(model, x). The extended density is evaluated by calling the model directly:For multivariate components, pass a coordinate vector:
To use the usual
pdf/logpdfinterface, convert to a normalized mixture first:For fitting,
extended_negative_log_likelihood(model, data)applies the standard extended NLL usingmodel(x)internally:Implemented Interface
ExtendedMixtureModel(components, yields): construct a distribution from components and yields.model(x): evaluate the yield-weighted extended density (univariatex::Realor multivariatex::AbstractVector).yields/total_yield: expose the expected event counts and their sum.extended_negative_log_likelihood: extended NLL built frommodel(x).support,minimum,maximum: component-wise bounds for nested product and mixture models.ncomponents,components,component,component_type: match the component-introspection vocabulary used byDistributions.MixtureModel.MixtureModel(model): convert to the corresponding normalized mixture whenpdf/logpdfare needed.length(model): multivariate dimension query.Interface Justification
The minimal functionality needed by the motivating fit is construction,
model(x), andtotal_yield: those are enough to write the extended likelihood. We deliberately omitpdf/logpdfonExtendedMixtureModelitself so the yield-weighted density is not silently treated as a normalized probability density.extended_negative_log_likelihoodis included because every user of this helper otherwise has to repeat the same formula and data iteration. It keeps the sign convention and the Poisson extended term next to the distribution type, while still remaining small and transparent.support,minimum, andmaximumare included because multivariate fit models are built from nested products and mixtures. These methods return the per-dimension union of component bounds and are tested for consistency with the rest of the package.The component accessors are not needed for the likelihood formula itself, but they are the standard
Distributions.jlmixture vocabulary. Keeping them makes this type inspectable in the same way asMixtureModeland avoids forcing users to reach into fields.MixtureModel(model)is also not required for fitting, but it is useful and unambiguous: divide yields bytotal_yield(model)to get the ordinary normalized mixture. This gives users an explicit bridge for diagnostics, sampling, or APIs that require a normalizedMixtureModel.The implementation intentionally does not subtype
AbstractMixtureModeland does not defineprobs. InDistributions.jl,probsmeans normalized prior probabilities. Exposing yields through that interface would be misleading, while normalizing them implicitly would lose the central feature of this model.Follow-up: coordinate marginalization
One-dimensional projections via
marginalize(model, k)are tracked in #53 (merge after this PR lands).Tests
julia --project=. -e 'using Pkg; Pkg.test()'