Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mode to Binomial #635

Merged
merged 5 commits into from
Feb 12, 2025
Merged

Add mode to Binomial #635

merged 5 commits into from
Feb 12, 2025

Conversation

rohanbabbar04
Copy link
Collaborator

@rohanbabbar04 rohanbabbar04 commented Jan 23, 2025

Description

  • Binomial

Checklist

  • Code style is correct (follows ruff and black guidelines)

@rohanbabbar04
Copy link
Collaborator Author

rohanbabbar04 commented Jan 23, 2025

Some things to ask here:

  1. In some cases, the binomial distribution is bimodal. Should we focus on the major mode only?
image
  1. For bimodal or multimodal like we discussed is it fine to return a tuple of modes and handle it in optimize max ent.

What do you suggest @aloctavodia ?

@Advaitgaur004
Copy link
Contributor

Advaitgaur004 commented Jan 23, 2025

I am adding a mode to other Python files, and I will make a pull request. is that fine @rohanbabbar04

@rohanbabbar04
Copy link
Collaborator Author

rohanbabbar04 commented Jan 23, 2025

I am adding a mode to other Python files, and I will make a pull request. is that fine @rohanbabbar04

Sure, can you comment on #604 which ones are you working on so that we don't pick the same ones?

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.39%. Comparing base (f25da81) to head (f6a599c).
Report is 99 commits behind head on main.

Files with missing lines Patch % Lines
preliz/distributions/binomial.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #635      +/-   ##
==========================================
- Coverage   82.23%   74.39%   -7.85%     
==========================================
  Files         101      105       +4     
  Lines        8020     8735     +715     
==========================================
- Hits         6595     6498      -97     
- Misses       1425     2237     +812     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Advaitgaur004
Copy link
Contributor

I am adding a mode to other Python files, and I will make a pull request. is that fine @rohanbabbar04

Sure, can you comment on #604 which ones are you working on so that we don't pick the same ones?

Sure, you have already implemented Rice and Binomial, so I will drop this since I have already implemented it in my local setup.

@rohanbabbar04 rohanbabbar04 changed the title Add mode to Distributions Add mode to Distributions and handle multimodal cases Jan 23, 2025
@rohanbabbar04 rohanbabbar04 marked this pull request as draft January 23, 2025 19:33
@rohanbabbar04 rohanbabbar04 changed the title Add mode to Distributions and handle multimodal cases Handle multimodal cases in maxent Jan 23, 2025
@aloctavodia
Copy link
Contributor

Some things to ask here:

  1. In some cases, the binomial distribution is bimodal. Should we focus on the major mode only?
image 2. For bimodal or multimodal like we discussed is it fine to return a tuple of modes and handle it in optimize max ent.

What do you suggest @aloctavodia ?

Not sure, but probably better to return a tuple if more than one mode. And as a first approach allow to fix a single mode in maxent, but handle de case that the mode method could return a tuple

@rohanbabbar04 rohanbabbar04 marked this pull request as ready for review February 8, 2025 09:09
@rohanbabbar04
Copy link
Collaborator Author

Numba vectorize doesn't support Tuple to be returned, is there a possible way to include this

def mode(self):
    y = (self.n + 1) * self.p
    if (np.isin(self.p, [0, 1])) | (np.mod(y, 1) != 0):
        return np.where(self.p == 1, self.n, np.floor(y))
    return y, y - 1

@rohanbabbar04 rohanbabbar04 changed the title Handle multimodal cases in maxent Add mode to Binomial Feb 8, 2025
@aloctavodia
Copy link
Contributor

Not sure what to do. Having to deal with multiple modes is quite annoying and I am not sure it is worth the effort.

@rohanbabbar04
Copy link
Collaborator Author

rohanbabbar04 commented Feb 11, 2025

Hmm...
Should we go with the major mode instead?. We show only one mode

@aloctavodia
Copy link
Contributor

How weird would be two return two modes (if they exists) only if all parameters are scalar. And return only one for vector parameters. We support vector parameters, but we mostly care of scalars

@rohanbabbar04
Copy link
Collaborator Author

rohanbabbar04 commented Feb 12, 2025

I think the latest commit should work for both scalar and vectors(with scalar giving bimodal result in that case)
What do you think @aloctavodia ?

@aloctavodia aloctavodia merged commit 5f7744e into arviz-devs:main Feb 12, 2025
4 checks 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.

4 participants