Dirac Delta & Independent Joint Distribution - #67
Merged
Merged
Conversation
…picking up variance() and skewness() methods
…cally. adapting code and regenerating images in datasets notebook.
Contributor
There was a problem hiding this comment.
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) andIndependentJoint(joint of independent component distributions). - Refactor
student_gradesandload_student_gradesto return/wrap exact distribution objects per student. - Extend
Distributionto 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
tolargument is ignored in the uniform-PDF branch: it usesself.tolrather than the resolvedtolvariable.
else:
return stats.uniform.pdf(x, loc=self.mean-self.tol/2, scale=self.tol)
uadapy/distributions/dirac_delta.py:115
- The
tolargument is ignored in the uniform-CDF branch: it usesself.tolrather than the resolvedtolvariable.
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_ordershould map requested output dims back to the original ordering usingorder, notorder_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 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 |
Collaborator
Author
There was a problem hiding this comment.
wait, univariate is forbidden. we can remove this entirely.
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. | ||
|
|
hageldave
commented
Aug 21, 2026
hageldave
commented
Aug 21, 2026
hageldave
commented
Aug 21, 2026
hageldave
commented
Aug 21, 2026
hageldave
commented
Aug 24, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: David Hägele <haegele.david@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
IndependentJointobject, for example:DiracDeltahas a tolerance parametertolwhich 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 newIndependentJointobjects.