npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

distance-correlation-fast

v1.1.0

Published

Calculates distance correlation in around O(n log(n)) time

Downloads

5

Readme

distance-correlation-fast

Performs distance correlation in around O(n lg(n)) time.

Distance correlation is a very appropriate method for getting the correlation between two sets of numbers when the correlation may or may not be linear.

Please avoid the Pearson or the Spearman rho for these purposes, use this instead.

For more reading about various correlation methods, I recommend https://m-clark.github.io/docs/CorrelationComparison.pdf

Traditionally, a limitation of distance correlation has been that it has only been computable in O(n^2) time.

However, in recent years O(n lg(n)) algorithms have been found.

This library uses the O(n lg(n)) algorithm of Arin Chaudhuri and Wenhao Hu of the SAS institute.

Their paper on this algorithm can be accessed here: https://arxiv.org/pdf/1810.11332.pdf

However I believe this implementation might be slightly slower for various reasons. It is, however, still far faster than O(n^2).

This is a purely TS library, not native.

To use, simply install with yarn add distance-correlation-fast or npm i distance-correlation-fast, then use:

import distanceCorrelation from "distance-correlation-fast";
console.log(distanceCorrelation(x,y)) //0-1

As a result of being O(n lg(n)), this library performs far better than distance-correlation.

Here is a basic benchmark result, though note that it wasn't exactly scientific. The differences are big enough that it is clear though.

There are some slight differences to the result, but that is simply because of floating point math. The operations are normally equivalent.

| iterations | distance-correlation | distance-correlation-fast | distance-correlation-result | distance-correlation-fast-result | |------------|----------------------|---------------------------|-----------------------------|----------------------------------| | 10 | '1 ms' | '1 ms' | 0.382825287690042 | 0.3828252876900454 | | 100 | '6 ms' | '2 ms' | 0.13829996604117056 | 0.13829996604116315 | | 1000 | '50 ms' | '15 ms' | 0.03628753210507448 | 0.036287532105186635 | | 10000 | '1549 ms' | '114 ms' | 0.02095419967874481 | 0.020954199678122964 | | 20000 | '5818 ms' | '175 ms' | 0.016086395312417248 | 0.016086395312258472 | | 30000 | '14288 ms' | '134 ms' | 0.015620504059051582 | 0.015620504059304258 | | 40000 | '25449 ms' | '179 ms' | 0.009919314920790408 | 0.009919314924033206 | | 50000 | '83536 ms' | '205 ms' | 0.014774905864089687 | 0.014774905865482699 | | 100000 | '--' | '508 ms' | -1 | 0.004405316342355193 | | 200000 | '--' | '1072 ms' | -1 | 0.002828554074877791 | | 500000 | '--' | '3038 ms' | -1 | 0.004200976314319337 | | 1000000 | '--' | '6875 ms' | -1 | 0.0014860766319187509 | | 2000000 | '--' | '14726 ms' | -1 | 0.0008937027074066065 | | 3000000 | '--' | '23555 ms' | -1 | 0.0008617030226743158 | | 4000000 | '--' | '32270 ms' | -1 | 0.0007113003632073607 | | 5000000 | '--' | '43564 ms' | -1 | 0.0005252420613586389 |