Open pauladkisson opened 1 year ago
Thanks @pauladkisson
Actually I think that the behavior is fair..the select peaks is used to limit computation time, so in my mind the n_peaks
is a maximum number of peaks..
Otherwise, one might need to change the parameter (sometimes deeply nested in the sorter params), in case of recordings shorter than usual, or with fewer peaks. I think it's good to avoid it.
Maybe changing the naming slightly or specify the behavior in the docs would be better.
@alejoe91 I think that kind of use case is best handled with a try/except block around the select_peaks
function if one anticipates the number of peaks in peaks
to be less than n_peaks
. The main use case of select_peaks
is to actually select a subset of peaks, so if n_peaks
is improperly specified, I think it's appropriate to raise an error (or at the very least a warning).
Yeah I see your point. I would actually vote for a warning, since the goal of this function is to limit the number of peaks to a certain amount and if you have less than you're probably happy with it :)
What @h-mayorquin @samuelgarcia and @yger think?
@alejoe91 I think that kind of use case is best handled with a try/except block around the
select_peaks
function if one anticipates the number of peaks inpeaks
to be less thann_peaks
. The main use case ofselect_peaks
is to actually select a subset of peaks, so ifn_peaks
is improperly specified, I think it's appropriate to raise an error (or at the very least a warning)
Am I understanding well that you are want to use an assertion to inform the user that he has unintendedly chosen a value of n_peaks
that is larger than number of peaks that he has? What are some possible bad consequences of us not informing the user of this?
Fixing for this would block a possible use of the function where I run detect_peaks
but I want just want to assure myself that downstream computations do not run in more than n_peaks=1000
. That is, I want to determine the upper bound of how many peaks should all the other methods handle without knowing in advance how many the first method will get (specially if sometimes select_peaks
is non-deterministic). If the detect_peaks
method produce less than 1000 peaks, then I am fine with the pipeline movin
So I think I agree with @alejoe91 that we should probably change the semantics. Select peaks should have an argument like max_n_peaks
which would be the upper bound of what the sampling returns.
Summarizing the solution we discussed yesterday:
select_peaks
should take two optional arguments to constrain the # of peaks returned/sampled:
max_n_peaks
: ensures that input_peaks
has no more than max_n_peaks
, if it does --> subsample down to max_n_peaks
min_n_peaks
: ensures that input_peaks
has no fewer than min_n_peaks
, if it does --> throw error select_peaks
to something more informative based on its function of constraining the number of peaks to some specified rangeSomething I just thought of while writing this:
min_n_peaks
problem differently, for example:
input_peaks
with replacement (bootstrapping)assert input_peaks.size >= min_n_peaks
in each method separately The opinion of this humble outsider, if I may offer it - if you're changing this argument structure I would additionally vote for a more standardized naming scheme that also matches other usage across the repo
Current suggestion - Standardized suggestion
max_n_peaks
- max_num_peaks
min_n_peaks
- min_num_peaks
which is then more similar to calls such as
get_num_channels
, get_num_units
@h-mayorquin, this is also over a year old at this point. Is this still on the todo list or should we close for inactivity?
I don't know what is the current status of detect_peaks after all this year refactoring. I might have to work on peak detection later this summer so I can take a look and come back to this. If not, and no one wants to work on this then we can close it.
Current Behavior
When
select_peaks(peaks, n_peaks=n_peaks, ...)
receives argumentn_peaks >= peaks.shape[0]
, it returnspeaks
.Expected behavior
When
select_peaks(peaks, n_peaks=n_peaks, ...)
receives argumentn_peaks >= peaks.shape[0]
, it should throw an error stating "Number of selected peaks greater than or equal to number of input peaks" (or something along those lines).Example Code to Reproduce Error