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 6974869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:17:36+00:00 2026-05-27T17:17:36+00:00

I am looking at the k-means++ initialization algorithm. The following two steps of the

  • 0

I am looking at the k-means++ initialization algorithm. The following two steps of the algorithm give rise to non-uniform probabilities:

For each data point x, compute D(x), the distance between x and the
nearest center that has already been chosen.

Choose one new data point at random as a new center, using a weighted
probability distribution where a point x is chosen with probability
proportional to D(x)^2.

How can I select with this stated weighted probability distribution in C++?

  • 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-27T17:17:37+00:00Added an answer on May 27, 2026 at 5:17 pm

    With a finite set of individual data points X, this calls for a discrete probability distribution.

    The easiest way to do this is to enumerate the points X in order, and calculate an array representing their cumulative probability distribution function: (pseudocode follows)

    /* 
     * xset is an array of points X,
     * cdf is a preallocated array of the same size
     */
    function prepare_cdf(X[] xset, float[] cdf)
    {
       float S = 0;
       int N = sizeof(xset);
       for i = 0:N-1
       {
          float weight = /* calculate D(xset[i])^2 here */
          // create cumulative sums and write to the element in cdf array
          S += weight;
          cdf[i] = S;
       }
    
       // now normalize so the CDF runs from 0 to 1
       for i = 0:N-1
       {
          cdf[i] /= S;
       }
    }
    
    function select_point(X[] xset, float[] cdf, Randomizer r)
    {
       // generate a random floating point number from a 
       // uniform distribution from 0 to 1
       float p = r.nextFloatUniformPDF();
       int i = binarySearch(cdf, p);
       // find the lowest index i such that p < cdf[i]
    
       return xset[i];
    }
    

    You call prepare_cdf once, and then call select_point as many times as you need to generate random points.

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

Sidebar

Related Questions

I was just looking through implementation of non local means algorithm via google (thanks
What does it means TableCardinality in execution plan? I am looking at data base
I'm looking for a grammar for analyzing two type of sentences, that means words
I am looking for Python implementation of k-means algorithm with examples to cluster and
I'm looking to unit testing as a means of regression testing on a project.
I'm looking for an example algorithm of smart pagination. By smart, what I mean
Looking for C# class which wraps calls to do the following: read and write
I am looking for means to highlight certain text on a page. I use
I am looking for a means to kill a Windows exe program that, when
I am looking for a means of implementing a Search routine/page that I can

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.