-
Notifications
You must be signed in to change notification settings - Fork 47
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
Added HPD calculation to ensemble #1431
base: develop
Are you sure you want to change the base?
Conversation
The ensemble from_sample method has now an additional rel_cutoff argument. rel_cutoff allwos to cut the posterior to the alpha % highest density (here non-normalized posterior probability).
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## develop #1431 +/- ##
===========================================
+ Coverage 83.43% 83.45% +0.02%
===========================================
Files 160 160
Lines 13473 13494 +21
===========================================
+ Hits 11241 11262 +21
Misses 2232 2232 ☔ View full report in Codecov by Sentry. |
fixes print statement that was only used for debugging
@shoepfl Thanks very much! @PaulJonasJost any thoughts on how to consolidate the two different cutoff methods? With this PR, using class Cutoff:
...
def __call__(self, xs, fs): # or rather pass a list of vectors and their fvals?
return self.apply_cutoff(xs=xs, fs=fs)
@abstractmethod
def apply_cutoff(self, xs=xs, fs=fs):
... # specific rel/chi2/hpd cutoff method here
class RelCutoff(Cutoff): ...
class Chi2Cutoff(Cutoff): ...
class HpdCutoff(Cutoff): ...
cutoff = Chi2Cutoff(percentile=...)
ensemble = Ensemble.from_sample(result=result, cutoff=cutoff) and inside def from_sample(..., cutoff: Cutoff):
...
x_vectors = cutoff(xs=result.sample_result.trace_x[0, burn_in:, :], fs=result.sample_result.trace_fval[0, burn_in:])
... We could also integrate things like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the addition. I think a test should be added as well, if you want we can help with that.
pass | ||
else: | ||
x_vectors = calculate_hpd(result=result, burn_in=burn_in, ci_level=rel_cutoff) | ||
|
||
if chain_slice is not None: | ||
x_vectors = x_vectors[chain_slice] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general remark, but it is not quite clear whether this is the desired order, it might be that we want to first slice and then calculate hpd. But that is only a minor thing here i guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, I would rather calculate the HPD first and then take a slice, as the HPD should become more precise that way; computationally, it's not an issue. But if there are other reasons to change the order, that would also be fine with me.
I think as it is currently used |
Adds default value for burn_in Co-authored-by: Paul Jonas Jost <[email protected]>
Fixes wrong default value for the ci_level Co-authored-by: Paul Jonas Jost <[email protected]>
@PaulJonasJost, a test sounds good. Indeed, it would be nice if you could assist here, as there may already be similar test cases in the toolbox that we could add to. |
I will look into it and write a test if you are fine with me editing the branch 👍🏼 |
yes of course, and if I can help you can just assign me some tasks |
added the test and renamed. Now i guess someone else has to review (@dilpath)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good 👍
Independently of a re-write into classes like HpdCutoff
as discussed above, I think it would already be valuable to change calculate_hpd
to instead take parameter vectors, and their objective function values (i.e., objects like result.sample_result.trace_x[0]
and result.sample_result.trace_fval
instead of result
). Currently, calculate_hpd
handles burn-in and is only applicable to result.sample_result
objects, which seems suboptimal, since the logic should apply to any collection of vectors and their functional values.
Anyway, fine to merge as-is, since these Ensemble.from_...
methods need some work anyway.
pypesto/ensemble/ensemble.py
Outdated
else: | ||
burn_in = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually just write burn_in = 0
above the if
statement.
pypesto/ensemble/ensemble.py
Outdated
# added cutoff | ||
if f_quantile is None: | ||
pass | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# added cutoff | |
if f_quantile is None: | |
pass | |
else: | |
# added cutoff | |
if f_quantile is not None: |
The ensemble from_sample method now has an additional rel_cutoff argument. rel_cutoff allows the posterior to be cut to the alpha % highest density (here, non-normalized posterior probability).
I checked the code with my workflow, and it worked. Anyway, I would be happy to receive suggestions for improvement.
Adresses #1117