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

ckmeans is not O(kn log(n))? #520

Closed
breck7 opened this issue Oct 30, 2020 · 1 comment · Fixed by #521
Closed

ckmeans is not O(kn log(n))? #520

breck7 opened this issue Oct 30, 2020 · 1 comment · Fixed by #521

Comments

@breck7
Copy link

breck7 commented Oct 30, 2020

We are using ckmeans for generating color scales for maps.

ckmeans seems to be giving roughly O(kn^2) performance.

With the code below, I am getting about .25s seconds when N is 10,000 and ~25s when N is 100,000 (so roughly 100x longer instead of 20x).

const ss = require("simple-statistics")
const lodash = require("lodash")
const range = lodash.range
const ckmeans = ss.ckmeans

const rands = (count) => range(0, count).map((i) => Math.floor(1000 * Math.random()))
const kSize = 5
range(1, 6).forEach((power) => {
  const start = Date.now()
  const nSize = Math.pow(10, power)
  const dataset = rands(nSize)
  const result = ckmeans(dataset, kSize)
  const time = Date.now() - start
  console.log([kSize, nSize, time])
})
// Outputs:
[ 5, 10, 2 ]
[ 5, 100, 5 ]
[ 5, 1000, 16 ]
[ 5, 10000, 444 ]
[ 5, 100000, 24337 ]
@breck7
Copy link
Author

breck7 commented Oct 30, 2020

Here's a slightly updated script for generating more data:

const ss = require("simple-statistics")
const lodash = require("lodash")
const range = lodash.range
const ckmeans = ss.ckmeans

const rands = (count) => range(0, count).map((i) => Math.floor(1000 * Math.random()))
const kSize = 5
const runs = []
range(3, 6).forEach((power) => {
  const start = Date.now()
  range(1, 3).forEach((multiple) => {
    const nSize = multiple * Math.pow(10, power)
    ckmeans(rands(nSize), kSize)
    runs.push([kSize, nSize, Date.now() - start])
  })
})

console.log(`kSize,nSize,time`)
console.log(runs.map((run) => run.join(",")).join("\n"))

kSize,nSize,time
5,1000,36
5,2000,53
5,10000,258
5,20000,1236
5,100000,23122
5,200000,113886

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant