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

I 1410 negbinom log priors #1415

Closed
wants to merge 8 commits into from

Conversation

I-Bouros
Copy link
Contributor

Closes #1410

@codecov
Copy link

codecov bot commented Nov 16, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (931d02b) 100.00% compared to head (cd95c71) 100.00%.
Report is 92 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1415    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           97        97            
  Lines         9532      9635   +103     
==========================================
+ Hits          9532      9635   +103     
Files Coverage Δ
pints/__init__.py 100.00% <ø> (ø)
pints/_log_priors.py 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

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

@MichaelClerx
Copy link
Member

MichaelClerx commented Nov 9, 2022

Is this one ready for review @I-Bouros ? Looks like it's just missing 4 tests: https://github.com/pints-team/pints/pull/1415/files

@I-Bouros
Copy link
Contributor Author

I-Bouros commented Nov 9, 2022

I honestly completely forgot about this! I will get to it as soon as I can!

@I-Bouros
Copy link
Contributor Author

I-Bouros commented Nov 9, 2022

@MichaelClerx , I included the tests, however, there was a merge conflict with the master branch and somehow I made this worse. What should I do? It seems to be the same problem as in #1473

@MichaelClerx
Copy link
Member

I think you did the merge well! The tests now failing is an unrelated issue :D

@martinjrobins @ben18785 PINTS currently won't pass tests on Python 3.11, which has become the default on github actions, due to a pystan and a nuts incompatibility (which will take a while to fix). Should we disable 3.11 testing for the time being?

@I-Bouros
Copy link
Contributor Author

I-Bouros commented Nov 9, 2022

I think you did the merge well! The tests now failing is an unrelated issue :D

@martinjrobins @ben18785 PINTS currently won't pass tests on Python 3.11, which has become the default on github actions, due to a pystan and a nuts incompatibility (which will take a while to fix). Should we disable 3.11 testing for the time being?

So I don't need to do anything myself?

@MichaelClerx
Copy link
Member

@I-Bouros I can make a PR that stops testing on 3.11 and you can review it?
Once that's in, you merge with main again and then this would be ready for review

@I-Bouros
Copy link
Contributor Author

I-Bouros commented Nov 9, 2022

@I-Bouros I can make a PR that stops testing on 3.11 and you can review it?
Once that's in, you merge with main again and then this would be ready for review

Sounds good!

@@ -36,9 +36,11 @@ def _load_version_int():
except Exception as e: # pragma: no cover
raise RuntimeError('Unable to read version number (' + str(e) + ').')


Copy link
Member

Choose a reason for hiding this comment

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

Did these changes get introduced when merging? Might be a good idea to remove them all again!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, I didn't use modify .init with anything like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason I cannot pull the master into my own repo? Does that happen to you too?

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, no! Do you have the right permissions to work on a branch in the PINTS repo directly? That might be easier

Copy link
Member

Choose a reason for hiding this comment

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

I've sent you an invitation!

Copy link
Member

Choose a reason for hiding this comment

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

Having said that, now that we've started this PR Maybe keep it on a fork :D
I think you might need to do something like:

  • switch to your local version of master git checkout master
  • make sure you have the pints-team/pints repo as a "remote". Check with git remote -v and if there's no sign of it you can add a remote with something like git remote add pints https://github.com/pints-team/pints.git (change "pints" to some name you like)
  • pull in master from the remote git pull pints master

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@MichaelClerx MichaelClerx left a comment

Choose a reason for hiding this comment

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

Can't vouch for the maths (which seems to mostly be in scipy anyway), but the code looks good! Left a few small comments

pints/_log_priors.py Show resolved Hide resolved
pints/_log_priors.py Show resolved Hide resolved
pints/_log_priors.py Show resolved Hide resolved
self._log_opo_prob = np.log(1 - self._prob)

def __call__(self, x):
if x[0] < 0.0 or x[0] > self._trials or not float(x[0]).is_integer():
Copy link
Member

Choose a reason for hiding this comment

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

  • You can use 0 instead of 0.0. Python doesn't mind if you mix floats and integers.
  • Does one of the parameters really need to be an integer? And are you sure you want to gloss over errors here by returning -inf instead of raising a TypeError (when it's not an int) or ValueError (when it has an invalid value i.e. > self._trials)

Copy link
Member

Choose a reason for hiding this comment

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

Also, does scipy do any of this checking too? Because then you don't have to do it here

def __call__(self, x):
if x[0] < 0.0 or x[0] > self._trials or not float(x[0]).is_integer():
return -np.inf
else:
Copy link
Member

Choose a reason for hiding this comment

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

Nothing wrong with this, but you can make it slightly more readable without the else ? Up to you! Personal style :D

""" See :meth:`LogPrior.mean()`. """
return self._trials * self._prob

def n_parameters(self):
Copy link
Member

Choose a reason for hiding this comment

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

Should this be 1? I don't see any use of x other than x[0]

@@ -977,6 +1066,92 @@ def sample(self, n=1):
self._mean, self._cov, size=n)


class NegBinomialLogPrior(pints.LogPrior):
Copy link
Member

Choose a reason for hiding this comment

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

See comments above :D

pints/_log_priors.py Show resolved Hide resolved
pints/_log_priors.py Show resolved Hide resolved
pints/_log_priors.py Show resolved Hide resolved
@I-Bouros I-Bouros closed this Nov 7, 2023
@I-Bouros
Copy link
Contributor Author

I-Bouros commented Nov 7, 2023

None of the current pints methods work with discrete parameters.

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.

Create log-priors for Binomial and Negative binomial distributions
2 participants