Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial sorting into unsorted groups #495

Open
Beliavsky opened this issue Aug 21, 2021 · 1 comment
Open

Partial sorting into unsorted groups #495

Beliavsky opened this issue Aug 21, 2021 · 1 comment
Labels
topic: algorithms searching and sorting, merging, ...

Comments

@Beliavsky
Copy link

Beliavsky commented Aug 21, 2021

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.

@milancurcic
Copy link
Member

I often use the histogram function in NumPy and matplotlib, and this seems somewhat related. The difference is that this function would return the index of the bin that each elements belongs in, whereas histogram returns the number of elements in each bin. Though I haven't had use for this myself, it sounds useful.

@awvwgk awvwgk added the topic: algorithms searching and sorting, merging, ... label Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: algorithms searching and sorting, merging, ...
Projects
None yet
Development

No branches or pull requests

3 participants