@@ -2926,18 +2926,18 @@ def nan_to_num(x, nan=0.0, posinf=None, neginf=None):
2926
2926
return x
2927
2927
2928
2928
2929
- def percentile (input , q , axis = None ):
2929
+ def quantile (input , q , axis = None ):
2930
2930
"""
2931
- Computes the percentile along the given axis(es) of a tensor `input` using linear interpolation.
2931
+ Computes the quantile along the given axis(es) of a tensor `input` using linear interpolation.
2932
2932
2933
2933
Parameters
2934
2934
----------
2935
2935
input: TensorVariable
2936
2936
The input tensor.
2937
2937
q: float or list of floats
2938
- Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
2938
+ Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
2939
2939
axis: None or int or list of int, optional
2940
- Axis or axes along which the percentiles are computed. The default is to compute the percentile (s) along a flattened version of the array.
2940
+ Axis or axes along which the quantiles are computed. The default is to compute the quantile (s) along a flattened version of the array.
2941
2941
"""
2942
2942
x = as_tensor_variable (input )
2943
2943
x_ndim = x .type .ndim
@@ -2967,13 +2967,13 @@ def percentile(input, q, axis=None):
2967
2967
if isinstance (q , (int | float )):
2968
2968
q = [q ]
2969
2969
2970
- for percentile in q :
2971
- if percentile < 0 or percentile > 100 :
2972
- raise ValueError ("Percentiles must be in the range [0, 100 ]" )
2970
+ for quantile in q :
2971
+ if quantile < 0 or quantile > 1 :
2972
+ raise ValueError ("Quantiles must be in the range [0, 1 ]" )
2973
2973
2974
2974
result = []
2975
- for percentile in q :
2976
- k = (percentile / 100.0 ) * (input_shape - 1 )
2975
+ for quantile in q :
2976
+ k = (quantile ) * (input_shape - 1 )
2977
2977
k_floor = floor (k ).astype ("int64" )
2978
2978
k_ceil = ceil (k ).astype ("int64" )
2979
2979
@@ -2983,42 +2983,42 @@ def percentile(input, q, axis=None):
2983
2983
val2 = sorted_input [tuple (slices2 )]
2984
2984
2985
2985
d = k - k_floor
2986
- percentile_val = val1 + d * (val2 - val1 )
2986
+ quantile_val = val1 + d * (val2 - val1 )
2987
2987
2988
- result .append (percentile_val .squeeze (axis = - 1 ))
2988
+ result .append (quantile_val .squeeze (axis = - 1 ))
2989
2989
2990
2990
if len (result ) == 1 :
2991
2991
result = result [0 ]
2992
2992
else :
2993
2993
result = stack (result )
2994
2994
2995
- result .name = "percentile "
2995
+ result .name = "quantile "
2996
2996
return result
2997
2997
2998
2998
2999
- def quantile (input , q , axis = None ):
2999
+ def percentile (input , q , axis = None ):
3000
3000
"""
3001
- Computes the quantile along the given axis(es) of a tensor `input` using linear interpolation.
3001
+ Computes the percentile along the given axis(es) of a tensor `input` using linear interpolation.
3002
3002
3003
3003
Parameters
3004
3004
----------
3005
3005
input: TensorVariable
3006
3006
The input tensor.
3007
3007
q: float or list of floats
3008
- Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
3008
+ Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
3009
3009
axis: None or int or list of int, optional
3010
- Axis or axes along which the quantiles are computed. The default is to compute the quantile (s) along a flattened version of the array.
3010
+ Axis or axes along which the percentiles are computed. The default is to compute the percentile (s) along a flattened version of the array.
3011
3011
"""
3012
3012
if isinstance (q , (int | float )):
3013
3013
q = [q ]
3014
3014
3015
- for quantile in q :
3016
- if quantile < 0 or quantile > 1 :
3017
- raise ValueError ("Quantiles must be in the range [0, 1 ]" )
3015
+ for percentile in q :
3016
+ if percentile < 0 or percentile > 100 :
3017
+ raise ValueError ("Percentiles must be in the range [0, 100 ]" )
3018
3018
3019
- percentiles = [100.0 * x for x in q ]
3019
+ quantiles = [x / 100 for x in q ]
3020
3020
3021
- return percentile (input , percentiles , axis )
3021
+ return quantile (input , quantiles , axis )
3022
3022
3023
3023
3024
3024
# NumPy logical aliases
0 commit comments