@@ -2870,18 +2870,18 @@ def nan_to_num(x, nan=0.0, posinf=None, neginf=None):
2870
2870
return x
2871
2871
2872
2872
2873
- def percentile (input , q , axis = None ):
2873
+ def quantile (input , q , axis = None ):
2874
2874
"""
2875
- Computes the percentile along the given axis(es) of a tensor `input` using linear interpolation.
2875
+ Computes the quantile along the given axis(es) of a tensor `input` using linear interpolation.
2876
2876
2877
2877
Parameters
2878
2878
----------
2879
2879
input: TensorVariable
2880
2880
The input tensor.
2881
2881
q: float or list of floats
2882
- Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
2882
+ Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
2883
2883
axis: None or int or list of int, optional
2884
- Axis or axes along which the percentiles are computed. The default is to compute the percentile (s) along a flattened version of the array.
2884
+ Axis or axes along which the quantiles are computed. The default is to compute the quantile (s) along a flattened version of the array.
2885
2885
"""
2886
2886
x = as_tensor_variable (input )
2887
2887
x_ndim = x .type .ndim
@@ -2911,13 +2911,13 @@ def percentile(input, q, axis=None):
2911
2911
if isinstance (q , (int | float )):
2912
2912
q = [q ]
2913
2913
2914
- for percentile in q :
2915
- if percentile < 0 or percentile > 100 :
2916
- raise ValueError ("Percentiles must be in the range [0, 100 ]" )
2914
+ for quantile in q :
2915
+ if quantile < 0 or quantile > 1 :
2916
+ raise ValueError ("Quantiles must be in the range [0, 1 ]" )
2917
2917
2918
2918
result = []
2919
- for percentile in q :
2920
- k = (percentile / 100.0 ) * (input_shape - 1 )
2919
+ for quantile in q :
2920
+ k = (quantile ) * (input_shape - 1 )
2921
2921
k_floor = floor (k ).astype ("int64" )
2922
2922
k_ceil = ceil (k ).astype ("int64" )
2923
2923
@@ -2927,42 +2927,42 @@ def percentile(input, q, axis=None):
2927
2927
val2 = sorted_input [tuple (slices2 )]
2928
2928
2929
2929
d = k - k_floor
2930
- percentile_val = val1 + d * (val2 - val1 )
2930
+ quantile_val = val1 + d * (val2 - val1 )
2931
2931
2932
- result .append (percentile_val .squeeze (axis = - 1 ))
2932
+ result .append (quantile_val .squeeze (axis = - 1 ))
2933
2933
2934
2934
if len (result ) == 1 :
2935
2935
result = result [0 ]
2936
2936
else :
2937
2937
result = stack (result )
2938
2938
2939
- result .name = "percentile "
2939
+ result .name = "quantile "
2940
2940
return result
2941
2941
2942
2942
2943
- def quantile (input , q , axis = None ):
2943
+ def percentile (input , q , axis = None ):
2944
2944
"""
2945
- Computes the quantile along the given axis(es) of a tensor `input` using linear interpolation.
2945
+ Computes the percentile along the given axis(es) of a tensor `input` using linear interpolation.
2946
2946
2947
2947
Parameters
2948
2948
----------
2949
2949
input: TensorVariable
2950
2950
The input tensor.
2951
2951
q: float or list of floats
2952
- Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
2952
+ Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
2953
2953
axis: None or int or list of int, optional
2954
- Axis or axes along which the quantiles are computed. The default is to compute the quantile (s) along a flattened version of the array.
2954
+ Axis or axes along which the percentiles are computed. The default is to compute the percentile (s) along a flattened version of the array.
2955
2955
"""
2956
2956
if isinstance (q , (int | float )):
2957
2957
q = [q ]
2958
2958
2959
- for quantile in q :
2960
- if quantile < 0 or quantile > 1 :
2961
- raise ValueError ("Quantiles must be in the range [0, 1 ]" )
2959
+ for percentile in q :
2960
+ if percentile < 0 or percentile > 100 :
2961
+ raise ValueError ("Percentiles must be in the range [0, 100 ]" )
2962
2962
2963
- percentiles = [100.0 * x for x in q ]
2963
+ quantiles = [x / 100 for x in q ]
2964
2964
2965
- return percentile (input , percentiles , axis )
2965
+ return quantile (input , quantiles , axis )
2966
2966
2967
2967
2968
2968
# NumPy logical aliases
0 commit comments