Skip to content

Dirac Delta & Independent Joint Distribution - #67

Merged
hageldave merged 12 commits into
mainfrom
special_distribs
Aug 24, 2026
Merged

hageldave merged 12 commits into
mainfrom
special_distribs

Conversation

@hageldave

Copy link
Copy Markdown
Collaborator

This PR introduces 2 new distribution classes.
DiracDelta - to model fixed values in algorithms/plots that expect distributions as input.
IndependentJoint - a multivariate distribution interface that wraps around a collection of independent other distribution objects acting as a joint distribution.

The motivation for these new classes stems from the student grades dataset, where each student has a set of univariate distributions, one for each subject (m1,m2,p1,p2). The students' joint distributions of all 4 subjects are typically used as multivariate input distributions. However, the possibility to have these distributions accurately wrapped in a Distribution object without estimation via KDE/Normal/GMM has been lacking.
The need for Dirac Delta is due to the fixed grades without uncertainty that students have in some subjects.

Now each student in the dataset is represented by an IndependentJoint object, for example:

def student_tom(tol=0.0):
    m1 = DiracDelta(15.0, tol=tol)
    m2 = stats.trapezoid(*fairly_good())
    p1 = stats.norm(loc=14, scale=5.7)
    p2 = stats.uniform(loc=14, scale=2)

    return IndependentJoint([m1, m2, p1, p2])

DiracDelta has a tolerance parameter tol which can be set to have it mimic a thin uniform distribution. This is to make things like the joint pdf computable (otherwise would be zero everywhere and infinity when hitting the delta peak).

Upon marginalization to retain a single dimension, the corresponding original distribution object is returned from IndependentJoint. Marginals covering several dimensions/distributions are realized with new IndependentJoint objects.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new distribution utilities to better represent deterministic variables and independent multivariate inputs, then refactors the student grades dataset to use these exact distribution objects instead of estimating joints via sampling/KDE.

Changes:

  • Add DiracDelta (fixed value with optional tolerance behaving like a thin uniform) and IndependentJoint (joint of independent component distributions).
  • Refactor student_grades and load_student_grades to return/wrap exact distribution objects per student.
  • Extend Distribution to accept RNG objects as seeds and to support additional variance/skew/kurtosis access patterns.

Reviewed changes

Copilot reviewed 7 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
uadapy/distributions/independent_joint.py New independent joint distribution wrapper with sampling/pdf/cov/mean/marginal utilities.
uadapy/distributions/dirac_delta.py New Dirac Delta-like distribution with optional tolerance.
uadapy/distributions/init.py Export newly added distribution classes.
uadapy/distribution.py Broaden seed/RNG support and add more moment/variance fallbacks.
uadapy/data/student_grades.py Represent each student as an IndependentJoint of per-subject distributions (incl. DiracDelta).
uadapy/data/data.py Update load_student_grades to return distribution objects directly (and accept tol).
tests/test_independentjoint.py Add tests for IndependentJoint mean/cov/pdf/permutation/marginal behavior.
Suppressed comments (3)

uadapy/distributions/dirac_delta.py:95

  • The tol argument is ignored in the uniform-PDF branch: it uses self.tol rather than the resolved tol variable.
        else:
            return stats.uniform.pdf(x, loc=self.mean-self.tol/2, scale=self.tol)

uadapy/distributions/dirac_delta.py:115

  • The tol argument is ignored in the uniform-CDF branch: it uses self.tol rather than the resolved tol variable.
        else:
            return stats.uniform.cdf(x, loc=self.mean-self.tol/2, scale=self.tol)

uadapy/distributions/independent_joint.py:168

  • Same permutation mapping issue in the multi-dimension branch: dims_in_order should map requested output dims back to the original ordering using order, not order_reverse.
        else:
            dims_in_order = order_reverse[dims]
            # find all distributions that contain the requested dimensions

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread uadapy/distributions/dirac_delta.py Outdated
Comment on lines +113 to +116
if dim == 1:
x_ = x_.ravel() # flatten to 1D array for univariate distributions
if len(x_) == 1:
x_ = x_.item() # convert to scalar if univariate and single sample

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, univariate is forbidden. we can remove this entirely.

Comment thread uadapy/distributions/independent_joint.py
Comment thread uadapy/distributions/independent_joint.py Outdated
Comment thread uadapy/distributions/independent_joint.py
Comment thread uadapy/data/student_grades.py
Comment thread tests/test_independentjoint.py
Comment on lines +4 to +10
class DiracDelta:
"""
Dirac Delta distribution class.
To actually be able to work with this distribution, a very small tolerance can be specified and the distribution will
then mimick a tiny uniform distribution.
This class is intended to be used when a variable has no uncertainty but the input needs to be specified in terms of a distribution.

Comment thread uadapy/data/data.py
Comment thread uadapy/distributions/independent_joint.py
Comment thread uadapy/distributions/dirac_delta.py Outdated
Comment thread uadapy/distributions/dirac_delta.py Outdated
Comment thread uadapy/distributions/independent_joint.py
Comment thread uadapy/distributions/independent_joint.py Outdated
Comment thread uadapy/distributions/independent_joint.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: David Hägele <haegele.david@gmail.com>
@hageldave
hageldave merged commit a2292f2 into main Aug 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants