Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ml-simple-clustering

mljs3.7kMIT1.0.0TypeScript support: included

Extracts the isolated sub-blocs of matrix

clustering

readme

simple-clustering

Finds the isolated clusters from a similarity/connectivity matrix.

The input could be a matrix (array of arrays) or it could be a single array containing the values of the upper triangular of that matrix.

By default the function returns a clustering matrix: It is a binary row wise matrix, where each row has n components. The ones at row i and column j indicates that element j belong to cluster i.

Installation

$ npm install ml-simple-clustering

Usage

import { simpleClustering } from 'ml-simple-clustering';

const clusters = simpleClustering(dataMatrix, options);

API Documentation

In order to get a general idea of the problem you could also check the Wikipedia article.

Examples

const { simpleClustering } = require('ml-simple-clustering');

let matrix = [
  [1, 2, 0, 0],
  [1, 2, 0, 0],
  [0, 0, 3, 4],
  [0, 0, 5, 6],
];

let clusters = simpleClustering(matrix, {
  threshold: 0,
  out: 'values',
});
console.log(`clusters = ${clusters}`);
/**
 clusters = [
  [
    [1, 2],
    [1, 2],
  ],
  [
    [3, 4],
    [5, 6],
  ],
]
  */

License

MIT

changelog

Changelog

1.0.0 (2025-05-25)

⚠ BREAKING CHANGES

  • migrate to TypeScript and ESM

Bug Fixes

  • bad name of babel config file (f5c1237)
  • return empty array instead of undefined when there is not clusters (5262edd)
  • return undefined when there is not clusters (97a2ba3)

Code Refactoring

  • migrate to TypeScript and ESM (6fc084d)