Return the Fractional rank of the input scalar string or contiguous
array
of rank 1
in ascending order or in the order specified by the input procedure isSorted()
using the Quicksort algorithm such that array(rank)
will be in ascending order (or in the requested order as specified by isSorted()
.
This kind of ranking of values is widely known as fractional (1 2.5 2.5 4
) ranking.
In Fractional ranking, items that compare equal receive the same ranking number, which is the mean of what they would have under ordinal rankings; equivalently, the ranking number of 1 plus the number of items ranked above it plus half the number of items equal to it.
This strategy has the property that the sum of the ranking numbers is the same as under ordinal ranking.
For this reason, it is used in computing Borda counts and ranking statistics (e.g., Spearman Correlation).
Thus if A ranks ahead of B and C (which compare equal) which are both ranked ahead of D, then A gets ranking number 1
(first), B and C each get ranking number 2.5
(average of joint second/third) and D gets ranking number 4
(fourth).
That is, if A < B == C < D
, then the sequence ABCD
has the Fractional ranking 1223
.
Example:
Suppose the data set is 1.0, 1.0, 2.0, 3.0, 3.0, 4.0, 5.0, 5.0, 5.0
.
The ordinal ranks are 1, 2, 3, 4, 5, 6, 7, 8, 9
.
For v = 1.0
, the Fractional rank is the average of the ordinal ranks: (1 + 2) / 2 = 1.5
.
In a similar manner, for v = 5.0
, the Fractional rank is (7 + 8 + 9) / 3 = 8.0
.
Thus the Fractional ranks are: 1.5, 1.5, 3.0, 4.5, 4.5, 6.0, 8.0, 8.0, 8.0
- Parameters
-
[out] | rank | : The output contiguous array of rank 1 of type real of default kind RK containing the ranks of the corresponding elements of array .
The size of rank must match that of array (or its length type parameter if array is a scalar string).
Read rank(i) as the Fractional rank of the i th element of array . |
[in] | array | : The input contiguous array of rank 1 of either
-
type css_pdt (parameterized container of string of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU)) or,
-
type css_type (container of string of default kind SK) or,
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter or,
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or,
-
type
logical of kind any supported by the processor (e.g., LK) or,
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or,
-
type
real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
-
a scalar of type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter,
whose elements rankings will be computed and returned. |
| isSorted | : The external user-specified function that takes two input scalar arguments of the same type and kind as the input array .
It returns a scalar logical of default kind LK that is .true. if the first input scalar argument is sorted with respect to the second input argument according to the user-defined sorting condition within isSorted() , otherwise, it is .false. .
If array is a Fortran string (i.e., a scalar character ), then both input arguments to isSorted() are single character(1,SKG) where SKG is the kind of array .
The following illustrates the generic interface of isSorted() when the rank of the input array is 1 , function isSorted(a,b) result (sorted)
TYPE(KIND) , intent(in) :: a, b
logical(LK) :: sorted
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CK The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
integer, parameter IK The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
where TYPE(KIND) represents the type and kind of the input argument array , which can be one of the following,
character(*, SK) , intent(in) :: a, b
integer(IK) , intent(in) :: a, b
logical(LK) , intent(in) :: a, b
complex(CK) , intent(in) :: a, b
real(RK) , intent(in) :: a, b
type(css_type) , intent(in) :: a, b
type(css_pdt(SK)) , intent(in) :: a, b
This module contains the derived types for generating allocatable containers of scalar,...
This is the css_pdt parameterized type for generating instances of container of scalar of string obje...
This is the css_type type for generating instances of container of scalar of string objects.
where the kinds SK , IK , LK , CK , RK , can refer to any kind type parameter that is supported by the processor.
The following illustrates the generic interface of isSorted() when the input array is a scalar string, function isSorted(a,b) result (sorted)
character(1,SKG), intent(in) :: a, b
logical(LK) :: sorted
end function
where SKG represents the kind of the input string argument array .
This user-defined equivalence check is extremely useful where a user-defined sorting criterion other than simple ascending order is needed, for example, when the case-sensitivity of an input string or array of strings is irrelevant or when sorting of the absolute values matters excluding the signs of the numbers, or when descending order is desired. In such cases, user can define a custom sorting condition within the user-defined external function isSorted to achieve the goal.
(optional, the default sorting condition is ascending order, that is a < b .) |
Possible calling interfaces ⛓
Return the Fractional rank of the input scalar string or contiguous array of rank 1 in ascending orde...
This module contains procedures and generic interfaces for obtaining various rankings of elements of ...
- Warning
- Note that the definition of
isSorted()
, if present, must be such that isSorted() .and. .not. isSorted()
is equivalent to an equality check for two elements of the input array
. This equality check is used to identify ties within the Fractional ranking of the input array
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
-
The procedures under this generic interface are always
impure
when the input argument isSorted
is present.
- See also
- setSelected
getRankDense
setRankDense
getRankOrdinal
setRankOrdinal
getRankFractional
setRankFractional
getRankStandard
setRankStandard
getRankModified
setRankModified
setSorted
setSorted
Example usage ⛓
12 integer(IK) ,
parameter :: NP
= 5_IK
17 real(RK) ,
allocatable ::
rank(:)
19 character(:, SK) ,
allocatable :: string_SK
20 character(
9, SK) ,
allocatable :: vector_SK(:)
21 real(RK) :: vector_RK(NP)
22 integer(IK) :: vector_IK(NP)
23 logical(LK) :: vector_LK(NP)
25 type(display_type) :: disp
38 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
39 call disp%show(
"!Sort string of characters in ascending order.")
40 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
43 string_SK
= SK_
"ParaMonte"
44 call allocateRank(
len(string_SK))
48 call disp%show( string_SK, deliml
= SK_
"""" )
49 call disp%show(
"call setRankFractional(rank, string_SK)")
51 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
56 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
57 call disp%show(
"!Sort array of strings of the same length in ascending order.")
58 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 vector_SK
= [
"ParaMonte" &
75 call allocateRank(
size(vector_SK))
78 call disp%show( vector_SK, deliml
= SK_
"""" )
79 call disp%show(
"call setRankFractional(rank, vector_SK)")
81 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
86 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
87 call disp%show(
"!Sort vector of integers of arbitrary kinds in ascending order.")
88 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
91 call allocateRank(
size(vector_IK))
95 call disp%show(
"call setRankFractional(rank, vector_IK)")
97 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
101 call allocateRank(
size(vector_IK))
103 call disp%show(
"vector_IK = [1_IK, 2_IK, 3_IK, 2_IK, 1_IK]")
104 vector_IK
= [
1_IK,
2_IK,
3_IK,
2_IK,
1_IK]
105 call disp%show(
"call setRankFractional(rank, vector_IK)")
107 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
112 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
113 call disp%show(
"!Sort vector of logicals of arbitrary kinds in ascending order.")
114 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
117 call allocateRank(
size(vector_LK))
121 call disp%show(
"call setRankFractional(rank, vector_LK)")
123 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
128 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
129 call disp%show(
"!Sort arrays of reals of arbitrary kinds in ascending order.")
130 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
133 call allocateRank(
size(vector_RK))
137 call disp%show(
"call setRankFractional(rank, vector_RK)")
139 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
144 real,
allocatable :: vector_RK(:)
145 vector_RK
= [
1.0,
1.0,
2.0,
3.0,
3.0,
4.0,
5.0,
5.0,
5.0]
146 call allocateRank(
size(vector_RK))
150 call disp%show(
"call setRankFractional(rank, vector_RK)")
152 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
158 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
159 call disp%show(
"!Sort according to an input user-defined comparison function.")
160 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
163 vector_IK
= int([(i, i
= 1_IK, NP)],
kind = IK)
164 call allocateRank(
size(vector_IK))
166 call disp%show(
"!Sort in DESCENDING (decreasing) order via an input custom-designed `isSorted()` function.")
170 call disp%show(
"call setRankFractional(rank, vector_IK, isSorted_IK)")
172 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
176 call random_number(vector_RK); vector_RK
= vector_RK
- 0.5_RK
177 call allocateRank(
size(vector_RK))
179 call disp%show(
"!Sort in ascending order solely based on the magnitude of numbers using a custom comparison function.")
183 call disp%show(
"call setRankFractional(rank, vector_RK, isSorted_RK)")
185 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
189 string_SK
= "ParaMonte"
190 call allocateRank(
len(string_SK))
192 call disp%show(
"!Sort string in ascending order without case-sensitivity via a custom-designed input comparison function.")
195 call disp%show( string_SK, deliml
= SK_
"""" )
196 call disp%show(
"call setRankFractional(rank, string_SK, isSorted_SK)")
198 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
204 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
205 call disp%show(
"!Sort array of strings of varying length in ascending order.")
206 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
211 type(css_pdt) ,
allocatable :: cssvec(:)
212 cssvec
= [
css_pdt(
"ParaMonte")
&
225 call allocateRank(
size(cssvec))
228 call disp%show( cssvec, deliml
= SK_
"""" )
229 call disp%show(
"call setRankFractional(rank, cssvec)")
231 call disp%show(
"getTrimmedTZ(getStr(rank, format = SK_'(*(g0,:,', '))'))")
239 function isSorted_IK(a,b)
result(isSorted)
241 integer(IK) ,
intent(in) :: a, b
242 logical(LK) :: isSorted
246 function isSorted_RK(a,b)
result(isSorted)
248 integer(IK) ,
intent(in) :: a, b
249 logical(LK) :: isSorted
250 isSorted
= abs(a)
< abs(b)
253 function isSorted_SK(a,b)
result(isSorted)
256 character(
1, SK),
intent(in) :: a, b
257 logical(LK) :: isSorted
261 subroutine allocateRank(size)
262 integer,
intent(in) :: size
263 if (
allocated(rank))
deallocate(rank)
Return a uniform random scalar or contiguous array of arbitrary rank of randomly uniformly distribute...
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
Generate and return the input string where the uppercase English alphabets are all converted to lower...
Generate and return a vector of single-characters each element of which corresponds to one character ...
Generate and return the conversion of the input value to an output Fortran string,...
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module contains the uncommon and hardly representable ASCII characters as well as procedures for...
This module contains classes and procedures for various string manipulations and inquiries.
This module contains the generic procedures for converting values of different types and kinds to For...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
112.,
3.5,
8.,
3.5,
1.,
7.,
6.,
9.,
5.
20"ParaMonte",
"V.2 ",
"is ",
"a ",
"Parallel ",
"Monte ",
"Carlo ",
"and ",
"a ",
"Machine ",
"Learning ",
"Library. "
236.,
8.,
12.,
9.5,
7.,
5.,
1.,
11.,
9.5,
4.,
2.,
3.
32+15,
+16,
+16,
+32,
+12
38vector_IK
= [
1_IK,
2_IK,
3_IK,
2_IK,
1_IK]
62-0.29834354589707723,
-0.79853087939261158E-1,
-0.35224369697215019,
+0.82491316678079407E-2,
+0.23005654895536276
69+1.00000000,
+1.00000000,
+2.00000000,
+3.00000000,
+3.00000000,
+4.00000000,
+5.00000000,
+5.00000000,
+5.00000000
721.5,
1.5,
3.,
4.5,
4.5,
6.,
8.,
8.,
8.
92-0.43697712267201105,
+0.18200587850142702,
-0.31451287924391569,
+0.43912847299116775,
+0.36496733600245612
1047.,
1.5,
8.,
1.5,
4.,
6.,
5.,
9.,
3.
- Test:
- test_pm_arrayRank
- Bug:
Status: Unresolved
Source: Intel Classic Fortran Compiler ifort
version 2021.5
Description: See pm_arraySplit for the description of a relevant bug in PDT name aliasing when compiled with Intel ifort 2021.5 that also applies to this module.
Remedy (as of ParaMonte Library version 2.0.0): See pm_arraySplit for the remedy.
- Todo:
- Low Priority: The current bypass for the PDT name aliasing bug can be reverted back to PDT name aliasing once the ifort bug is resolved.
- Todo:
- Low Priority: A test should be implemented for arrays of size that can be represented only by an IKD integer.
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
-
If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
-
If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, April 21, 2017, 1:54 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 3751 of file pm_arrayRank.F90.