You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
circmean() changed behaviour from 0.17 to 0.18 #6420
Commit 6f799a807bde2b4391857 appears to have changed the behaviour of scipy.stats.circmean().
Yet I can't find this documented anywhere.
Is this correct?
by checking the code, looks that there's an additional step to make all values within range [0, 2*pi] missing...
In [13]: import numpy as np
In [14]: from scipy.stats import circmean
In [15]: a=np.linspace(-0.2,0,10)
In [16]: circmean(a)
Out[16]: -0.10000000000000001
clearly this doesn't look like correct behavior. Wonder how it can pass testing...
@pv thanks. this is just my understanding of how circmean works.
samples is assumed to lie in [low, high], and in the first step, _circfuncs_common is used to scale and shift these values to [0, 2*pi]. //well more precisely, modulo operation will be done on samples according to low and high.
compute circular mean of scaled and shifted samples.
transform the computed mean in the "canonical domain" back to [low, high].
Currently, steps 2&3 are combined together incorrectly, since arctan2 produces values within [-pi, pi].
Previously, mask in the code is to make negative values positive. Now, it's used to mask undefined values for arctan2.
Several enhancements I propose to be added:
Clarify what low and high mean in the doc.
add some check to input and boundaries.
the mask is inconsistent for scalar and array values, since it will only work for array values (mask.ndim > 0). So it should be fixed.
clarify how undefined values (those marked nan by the mask in the new version) are handled in the doc.
I'm sorry for introducing this bug!
This evening (CET) I will try to clear up the mess.
I have a question concerning the normalization of values:
What should be the default behaviour in case samples is not in [low, high] range?
In particular, the example from @zym1010 : circmean(np.linspace(-0.2, 0, 10), 2*pi, 0).
Should the values be normalised anyway assuming modulo of 2*pi? In this case ang = 2*pi + np.linspace(-0.2, 0, 10). Or should we expect some other behaviour: nan values, an error, or a warning?
@kleskjr I guess for normalization, you can simply leave it as is, and maybe later on some keyword arguments such as strict can be added to _circfuncs_common to throw out some exception in case samples is not in [low, high].
Also, I think maybe such check is not needed, as [low, high] only specifies how to to modulo on samples, and samples will be automatically processed as modulo, due to use of sin and cos.
Activity
[-]`circmean` changed behaviour from 0.17 to 0.18[/-][+]circmean() changed behaviour from 0.17 to 0.18[/+]zym1010 commentedon Jul 27, 2016
by checking the code, looks that there's an additional step to make all values within range
[0, 2*pi]missing...clearly this doesn't look like correct behavior. Wonder how it can pass testing...
pv commentedon Jul 27, 2016
@larsmans, @kleskjr: ping
pv commentedon Jul 27, 2016
zym1010 commentedon Jul 27, 2016
@pv thanks. this is just my understanding of how
circmeanworks.samplesis assumed to lie in[low, high], and in the first step,_circfuncs_commonis used to scale and shift these values to[0, 2*pi]. //well more precisely, modulo operation will be done onsamplesaccording tolowandhigh.[low, high].Currently, steps 2&3 are combined together incorrectly, since
arctan2produces values within[-pi, pi].Previously,
maskin the code is to make negative values positive. Now, it's used to mask undefined values forarctan2.Several enhancements I propose to be added:
lowandhighmean in the doc.maskis inconsistent for scalar and array values, since it will only work for array values (mask.ndim > 0). So it should be fixed.nanby themaskin the new version) are handled in the doc.kleskjr commentedon Jul 27, 2016
I'm sorry for introducing this bug!
This evening (CET) I will try to clear up the mess.
I have a question concerning the normalization of values:
What should be the default behaviour in case
samplesis not in[low, high]range?In particular, the example from @zym1010 :
circmean(np.linspace(-0.2, 0, 10), 2*pi, 0).Should the values be normalised anyway assuming modulo of
2*pi? In this caseang = 2*pi + np.linspace(-0.2, 0, 10). Or should we expect some other behaviour:nanvalues, an error, or a warning?zym1010 commentedon Jul 27, 2016
@kleskjr I guess for normalization, you can simply leave it as is, and maybe later on some keyword arguments such as
strictcan be added to_circfuncs_commonto throw out some exception in casesamplesis not in[low, high].Also, I think maybe such check is not needed, as
[low, high]only specifies how to to modulo onsamples, andsampleswill be automatically processed as modulo, due to use ofsinandcos.BUG: issue scipy#6420
kleskjr commentedon Jul 28, 2016
Tomorrow I will add some additional test(s) to cover the last misbehaviour.
BUG: issue scipy#6420
BUG: issue scipy#6420
BUG: issue scipy#6420
BUG: issue scipy#6420