Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6197473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:49:38+00:00 2026-05-24T03:49:38+00:00

I’m working on implementing a histogram, and one of the key points is the

  • 0

I’m working on implementing a histogram, and one of the key points is the quick merging of histogram bins. Because I don’t have a priori knowledge of the data set being approximated by the histogram, I need to come up with a way that quickly merges neighboring bins, after I’ve exceeded the maximum number of bins.

So, as an example, if you’re approximating a data stream 23, 19, 10, 16, 36, 2, 9, 32, 30, 45 with five histogram bins, you’d read in the first five elements, obtaining:

(23, 1), (19,1), (10,1), (16,1), (36,1)

Adding the bin (2,1) causes an issue, since we’ve exceeded the maximum number of bins. So, we add (2,1) and merge the two closest bins — (16,1) and (19,1) — to get a new bin (17.5,2) that replaces those two.

Repeating this method for the rest of the histogram gives us the final output:

(2,1), (9.5,2), (19.33,3), (32.67,3), (45,1).

Implementing this without respect for complexity issues is trivial. However, I’m really concerned about optimizing this for large data sets, because my “trivial” implementation ends up taking 15 seconds to run on a stream of 100,000 gaussian distributed values.

My current thought is to use boost::multi_index to keep track of my HistogramBin struct, which is defined as:

struct HistogramBin
{
    double bin;
    unsigned long count;
    bool isNull;

    HistogramBin(double x, bool n = false)
    : bin(x), count(1), isNull(n) {}

    bool operator<(const HistogramBin &other) const
    { return (bin < other.bin); }

    // Merges other with this histogram bin
    // E.g., if you have (2.0,1) and (3.0,2), you'd merge them into (2.67,3)
    void merge(const HistogramBin &other)
    {
        unsigned long old_count = count;
        count += other.count;
        bin = (bin*old_count + other.bin*other.count)/count;
    }

    // Gets the difference between two histogram bins
    const double getDifference(const HistogramBin &other) const
    { return (double)abs(bin - other.bin); }
};

So, the multi_index would use ordered_unique<> to sort on HistogramBin::bin.

Now, this doesn’t resolve the issue of sorting the bins by the differences between neighboring bins. Indexing by HistogramBin::bin gives us an ordered list of HistogramBin objects, but then the next step is to calculate the difference between the current bin and the next one, and then to sort on those values as well.

Is there any way to sort on those values, while maintaining the integrity of the list, and without introducing a new container (such as a multimap of difference/iterator key/value pairs)?

Maintaining this list is my current idea on a near-optimal solution to the complexity problem, because it only needs to be changed when there’s a merge, and a merge only happens when a new value is added.

Any thoughts or insight would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:49:39+00:00Added an answer on May 24, 2026 at 3:49 am

    Posting this as an answer:

    Take a look at the answer to this question: Online k-means clustering. If I understand your problem correctly, that’s pretty much what your looking for, where the initial k guesses are your first k values.

    If you keep your bin centers ordered, you can binary search into the list and the closest value is either the one before or the one after it, with an overall complexity of O(n*log(m)) where m is the number of bins and n is the amount of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.