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

codedix-cytoscape-k-means

v1.0.0

Published

The k-means algorithm for Cytoscape.js

Downloads

3

Readme

cytoscape-k-means and cytoscape-k-medoids

Screenshot of clusters returned from K-Means algorithm

k-means and k-medoids algorithms for Cytoscape.js.

Zoe Xi, for Google Summer of Code.

Join the chat at https://gitter.im/cytoscape/cytoscape.js-k-means

Dependencies

  • Cytoscape.js >= 2.6.12

Usage instructions

Download the library:

  • via npm: npm install cytoscape-k-means,
  • via bower: bower install cytoscape-k-means, or
  • via direct download in the repository (probably from a tag).

require() the library as appropriate for your project:

CommonJS:

var cytoscape = require('cytoscape');
var kMeans = require('cytoscape-k-means');

kMeans( cytoscape ); // register extension

AMD:

require(['cytoscape', 'cytoscape-k-means'], function( cytoscape, kMeans ){
  kMeans( cytoscape ); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

API

The k-means and k-medoids algorithms return an array of clusters generated from the data set (nodes of the calling graph instance). Each cluster contains references to the nodes that belong to that cluster.

var options = {
    k: '3',                               // number of clusters to return
    distance: 'euclidean',                // distance classifier
    maxIterations: 12,                    // maximum number of iterations of the k-means algorithm in a single run
    attributes: [                         // attributes/features used to group nodes
        function(node) {
            return node.data('attrA');
        },
        function(node) {
            return node.data('attrB');
        },
        function(node) {
            return node.data('attrC');
        },
        // And so on...
    ]
};

var clusters = cy.elements().kMeans( options ); // Run the k-means algorithm.

clusters[0].myFunc(); // Do something cool with the nodes found in the first cluster.

var clusters = cy.elements().kMedoids({ // Run the k-medoids algorithm.

    /**
     * Note: The same options apply for the k-medoids algorithm.
     *
     * One of the major differences between the k-means and k-medoids algorithms
     * is the manner in which the cluster centers are initialized. In k-means,
     * the cluster centers (centroids) are vectors with elements initialized to
     * random values within each dimension's range. In k-medoids, the cluster
     * centers (medoids) are random nodes from the data set.
     *
     * The other is that the k-means algorithm determines new cluster centers
     * by taking the average of all the nodes within that cluster, whereas
     * k-medoids selects the node with the lowest configuration cost as the new
     * cluster center.
     */
});

Distance metric

The metric used to measure the distance between two nodes. By default it is set to 'euclidean' distance. It can be one of the pre-defined functions: 'euclidean', 'manhattan', 'max', or you may pass in your own function (see the distances object for examples) that returns a float representing the distance between a node and cluster center.

Publishing instructions

This project is set up to automatically be published to npm and bower. To publish:

  1. Set the version number environment variable: export VERSION=1.2.3
  2. Publish: gulp publish
  3. If publishing to bower for the first time, you'll need to run bower register cytoscape-k-means https://github.com/cytoscape/cytoscape.js-k-means.git