sliding_conditional_percentile¶
- halotools.utils.sliding_conditional_percentile(x, y, window_length, assume_x_is_sorted=False, add_subgrid_noise=True, seed=None)[source]¶
Estimate the cumulative distribution function Prob(< y | x).
- Parameters:
- xndarray
Array of shape (npts, )
- yndarray
Array of shape (npts, )
- window_lengthint
Integer must be odd and less than
npts
- assume_x_is_sortedbool, optional
Performance enhancement flag that can be used for cases where input
x
has already been sorted. Default is False.- add_subgrid_noisebool, optional
Flag determines whether random uniform noise will be added to fill in the gaps at the sub-grid level determined by
window_length
. Default is True.- seedint, optional
Random number seed used together with the
add_subgrid_noise
argument to minimize discreteness effects due to the finite window size over which Prob(< y | x) is estimated. Default is None, for stochastic results.
- Returns:
- rank_order_percentilesndarray
Numpy array of shape (npts, ) storing values in the open interval (0, 1). Larger values of the returned array correspond to values of
y
that are larger-than-average for the corresponding value ofx
.
Notes
The
window_length
argument controls the precision of the calculation, and also the performance. For estimations of Prob(< y | x) with sub-percent accuracy, values ofwindow_length
must exceed 100.See Tutorial on Conditional Abundance Matching demonstrating how to use this function in galaxy-halo modeling with several worked examples.
Examples
>>> x = np.random.rand(100) >>> y = np.random.rand(100) >>> window_length = 5 >>> result = sliding_conditional_percentile(x, y, window_length)