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

Implement moving histogram algorithm #752

Closed
gavv opened this issue Jul 12, 2024 · 5 comments · Fixed by #760
Closed

Implement moving histogram algorithm #752

gavv opened this issue Jul 12, 2024 · 5 comments · Fixed by #760
Assignees
Labels
algorithms Algorithms and data structures easy hacks The solution is expected to be straightforward even if you are new to the project enhancement help wanted An important and awaited task but we have no human resources for it yet
Milestone

Comments

@gavv
Copy link
Member

gavv commented Jul 12, 2024

Add a class that implements moving histogram.

The idea is simple:

  • a few parameters are given: value range, number of bins to split range into (N), and value window length (K)
  • we allocate N bins, each one corresponds to sub-range of value range
  • we allocate a ring buffer for last K values
  • each bin holds a counter
  • when a new value is added, we:
    • add it to ring buffer tail
    • remove oldest value from ring buffer head
    • increment counter of the bin corresponding to the added value
    • decrement counter of the bin corresponding to the removed value

The new class can be named MovHistogram. Interface should be similar to core::MovStats class, which implements moving minimum, maximum, and variance.

We need a method to add a value, and to get counter value for every bin.

We also need unit tests, you can find example here.

Please use core::RingQueue for ring buffer and core::Array for bins.

This task is needed for #712.

@gavv gavv added enhancement help wanted An important and awaited task but we have no human resources for it yet easy hacks The solution is expected to be straightforward even if you are new to the project algorithms Algorithms and data structures labels Jul 12, 2024
@spran180
Copy link

Hi, I am interested in solving this issue.

@gavv
Copy link
Member Author

gavv commented Jul 13, 2024

@spran180 Welcome, thanks!

@gavv gavv added this to Roc Toolkit Jul 13, 2024
@gavv gavv moved this to Help wanted in Roc Toolkit Jul 13, 2024
@gavv gavv added this to the next milestone Jul 28, 2024
gavv pushed a commit to spran180/roc-toolkit that referenced this issue Jul 28, 2024
@gavv
Copy link
Member Author

gavv commented Jul 28, 2024

What to cover in unit tests, as discussed in #760:

  • T = float
  • min and max < 0
  • win_length == 1
  • when there are multiple values in every bin (currently every bin is either 0 or 1)
  • how bin counters increment and decrement when rolling window is moved (e.g. you call add_value, some bin changes from N to N-1, and another bin changes from K to K+1)
  • out of bounds values (clamping)

@spran180
Copy link

Hey @gavv,

I'll soon create the pull request including these tests.

@gavv
Copy link
Member Author

gavv commented Aug 1, 2024

Landed

@gavv gavv closed this as completed Aug 1, 2024
@github-project-automation github-project-automation bot moved this from Help wanted to Done in Roc Toolkit Aug 1, 2024
jeshwanthreddy13 pushed a commit to jeshwanthreddy13/roc-toolkit that referenced this issue Aug 6, 2024
jeshwanthreddy13 pushed a commit to jeshwanthreddy13/roc-toolkit that referenced this issue Aug 6, 2024
gavv added a commit to gavv/roc-toolkit that referenced this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
algorithms Algorithms and data structures easy hacks The solution is expected to be straightforward even if you are new to the project enhancement help wanted An important and awaited task but we have no human resources for it yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants