Skip to content

Partial sorting into unsorted groups #495

Open
@Beliavsky

Description

@Beliavsky

Sometimes you don't need the exact ranks of elements in a vector but what quantile each value is in. For quintiles you would return an integer from 1 to 5 corresponding to each element. Such partial ranking ought to be faster than full ranking, especially when the number of groups is small compared to the size of the vector. The interface could be

pure function quantile(x,ngroups) result(igroup)
real, intent(in) :: x(:) ! data to be grouped
integer, intent(in) :: ngroups ! # of groups
integer :: igroup(size(x)) ! returned values will be between 1 and ngroups, inclusive       
end function quantile

There was a Stack Overflow thread Efficient algorithm of partial sorting into N unsorted groups

In finance, researchers commonly group stocks into quintiles or deciles based on some characteristic, such as price/earnings ratio, and then study future performance by quintile. The exact ranks of stocks are not needed for such studies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: algorithmssearching and sorting, merging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions